mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
added __delAttribs__ support
This commit is contained in:
parent
62d9c57f11
commit
426164d9dc
@ -38,6 +38,9 @@ class NodePathAttribs:
|
||||
def setSz(self, *args): self.getNodePath().setSz(*args)
|
||||
|
||||
class privNodePathImpl(NodePath.NodePath):
|
||||
__attribs__ = (
|
||||
'parent', 'pos', 'hpr',
|
||||
)
|
||||
def __init__(self, name):
|
||||
node = hidden.attachNewNode(name)
|
||||
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.
|
||||
It may be instantiated directly or used as a base class for other
|
||||
entity types."""
|
||||
__attribs__ = (
|
||||
'parent', 'pos', 'hpr',
|
||||
)
|
||||
def __init__(self, level, entId):
|
||||
privNodePathImpl.__init__(self, '')
|
||||
Entity.Entity.__init__(self, level, entId)
|
||||
@ -81,9 +81,6 @@ class DistributedNodePathEntity(DistributedEntity.DistributedEntity,
|
||||
"""This is a distributed version of NodePathEntity. It should not
|
||||
be instantiated directly; derive your client-side distEntity from
|
||||
this class instead of DistributedEntity."""
|
||||
__attribs__ = (
|
||||
'parent', 'pos', 'hpr',
|
||||
)
|
||||
def __init__(self, cr):
|
||||
DistributedEntity.DistributedEntity.__init__(self, cr)
|
||||
privNodePathImpl.__init__(self, 'DistributedNodePathEntity')
|
||||
|
@ -133,31 +133,46 @@ class Entity(DirectObject):
|
||||
|
||||
while len(classList):
|
||||
cl = classList.pop()
|
||||
Entity.notify.debug('looking for attribs for %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
|
||||
Entity.notify.debug('looking for attribs on %s' % cl.__name__)
|
||||
|
||||
for attrib in cAttribs:
|
||||
if attrib not in allAttribs:
|
||||
allAttribs.append(attrib)
|
||||
def getClassAttr(cl, name, self=self):
|
||||
"""grab an attribute, such as __attribs__, off of a class"""
|
||||
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
|
||||
# for this class. Cache it on the class object
|
||||
|
@ -4,8 +4,11 @@ import ZoneEntityBase
|
||||
import BasicEntities
|
||||
|
||||
class ZoneEntity(ZoneEntityBase.ZoneEntityBase, BasicEntities.NodePathAttribs):
|
||||
__attribs = (
|
||||
'modelZoneNum',
|
||||
__delAttribs__ = (
|
||||
'parent', 'pos', 'hpr',
|
||||
)
|
||||
__attribs__ = (
|
||||
'description', 'modelZoneNum',
|
||||
)
|
||||
|
||||
def __init__(self, level, entId):
|
||||
@ -14,6 +17,5 @@ class ZoneEntity(ZoneEntityBase.ZoneEntityBase, BasicEntities.NodePathAttribs):
|
||||
self.nodePath = self.level.getZoneNode(self.modelZoneNum)
|
||||
self.initNodePathAttribs(doReparent=0)
|
||||
|
||||
|
||||
def getNodePath(self):
|
||||
return self.nodePath
|
||||
|
Loading…
x
Reference in New Issue
Block a user