Poodletooth-iLand/toontown/hood/GenericAnimatedProp.py

110 lines
3.8 KiB
Python
Raw Normal View History

2015-03-03 16:10:12 -06:00
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')
2015-06-24 17:00:15 -05:00
2015-03-03 16:10:12 -06:00
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]
2015-06-24 17:00:15 -05:00
2015-03-03 16:10:12 -06:00
phaseDelimeter = len('phase_') + pathStr[len('phase_'):].find('_')
phaseStr = pathStr[:phaseDelimeter]
pathTokens = pathStr[phaseDelimeter + 1:].split('_')
self.path = phaseStr
2015-06-24 17:00:15 -05:00
2015-03-03 16:10:12 -06:00
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)
2015-06-24 17:00:15 -05:00
if hasattr(self, 'soundNode'):
self.soundNode.removeNode()
2015-06-24 17:00:15 -05:00
del self.soundNode
2015-03-03 16:10:12 -06:00
self.node.cleanup()
del self.node
del self.trashcan
def enter(self):
self.node.postFlatten()
AnimatedProp.AnimatedProp.enter(self)
2015-06-21 14:33:39 -05:00
self.node.loop('anim')
2015-03-03 16:10:12 -06:00
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('/')
2015-06-24 17:00:15 -05:00
2015-04-09 12:17:24 -05:00
if len(splits) >= 5:
visId = int(splits[4])
2015-03-03 16:10:12 -06:00
self.visId = visId
self.hoodId = ZoneUtil.getCanonicalHoodId(visId)
2015-03-03 16:10:12 -06:00
self.notify.debug('calcHoodId %d from %s' % (self.hoodId, fullString))
2015-04-09 12:17:24 -05:00
else:
self.notify.warning("calcHoodId couldn't parse %s using 0" % fullString)
2015-03-03 16:10:12 -06:00
self.hoodId = 0
self.visId = 0
def createSoundInterval(self, origAnimNameWithPath, maximumDuration):
if not hasattr(base, 'localAvatar'):
return Sequence()
2015-06-24 17:00:15 -05:00
2015-03-03 16:10:12 -06:00
if not hasattr(self, 'soundPath'):
self.soundPath = self.path.replace('/models/char', '/audio/sfx')
2015-06-24 17:00:15 -05:00
2015-03-03 16:10:12 -06:00
origAnimName = origAnimNameWithPath.split('/')[-1]
2015-06-24 17:00:15 -05:00
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))
2015-07-05 18:59:25 -05:00
return Sequence()