Update torchlight_changes_unloze/torchlight3/Torchlight/AudioManager.py

This commit is contained in:
Metroid_Skittles 2026-02-06 19:39:53 +01:00
parent 3067dc423c
commit 67529b652f

View File

@ -1,352 +1,367 @@
#!/usr/bin/python3 #!/usr/bin/python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import logging import logging
import sys import sys
import io import io
import math import math
from .FFmpegAudioPlayer import FFmpegAudioPlayerFactory from .FFmpegAudioPlayer import FFmpegAudioPlayerFactory
class AudioPlayerFactory(): class AudioPlayerFactory():
AUDIOPLAYER_FFMPEG = 1 AUDIOPLAYER_FFMPEG = 1
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
self.Torchlight = self.Master.Torchlight self.Torchlight = self.Master.Torchlight
self.FFmpegAudioPlayerFactory = FFmpegAudioPlayerFactory(self) self.FFmpegAudioPlayerFactory = FFmpegAudioPlayerFactory(self)
def __del__(self): def __del__(self):
self.Logger.info("~AudioPlayerFactory()") self.Logger.info("~AudioPlayerFactory()")
def NewPlayer(self, _type): def NewPlayer(self, _type):
if _type == self.AUDIOPLAYER_FFMPEG: if _type == self.AUDIOPLAYER_FFMPEG:
return self.FFmpegAudioPlayerFactory.NewPlayer() return self.FFmpegAudioPlayerFactory.NewPlayer()
class AntiSpam(): class AntiSpam():
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
self.Torchlight = self.Master.Torchlight self.Torchlight = self.Master.Torchlight
self.LastClips = dict() self.LastClips = dict()
self.DisabledTime = None self.DisabledTime = None
self.SaidHint = False self.SaidHint = False
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"]):
self.Torchlight().SayPrivate(player, "Torchlight is currently on cooldown! ({0} seconds left)".format( self.Torchlight().SayPrivate(player, "Torchlight is currently on cooldown! ({0} seconds left)".format(
math.ceil(self.DisabledTime - self.Torchlight().Master.Loop.time()))) math.ceil(self.DisabledTime - self.Torchlight().Master.Loop.time())))
return False return False
return True return True
def SpamCheck(self, Delta): def SpamCheck(self, Delta):
Now = self.Torchlight().Master.Loop.time() Now = self.Torchlight().Master.Loop.time()
Duration = 0.0 Duration = 0.0
for Key, Clip in list(self.LastClips.items()): for Key, Clip in list(self.LastClips.items()):
if not Clip["timestamp"]: if not Clip["timestamp"]:
continue continue
if Clip["timestamp"] + Clip["duration"] + self.Torchlight().Config["AntiSpam"]["MaxUsageSpan"] < Now: if Clip["timestamp"] + Clip["duration"] + self.Torchlight().Config["AntiSpam"]["MaxUsageSpan"] < Now:
if not Clip["active"]: if not Clip["active"]:
del self.LastClips[Key] del self.LastClips[Key]
continue continue
Duration += Clip["duration"] Duration += Clip["duration"]
if Duration > self.Torchlight().Config["AntiSpam"]["MaxUsageTime"]: if Duration > self.Torchlight().Config["AntiSpam"]["MaxUsageTime"]:
self.DisabledTime = self.Torchlight().Master.Loop.time() + self.Torchlight().Config["AntiSpam"]["PunishDelay"] self.DisabledTime = self.Torchlight().Master.Loop.time() + self.Torchlight().Config["AntiSpam"]["PunishDelay"]
self.Torchlight().SayChat("Blocked voice commands for the next {0} seconds. Used {1} seconds within {2} seconds.".format( self.Torchlight().SayChat("Blocked voice commands for the next {0} seconds. Used {1} seconds within {2} seconds.".format(
self.Torchlight().Config["AntiSpam"]["PunishDelay"], self.Torchlight().Config["AntiSpam"]["MaxUsageTime"], self.Torchlight().Config["AntiSpam"]["MaxUsageSpan"])) self.Torchlight().Config["AntiSpam"]["PunishDelay"], self.Torchlight().Config["AntiSpam"]["MaxUsageTime"], self.Torchlight().Config["AntiSpam"]["MaxUsageSpan"]))
# Make a copy of the list since AudioClip.Stop() will change the list # Make a copy of the list since AudioClip.Stop() will change the list
for AudioClip in self.Master.AudioClips[:]: for AudioClip in self.Master.AudioClips[:]:
if AudioClip.Level < self.Torchlight().Config["AntiSpam"]["ImmunityLevel"]: if AudioClip.Level < self.Torchlight().Config["AntiSpam"]["ImmunityLevel"]:
AudioClip.Stop() AudioClip.Stop()
self.LastClips.clear() self.LastClips.clear()
def OnPlay(self, clip): def OnPlay(self, clip):
Now = self.Torchlight().Master.Loop.time() Now = self.Torchlight().Master.Loop.time()
self.LastClips[hash(clip)] = dict({"timestamp": Now, "duration": 0.0, "dominant": False, "active": True}) self.LastClips[hash(clip)] = dict({"timestamp": Now, "duration": 0.0, "dominant": False, "active": True})
HasDominant = False HasDominant = False
for Key, Clip in self.LastClips.items(): for Key, Clip in self.LastClips.items():
if Clip["dominant"]: if Clip["dominant"]:
HasDominant = True HasDominant = True
break break
self.LastClips[hash(clip)]["dominant"] = not HasDominant self.LastClips[hash(clip)]["dominant"] = not HasDominant
def OnStop(self, clip): def OnStop(self, clip):
if hash(clip) not in self.LastClips: if hash(clip) not in self.LastClips:
return return
self.LastClips[hash(clip)]["active"] = False self.LastClips[hash(clip)]["active"] = False
if self.LastClips[hash(clip)]["dominant"]: if self.LastClips[hash(clip)]["dominant"]:
for Key, Clip in self.LastClips.items(): for Key, Clip in self.LastClips.items():
if Clip["active"]: if Clip["active"]:
Clip["dominant"] = True Clip["dominant"] = True
break break
self.LastClips[hash(clip)]["dominant"] = False self.LastClips[hash(clip)]["dominant"] = False
def OnUpdate(self, clip, old_position, new_position): def OnUpdate(self, clip, old_position, new_position):
Delta = new_position - old_position Delta = new_position - old_position
Clip = self.LastClips[hash(clip)] clip_key = hash(clip)
if clip_key not in self.LastClips:
if not Clip["dominant"]: if self.Logger.isEnabledFor(logging.DEBUG):
return self.Logger.debug(
"OnUpdate called for unknown clip key %r; %d known keys",
Clip["duration"] += Delta clip_key,
self.SpamCheck(Delta) len(self.LastClips),
)
return
class Advertiser(): Clip = self.LastClips[clip_key]
def __init__(self, master):
self.Logger = logging.getLogger(__class__.__name__) if not Clip["dominant"]:
self.Master = master return
self.Torchlight = self.Master.Torchlight
Clip["duration"] += Delta
self.LastClips = dict() self.SpamCheck(Delta)
self.AdStop = 0
self.NextAdStop = 0
class Advertiser():
def Think(self, Delta): def __init__(self, master):
Now = self.Torchlight().Master.Loop.time() self.Logger = logging.getLogger(__class__.__name__)
Duration = 0.0 self.Master = master
self.Torchlight = self.Master.Torchlight
for Key, Clip in list(self.LastClips.items()):
if not Clip["timestamp"]: self.LastClips = dict()
continue self.AdStop = 0
self.NextAdStop = 0
if Clip["timestamp"] + Clip["duration"] + self.Torchlight().Config["Advertiser"]["MaxSpan"] < Now:
if not Clip["active"]: def Think(self, Delta):
del self.LastClips[Key] Now = self.Torchlight().Master.Loop.time()
continue Duration = 0.0
Duration += Clip["duration"] for Key, Clip in list(self.LastClips.items()):
if not Clip["timestamp"]:
self.NextAdStop -= Delta continue
CeilDur = math.ceil(Duration)
if CeilDur > self.AdStop and self.NextAdStop <= 0 and CeilDur % self.Torchlight().Config["Advertiser"]["AdStop"] == 0: if Clip["timestamp"] + Clip["duration"] + self.Torchlight().Config["Advertiser"]["MaxSpan"] < Now:
self.Torchlight().SayChat("Hint: Type \x07FF0000!stop(ze) !pls(mg)\x01 to stop all currently playing sounds.") if not Clip["active"]:
self.AdStop = CeilDur del self.LastClips[Key]
self.NextAdStop = 0 continue
elif CeilDur < self.AdStop:
self.AdStop = 0 Duration += Clip["duration"]
self.NextAdStop = self.Torchlight().Config["Advertiser"]["AdStop"] / 2
self.NextAdStop -= Delta
def OnPlay(self, clip): CeilDur = math.ceil(Duration)
Now = self.Torchlight().Master.Loop.time() if CeilDur > self.AdStop and self.NextAdStop <= 0 and CeilDur % self.Torchlight().Config["Advertiser"]["AdStop"] == 0:
self.LastClips[hash(clip)] = dict({"timestamp": Now, "duration": 0.0, "dominant": False, "active": True}) self.Torchlight().SayChat("Hint: Type \x07FF0000!stop(ze) !pls(mg)\x01 to stop all currently playing sounds.")
self.AdStop = CeilDur
HasDominant = False self.NextAdStop = 0
for Key, Clip in self.LastClips.items(): elif CeilDur < self.AdStop:
if Clip["dominant"]: self.AdStop = 0
HasDominant = True self.NextAdStop = self.Torchlight().Config["Advertiser"]["AdStop"] / 2
break
def OnPlay(self, clip):
self.LastClips[hash(clip)]["dominant"] = not HasDominant Now = self.Torchlight().Master.Loop.time()
self.LastClips[hash(clip)] = dict({"timestamp": Now, "duration": 0.0, "dominant": False, "active": True})
def OnStop(self, clip):
if hash(clip) not in self.LastClips: HasDominant = False
return for Key, Clip in self.LastClips.items():
if Clip["dominant"]:
self.LastClips[hash(clip)]["active"] = False HasDominant = True
break
if self.LastClips[hash(clip)]["dominant"]:
for Key, Clip in self.LastClips.items(): self.LastClips[hash(clip)]["dominant"] = not HasDominant
if Clip["active"]:
Clip["dominant"] = True def OnStop(self, clip):
break if hash(clip) not in self.LastClips:
return
self.LastClips[hash(clip)]["dominant"] = False
self.LastClips[hash(clip)]["active"] = False
def OnUpdate(self, clip, old_position, new_position):
Delta = new_position - old_position if self.LastClips[hash(clip)]["dominant"]:
Clip = self.LastClips[hash(clip)] for Key, Clip in self.LastClips.items():
if Clip["active"]:
if not Clip["dominant"]: Clip["dominant"] = True
return break
Clip["duration"] += Delta self.LastClips[hash(clip)]["dominant"] = False
self.Think(Delta)
def OnUpdate(self, clip, old_position, new_position):
Delta = new_position - old_position
class AudioManager(): clip_key = hash(clip)
def __init__(self, torchlight): if clip_key not in self.LastClips:
self.Logger = logging.getLogger(__class__.__name__) return
self.Torchlight = torchlight Clip = self.LastClips[clip_key]
self.AntiSpam = AntiSpam(self)
self.Advertiser = Advertiser(self) if not Clip["dominant"]:
self.AudioPlayerFactory = AudioPlayerFactory(self) return
self.AudioClips = []
Clip["duration"] += Delta
def __del__(self): self.Think(Delta)
self.Logger.info("~AudioManager()")
def CheckLimits(self, player): class AudioManager():
Level = 0 def __init__(self, torchlight):
if player.Access: self.Logger = logging.getLogger(__class__.__name__)
Level = player.Access["level"] self.Torchlight = torchlight
self.AntiSpam = AntiSpam(self)
if str(Level) in self.Torchlight().Config["AudioLimits"]: self.Advertiser = Advertiser(self)
if self.Torchlight().Config["AudioLimits"][str(Level)]["Uses"] >= 0 and \ self.AudioPlayerFactory = AudioPlayerFactory(self)
player.Storage["Audio"]["Uses"] >= self.Torchlight().Config["AudioLimits"][str(Level)]["Uses"]: self.AudioClips = []
self.Torchlight().SayPrivate(player, "You have used up all of your free uses! ({0} uses)".format( def __del__(self):
self.Torchlight().Config["AudioLimits"][str(Level)]["Uses"])) self.Logger.info("~AudioManager()")
return False
def CheckLimits(self, player):
if player.Storage["Audio"]["TimeUsed"] >= self.Torchlight().Config["AudioLimits"][str(Level)]["TotalTime"]: Level = 0
self.Torchlight().SayPrivate(player, "You have used up all of your free time! ({0} seconds)".format( if player.Access:
self.Torchlight().Config["AudioLimits"][str(Level)]["TotalTime"])) Level = player.Access["level"]
return False
if str(Level) in self.Torchlight().Config["AudioLimits"]:
TimeElapsed = self.Torchlight().Master.Loop.time() - player.Storage["Audio"]["LastUse"] if self.Torchlight().Config["AudioLimits"][str(Level)]["Uses"] >= 0 and \
UseDelay = player.Storage["Audio"]["LastUseLength"] * self.Torchlight().Config["AudioLimits"][str(Level)]["DelayFactor"] player.Storage["Audio"]["Uses"] >= self.Torchlight().Config["AudioLimits"][str(Level)]["Uses"]:
if TimeElapsed < UseDelay: self.Torchlight().SayPrivate(player, "You have used up all of your free uses! ({0} uses)".format(
self.Torchlight().SayPrivate(player, "You are currently on cooldown! ({0} seconds left)".format( self.Torchlight().Config["AudioLimits"][str(Level)]["Uses"]))
round(UseDelay - TimeElapsed))) return False
return False
if player.Storage["Audio"]["TimeUsed"] >= self.Torchlight().Config["AudioLimits"][str(Level)]["TotalTime"]:
return True self.Torchlight().SayPrivate(player, "You have used up all of your free time! ({0} seconds)".format(
self.Torchlight().Config["AudioLimits"][str(Level)]["TotalTime"]))
def Stop(self, player, extra): return False
Level = 0
if player.Access: TimeElapsed = self.Torchlight().Master.Loop.time() - player.Storage["Audio"]["LastUse"]
Level = player.Access["level"] UseDelay = player.Storage["Audio"]["LastUseLength"] * self.Torchlight().Config["AudioLimits"][str(Level)]["DelayFactor"]
for AudioClip in self.AudioClips[:]: if TimeElapsed < UseDelay:
if extra and not extra.lower() in AudioClip.Player.Name.lower(): self.Torchlight().SayPrivate(player, "You are currently on cooldown! ({0} seconds left)".format(
continue round(UseDelay - TimeElapsed)))
return False
if not Level or (Level < AudioClip.Level and Level < self.Torchlight().Config["AntiSpam"]["StopLevel"]):
AudioClip.Stops.add(player.UserID) return True
if len(AudioClip.Stops) >= 3: def Stop(self, player, extra):
AudioClip.Stop() Level = 0
self.Torchlight().SayPrivate(AudioClip.Player, "Your audio clip was stopped.") if player.Access:
if player != AudioClip.Player: Level = player.Access["level"]
self.Torchlight().SayPrivate(player, "Stopped \"{0}\"({1}) audio clip.".format(AudioClip.Player.Name, AudioClip.Player.UserID))
else: for AudioClip in self.AudioClips[:]:
self.Torchlight().SayPrivate(player, "This audio clip needs {0} more !stop's.".format(3 - len(AudioClip.Stops))) if extra and not extra.lower() in AudioClip.Player.Name.lower():
else: continue
AudioClip.Stop()
self.Torchlight().SayPrivate(AudioClip.Player, "Your audio clip was stopped.") if not Level or (Level < AudioClip.Level and Level < self.Torchlight().Config["AntiSpam"]["StopLevel"]):
if player != AudioClip.Player: AudioClip.Stops.add(player.UserID)
self.Torchlight().SayPrivate(player, "Stopped \"{0}\"({1}) audio clip.".format(AudioClip.Player.Name, AudioClip.Player.UserID))
if len(AudioClip.Stops) >= 3:
def AudioClip(self, player, uri, _type = AudioPlayerFactory.AUDIOPLAYER_FFMPEG): AudioClip.Stop()
Level = 0 self.Torchlight().SayPrivate(AudioClip.Player, "Your audio clip was stopped.")
if player.Access: if player != AudioClip.Player:
Level = player.Access["level"] self.Torchlight().SayPrivate(player, "Stopped \"{0}\"({1}) audio clip.".format(AudioClip.Player.Name, AudioClip.Player.UserID))
else:
if self.Torchlight().Disabled and self.Torchlight().Disabled > Level: self.Torchlight().SayPrivate(player, "This audio clip needs {0} more !stop's.".format(3 - len(AudioClip.Stops)))
self.Torchlight().SayPrivate(player, "Torchlight is currently disabled!") else:
return None AudioClip.Stop()
self.Torchlight().SayPrivate(AudioClip.Player, "Your audio clip was stopped.")
if not self.AntiSpam.CheckAntiSpam(player): if player != AudioClip.Player:
return None self.Torchlight().SayPrivate(player, "Stopped \"{0}\"({1}) audio clip.".format(AudioClip.Player.Name, AudioClip.Player.UserID))
if not self.CheckLimits(player): def AudioClip(self, player, uri, _type = AudioPlayerFactory.AUDIOPLAYER_FFMPEG):
return None Level = 0
if player.Access:
Clip = AudioClip(self, player, uri, _type) Level = player.Access["level"]
self.AudioClips.append(Clip)
if self.Torchlight().Disabled and self.Torchlight().Disabled > Level:
if not player.Access or player.Access["level"] < self.Torchlight().Config["AntiSpam"]["ImmunityLevel"]: self.Torchlight().SayPrivate(player, "Torchlight is currently disabled!")
Clip.AudioPlayer.AddCallback("Play", lambda *args: self.AntiSpam.OnPlay(Clip, *args)) return None
Clip.AudioPlayer.AddCallback("Stop", lambda *args: self.AntiSpam.OnStop(Clip, *args))
Clip.AudioPlayer.AddCallback("Update", lambda *args: self.AntiSpam.OnUpdate(Clip, *args)) if not self.AntiSpam.CheckAntiSpam(player):
return None
Clip.AudioPlayer.AddCallback("Play", lambda *args: self.Advertiser.OnPlay(Clip, *args))
Clip.AudioPlayer.AddCallback("Stop", lambda *args: self.Advertiser.OnStop(Clip, *args)) if not self.CheckLimits(player):
Clip.AudioPlayer.AddCallback("Update", lambda *args: self.Advertiser.OnUpdate(Clip, *args)) return None
return Clip Clip = AudioClip(self, player, uri, _type)
self.AudioClips.append(Clip)
def OnDisconnect(self, player):
for AudioClip in self.AudioClips[:]: if not player.Access or player.Access["level"] < self.Torchlight().Config["AntiSpam"]["ImmunityLevel"]:
if AudioClip.Player == player: Clip.AudioPlayer.AddCallback("Play", lambda *args: self.AntiSpam.OnPlay(Clip, *args))
AudioClip.Stop() Clip.AudioPlayer.AddCallback("Stop", lambda *args: self.AntiSpam.OnStop(Clip, *args))
Clip.AudioPlayer.AddCallback("Update", lambda *args: self.AntiSpam.OnUpdate(Clip, *args))
class AudioClip(): Clip.AudioPlayer.AddCallback("Play", lambda *args: self.Advertiser.OnPlay(Clip, *args))
def __init__(self, master, player, uri, _type): Clip.AudioPlayer.AddCallback("Stop", lambda *args: self.Advertiser.OnStop(Clip, *args))
self.Logger = logging.getLogger(__class__.__name__) Clip.AudioPlayer.AddCallback("Update", lambda *args: self.Advertiser.OnUpdate(Clip, *args))
self.Master = master
self.Torchlight = self.Master.Torchlight return Clip
self.Player = player
self.Type = _type def OnDisconnect(self, player):
self.URI = uri for AudioClip in self.AudioClips[:]:
self.LastPosition = None if AudioClip.Player == player:
self.Stops = set() AudioClip.Stop()
self.Level = 0
if self.Player.Access: class AudioClip():
self.Level = self.Player.Access["level"] def __init__(self, master, player, uri, _type):
self.Logger = logging.getLogger(__class__.__name__)
self.AudioPlayer = self.Master.AudioPlayerFactory.NewPlayer(self.Type) self.Master = master
self.AudioPlayer.AddCallback("Play", self.OnPlay) self.Torchlight = self.Master.Torchlight
self.AudioPlayer.AddCallback("Stop", self.OnStop) self.Player = player
self.AudioPlayer.AddCallback("Update", self.OnUpdate) self.Type = _type
self.URI = uri
def __del__(self): self.LastPosition = None
self.Logger.info("~AudioClip()") self.Stops = set()
def Play(self, seconds = None, rubberband = None, dec_params = None, bitrate = None, backwards = None, *args): self.Level = 0
return self.AudioPlayer.PlayURI(self.URI, position = seconds, rubberband = rubberband, dec_params = dec_params, bitrate = bitrate, if self.Player.Access:
backwards = backwards, *args) self.Level = self.Player.Access["level"]
def Stop(self): self.AudioPlayer = self.Master.AudioPlayerFactory.NewPlayer(self.Type)
return self.AudioPlayer.Stop() self.AudioPlayer.AddCallback("Play", self.OnPlay)
self.AudioPlayer.AddCallback("Stop", self.OnStop)
def OnPlay(self): self.AudioPlayer.AddCallback("Update", self.OnUpdate)
self.Logger.debug(sys._getframe().f_code.co_name + ' ' + self.URI)
def __del__(self):
self.Player.Storage["Audio"]["Uses"] += 1 self.Logger.info("~AudioClip()")
self.Player.Storage["Audio"]["LastUse"] = self.Torchlight().Master.Loop.time()
self.Player.Storage["Audio"]["LastUseLength"] = 0.0 def Play(self, seconds = None, rubberband = None, dec_params = None, bitrate = None, backwards = None, *args):
return self.AudioPlayer.PlayURI(self.URI, position = seconds, rubberband = rubberband, dec_params = dec_params, bitrate = bitrate,
def OnStop(self): backwards = backwards, *args)
self.Logger.debug(sys._getframe().f_code.co_name + ' ' + self.URI)
self.Master.AudioClips.remove(self) def Stop(self):
return self.AudioPlayer.Stop()
if self.AudioPlayer.Playing:
Delta = self.AudioPlayer.Position - self.LastPosition def OnPlay(self):
self.Player.Storage["Audio"]["TimeUsed"] += Delta self.Logger.debug(sys._getframe().f_code.co_name + ' ' + self.URI)
self.Player.Storage["Audio"]["LastUseLength"] += Delta
self.Player.Storage["Audio"]["Uses"] += 1
if str(self.Level) in self.Torchlight().Config["AudioLimits"]: self.Player.Storage["Audio"]["LastUse"] = self.Torchlight().Master.Loop.time()
if self.Player.Storage: self.Player.Storage["Audio"]["LastUseLength"] = 0.0
if self.Player.Storage["Audio"]["TimeUsed"] >= self.Torchlight().Config["AudioLimits"][str(self.Level)]["TotalTime"]:
self.Torchlight().SayPrivate(self.Player, "You have used up all of your free time! ({0} seconds)".format( def OnStop(self):
self.Torchlight().Config["AudioLimits"][str(self.Level)]["TotalTime"])) self.Logger.debug(sys._getframe().f_code.co_name + ' ' + self.URI)
elif self.Player.Storage["Audio"]["LastUseLength"] >= self.Torchlight().Config["AudioLimits"][str(self.Level)]["MaxLength"]: if self in self.Master.AudioClips:
self.Torchlight().SayPrivate(self.Player, "Your audio clip exceeded the maximum length! ({0} seconds)".format( self.Master.AudioClips.remove(self)
self.Torchlight().Config["AudioLimits"][str(self.Level)]["MaxLength"]))
if self.AudioPlayer.Playing:
del self.AudioPlayer if self.LastPosition is None:
self.LastPosition = self.AudioPlayer.Position
def OnUpdate(self, old_position, new_position): Delta = self.AudioPlayer.Position - self.LastPosition
Delta = new_position - old_position self.Player.Storage["Audio"]["TimeUsed"] += Delta
self.LastPosition = new_position self.Player.Storage["Audio"]["LastUseLength"] += Delta
self.Player.Storage["Audio"]["TimeUsed"] += Delta if str(self.Level) in self.Torchlight().Config["AudioLimits"]:
self.Player.Storage["Audio"]["LastUseLength"] += Delta if self.Player.Storage:
if self.Player.Storage["Audio"]["TimeUsed"] >= self.Torchlight().Config["AudioLimits"][str(self.Level)]["TotalTime"]:
if not str(self.Level) in self.Torchlight().Config["AudioLimits"]: self.Torchlight().SayPrivate(self.Player, "You have used up all of your free time! ({0} seconds)".format(
return self.Torchlight().Config["AudioLimits"][str(self.Level)]["TotalTime"]))
elif self.Player.Storage["Audio"]["LastUseLength"] >= self.Torchlight().Config["AudioLimits"][str(self.Level)]["MaxLength"]:
if (self.Player.Storage["Audio"]["TimeUsed"] >= self.Torchlight().Config["AudioLimits"][str(self.Level)]["TotalTime"] or self.Torchlight().SayPrivate(self.Player, "Your audio clip exceeded the maximum length! ({0} seconds)".format(
self.Player.Storage["Audio"]["LastUseLength"] >= self.Torchlight().Config["AudioLimits"][str(self.Level)]["MaxLength"]): self.Torchlight().Config["AudioLimits"][str(self.Level)]["MaxLength"]))
self.Stop()
del self.AudioPlayer
def OnUpdate(self, old_position, new_position):
Delta = new_position - old_position
self.LastPosition = new_position
self.Player.Storage["Audio"]["TimeUsed"] += Delta
self.Player.Storage["Audio"]["LastUseLength"] += Delta
if not str(self.Level) in self.Torchlight().Config["AudioLimits"]:
return
if (self.Player.Storage["Audio"]["TimeUsed"] >= self.Torchlight().Config["AudioLimits"][str(self.Level)]["TotalTime"] or
self.Player.Storage["Audio"]["LastUseLength"] >= self.Torchlight().Config["AudioLimits"][str(self.Level)]["MaxLength"]):
self.Stop()