aboutsummaryrefslogtreecommitdiff
path: root/behaviors/XYMove.py
blob: 11cee96dfe45cda1972c40cda9bc5220da65b393 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from operationscore.Behavior import *
import util.Geo as Geo
class XYMove(Behavior):
    """XYMove is a behavior designed to be used as a recursive hook to ResponseMover to move pixels by
    XStep and YStep.  As XStep and YStep are maintained in the responses itself, they can be
    modulated to facilitate, acceleration, modulation, bouncing, etc.  Specify:
    <XStep> -- the starting XStep
    <YStep> -- the starting YStep
    """

    def processResponse(self, sensor, recurs):
        ret = []
        for loc in sensor:
            oploc = dict(loc)
            self.insertStepIfMissing(oploc)
            oploc['Location'] = Geo.addLocations((oploc['XStep'], oploc['YStep']), oploc['Location']) 
            ret.append(oploc)
        return (ret, []) 
    def insertStepIfMissing(self, data):
        if not 'XStep' in data:
            data['XStep'] = self['XStep']
        if not 'YStep' in data:
            data['YStep'] = self['YStep']