added default attrib values

This commit is contained in:
Darren Ranalli 2003-10-03 20:18:02 +00:00
parent 7654b0db97
commit d79cbf1179
3 changed files with 130 additions and 119 deletions

View File

@ -4,12 +4,21 @@ class AttribDesc:
"""
Entity attribute descriptor
name == name of attribute
default == default value for attrib
"""
def __init__(self, name):
def __init__(self, name, default):
self.name = name
self.default = default
def getName(self):
return self.name
def getDefaultValue(self):
return self.default
def __str__(self):
return self.name
def __repr__(self):
return "AttribDesc('%s')" % self.name
return "AttribDesc(%s, %s)" % (
repr(self.name),
repr(self.default)
)

View File

@ -12,7 +12,7 @@ class EntityTypeRegistry:
def __init__(self, entityTypeModule=EntityTypes):
"""pass in a module that contains EntityType classes"""
# maps entity typename to type class
self.name2typeClass = {}
self.typeName2class = {}
# get a list of the entity type classes in the type module
classes = []
@ -28,17 +28,17 @@ class EntityTypeRegistry:
# attribute descriptor lists for each concrete Entity type class
for c in classes:
# if this is a concrete Entity type, add it to the dict
if c.__dict__.has_key('name'):
if self.name2typeClass.has_key(c.name):
if c.__dict__.has_key('type'):
if self.typeName2class.has_key(c.type):
EntityTypeRegistry.notify.debug(
"replacing %s with %s for type '%s'" %
(self.name2typeClass[c.name], c, c.name))
self.name2typeClass[c.name] = c
(self.typeName2class[c.type], c, c.type))
self.typeName2class[c.type] = c
self.privCompileAttribDescs(c)
def getAttributeDescriptors(self, entityTypeName):
return self.name2typeClass[entityTypeName]._attribDescs
return self.typeName2class[entityTypeName]._attribDescs
def privCompileAttribDescs(self, entTypeClass):
# has someone already compiled the info?
@ -83,7 +83,7 @@ class EntityTypeRegistry:
attribDescs = []
if c.__dict__.has_key('attribs'):
for attrib in c.attribs:
desc = AttribDesc.AttribDesc(attrib)
desc = AttribDesc.AttribDesc(*attrib)
# if we picked up an attribute with the same name from a base
# class, this overrides it

View File

