Exemplo n.º 1
0
class Timer(Clock):
    def __init__(self, instanceId, sceneId=None):
        super(Clock, self).__init__()
        self.id = instanceId
        self.sceneId = sceneId
        self.instanceObj = None
        self.callback = None
        self.timerLimit = None
        self.scene = Scene(sceneId).getscene()

        if 'timer_instances' not in logic.globalDict:
            logic.globalDict['timer_instances'] = {}

    def load(self):
        instance = logic.globalDict['timer_instances'][self.id]
        self.sceneId = instance['scene_id']
        self.callback = instance['callback']
        self.scene = Scene(self.sceneId).getscene()
        self.timerLimit = instance['time_limit']
        self.instanceObj = ObjProperties().getObjByPropVal(
            'instance_id', self.id, self.scene.objects)
        Clock.__init__(self, self.instanceObj)

    def _addInstance(self):
        log.debug("Creating timer instance %s", self.id)
        obj = ObjProperties()
        idleInstanceList = obj.getPropObjGroup('timer_instance', self.scene, 0)
        idleInstanceObj = idleInstanceList[0]
        idleInstanceObj['instance_id'] = self.id
        self.scene.addObject(idleInstanceObj)
        timerObj = obj.getObjByPropVal('instance_id', self.id,
                                       self.scene.objects)
        return timerObj

    def _setGlobals(self):
        logic.globalDict['timer_instances'][self.id] = {
            'callback': self.callback,
            'scene_id': self.sceneId,
            'time_limit': self.timerLimit
        }

    def isAlive(self):
        return self.id in logic.globalDict['timer_instances']

    def destroy(self):
        log.debug("destroying timer instance %s", self.id)
        if not self.instanceObj:
            return
        self.instanceObj.endObject()
        del logic.globalDict['timer_instances'][self.id]

    def setTimer(self, time, func, *args, **kwargs):
        instanceObj = self._addInstance()
        self.timerLimit = time
        self.callback = lambda: func(*args, **kwargs)
        self.instanceObj = instanceObj
        self._setGlobals()
        Clock.__init__(self, instanceObj)
Exemplo n.º 2
0
def _attachBg(targetObj, col, sceneName, visible=True):
    from objproperties import ObjProperties
    from scene_helper import Scene

    scene = Scene(sceneName).getscene()
    bg = ObjProperties().getPropObjGroup('background_view', scene, 0)[0]
    bg['target_obj'] = str(targetObj)
    bg.visible = visible
    bg.color = col
    scene.addObject(bg)
    bg = ObjProperties().getObjByPropVal('target_obj', str(targetObj),
                                         scene.objects)
    bg.position = targetObj.position
    # push it back alittle
    bg.position[2] -= 0.4
    bg.setParent(targetObj)
Exemplo n.º 3
0
def loadCursorObjs():
    '''
    Loads all cursor objects from hidden layer into active layer.
    Cursors are parented to an empty cursor object and 
    visibility set to False.
    '''

    from objproperties import ObjProperties

    scene = Scene('HUD').getscene()
    parentCursor = getCursorObj()
    cursorList = ObjProperties().getPropObjGroup('mouse_pointer', scene, 0)

    for cursor in cursorList:
        cursor.visible = False
        scene.addObject(cursor, parentCursor)
        scene.objects[str(cursor)].setParent(parentCursor)