mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-20 05:54:54 -04:00
first rev
This commit is contained in:
parent
052ff3e8cf
commit
e78ae19bdb
29
direct/src/showbase/Factory.py
Executable file
29
direct/src/showbase/Factory.py
Executable file
@ -0,0 +1,29 @@
|
|||||||
|
from direct.directnotify.DirectNotifyGlobal import directNotify
|
||||||
|
|
||||||
|
class Factory:
|
||||||
|
"""This class manages a list of object types and their corresponding constructors.
|
||||||
|
Objects may be created on-demand from their type. Object types may be any hashable
|
||||||
|
piece of unique data (such as a string).
|
||||||
|
|
||||||
|
This class is intended to be derived from. Subclasses should call self._registerTypes
|
||||||
|
to set up type constructors."""
|
||||||
|
notify = directNotify.newCategory('Factory')
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self._type2ctor = {}
|
||||||
|
|
||||||
|
def create(self, type, *args, **kwArgs):
|
||||||
|
return self._type2ctor[type](*args, **kwArgs)
|
||||||
|
|
||||||
|
def _registerType(self, type, ctor):
|
||||||
|
if self._type2ctor.has_key(type):
|
||||||
|
self.notify.debug('replacing %s ctor %s with %s' %
|
||||||
|
(type, self._type2ctor[type], ctor))
|
||||||
|
self._type2ctor[type] = ctor
|
||||||
|
def _registerTypes(self, type2ctor):
|
||||||
|
for type, ctor in type2ctor.items():
|
||||||
|
self._registerType(type, ctor)
|
||||||
|
|
||||||
|
def nullCtor(self, *args, **kwArgs):
|
||||||
|
return None
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user