oldschool-toontown/otp/level/PropSpinner.py

58 lines
1.6 KiB
Python
Raw Normal View History

2019-11-02 17:27:54 -05:00
from direct.interval.IntervalGlobal import *
from .Entity import Entity
from panda3d.core import Vec3
2019-11-02 17:27:54 -05:00
class PropSpinner(Entity):
def __init__(self, level, entId):
Entity.__init__(self, level, entId)
self.initProps()
def destroy(self):
self.destroyProps()
Entity.destroy(self)
def initProps(self):
topNode = self.getZoneNode()
props = topNode.findAllMatches('**/Prop_*')
spinTracks = Parallel()
for prop in props:
name = prop.getName()
nameParts = name.split('_')
axis = nameParts[2]
rate = 0
2020-01-08 16:47:17 -06:00
neg = nameParts[3][0].upper() == 'N'
2019-11-02 17:27:54 -05:00
if neg:
nameParts[3] = nameParts[3][1:]
try:
rate = int(nameParts[3])
except:
print('invalid prop rotate string: %s' % name)
2019-11-02 17:27:54 -05:00
if neg:
rate = -rate
prop.setHpr(0, 0, 0)
if axis == 'X':
hpr = Vec3(0, rate * 360, 0)
elif axis == 'Y':
hpr = Vec3(rate * 360, 0, 0)
elif axis == 'Z':
hpr = Vec3(0, 0, rate * 360)
else:
print('error', axis)
2019-11-02 17:27:54 -05:00
spinTracks.append(LerpHprInterval(prop, 60, hpr))
spinTracks.loop()
self.spinTracks = spinTracks
def destroyProps(self):
if hasattr(self, 'spinTracks'):
self.spinTracks.pause()
del self.spinTracks
if __dev__:
def attribChanged(self, *args):
self.destroyProps()
self.initProps()