Update torchlight_changes_unloze/torchlight3/Torchlight/AudioManager.py

This commit is contained in:
Metroid_Skittles 2026-02-07 08:40:15 +01:00
parent 58afbe66af
commit fbd7a5112e

View File

@ -44,6 +44,8 @@ class AudioPlayerFactory():
class AntiSpam():
GLOBAL_PLAY_TIME_IMMUNITY_LEVEL = 10
def __init__(self, master):
self.Logger = logging.getLogger(__class__.__name__)
self.Master = master
@ -52,6 +54,9 @@ class AntiSpam():
self.LastClips = dict()
self.DisabledTime = None
def _counts_toward_global_play_time(self, level):
return level < self.GLOBAL_PLAY_TIME_IMMUNITY_LEVEL
def CheckAntiSpam(self, player):
if self.DisabledTime and self.DisabledTime > self.Torchlight().Master.Loop.time() and \
not (player.Access and player.Access["level"] >= self.Torchlight().Config["AntiSpam"]["ImmunityLevel"]):
@ -91,6 +96,9 @@ class AntiSpam():
self.LastClips.clear()
def OnPlay(self, clip):
if not self._counts_toward_global_play_time(clip.Level):
return
Now = self.Torchlight().Master.Loop.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
def OnStop(self, clip):
if not self._counts_toward_global_play_time(clip.Level):
return
if clip not in self.LastClips:
return
@ -117,6 +128,9 @@ class AntiSpam():
self.LastClips[clip]["dominant"] = False
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 self.Logger.isEnabledFor(logging.DEBUG):
self.Logger.debug(
@ -305,7 +319,11 @@ class AudioManager():
return None
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("Stop", lambda *args: self.AntiSpam.OnStop(Clip, *args))
Clip.AudioPlayer.AddCallback("Update", lambda *args: self.AntiSpam.OnUpdate(Clip, *args))