View difference between Paste ID: 3ibVzrZH and HJnw0Fa4
SHOW: | | - or go back to the newest paste.
1
-- RGR - Tabellone partenze (e in futuro arrivi) treni alla stazione
2
-- (C) 2026 interSex S.p.A.
3
4
-- Carica o genera la configurazione
5-
screen_side = "bottom"
5+
if fs.exists("config") == true then
6-
station_name = "New Radeon Centrale"
6+
    local h = fs.open("config", "r")
7-
station_code = "S0001"
7+
    ref_config = textutils.unserialize(h.readAll())
8
    h.close()
9
else
10
    print("Per favore, inserisci il lato dello schermo:")
11
    local ref_side = read()
12
    print("Ora inserisci il nome della stazione:")
13
    local ref_name = read()
14
    print("Ora inserisci il codice SGI della stazione:")
15
    local ref_code = read()
16
    print("Grazie!")
17
    local h = fs.open("config", "w")
18
    local obj = {side=ref_side, name=ref_name, code=ref_code}
19
    h.write(textutils.serialize(obj))
20
    h.close()
21
    print("Configurazione salvata con successo!")
22
    print("Riavvio il computer...")
23
    sleep(2)
24
    os.reboot()
25
end
26
27
-- Aggiorna lo script
28
shell.run("rm startup")
29
shell.run("pastebin get 3ibVzrZH startup")
30
 
31
-- Variabili da popolare
32
screen_side = ref_config.side
33
station_name = ref_config.name
34
station_code = ref_config.code
35
large_mode = true
36
reduced = true
37
target_width = 55
38
39
if reduced then
40
    target_width = 39
41
end
42
 
43
-- Recupero periferiche
44
screen = peripheral.wrap(screen_side)
45
46
screen.setTextScale(1)
47-
if height < 10 then
47+
48
-- Verifichiamo le specifiche
49
width, height  = screen.getSize()
50
51
local scale = (width/target_width)
52
53
scale = scale + 0.24
54-
    sfondo(colors.gray)
54+
55
if scale < 0.5 then
56
    scale = 0.5
57
end
58
59
screen.setTextScale(scale)
60
width, height = screen.getSize()
61
62
if width < target_width then
63
    scale = scale - 0.44
64
    screen.setTextScale(scale)
65
    width, height = screen.getSize()
66
end
67
 
68
if width < target_width then
69
    -- Adjust scale
70
    print("DIMENSIONI TROPPO PICCOLE ANCHE CON SCALA SISTEMATA! "..width)
71
    exit()
72
end
73
 
74
if height < 6 then
75
    print("DIMENSIONI TROPPO PICCOLE! (y) "..height)
76
    exit()
77
end
78
 
79
-- Definizione funzioni (copiate da lego11 obv)
80
function clear()
81
    sfondo(colors.black)
82
    screen.clear()
83
    screen.setCursorPos(1, 1)
84
end
85
 
86
function clearRed()
87
    sfondo(colors.red)
88
    screen.clear()
89
    screen.setCursorPos(1, 1)
90
end
91
 
92
function colore(sfumatura)
93
    screen.setTextColour(sfumatura)
94
end
95
 
96
function sfondo(sfumaturaSfondo)
97
    screen.setBackgroundColour(sfumaturaSfondo)
98
end
99
 
100
function fineColore()
101
    screen.setTextColour(colours.white)
102
end
103
 
104
function fineSfondo()
105
    screen.setBackgroundColour(colours.black)
106
end
107
 
108
-- IMPLEMENTAZIONE DEL DRAWFILLEDBOX
109
local function drawPixelInternal(xPos, yPos)
110
    screen.setCursorPos(xPos, yPos)
111
    screen.write(" ")
112
end
113
 
114
local tColourLookup = {}
115
for n = 1, 16 do
116
    tColourLookup[string.byte("0123456789abcdef", n, n)] = 2 ^ (n - 1)
117
end
118
 
119
function drawFilledBox(startX, startY, endX, endY, nColour)
120
    if type(startX) ~= "number" or type(startX) ~= "number" or type(endX) ~= "number" or type(endY) ~= "number" or
121
        (nColour ~= nil and type(nColour) ~= "number") then
122
        error("Expected startX, startY, endX, endY, colour", 2)
123
    end
124
 
125
    startX = math.floor(startX)
126
    startY = math.floor(startY)
127
    endX = math.floor(endX)
128
    endY = math.floor(endY)
129
 
130
    if nColour then
131
        screen.setBackgroundColor(nColour)
132
    end
133
    if startX == endX and startY == endY then
134
        drawPixelInternal(startX, startY)
135
        return
136
    end
137
 
138
    local minX = math.min(startX, endX)
139
    if minX == startX then
140
        minY = startY
141
        maxX = endX
142
        maxY = endY
143
    else
144
        minY = endY
