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)
|
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')
|
||||||
|
@ -133,11 +133,15 @@ 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__
|
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):
|
elif isDistObjAI(cl):
|
||||||
# It's a distributed AI class. Check the client-side class
|
# It's a distributed AI class.
|
||||||
|
# Check the client-side class
|
||||||
globals = {}
|
globals = {}
|
||||||
locals = {}
|
locals = {}
|
||||||
ccn = cl.__name__[:-2] # clientClassName
|
ccn = cl.__name__[:-2] # clientClassName
|
||||||
@ -146,16 +150,27 @@ class Entity(DirectObject):
|
|||||||
exec 'import %s' % ccn in globals, locals
|
exec 'import %s' % ccn in globals, locals
|
||||||
except:
|
except:
|
||||||
print 'could not import %s' % ccn
|
print 'could not import %s' % ccn
|
||||||
continue
|
return None
|
||||||
exec 'cAttribs = %s.%s.__dict__.get("__attribs__")' % (
|
exec 'attr = %s.%s.__dict__.get("%s")' % (
|
||||||
ccn, ccn) in globals, locals
|
ccn, ccn, name) in globals, locals
|
||||||
cAttribs = locals['cAttribs']
|
return locals['attr']
|
||||||
if cAttribs is None:
|
|
||||||
continue
|
|
||||||
else:
|
else:
|
||||||
continue
|
return None
|
||||||
|
|
||||||
for attrib in cAttribs:
|
# 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:
|
if attrib not in allAttribs:
|
||||||
allAttribs.append(attrib)
|
allAttribs.append(attrib)
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user