Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- RGR - Tabellone partenze (e in futuro arrivi) treni alla stazione
- -- (C) 2026 interSex S.p.A.
- -- Variabili da popolare
- screen_side = "bottom"
- station_name = "New Radeon Centrale"
- station_code = "S0001"
- large_mode = true
- reduced = true
- target_width = 55
- if reduced then
- target_width = 39
- end
- -- Recupero periferiche
- screen = peripheral.wrap(screen_side)
- screen.setTextScale(1)
- -- Verifichiamo le specifiche
- width, height = screen.getSize()
- local scale = (width/target_width)
- scale = scale + 0.24
- if scale < 0.5 then
- scale = 0.5
- end
- screen.setTextScale(scale)
- width, height = screen.getSize()
- if width < target_width then
- scale = scale - 0.44
- screen.setTextScale(scale)
- width, height = screen.getSize()
- end
- if width < target_width then
- -- Adjust scale
- print("DIMENSIONI TROPPO PICCOLE ANCHE CON SCALA SISTEMATA! "..width)
- exit()
- end
- if height < 10 then
- print("DIMENSIONI TROPPO PICCOLE! (y) "..height)
- exit()
- end
- -- Definizione funzioni (copiate da lego11 obv)
- function clear()
- sfondo(colors.gray)
- screen.clear()
- screen.setCursorPos(1, 1)
- end
- function clearRed()
- sfondo(colors.red)
- screen.clear()
- screen.setCursorPos(1, 1)
- end
- function colore(sfumatura)
- screen.setTextColour(sfumatura)
- end
- function sfondo(sfumaturaSfondo)
- screen.setBackgroundColour(sfumaturaSfondo)
- end
- function fineColore()
- screen.setTextColour(colours.white)
- end
- function fineSfondo()
- screen.setBackgroundColour(colours.black)
- end
- -- IMPLEMENTAZIONE DEL DRAWFILLEDBOX
- local function drawPixelInternal(xPos, yPos)
- screen.setCursorPos(xPos, yPos)
- screen.write(" ")
- end
- local tColourLookup = {}
- for n = 1, 16 do
- tColourLookup[string.byte("0123456789abcdef", n, n)] = 2 ^ (n - 1)
- end
- function drawFilledBox(startX, startY, endX, endY, nColour)
- if type(startX) ~= "number" or type(startX) ~= "number" or type(endX) ~= "number" or type(endY) ~= "number" or
- (nColour ~= nil and type(nColour) ~= "number") then
- error("Expected startX, startY, endX, endY, colour", 2)
- end
- startX = math.floor(startX)
- startY = math.floor(startY)
- endX = math.floor(endX)
- endY = math.floor(endY)
- if nColour then
- screen.setBackgroundColor(nColour)
- end
- if startX == endX and startY == endY then
- drawPixelInternal(startX, startY)
- return
- end
- local minX = math.min(startX, endX)
- if minX == startX then
- minY = startY
- maxX = endX
- maxY = endY
- else
- minY = endY
- maxX = startX
- maxY = startY
- end
- for x = minX, maxX do
- for y = minY, maxY do
- drawPixelInternal(x, y)
- end
- end
- end
- function titolo(testo)
- drawFilledBox(1, 1, width, 1, colors.yellow)
- screen.setCursorPos((width - #testo) / 2, 1)
- colore(colors.black)
- screen.write(testo)
- sfondo(colors.black)
- end
- spazio_usato = 0
- function scriviInSpazio(x, y, localwidth, testo, align)
- spazio_usato = spazio_usato + localwidth
- if align == true then
- screen.setCursorPos(x + (localwidth - #testo) / 2, y)
- else
- screen.setCursorPos(x, y)
- end
- screen.write(testo)
- end
- while true do
- -- Richiediamo i dati
- local data = textutils.unserialize(http.get("https://rgr.rgbcraft.com/api/cc/tabellone.php?station="..station_code).readAll())
- local gray = true
- clear()
- titolo(station_name.." - Partenze")
- if large_mode == false then
- drawFilledBox(1, 2, width, 2, colors.yellow)
- else
- drawFilledBox(1, 2, width, 2, colors.gray)
- colore(colors.yellow)
- end
- if reduced == false then
- scriviInSpazio(1, 2, 7, " ", true)
- else
- spazio_usato = 1
- end
- pos_dest = width-7-7-20
- if reduced then
- pos_dest = width-7-7-5
- end
- scriviInSpazio(spazio_usato, 2, 8, "Numero", true)
- scriviInSpazio(spazio_usato, 2, 7, "Ora", true)
- scriviInSpazio(spazio_usato, 2, pos_dest, "Destinazione", true)
- scriviInSpazio(spazio_usato, 2, 5, "Bin", true)
- if reduced == false then
- scriviInSpazio(spazio_usato, 2, 5, "Rit", true)
- scriviInSpazio(spazio_usato, 2, 5, " ", true)
- end
- spazio_usato = 0
- for k, train in pairs(data.trains) do
- local row = k+2
- if row >= height-1 then
- break
- end
- if large_mode == false then
- if gray == false then
- drawFilledBox(1, row, width, row, colors.yellow)
- colore(colors.black)
- gray = true
- else
- drawFilledBox(1, row, width, row, colors.gray)
- colore(colors.white)
- gray = false
- end
- else
- drawFilledBox(1, row, width, row, colors.gray)
- colore(colors.yellow)
- end
- if reduced == false then
- scriviInSpazio(1, row, 7, train.company, true)
- else
- spazio_usato = 1
- end
- scriviInSpazio(spazio_usato, row, 8, train.classification.." "..tostring(train.number), true)
- scriviInSpazio(spazio_usato, row, 7, train.time, true)
- if reduced then
- scriviInSpazio(spazio_usato, row, pos_dest, " "..train.destination, false)
- else
- scriviInSpazio(spazio_usato, row, pos_dest, " "..train.destination, false)
- end
- scriviInSpazio(spazio_usato, row, 5, train.platform, true)
- if reduced == false then
- scriviInSpazio(spazio_usato, row, 5, train.delay, true)
- scriviInSpazio(spazio_usato, row, 5, train.departing_ico, true)
- end
- spazio_usato = 0
- end
- -- Write message
- message = data.message
- pool = message.." "..message.." "..message.." "..message
- message_index = 0
- speed = 0.18
- spent = 0
- name = "interSex S.p.A."
- while spent < 10 do
- -- Set pos at the end
- screen.setCursorPos(1, height)
- colore(colors.yellow)
- sfondo(colors.gray)
- screen.write(string.sub(message, message_index, message_index + width-#name))
- -- interSex S.p.A.
- screen.setCursorPos(width-#name+1, height)
- colore(colors.gray)
- sfondo(colors.yellow)
- screen.write(name)
- message_index = message_index + 1
- spent = spent + speed
- sleep(speed)
- end
- --screen.write(textutils.serialize(data))
- --sleep(10)
- end
Advertisement
Add Comment
Please, Sign In to add comment