|
|
@@ -4,11 +4,12 @@ import Entity
|
|
|
import DistributedEntity
|
|
|
import NodePath
|
|
|
|
|
|
-# this is an abstract class, do not instantiate.
|
|
|
-class NodePathAttribs:
|
|
|
- """Derive from this class to give an entity the behavior of a
|
|
|
- NodePath, without necessarily deriving from NodePath. Derived class
|
|
|
- must implement getNodePath()."""
|
|
|
+# base class for entities that support NodePath attributes
|
|
|
+# *** Don't derive directly from this class; derive from the appropriate
|
|
|
+# specialized class from the classes defined below.
|
|
|
+class NodePathEntityBase:
|
|
|
+ # we don't call this __init__ because it doesn't have to be called
|
|
|
+ # upon object init
|
|
|
def initNodePathAttribs(self, doReparent=1):
|
|
|
"""Call this after the entity has been initialized"""
|
|
|
self.callSetters('pos','x','y','z',
|
|
|
@@ -17,9 +18,64 @@ class NodePathAttribs:
|
|
|
if doReparent:
|
|
|
self.callSetters('parentEntId')
|
|
|
|
|
|
+ self.getNodePath().setName('%s-%s' %
|
|
|
+ (self.__class__.__name__, self.entId))
|
|
|
+
|
|
|
if __debug__:
|
|
|
+ # for the editor
|
|
|
self.getNodePath().setTag('entity', '1')
|
|
|
|
|
|
+ def setParentEntId(self, parentEntId):
|
|
|
+ self.parentEntId = parentEntId
|
|
|
+ self.level.requestReparent(self, self.parentEntId)
|
|
|
+
|
|
|
+ def destroy(self):
|
|
|
+ if __debug__:
|
|
|
+ # for the editor
|
|
|
+ self.getNodePath().clearTag('entity')
|
|
|
+
|
|
|
+# Entities that already derive from NodePath and Entity should derive
|
|
|
+# from this class
|
|
|
+class NodePathAttribs(NodePathEntityBase):
|
|
|
+ def initNodePathAttribs(self, doReparent=1):
|
|
|
+ NodePathEntityBase.initNodePathAttribs(self, doReparent)
|
|
|
+
|
|
|
+ def destroy(self):
|
|
|
+ NodePathEntityBase.destroy(self)
|
|
|
+
|
|
|
+ def getNodePath(self):
|
|
|
+ return self
|
|
|
+
|
|
|
+# Entities that already derive from Entity, and do not derive from NodePath,
|
|
|
+# but want to be a NodePath, should derive from this.
|
|
|
+class NodePathAndAttribs(NodePathEntityBase, NodePath.NodePath):
|
|
|
+ def __init__(self):
|
|
|
+ node = hidden.attachNewNode('EntityNodePath')
|
|
|
+ NodePath.NodePath.__init__(self, node)
|
|
|
+
|
|
|
+ def initNodePathAttribs(self, doReparent=1):
|
|
|
+ NodePathEntityBase.initNodePathAttribs(self, doReparent)
|
|
|
+
|
|
|
+ def destroy(self):
|
|
|
+ NodePathEntityBase.destroy(self)
|
|
|
+ self.removeNode()
|
|
|
+
|
|
|
+ def getNodePath(self):
|
|
|
+ return self
|
|
|
+
|
|
|
+# Entities that already derive from Entity, and do not derive from NodePath,
|
|
|
+# but HAVE a NodePath that they want to represent them, should derive from
|
|
|
+# this. They must define getNodePath(), which should return their 'proxy'
|
|
|
+# NodePath instance.
|
|
|
+class NodePathAttribsProxy(NodePathEntityBase):
|
|
|
+ def initNodePathAttribs(self, doReparent=1):
|
|
|
+ """Call this after the entity has been initialized"""
|
|
|
+ NodePathEntityBase.initNodePathAttribs(self, doReparent)
|
|
|
+ assert self.getNodePath() != self
|
|
|
+
|
|
|
+ def destroy(self):
|
|
|
+ NodePathEntityBase.destroy(self)
|
|
|
+
|
|
|
def setPos(self, *args): self.getNodePath().setPos(*args)
|
|
|
def setX(self, *args): self.getNodePath().setX(*args)
|
|
|
def setY(self, *args): self.getNodePath().setY(*args)
|
|
|
@@ -37,85 +93,39 @@ class NodePathAttribs:
|
|
|
|
|
|
def reparentTo(self, *args): self.getNodePath().reparentTo(*args)
|
|
|
|
|
|
- def setParentEntId(self, parentEntId):
|
|
|
- self.parentEntId = parentEntId
|
|
|
- self.level.requestReparent(self, self.parentEntId)
|
|
|
-
|
|
|
-# this is an abstract class, do not instantiate.
|
|
|
-class NodePathSelfAttribs:
|
|
|
- """Derive from this class to give an entity that is already a Nodepath
|
|
|
- the behavior of a NodePathEntity, with ability to reparent and be
|
|
|
- picked from the Direct/FactoryEditor interface"""
|
|
|
- def initNodePathSelfAttribs(self):
|
|
|
- if __debug__:
|
|
|
- self.setTag('entity', '1')
|
|
|
- self.callSetters('parentEntId')
|
|
|
-
|
|
|
- def setParentEntId(self, parentEntId):
|
|
|
- self.parentEntId = parentEntId
|
|
|
- self.level.requestReparent(self, self.parentEntId)
|
|
|
-
|
|
|
-
|
|
|
-class privNodePathImpl(NodePath.NodePath):
|
|
|
- def __init__(self, name):
|
|
|
- node = hidden.attachNewNode(name)
|
|
|
- NodePath.NodePath.__init__(self, node)
|
|
|
- if __debug__:
|
|
|
- self.setTag('entity', '1')
|
|
|
-
|
|
|
- def initNodePathAttribs(self):
|
|
|
- """Call this after the entity has been initialized, and all
|
|
|
- of its attributes have been set"""
|
|
|
- self.callSetters('pos','x','y','z',
|
|
|
- 'hpr','h','p','r',
|
|
|
- 'scale','sx','sy','sz',
|
|
|
- 'parentEntId')
|
|
|
-
|
|
|
- def setParentEntId(self, parentEntId):
|
|
|
- self.parentEntId = parentEntId
|
|
|
- self.level.requestReparent(self.getNodePath(), self.parentEntId)
|
|
|
-
|
|
|
- def destroy(self):
|
|
|
- if __debug__:
|
|
|
- self.clearTag('entity')
|
|
|
- self.removeNode()
|
|
|
-
|
|
|
- def getNodePath(self):
|
|
|
- return self
|
|
|
-
|
|
|
-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."""
|
|
|
+# 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 that 'are' NodePaths.
|
|
|
+class NodePathEntity(Entity.Entity, NodePath.NodePath, NodePathAttribs):
|
|
|
def __init__(self, level, entId):
|
|
|
- privNodePathImpl.__init__(self, '')
|
|
|
+ node = hidden.attachNewNode('NodePathEntity')
|
|
|
+ NodePath.NodePath.__init__(self, node)
|
|
|
Entity.Entity.__init__(self, level, entId)
|
|
|
- self.setName(str(self))
|
|
|
- privNodePathImpl.initNodePathAttribs(self)
|
|
|
+ NodePathAttribs.initNodePathAttribs(self)
|
|
|
|
|
|
def destroy(self):
|
|
|
+ NodePathAttribs.destroy(self)
|
|
|
Entity.Entity.destroy(self)
|
|
|
- privNodePathImpl.destroy(self)
|
|
|
-
|
|
|
- def getNodePath(self):
|
|
|
- return self
|
|
|
+ self.removeNode()
|
|
|
|
|
|
+# This is a distributed version of NodePathEntity. It should not
|
|
|
+# be instantiated directly; distributed entities that are also NodePaths
|
|
|
+# may derive from this instead of DistributedEntity.
|
|
|
class DistributedNodePathEntity(DistributedEntity.DistributedEntity,
|
|
|
- privNodePathImpl):
|
|
|
- """This is a distributed version of NodePathEntity. It should not
|
|
|
- be instantiated directly; derive your client-side distEntity from
|
|
|
- this class instead of DistributedEntity."""
|
|
|
+ NodePath.NodePath, NodePathAttribs):
|
|
|
def __init__(self, cr):
|
|
|
DistributedEntity.DistributedEntity.__init__(self, cr)
|
|
|
- privNodePathImpl.__init__(self, 'DistributedNodePathEntity')
|
|
|
+ node = hidden.attachNewNode('DistributedNodePathEntity')
|
|
|
+ NodePath.NodePath.__init__(self, node)
|
|
|
|
|
|
def announceGenerate(self):
|
|
|
DistributedEntity.DistributedEntity.announceGenerate(self)
|
|
|
- privNodePathImpl.initNodePathAttribs(self)
|
|
|
+ NodePathAttribs.initNodePathAttribs(self)
|
|
|
|
|
|
- def destroy(self):
|
|
|
- DistributedEntity.DistributedEntity.destroy(self)
|
|
|
- privNodePathImpl.destroy(self)
|
|
|
+ def disable(self):
|
|
|
+ NodePathAttribs.destroy(self)
|
|
|
+ DistributedEntity.DistributedEntity.disable(self)
|
|
|
|
|
|
- def getNodePath(self):
|
|
|
- return self
|
|
|
+ def delete(self):
|
|
|
+ self.removeNode()
|
|
|
+ DistributedEntity.DistributedEntity.delete(self)
|