/traderous

To get this branch, use:
bzr branch http://9ix.org/bzr/traderous

« back to all changes in this revision

Viewing changes to wrap_tile.lua

  • Committer: Josh C
  • Date: 2013-05-13 21:31:23 UTC
  • Revision ID: josh@9ix.org-20130513213123-n21tkmyb2u7xcjtz
monkey patch group to add onRemove hook.  remove mirrors on remove.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 
30
30
               if self.x ~= mirrorX then
31
31
                  if not self.xMirror then
32
 
                     --print('creating mirror: X='..mirrorX..' Y='..mirrorY)
 
32
                     --print('creating mirror: X='..xMirrorX..' Y='..xMirrorY)
33
33
 
34
 
                     self.xMirror = Mirror:new{ of = self, image = self.image }
35
 
                     the.mirrors:add(self.xMirror)
 
34
                     self.xMirror = Tile:new{ image = self.image }
 
35
                     the.app.view:add(self.xMirror)
36
36
                  end
37
37
 
38
38
                  self.xMirror.x = mirrorX
39
39
                  self.xMirror.y = self.y
40
40
                  self.xMirror.rotation = self.rotation
41
 
                  self.xMirror.scale = self.scale
42
41
               elseif self.xMirror then
43
 
                  if self.type == 'bullet' then
44
 
                     --print('pruning bullet')
45
 
                  end
46
 
                  the.mirrors:remove(self.xMirror)
47
 
                  self.xMirror.of = nil -- break circular reference
 
42
                  the.app.view:remove(self.xMirror)
48
43
                  self.xMirror = nil
49
44
                  -- die?
50
45
               end
51
46
 
52
47
               if self.y ~= mirrorY then
53
48
                  if not self.yMirror then
54
 
                     --print('creating mirror: X='..mirrorX..' Y='..mirrorY)
 
49
                     --print('creating mirror: X='..yMirrorX..' Y='..yMirrorY)
55
50
 
56
 
                     self.yMirror = Mirror:new{ of = self, image = self.image }
57
 
                     the.mirrors:add(self.yMirror)
 
51
                     self.yMirror = Tile:new{ image = self.image }
 
52
                     the.app.view:add(self.yMirror)
58
53
                  end
59
54
 
60
55
                  self.yMirror.x = self.x
61
56
                  self.yMirror.y = mirrorY
62
57
                  self.yMirror.rotation = self.rotation
63
 
                  self.yMirror.scale = self.scale
64
58
               elseif self.yMirror then
65
 
                  if self.type == 'bullet' then
66
 
                     --print('pruning bullet')
67
 
                  end
68
 
                  the.mirrors:remove(self.yMirror)
69
 
                  self.yMirror.of = nil -- break circular reference
 
59
                  the.app.view:remove(self.yMirror)
70
60
                  self.yMirror = nil
71
61
                  -- die?
72
62
               end
73
63
 
74
64
               if self.x ~= mirrorX and self.y ~= mirrorY then
75
65
                  if not self.xyMirror then
76
 
                     --print('creating mirror: X='..mirrorX..' Y='..mirrorY)
 
66
                     --print('creating mirror: X='..xyMirrorX..' Y='..xyMirrorY)
77
67
 
78
 
                     self.xyMirror = Mirror:new{ of = self, image = self.image }
79
 
                     the.mirrors:add(self.xyMirror)
 
68
                     self.xyMirror = Tile:new{ image = self.image }
 
69
                     the.app.view:add(self.xyMirror)
80
70
                  end
81
71
 
82
72
                  self.xyMirror.x = mirrorX
83
73
                  self.xyMirror.y = mirrorY
84
74
                  self.xyMirror.rotation = self.rotation
85
 
                  self.xyMirror.scale = self.scale
86
75
               elseif self.xyMirror then
87
 
                  if self.type == 'bullet' then
88
 
                     --print('pruning bullet')
89
 
                  end
90
 
                  the.mirrors:remove(self.xyMirror)
91
 
                  self.xyMirror.of = nil -- break circular reference
 
76
                  the.app.view:remove(self.xyMirror)
92
77
                  self.xyMirror = nil
93
78
                  -- die?
94
79
               end
95
80
            end,
96
81
   onRemove = function(self)
97
82
                 if self.xMirror then
98
 
                    if self.type == 'bullet' then
99
 
                       --print('removing bullet, so removing mirror')
100
 
                    end
101
 
                    the.mirrors:remove(self.xMirror)
102
 
                    self.xMirror.of = nil -- break circular reference
103
 
                    self.xMirror = nil
 
83
                    the.app.view:remove(self.xMirror)
104
84
                 end
105
85
 
106
86
                 if self.yMirror then
107
 
                    if self.type == 'bullet' then
108
 
                       --print('removing bullet, so removing mirror')
109
 
                    end
110
 
                    the.mirrors:remove(self.yMirror)
111
 
                    self.yMirror.of = nil -- break circular reference
112
 
                    self.yMirror = nil
 
87
                    the.app.view:remove(self.yMirror)
113
88
                 end
114
89
 
115
90
                 if self.xyMirror then
116
 
                    if self.type == 'bullet' then
117
 
                       --print('removing bullet, so removing mirror')
118
 
                    end
119
 
                    the.mirrors:remove(self.xyMirror)
120
 
                    self.xyMirror.of = nil -- break circular reference
121
 
                    self.xyMirror = nil
 
91
                    the.app.view:remove(self.xyMirror)
122
92
                 end
123
93
              end,
124
94
   update = function (self, elapsed)
125
95
               Tile.update(self, elapsed)
126
96
 
127
97
               self:wrap()
128
 
               if self.active then
129
 
                  self:reflect()
130
 
               end
 
98
               self:reflect()
 
99
 
 
100
               -- TODO: make sure mirrors are cleaned up when we are
 
101
               -- killed / removed from view
131
102
            end
132
103
}
 
 
b'\\ No newline at end of file'