Guest User

startup

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