2019-11-02 17:27:54 -05:00
|
|
|
from direct.directnotify import DirectNotifyGlobal
|
|
|
|
|
|
|
|
class EntityCreatorBase:
|
|
|
|
notify = DirectNotifyGlobal.directNotify.newCategory('EntityCreator')
|
|
|
|
|
|
|
|
def __init__(self, level):
|
|
|
|
self.level = level
|
|
|
|
self.entType2Ctor = {}
|
|
|
|
|
|
|
|
def createEntity(self, entId):
|
|
|
|
entType = self.level.getEntityType(entId)
|
2019-12-30 00:00:16 -06:00
|
|
|
if entType not in self.entType2Ctor:
|
2019-11-02 17:27:54 -05:00
|
|
|
self.notify.error('unknown entity type: %s (ent%s)' % (entType, entId))
|
|
|
|
ent = self.doCreateEntity(self.entType2Ctor[entType], entId)
|
|
|
|
return ent
|
|
|
|
|
|
|
|
def getEntityTypes(self):
|
2019-12-30 00:00:16 -06:00
|
|
|
return list(self.entType2Ctor.keys())
|
2019-11-02 17:27:54 -05:00
|
|
|
|
|
|
|
def privRegisterType(self, entType, ctor):
|
2019-12-30 00:00:16 -06:00
|
|
|
if entType in self.entType2Ctor:
|
2019-11-02 17:27:54 -05:00
|
|
|
self.notify.debug('replacing %s ctor %s with %s' % (entType, self.entType2Ctor[entType], ctor))
|
|
|
|
self.entType2Ctor[entType] = ctor
|
|
|
|
|
|
|
|
def privRegisterTypes(self, type2ctor):
|
2019-12-30 00:00:16 -06:00
|
|
|
for entType, ctor in list(type2ctor.items()):
|
2019-11-02 17:27:54 -05:00
|
|
|
self.privRegisterType(entType, ctor)
|