Source code for yyagl.gameobject

from direct.fsm.FSM import FSM
from direct.showbase.DirectObject import DirectObject
from yyagl.observer import Subject


[docs]class Colleague(Subject): eng = None def __init__(self, mediator): Subject.__init__(self) self.mediator = mediator # refactor: remove it
[docs] def destroy(self): self.mediator = None Subject.destroy(self)
[docs]class FsmColleague(FSM, Colleague): def __init__(self, mediator): FSM.__init__(self, self.__class__.__name__) Colleague.__init__(self, mediator)
[docs] def destroy(self): if self.state: self.cleanup() Colleague.destroy(self)
[docs]class EventColleague(Colleague, DirectObject):
[docs] def destroy(self): self.ignoreAll() Colleague.destroy(self)
[docs]class AudioColleague(Colleague): pass
[docs]class AiColleague(Colleague): pass
[docs]class GfxColleague(Colleague): pass
[docs]class GuiColleague(Colleague): pass
[docs]class LogicColleague(Colleague):
[docs] def on_start(self): pass
[docs]class PhysColleague(Colleague): pass
[docs]class GODirector: def __init__(self, tgt_obj, init_lst, end_cb): self.__obj = tgt_obj tgt_obj.attach(self.on_comp_blt) self.end_cb = end_cb self.completed = [False for _ in init_lst] self.pending = {} self.__init_lst = init_lst for idx, _ in enumerate(init_lst): self.__process_lst(tgt_obj, idx) def __process_lst(self, obj, idx): if not self.__init_lst[idx]: self.end_lst(idx) return comp_info = self.__init_lst[idx].pop(0) attr_name, cls, arguments = comp_info self.pending[cls.__name__] = idx setattr(obj, attr_name, cls(*arguments))
[docs] def on_comp_blt(self, obj): self.__process_lst(obj.mediator, self.pending[obj.__class__.__name__])
[docs] def end_lst(self, idx): self.completed[idx] = True if all(self.completed): if self.end_cb: self.end_cb() self.destroy()
[docs] def destroy(self): self.__obj.detach(self.on_comp_blt) self.__obj = self.end_cb = self.__init_lst = None
[docs]class GameObject(Subject): pass