1+ walltimer = class (" walltimer" )
2+
3+ function walltimer :init (x , y , r )
4+ self .x = x
5+ self .y = y
6+ self .cox = x
7+ self .coy = y
8+
9+ self .outtable = {}
10+ self .lighted = false
11+ self .time = 1
12+ self .quad = 1
13+
14+ self .input1state = " off"
15+
16+ -- Input list
17+ self .r = {unpack (r )}
18+ table.remove (self .r , 1 )
19+ table.remove (self .r , 1 )
20+ -- TIME
21+ if # self .r > 0 and self .r [1 ] ~= " link" then
22+ self .time = tonumber (self .r [1 ])
23+ table.remove (self .r , 1 )
24+ end
25+
26+ self .timer = self .time
27+ end
28+
29+ function walltimer :link ()
30+ while # self .r > 3 do
31+ for j , w in pairs (outputs ) do
32+ for i , v in pairs (objects [w ]) do
33+ if tonumber (self .r [3 ]) == v .cox and tonumber (self .r [4 ]) == v .coy then
34+ v :addoutput (self , self .r [2 ])
35+ end
36+ end
37+ end
38+ table.remove (self .r , 1 )
39+ table.remove (self .r , 1 )
40+ table.remove (self .r , 1 )
41+ table.remove (self .r , 1 )
42+ end
43+ end
44+
45+ function walltimer :addoutput (a , t )
46+ table.insert (self .outtable , {a , t })
47+ end
48+
49+ function walltimer :update (dt )
50+ if self .lighted then
51+ self .quad = 2
52+ elseif self .timer == self .time then
53+ self .quad = 1
54+ else
55+ self .timer = self .timer + dt
56+ local div = self .time / 10
57+ for i = 1 , 9 do
58+ if i == math.floor (self .timer * (1 / div )) then
59+ self .quad = i + 1
60+ end
61+ end
62+
63+ if self .timer >= self .time then
64+ self :out (" off" )
65+ self .timer = self .time
66+ end
67+ end
68+ end
69+
70+ function walltimer :draw ()
71+ love .graphics .setColor (255 , 255 , 255 )
72+
73+ love .graphics .drawq (walltimerimg , walltimerquad [self .quad ], math.floor ((self .x - 1 - xscroll )* 16 * scale ), ((self .y - yscroll - 1 )* 16 - 8 )* scale , 0 , scale , scale )
74+ end
75+
76+ function walltimer :out (t )
77+ for i = 1 , # self .outtable do
78+ if self .outtable [i ][1 ].input then
79+ self .outtable [i ][1 ]:input (t , self .outtable [i ][2 ])
80+ end
81+ end
82+ end
83+
84+ function walltimer :input (t , input )
85+ if input == " power" then
86+ if t == " on" and self .input1state == " off" then
87+ self :out (" on" )
88+ self .timer = self .time
89+ self .lighted = true
90+ self .quad = 2
91+ elseif t == " off" and self .input1state == " on" then
92+ self .lighted = false
93+ self .timer = 0
94+ elseif t == " toggle" then
95+ self .timer = 0
96+ self .quad = 2
97+ self .lighted = false
98+ self :out (" on" )
99+ end
100+
101+ self .input1state = t
102+ end
103+ end
0 commit comments