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