oldschool-toontown/toontown/coghq/MovingPlatform.py

88 lines
3.1 KiB
Python
Raw Normal View History

from panda3d.core import *
2019-11-02 17:27:54 -05:00
from direct.interval.IntervalGlobal import *
from direct.showbase import DirectObject
from toontown.toonbase import ToontownGlobals
from direct.directnotify import DirectNotifyGlobal
class MovingPlatform(DirectObject.DirectObject, NodePath):
notify = DirectNotifyGlobal.directNotify.newCategory('MovingPlatform')
def __init__(self):
self.hasLt = 0
DirectObject.DirectObject.__init__(self)
NodePath.__init__(self)
def setupCopyModel(self, parentToken, model, floorNodeName = None, parentingNode = None):
if floorNodeName is None:
floorNodeName = 'floor'
if type(parentToken) == int:
2019-11-02 17:27:54 -05:00
parentToken = ToontownGlobals.SPDynamic + parentToken
self.parentToken = parentToken
2019-12-31 00:11:28 -06:00
self._name = 'MovingPlatform-%s' % parentToken
self.assign(hidden.attachNewNode(self._name))
2019-11-02 17:27:54 -05:00
self.model = model.copyTo(self)
self.ownsModel = 1
floorList = self.model.findAllMatches('**/%s' % floorNodeName)
if len(floorList) == 0:
MovingPlatform.notify.warning('no floors in model')
return
for floor in floorList:
2019-12-31 00:11:28 -06:00
floor.setName(self._name)
2019-11-02 17:27:54 -05:00
if parentingNode == None:
parentingNode = self
base.cr.parentMgr.registerParent(self.parentToken, parentingNode)
self.parentingNode = parentingNode
2019-12-31 00:11:28 -06:00
self.accept('enter%s' % self._name, self.__handleEnter)
self.accept('exit%s' % self._name, self.__handleExit)
2019-11-02 17:27:54 -05:00
return
def destroy(self):
base.cr.parentMgr.unregisterParent(self.parentToken)
self.ignoreAll()
if self.hasLt:
self.__releaseLt()
if self.ownsModel:
self.model.removeNode()
del self.model
if hasattr(self, 'parentingNode') and self.parentingNode is self:
del self.parentingNode
def getEnterEvent(self):
2019-12-31 00:11:28 -06:00
return '%s-enter' % self._name
2019-11-02 17:27:54 -05:00
def getExitEvent(self):
2019-12-31 00:11:28 -06:00
return '%s-exit' % self._name
2019-11-02 17:27:54 -05:00
def releaseLocalToon(self):
if self.hasLt:
self.__releaseLt()
def __handleEnter(self, collEntry):
2019-12-31 00:11:28 -06:00
self.notify.debug('on movingPlatform %s' % self._name)
2019-11-02 17:27:54 -05:00
self.__grabLt()
messenger.send(self.getEnterEvent())
def __handleExit(self, collEntry):
2019-12-31 00:11:28 -06:00
self.notify.debug('off movingPlatform %s' % self._name)
2019-11-02 17:27:54 -05:00
self.__releaseLt()
messenger.send(self.getExitEvent())
def __handleOnFloor(self, collEntry):
2019-12-31 00:11:28 -06:00
if collEntry.getIntoNode().getName() == self._name:
2019-11-02 17:27:54 -05:00
self.__handleEnter(collEntry)
def __handleOffFloor(self, collEntry):
2019-12-31 00:11:28 -06:00
if collEntry.getIntoNode().getName() == self._name:
2019-11-02 17:27:54 -05:00
self.__handleExit(collEntry)
def __grabLt(self):
base.localAvatar.b_setParent(self.parentToken)
self.hasLt = 1
def __releaseLt(self):
if base.localAvatar.getParent().compareTo(self.parentingNode) == 0:
base.localAvatar.b_setParent(ToontownGlobals.SPRender)
base.localAvatar.controlManager.currentControls.doDeltaPos()
self.hasLt = 0