SHOW:
|
|
- or go back to the newest paste.
1 | os.loadAPI("json") | |
2 | local mn = peripheral.wrap("monitor_2") | |
3 | mn.setBackgroundColor(colors.white) | |
4 | mn.clear() | |
5 | local mnside = "monitor_2" -- monitor side | |
6 | str = http.get("http://worldtimeapi.org/api/timezone/Europe/Moscow").readAll() | |
7 | obj = json.decode(str) | |
8 | print(obj.datetime) | |
9 | value = obj.datetime | |
10 | ttt,h,min,sec,tt2 = string.match(value, "(%w*)T(%w+):(%w+):(%w+).(%w*)") | |
11 | local sx,sy = mn.getSize() | |
12 | local function clear() | |
13 | mn.clear() | |
14 | end | |
15 | local function sbc(clr) | |
16 | mn.setBackgroundColor(clr) | |
17 | end | |
18 | local function stc(clr) | |
19 | mn.setTextColor(clr) | |
20 | end | |
21 | local function scp(x, y) | |
22 | mn.setCursorPos(x,y) | |
23 | end | |
24 | local function sccp(y,txt) | |
25 | mn.setCursorPos(math.ceil((sx/2) - (txt:len() / 2)), y) | |
26 | end | |
27 | local function write(txt) | |
28 | mn.write(txt) | |
29 | end | |
30 | ||
31 | print("H "..h.." .MIN: "..min.." .SEC: "..sec) | |
32 | local tupiks = 3 | |
33 | local timesl = {} | |
34 | for i=1,tupiks do | |
35 | local file = fs.open("/dates/"..i,"r") | |
36 | timesl[i] = file.readAll() | |
37 | file.close() | |
38 | end | |
39 | local tmpl = 0 | |
40 | mn.setTextScale(1) | |
41 | -- gui | |
42 | local function drawmscr() | |
43 | for i=1,3 do | |
44 | for g=1,sx do | |
45 | scp(g,i) | |
46 | sbc(colors.lightBlue) | |
47 | write(" ") | |
48 | end | |
49 | end | |
50 | end | |
51 | local buttonsx5 = {} | |
52 | local buttonsy = {} | |
53 | local buttonback = {} | |
54 | buttonback[1] = 2 | |
55 | buttonback[2] = sy-2 | |
56 | local function parkbt(clr) | |
57 | scp(1,5) | |
58 | sbc(clr) | |
59 | write(" ") | |
60 | local txt = "Park" | |
61 | for i=1,txt:len() do | |
62 | scp(1+1,5) | |
63 | write(" ") | |
64 | end | |
65 | scp(1,5) | |
66 | write(txt) | |
67 | buttonsx5[1] = "1".."|"..tostring(txt:len()) | |
68 | buttonsy[1] = 5 | |
69 | end | |
70 | parkbt(colors.lightBlue) | |
71 | local scr = "start" | |
72 | local tpkbtx = {} | |
73 | local claimed = {} | |
74 | local tmpdd = 0 | |
75 | local tdays = 0 | |
76 | local function drawmain() | |
77 | mn.setBackgroundColor(colors.white) | |
78 | clear() | |
79 | parkbt(colors.lightBlue) | |
80 | drawmscr() | |
81 | for i=1,tupiks do | |
82 | scp(1,8+i) | |
83 | local file = fs.open("/dates/"..i,"r") | |
84 | tmpdd = file.readAll() | |
85 | file.close() | |
86 | local filec = fs.open("/days/"..i,"r") | |
87 | tdays = filec.readAll() | |
88 | write("T"..i..": "..tmpdd.."("..tdays..")") | |
89 | filec.close() | |
90 | end | |
91 | end | |
92 | drawmain() | |
93 | local function drawparkscr() | |
94 | mn.setBackgroundColor(colors.white) | |
95 | clear() | |
96 | drawmscr() | |
97 | parkbt(colors.lightBlue) | |
98 | for i=1,sx do | |
99 | scp(i,sy-2) | |
100 | sbc(colors.red) | |
101 | write(" ") | |
102 | end | |
103 | scp(2,sy-2) | |
104 | sbc(colors.red) | |
105 | write("Back") | |
106 | sbc(colors.white) | |
107 | scr = "park" | |
108 | scp(1,7) | |
109 | for i=1,tupiks do | |
110 | scp(1+(i*2),7) | |
111 | local file = fs.open("/dates/"..tostring(i),"r") | |
112 | if file then print("file") end | |
113 | if string.find(file.readLine(),"null") then | |
114 | sbc(colors.lime) | |
115 | claimed[i] = false | |
116 | else | |
117 | sbc(colors.green) | |
118 | claimed[i] = true | |
119 | end | |
120 | file.close() | |
121 | write(tostring(i)) | |
122 | tpkbtx[i] = 1+(i*2) | |
123 | end | |
124 | end | |
125 | local bt = 0 | |
126 | local selc = 0 | |
127 | function getclick() | |
128 | while true do | |
129 | bt = 0 | |
130 | event, side, xPos, yPos = os.pullEvent("monitor_touch") | |
131 | print(scr) | |
132 | if side == mnside then | |
133 | for i=1,#buttonsy do | |
134 | if yPos == buttonsy[i] then | |
135 | if yPos == 5 then | |
136 | for g=1,#buttonsx5 do | |
137 | local xs,xe = string.match(buttonsx5[g], "(%w+)|(%w+)") | |
138 | xs = tonumber(xs) | |
139 | xe = tonumber(xe) | |
140 | if (xs >= xPos) or (xPos <= xe) then | |
141 | if bt ~= 1 then | |
142 | bt = 1 | |
143 | parkbt(colors.blue) | |
144 | drawparkscr() | |
145 | else | |
146 | parkbt(colors.lightBlue) | |
147 | end | |
148 | end | |
149 | print(bt) | |
150 | end | |
151 | end | |
152 | elseif (yPos == 7) and (scr == "park") then | |
153 | selc = 0 | |
154 | for g=1,#tpkbtx do | |
155 | if xPos == tpkbtx[g] then | |
156 | selc = g | |
157 | print("tupik get: "..selc) | |
158 | if claimed[g] == false then | |
159 | local file = fs.open("/dates/"..g,"w") | |
160 | file.write(h..":"..min..":"..sec) | |
161 | file.close() | |
162 | claimed[g] = true | |
163 | drawmain() | |
164 | elseif claimed[g] == true then | |
165 | local file = fs.open("/dates/"..g,"w") | |
166 | file.write("null") | |
167 | file.close() | |
168 | claimed[g] = false | |
169 | drawmain() | |
170 | end | |
171 | end | |
172 | end | |
173 | elseif (yPos == buttonback[2]) and (scr == "park") then | |
174 | scr = "main" | |
175 | drawmain() | |
176 | end | |
177 | end | |
178 | end | |
179 | end | |
180 | end | |
181 | -- Timer | |
182 | local function counttime() | |
183 | while true do | |
184 | if sec == 59 then | |
185 | sec = 0 | |
186 | min = min + 1 | |
187 | end | |
188 | if min == 60 then | |
189 | min = 0 | |
190 | h = h + 1 | |
191 | sec = 0 | |
192 | end | |
193 | if h == 24 then | |
194 | h = 0 | |
195 | sec = 0 | |
196 | min = 0 | |
197 | end | |
198 | sleep(1) | |
199 | if (sec ~= 60) or (h ~= 24) or (min ~= 60) then | |
200 | sec = sec + 1 | |
201 | end | |
202 | sbc(colors.lightBlue) | |
203 | sccp(2,h..";"..min..":"..sec) | |
204 | write(" ".. h..":"..min..":"..sec) | |
205 | for i=1,#timesl do | |
206 | if timesl[i] == h..":"..min..":"..sec then | |
207 | local file = fs.open("/days/"..i,"r") | |
208 | tmpl = tonumber(file.readAll()) | |
209 | file.close() | |
210 | tmpl = tmpl + 1 | |
211 | local file = fs.open("/days/"..i,"w") | |
212 | print("Overwriting "..i.." with "..tmpl) | |
213 | file.write(tostring(tmpl)) | |
214 | drawmain() | |
215 | end | |
216 | end | |
217 | end | |
218 | end | |
219 | parallel.waitForAll(getclick,counttime) | |
220 |