@ -1,59 +1,61 @@
"""EntityTypes module: contains classes that describe Entity types"""
from SpecImports import *
class Entity:
attribs = (
'type',
'name',
'comment',
('type', None),
('name', 'unnamed'),
('comment', ''),
)
class LevelMgr(Entity):
name = 'levelMgr'
type = 'levelMgr'
attribs = (
'cogLevel',
'cogTrack',
'modelFilename',
('cogLevel', 0),
('cogTrack', 'c'),
('modelFilename', None),
)
class LogicGate(Entity):
name = 'logicGate'
type = 'logicGate'
attribs = (
'input_input1_bool',
'input_input2_bool',
'isInput1',
'isInput2',
'logicType',
'output',
('input_input1_bool', 0),
('input_input2_bool', 0),
('isInput1', 0),
('isInput2', 0),
('logicType', 'or'),
('output', 'bool'),
)
class NodepathImpl:
attribs = (
'parent',
'pos',
'hpr',
('parent', 0),
('pos', Point3(0,0,0)),
('hpr', Vec3(0,0,0)),
)
# Note: this covers Nodepath and DistributedNodepath
class Nodepath(Entity, NodepathImpl):
name = 'nodepath'
type = 'nodepath'
class NodepathAttribs:
attribs = (
'parent',
'pos',
'hpr',
('parent', 0),
('pos', Point3(0,0,0)),
('hpr', Vec3(0,0,0)),
)
class Zone(Entity, NodepathAttribs):
name = 'zone'
type = 'zone'
delAttribs = (
'parent',
'pos',
'hpr',
)
attribs = (
'description',
'modelZoneNum',
('description', ''),
('modelZoneNum', None),
)
class BarrelBase(Nodepath):
@ -61,148 +63,148 @@ class BarrelBase(Nodepath):
'hpr',
)
attribs = (
'h',
('h', 0),
)
class BeanBarrel(BarrelBase):
name = 'beanBarrel'
type = 'beanBarrel'
class GagBarrel(BarrelBase):
name = 'gagBarrel'
type = 'gagBarrel'
attribs = (
'gagLevel',
'gagTrack',
('gagLevel', 0),
('gagTrack', 0),
)
class Switch(Entity, NodepathImpl):
attribs = (
'scale',
'color',
'model',
'input_isOn_bool',
'isOn',
'output',
'secondsOn',
('scale', 1),
('color', Vec4(1,1,1,1)),
('model', None),
('input_isOn_bool', 0),
('isOn', 0),
('output', 'bool'),
('secondsOn', 1),
)
class Button(Switch):
name = 'button'
type = 'button'
class Trigger(Switch):
name = 'trigger'
type = 'trigger'
class Crate(Nodepath):
name = 'crate'
type = 'crate'
delAttribs = (
'hpr',
)
attribs = (
'scale',
'gridId',
'pushable',
('scale', 1),
('gridId', None),
('pushable', 1),
)
class Door(Entity):
name = 'door'
type = 'door'
attribs = (
'parent',
'pos',
'hpr',
'scale',
'color',
'model',
'doorwayNum',
'input_Lock0_bool',
'input_Lock1_bool',
'input_Lock2_bool',
'input_Lock3_bool',
'input_isOpen_bool',
'isLock0Unlocked',
'isLock1Unlocked',
'isLock2Unlocked',
'isLock3Unlocked',
'isOpen',
'output',
'secondsOpen',
('parent', 0),
('pos', Point3(0,0,0)),
('hpr', Vec3(0,0,0)),
('scale', 1),
('color', Vec4(1,1,1,1)),
('model', None),
('doorwayNum', 0),
('input_Lock0_bool', 0),
('input_Lock1_bool', 0),
('input_Lock2_bool', 0),
('input_Lock3_bool', 0),
('input_isOpen_bool', 0),
('isLock0Unlocked', 0),
('isLock1Unlocked', 0),
('isLock2Unlocked', 0),
('isLock3Unlocked', 0),
('isOpen', 0),
('output', 'bool'),
('secondsOpen', 1),
)
class Grid(Nodepath):
name = 'grid'
type = 'grid'
delAttribs = (
'hpr',
)
attribs = (
'cellSize',
'numCol',
'numRow',
('cellSize', 3),
('numCol', 3),
('numRow', 3),
)
class Lift(Nodepath):
name = 'lift'
type = 'lift'
attribs = (
'duration',
'startPos',
'endPos',
'modelPath',
'floorName',
'modelScale',
('duration', 1),
('startPos', Point3(0,0,0)),
('endPos', Point3(0,0,0)),
('modelPath', ''),
('floorName', ''),
('modelScale', 1),
)
class Platform(Nodepath):
name = 'platform'
type = 'platform'
delAttribs = (
'pos',
)
attribs = (
'startPos',
'endPos',
'speed',
'waitDur',
'phaseShift',
('startPos', Point3(0,0,0)),
('endPos', Point3(0,0,0)),
('speed', 1),
('waitDur', 1),
('phaseShift', 0.),
)
class SinkingPlatform(Nodepath):
name = 'sinkingPlatform'
type = 'sinkingPlatform'
delAttribs = (
'pos',
)
attribs = (
'endPos',
'phaseShift',
'startPos',
'verticalRange',
'sinkRate',
'riseRate',
'speed',
'waitDur',
('endPos', Point3(0,0,0)),
('phaseShift', 0.),
('startPos', Point3(0,0,0)),
('verticalRange', 1),
('sinkRate', 1),
('riseRate', 1),
('speed', 1),
('waitDur', 1),
)
class Stomper(Nodepath):
name = 'stomper'
type = 'stomper'
attribs = (
'headScale',
'motion',
'period',
'phaseShift',
'range',
'shaftScale',
'soundLen',
'soundOn',
'style',
'zOffset',
('headScale', Vec3(1,1,1)),
('motion', 3),
('period', 2.),
('phaseShift', 0.),
('range', 6),
('shaftScale', Vec3(1,1,1)),
('soundLen', 0),
('soundOn', 0),
('style', 'horizontal'),
('zOffset', 0),
)
class StomperPair(Nodepath):
name = 'stomperPair'
type = 'stomperPair'
attribs = (
'headScale',
'motion',
'period',
'phaseShift',
'range',
'shaftScale',
'soundLen',
'soundOn',
'stomperIds',
'style',
('headScale', Vec3(1,1,1)),
('motion', 3),
('period', 2.),
('phaseShift', 0.),
('range', 6),
('shaftScale', Vec3(1,1,1)),
('soundLen', 0),
('soundOn', 0),
('stomperIds', []),
('style', 'horizontal'),
)