File: plugin.py

package info (click to toggle)
snowballz 0.9.5.1-2
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 10,888 kB
  • ctags: 1,242
  • sloc: python: 7,511; makefile: 53; sh: 2
file content (112 lines) | stat: -rw-r--r-- 3,543 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import data
from textures import Texture

try:
    import networking
except ImportError:
    networking = None


class Emblem(object):
    def __init__(self, image_name, animate=False, offset=(0,0)):
        self.image_name = image_name
        self.animate = animate
        self.speed = 0.02
        self.offset = offset
        if self.animate:
            self.alpha = 0.5
        else:
            self.alpha = 1

    def doanimate(self):
        if self.animate:
            self.alpha += self.speed
            if self.alpha > 0.8:
                self.alpha = 0.8
                self.speed = -self.speed
            elif self.alpha < 0.4:
                self.alpha = 0.4
                self.speed = -self.speed

    def rendered(self, x, y):
        return data.Rendered(Texture.get(self.image_name),
                x+self.offset[0], y+self.offset[1], z=5, alpha=self.alpha)

    def draw(self, x, y):
        """ Appends a rendered to the data draw buffer. Does not render immediately. """
        data.draw_buffer.append(self.rendered(x,y))


class BaseDynamicMapObject(object):
    def __init__(self, image_name, position, hidden=True, obstruction=False,
                minimapimage=None, animate=False):
        self.minimapimage = minimapimage
        self.image_name = image_name
        self.position = position
        self.hidden = hidden
        self.obstruction = obstruction
        data.map.add_dynamic_object(self)

        self.animate = animate
        self.speed = 0.02
        if self.animate:
            self.alpha = 0.5
        else:
            self.alpha = 1

    def doanimate(self):
        if self.animate:
            self.alpha += self.speed
            if self.alpha > 0.8:
                self.alpha = 0.8
                self.speed = -self.speed
            elif self.alpha < 0.4:
                self.alpha = 0.4
                self.speed = -self.speed

    def minimapicon(self):
        return data.Rendered(Texture.get(self.minimapimage),
                self.position[0], -self.position[1], alpha=self.alpha)
    minimapicon = property(minimapicon)

    def destroy(self):
        data.map.remove_dynamic_object(self)


class DynamicMapObject(BaseDynamicMapObject):
    def alert_creation(self, to="*", exclude=()):
        if not networking:
            return
        m = networking.MCreateDynamicMapObject(self.dmo_id, self.image_name,
                self.position, self.obstruction, self.hidden, self.minimapimage)
        networking.send(m, to=to, exclude=exclude)

    #def destroy(self):
        #BaseDynamicMapObject.destroy(self)
        #self.call_remote("destroy")

    #def _set_position(self, p):
        #if not hasattr(self, '_position'):
            #self._position = p
        #elif p != self.position:
            #self._position = p
            #self.call_remote("position", p)
    #position = property((lambda self:self._position), _set_position)

    def _set_hidden(self, h):
        if not hasattr(self, '_hidden'):
            self._hidden = h
        elif h != self.hidden:
            self._hidden = h
            if networking:
                networking.send(networking.MDMOHidden(self.dmo_id, h))
    hidden = property((lambda self:self._hidden), _set_hidden)

    #def getStateToCacheAndObserveFor(self, perspective, observer):
        #self.observers.append(observer)
        #d = {}
        #for key in ("image_name", "position", "hidden", "obstruction",
                #"minimapimage", "animate"):
            #d[key] = getattr(self, key)
        #return d