Source

pygamekit / animation.pxi

Full commit

cdef enum akAnimationEvalMode:
    AK_ACT_LOOP
    AK_ACT_END
    AK_ACT_INVERSE

# This wraps gkAnimationPlayer
cdef class Animation(pywrap):
    
    cdef gkGameObject *ob
    cdef public Real blend_time
    cdef public int priority
    
    def play(self):
        self.ob.playAnimation(
            <gkAnimationPlayer*>self._p,
            self.blend_time, AK_ACT_END, self.priority)
        
    def stop(self):
        self.ob.stopAnimation(<gkAnimationPlayer*>self._p)
        
    property weight:
        def __get__(self):
            return (<gkAnimationPlayer*>self._p).getWeight()
        def __set__(self,  v):
            (<gkAnimationPlayer*>self._p).setWeight(v)
            
    property length:
        def __get__(self):
            return (<gkAnimationPlayer*>self._p).getLength()
        #def __set__(self,  v):
            #(<gkAnimationPlayer*>self._p).setLength(v)
            
    property speed_factor:
        def __get__(self):
            return (<gkAnimationPlayer*>self._p).getSpeedFactor()
        def __set__(self, v):
            (<gkAnimationPlayer*>self._p).setSpeedFactor(v)
    

cdef class AnimationList(pywrap):
        
    def aaa__dict__(self): # this should returna dict with all the animations, but it only returns the active one.
        cdef int hack1 "h;/*" = 0
        cdef gkAnimationsIterator it, hack2 "utHashTable<gkHashedString, gkAnimationPlayer*>::Iterator __pyx_v_it /**/"
        hack2 = (<gkGameObject*>self._p).getAnimations().iterator()
        
        cdef Animation a
        ret = {}
        
        while it.hasMoreElements():
            a = Animation().P(it.peekNextValue())
            a.ob = <gkGameObject*>self._p
            ret[it.peekNextKey().str().c_str()] = a
            it.next()
        
        return ret
        
    def __iter__(self):
        return self.__dict__().__iter__() #TODO: can be made more efficient
        
    def __getitem__(self,item):
        cdef Animation a
        cdef gkAnimationPlayer *ap
        ap = (<gkGameObject*>self._p).getAnimationPlayer(to_stdstring(item))
        if ap==NULL:
            ap = (<gkGameObject*>self._p).addAnimation(to_stdstring(item))
            if ap==NULL:
                return None
        a = Animation().P(ap)
        a.ob = <gkGameObject*>self._p
        return a

    def __len__(self):
        return (<gkGameObject*>self._p).getAnimations().size()