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