145
        maxX = startX
146
        maxY = startY
147
    end
148
 
149
    for x = minX, maxX do
150
        for y = minY, maxY do
151
            drawPixelInternal(x, y)
152
        end
153
    end
154
end
155
 
156
function titolo(testo)
157
    drawFilledBox(1, 1, width, 1, colors.yellow)
158
    screen.setCursorPos((width - #testo) / 2, 1)
159
    colore(colors.black)
160-
        drawFilledBox(1, 2, width, 2, colors.gray)
160+
161
    sfondo(colors.black)
162
end
163
164
spazio_usato = 0
165
function scriviInSpazio(x, y, localwidth, testo, align)
166
    spazio_usato = spazio_usato + localwidth
167
168
    if align == true then
169
        screen.setCursorPos(x + (localwidth - #testo) / 2, y)
170
    else
171
        screen.setCursorPos(x, y)
172
    end
173
    screen.write(testo)
174
end
175
 
176
while true do
177
    -- Richiediamo i dati
178
    local data = textutils.unserialize(http.get("https://rgr.rgbcraft.com/api/cc/tabellone.php?station="..station_code).readAll())
179
    local gray = true
180
 
181
    clear()
182
    titolo(station_name.." - Partenze")
183
184
    if large_mode == false then
185
        drawFilledBox(1, 2, width, 2, colors.yellow)
186
    else
187
        drawFilledBox(1, 2, width, 2, colors.black)
188
        colore(colors.yellow)
189
    end
190
191
    if reduced == false then
192
        scriviInSpazio(1, 2, 7, "    ", true)
193
    else
194
        spazio_usato = 1
195
    end
196
197
    pos_dest = width-7-7-20
198
199
    if reduced then
200
        pos_dest = width-7-7-5
201-
                drawFilledBox(1, row, width, row, colors.gray)
201+
202
203
    scriviInSpazio(spazio_usato, 2, 8, "Numero", true)
204
    scriviInSpazio(spazio_usato, 2, 7, "Ora", true)
205
    scriviInSpazio(spazio_usato, 2, pos_dest, "Destinazione", true)
206-
            drawFilledBox(1, row, width, row, colors.gray)
206+
207
208
    if reduced == false then
209
        scriviInSpazio(spazio_usato, 2, 5, "Rit", true)
210
        scriviInSpazio(spazio_usato, 2, 5, "   ", true)
211
    end
212
213
    spazio_usato = 0
214
215
    for k, train in pairs(data.trains) do
216
        local row = k+2
217
218
        if row >= height-1 then
219
            break
220
        end
221
222
        if large_mode == false then
223
            if gray == false then
224
                drawFilledBox(1, row, width, row, colors.yellow)
225
                colore(colors.black)
226
                gray = true
227
            else
228
                drawFilledBox(1, row, width, row, colors.black)
229
                colore(colors.white)
230
                gray = false  
231
            end
232
        else
233
            drawFilledBox(1, row, width, row, colors.black)
234
            colore(colors.yellow)
235
        end
236
237
        if reduced == false then
238
            scriviInSpazio(1, row, 7, train.company, true)
239
        else
240
            spazio_usato = 1
241
        end
242
        scriviInSpazio(spazio_usato, row, 8, train.classification.." "..tostring(train.number), true)
243
        scriviInSpazio(spazio_usato, row, 7, train.time, true)
244
245-
        sfondo(colors.gray)
245+
246
            scriviInSpazio(spazio_usato, row, pos_dest, " "..train.destination, false)
247
        else
248
            scriviInSpazio(spazio_usato, row, pos_dest, "  "..train.destination, false)
249
        end
250-
        colore(colors.gray)
250+
251
252
        if reduced == false then
253
            scriviInSpazio(spazio_usato, row, 5, train.delay, true)
254
            scriviInSpazio(spazio_usato, row, 5, train.departing_ico, true)
255
        end
256
257
        spazio_usato = 0
258
    end
259
260
    -- Write message
261
    message = data.message
262
    pool = message.."  "..message.."  "..message.."  "..message
263
    message_index = 0
264
    speed = 0.18
265
    spent = 0
266
    name = "interSex S.p.A."
267
268
    while spent < 10 do
269
        -- Set pos at the end
270
        screen.setCursorPos(1, height)
271
        colore(colors.yellow)
272
        sfondo(colors.black)
273
        screen.write(string.sub(message, message_index, message_index + width-#name))
274
275
        -- interSex S.p.A.
276
        screen.setCursorPos(width-#name+1, height)
277
        colore(colors.black)
278
        sfondo(colors.yellow)
279
        screen.write(name)
280
281
        message_index = message_index + 1
282
        spent = spent + speed
283
        sleep(speed)
284
    end
285
 
286
    --screen.write(textutils.serialize(data))
287
 
288
    --sleep(10)
289
end