mirror of
https://github.com/Sneed-Group/Poodletooth-iLand
synced 2024-12-23 03:35:12 -06:00
109 lines
3.8 KiB
Python
109 lines
3.8 KiB
Python
import AnimatedProp
|
|
from direct.actor import Actor
|
|
from direct.interval.IntervalGlobal import *
|
|
from direct.directnotify import DirectNotifyGlobal
|
|
from toontown.toonbase import ToontownGlobals
|
|
from toontown.hood import ZoneUtil
|
|
from toontown.hood import HoodUtil
|
|
|
|
class GenericAnimatedProp(AnimatedProp.AnimatedProp):
|
|
notify = DirectNotifyGlobal.directNotify.newCategory('GenericAnimatedProp')
|
|
|
|
def __init__(self, node):
|
|
AnimatedProp.AnimatedProp.__init__(self, node)
|
|
self.origAnimNameToSound = {}
|
|
code = node.getTag('DNACode')
|
|
|
|
if code.startswith('interactive_prop_'):
|
|
pathStr = code[len('interactive_prop_'):].split('__')[0]
|
|
elif code.startswith('animated_prop_generic_'):
|
|
pathStr = code[len('animated_prop_generic_'):].split('__')[0]
|
|
elif code.startswith('animated_prop_'):
|
|
tempStr = code[len('animated_prop_'):]
|
|
nextUnderscore = tempStr.find('_')
|
|
finalStr = tempStr[nextUnderscore + 1:]
|
|
pathStr = finalStr.split('__')[0]
|
|
|
|
phaseDelimeter = len('phase_') + pathStr[len('phase_'):].find('_')
|
|
phaseStr = pathStr[:phaseDelimeter]
|
|
pathTokens = pathStr[phaseDelimeter + 1:].split('_')
|
|
self.path = phaseStr
|
|
|
|
for path in pathTokens:
|
|
self.path += '/'
|
|
self.path += path
|
|
|
|
self.notify.debug('self.path=%s' % self.path)
|
|
self.calcHoodId(node)
|
|
self.propType = HoodUtil.calcPropType(node)
|
|
self.setupActor(node)
|
|
self.code = code
|
|
|
|
def delete(self):
|
|
AnimatedProp.AnimatedProp.delete(self)
|
|
|
|
if hasattr(self, 'soundNode'):
|
|
self.soundNode.removeNode()
|
|
del self.soundNode
|
|
|
|
self.node.cleanup()
|
|
del self.node
|
|
del self.trashcan
|
|
|
|
def enter(self):
|
|
self.node.postFlatten()
|
|
AnimatedProp.AnimatedProp.enter(self)
|
|
self.node.loop('anim')
|
|
|
|
def exit(self):
|
|
AnimatedProp.AnimatedProp.exit(self)
|
|
self.node.stop()
|
|
|
|
def getActor(self):
|
|
return self.node
|
|
|
|
def setupActor(self, node):
|
|
anim = node.getTag('DNAAnim')
|
|
self.trashcan = Actor.Actor(node, copy=0)
|
|
self.trashcan.reparentTo(node)
|
|
self.trashcan.loadAnims({'anim': '%s/%s' % (self.path, anim)})
|
|
self.trashcan.pose('anim', 0)
|
|
self.node = self.trashcan
|
|
|
|
def calcHoodId(self, node):
|
|
self.hoodId = ToontownGlobals.ToontownCentral
|
|
fullString = str(node)
|
|
splits = fullString.split('/')
|
|
|
|
if len(splits) >= 5:
|
|
visId = int(splits[4])
|
|
self.visId = visId
|
|
self.hoodId = ZoneUtil.getCanonicalHoodId(visId)
|
|
self.notify.debug('calcHoodId %d from %s' % (self.hoodId, fullString))
|
|
else:
|
|
self.notify.warning("calcHoodId couldn't parse %s using 0" % fullString)
|
|
self.hoodId = 0
|
|
self.visId = 0
|
|
|
|
def createSoundInterval(self, origAnimNameWithPath, maximumDuration):
|
|
if not hasattr(base, 'localAvatar'):
|
|
return Sequence()
|
|
|
|
if not hasattr(self, 'soundPath'):
|
|
self.soundPath = self.path.replace('/models/char', '/audio/sfx')
|
|
|
|
origAnimName = origAnimNameWithPath.split('/')[-1]
|
|
sound = self.origAnimNameToSound.get(origAnimName)
|
|
|
|
if not sound:
|
|
sound = loader.loadSfx('%s/%s.ogg' % (self.soundPath, origAnimName.replace('tt_a_ara', 'tt_s_ara')))
|
|
self.origAnimNameToSound[origAnimName] = sound
|
|
|
|
if sound:
|
|
if not hasattr(self, 'soundNode'):
|
|
self.soundNode = render.attachNewNode('Sound Node')
|
|
self.soundNode.setPos(self.trashcan.getBounds().getCenter())
|
|
|
|
return SoundInterval(sound, node=self.soundNode, listenerNode=base.localAvatar, volume=1.0, cutOff=45, startTime=0, duration=min(sound.length(), maximumDuration))
|
|
|
|
return Sequence()
|