added __delAttribs__ support

This commit is contained in:
Darren Ranalli 2003-09-27 02:54:23 +00:00
parent 62d9c57f11
commit 426164d9dc
3 changed files with 47 additions and 33 deletions

View File

@ -38,6 +38,9 @@ class NodePathAttribs:
def setSz(self, *args): self.getNodePath().setSz(*args) def setSz(self, *args): self.getNodePath().setSz(*args)
class privNodePathImpl(NodePath.NodePath): class privNodePathImpl(NodePath.NodePath):
__attribs__ = (
'parent', 'pos', 'hpr',
)
def __init__(self, name): def __init__(self, name):
node = hidden.attachNewNode(name) node = hidden.attachNewNode(name)
NodePath.NodePath.__init__(self, node) NodePath.NodePath.__init__(self, node)
@ -60,9 +63,6 @@ class NodePathEntity(Entity.Entity, privNodePathImpl):
"""This is an entity that represents a NodePath on the client. """This is an entity that represents a NodePath on the client.
It may be instantiated directly or used as a base class for other It may be instantiated directly or used as a base class for other
entity types.""" entity types."""
__attribs__ = (
'parent', 'pos', 'hpr',
)
def __init__(self, level, entId): def __init__(self, level, entId):
privNodePathImpl.__init__(self, '') privNodePathImpl.__init__(self, '')
Entity.Entity.__init__(self, level, entId) Entity.Entity.__init__(self, level, entId)
@ -81,9 +81,6 @@ class DistributedNodePathEntity(DistributedEntity.DistributedEntity,
"""This is a distributed version of NodePathEntity. It should not """This is a distributed version of NodePathEntity. It should not
be instantiated directly; derive your client-side distEntity from be instantiated directly; derive your client-side distEntity from
this class instead of DistributedEntity.""" this class instead of DistributedEntity."""
__attribs__ = (
'parent', 'pos', 'hpr',
)
def __init__(self, cr): def __init__(self, cr):
DistributedEntity.DistributedEntity.__init__(self, cr) DistributedEntity.DistributedEntity.__init__(self, cr)
privNodePathImpl.__init__(self, 'DistributedNodePathEntity') privNodePathImpl.__init__(self, 'DistributedNodePathEntity')

View File

@ -133,31 +133,46 @@ class Entity(DirectObject):
while len(classList): while len(classList):
cl = classList.pop() cl = classList.pop()
Entity.notify.debug('looking for attribs for %s' % cl.__name__) Entity.notify.debug('looking for attribs on %s' % cl.__name__)
if cl.__dict__.has_key('__attribs__'):
cAttribs = cl.__attribs__
elif isDistObjAI(cl):
# It's a distributed AI class. Check the client-side class
globals = {}
locals = {}
ccn = cl.__name__[:-2] # clientClassName
Entity.notify.debug('importing client class %s' % ccn)
try:
exec 'import %s' % ccn in globals, locals
except:
print 'could not import %s' % ccn
continue
exec 'cAttribs = %s.%s.__dict__.get("__attribs__")' % (
ccn, ccn) in globals, locals
cAttribs = locals['cAttribs']
if cAttribs is None:
continue
else:
continue
for attrib in cAttribs: def getClassAttr(cl, name, self=self):
if attrib not in allAttribs: """grab an attribute, such as __attribs__, off of a class"""
allAttribs.append(attrib) if cl.__dict__.has_key(name):
return cl.__dict__[name]
elif isDistObjAI(cl):
# It's a distributed AI class.
# Check the client-side class
globals = {}
locals = {}
ccn = cl.__name__[:-2] # clientClassName
Entity.notify.debug('importing client class %s' % ccn)
try:
exec 'import %s' % ccn in globals, locals
except:
print 'could not import %s' % ccn
return None
exec 'attr = %s.%s.__dict__.get("%s")' % (
ccn, ccn, name) in globals, locals
return locals['attr']
else:
return None
# delete some attribs?
delAttribs = getClassAttr(cl, '__delAttribs__')
if delAttribs is not None:
assert type(delAttribs) in (types.TupleType, types.ListType)
Entity.notify.debug('delAttribs: %s' % list(delAttribs))
for attrib in delAttribs:
if attrib in allAttribs:
allAttribs.remove(attrib)
attribs = getClassAttr(cl, '__attribs__')
if attribs is not None:
assert type(attribs) in (types.TupleType, types.ListType)
Entity.notify.debug('attribs: %s' % list(attribs))
for attrib in attribs:
if attrib not in allAttribs:
allAttribs.append(attrib)
# we now have an ordered list of all of the attribute descriptors # we now have an ordered list of all of the attribute descriptors
# for this class. Cache it on the class object # for this class. Cache it on the class object

View File

@ -4,8 +4,11 @@ import ZoneEntityBase
import BasicEntities import BasicEntities
class ZoneEntity(ZoneEntityBase.ZoneEntityBase, BasicEntities.NodePathAttribs): class ZoneEntity(ZoneEntityBase.ZoneEntityBase, BasicEntities.NodePathAttribs):
__attribs = ( __delAttribs__ = (
'modelZoneNum', 'parent', 'pos', 'hpr',
)
__attribs__ = (
'description', 'modelZoneNum',
) )
def __init__(self, level, entId): def __init__(self, level, entId):
@ -14,6 +17,5 @@ class ZoneEntity(ZoneEntityBase.ZoneEntityBase, BasicEntities.NodePathAttribs):
self.nodePath = self.level.getZoneNode(self.modelZoneNum) self.nodePath = self.level.getZoneNode(self.modelZoneNum)
self.initNodePathAttribs(doReparent=0) self.initNodePathAttribs(doReparent=0)
def getNodePath(self): def getNodePath(self):
return self.nodePath return self.nodePath