Update torchlight_changes_unloze/torchlight3/Torchlight/AudioManager.py
This commit is contained in:
parent
58afbe66af
commit
fbd7a5112e
@ -44,6 +44,8 @@ class AudioPlayerFactory():
|
|||||||
|
|
||||||
|
|
||||||
class AntiSpam():
|
class AntiSpam():
|
||||||
|
GLOBAL_PLAY_TIME_IMMUNITY_LEVEL = 10
|
||||||
|
|
||||||
def __init__(self, master):
|
def __init__(self, master):
|
||||||
self.Logger = logging.getLogger(__class__.__name__)
|
self.Logger = logging.getLogger(__class__.__name__)
|
||||||
self.Master = master
|
self.Master = master
|
||||||
@ -52,6 +54,9 @@ class AntiSpam():
|
|||||||
self.LastClips = dict()
|
self.LastClips = dict()
|
||||||
self.DisabledTime = None
|
self.DisabledTime = None
|
||||||
|
|
||||||
|
def _counts_toward_global_play_time(self, level):
|
||||||
|
return level < self.GLOBAL_PLAY_TIME_IMMUNITY_LEVEL
|
||||||
|
|
||||||
def CheckAntiSpam(self, player):
|
def CheckAntiSpam(self, player):
|
||||||
if self.DisabledTime and self.DisabledTime > self.Torchlight().Master.Loop.time() and \
|
if self.DisabledTime and self.DisabledTime > self.Torchlight().Master.Loop.time() and \
|
||||||
not (player.Access and player.Access["level"] >= self.Torchlight().Config["AntiSpam"]["ImmunityLevel"]):
|
not (player.Access and player.Access["level"] >= self.Torchlight().Config["AntiSpam"]["ImmunityLevel"]):
|
||||||
@ -91,6 +96,9 @@ class AntiSpam():
|
|||||||
self.LastClips.clear()
|
self.LastClips.clear()
|
||||||
|
|
||||||
def OnPlay(self, clip):
|
def OnPlay(self, clip):
|
||||||
|
if not self._counts_toward_global_play_time(clip.Level):
|
||||||
|
return
|
||||||
|
|
||||||
Now = self.Torchlight().Master.Loop.time()
|
Now = self.Torchlight().Master.Loop.time()
|
||||||
self.LastClips[clip] = dict({"timestamp": Now, "duration": 0.0, "dominant": False, "active": True, "last_update_realtime": time.time()})
|
self.LastClips[clip] = dict({"timestamp": Now, "duration": 0.0, "dominant": False, "active": True, "last_update_realtime": time.time()})
|
||||||
|
|
||||||
@ -103,6 +111,9 @@ class AntiSpam():
|
|||||||
self.LastClips[clip]["dominant"] = not HasDominant
|
self.LastClips[clip]["dominant"] = not HasDominant
|
||||||
|
|
||||||
def OnStop(self, clip):
|
def OnStop(self, clip):
|
||||||
|
if not self._counts_toward_global_play_time(clip.Level):
|
||||||
|
return
|
||||||
|
|
||||||
if clip not in self.LastClips:
|
if clip not in self.LastClips:
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -117,6 +128,9 @@ class AntiSpam():
|
|||||||
self.LastClips[clip]["dominant"] = False
|
self.LastClips[clip]["dominant"] = False
|
||||||
|
|
||||||
def OnUpdate(self, clip, old_position, new_position):
|
def OnUpdate(self, clip, old_position, new_position):
|
||||||
|
if not self._counts_toward_global_play_time(clip.Level):
|
||||||
|
return
|
||||||
|
|
||||||
if clip not in self.LastClips:
|
if clip not in self.LastClips:
|
||||||
if self.Logger.isEnabledFor(logging.DEBUG):
|
if self.Logger.isEnabledFor(logging.DEBUG):
|
||||||
self.Logger.debug(
|
self.Logger.debug(
|
||||||
@ -305,7 +319,11 @@ class AudioManager():
|
|||||||
return None
|
return None
|
||||||
self.AudioClips.append(Clip)
|
self.AudioClips.append(Clip)
|
||||||
|
|
||||||
if not player.Access or player.Access["level"] < self.Torchlight().Config["AntiSpam"]["ImmunityLevel"]:
|
anti_spam_track_ceiling = min(
|
||||||
|
self.Torchlight().Config["AntiSpam"]["ImmunityLevel"],
|
||||||
|
self.AntiSpam.GLOBAL_PLAY_TIME_IMMUNITY_LEVEL,
|
||||||
|
)
|
||||||
|
if not player.Access or player.Access["level"] < anti_spam_track_ceiling:
|
||||||
Clip.AudioPlayer.AddCallback("Play", lambda *args: self.AntiSpam.OnPlay(Clip, *args))
|
Clip.AudioPlayer.AddCallback("Play", lambda *args: self.AntiSpam.OnPlay(Clip, *args))
|
||||||
Clip.AudioPlayer.AddCallback("Stop", lambda *args: self.AntiSpam.OnStop(Clip, *args))
|
Clip.AudioPlayer.AddCallback("Stop", lambda *args: self.AntiSpam.OnStop(Clip, *args))
|
||||||
Clip.AudioPlayer.AddCallback("Update", lambda *args: self.AntiSpam.OnUpdate(Clip, *args))
|
Clip.AudioPlayer.AddCallback("Update", lambda *args: self.AntiSpam.OnUpdate(Clip, *args))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user