PeeWeeSweden

ComputerCraft.SJ

Oct 8th, 2013
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.30 KB | None | 0 0
  1. --[ VARS ]--
  2. monitor = peripheral.wrap("back")
  3. local monitorX,monitorY = term.getSize()
  4.  
  5. timeTable = {}
  6.  
  7. timeTable = {   {   {6.32,1,"Grottköping"}, --[ DEPARTURES ]--
  8.             {7.15,3,"Roffeborg"},
  9.             {7.25,3,"Roffeborg"},
  10.             {8.15,3,"Roffeborg"},
  11.             {8.28,3,"Hashtofta"},
  12.             {8.45,3,"Roffeborg"},
  13.             {9.12,3,"Roffeborg"},
  14.             {11.55,3,"Roffeborg"},
  15.             {15.15,1,"Petershus"},
  16.             {18.15,2,"Rökköping"},
  17.             {18.19,1,"Roffeborg"},
  18.             {19.37,3,"Roffeborg"},
  19.             {22.38,1,"Petershus"},
  20.         },
  21.         {   {12.31,1,"Grottköping"}, --[ ARRIVALS ]--
  22.             {14.55,3,"Roffeborg"},
  23.             {15.15,1,"Petershus"},
  24.             {18.11,2,"Rökköping"},
  25.             {18.11,1,"Roffeborg"},
  26.             {19.31,3,"Roffeborg"},
  27.             {22.38,1,"Petershus"},
  28.         }
  29.     }
  30.  
  31.  
  32. --[ FUNCTIONS ]--
  33. function writeInfo()
  34.     -- rensa skärmen
  35.     for i=5,18 do
  36.         term.setCursorPos(1,i)
  37.         term.clearLine()
  38.     end
  39.  
  40.     local lines = 0
  41.     local maxLines = 12
  42.  
  43.     -- [ DEPARTURES ]--
  44.     -- SKRIV BARA UT DE TÅG SOM INTE GÅTT ÄN
  45.     for i=1,#timeTable[1] do
  46.         if lines < maxLines then
  47.             local tMinutes = math.fmod (timeTable[1][i][1], 1) * 100/60
  48.             local tHours = math.floor (timeTable[1][i][1])
  49.             local tTime = tHours + tMinutes --skapar en float med tiden
  50.             local sTime = ""
  51.  
  52.             if os.time() < tTime then
  53.                 --formattera tiden
  54.                 if math.floor (timeTable[1][i][1]) < 10 then
  55.                     sTime = sTime.."0"
  56.                 end
  57.                 sTime = sTime..timeTable[1][i][1]
  58.                
  59.                 term.setCursorPos(2,5+lines)
  60.                 local line = string.format("%5s %2i %15s",
  61.                     sTime,
  62.                     timeTable[1][i][2],
  63.                     timeTable[1][i][3])
  64.                 write(line)
  65.                 lines = lines + 1
  66.             end
  67.         end
  68.     end
  69.     -- SKRIV UT TÅG FÖR IMORGON
  70.     for i=1,#timeTable[1] do
  71.         if lines < maxLines then
  72.             local tMinutes = math.fmod (timeTable[1][i][1], 1) * 100/60 --minuter
  73.             local tHours = math.floor (timeTable[1][i][1])
  74.             local tTime = tHours + tMinutes --skapar en float med tiden
  75.             local sTime = ""
  76.            
  77.             if os.time() > tTime then
  78.                 --formattera tiden
  79.                 if math.floor (timeTable[1][i][1]) < 10 then
  80.                     sTime = sTime.."0"
  81.                 end
  82.                 sTime = sTime..timeTable[1][i][1]
  83.  
  84.                 term.setCursorPos(1,5+lines)
  85.                 local line = string.format("*%5s %2i %15s",
  86.                     sTime,
  87.                     timeTable[1][i][2],
  88.                     timeTable[1][i][3])
  89.                
  90.                 write(line)
  91.                 lines = lines + 1      
  92.             end
  93.         end
  94.     end
  95.  
  96.     -- [ ARRIVALS ]--  
  97.     lines = 0
  98.     -- SKRIV BARA UT DE TÅG SOM INTE GÅTT ÄN
  99.     for i=1,#timeTable[2] do
  100.         if lines < maxLines then
  101.             local tMinutes = math.fmod (timeTable[2][i][1], 1) * 100/60
  102.             local tHours = math.floor (timeTable[2][i][1])
  103.             local tTime = tHours + tMinutes --skapar en float med tiden
  104.             local sTime = ""
  105.  
  106.             if os.time() < tTime then
  107.                 --formattera tiden
  108.                 if math.floor (timeTable[2][i][1]) < 10 then
  109.                     sTime = sTime.."0"
  110.                 end
  111.                 sTime = sTime..timeTable[2][i][1]
  112.                
  113.                 term.setCursorPos(27,5+lines)
  114.                 local line = string.format("%5s %2i %15s",
  115.                     sTime,
  116.                     timeTable[2][i][2],
  117.                     timeTable[2][i][3])
  118.                 write(line)
  119.                 lines = lines + 1
  120.             end
  121.         end
  122.     end
  123.     -- SKRIV UT TÅG FÖR IMORGON
  124.     for i=1,#timeTable[2] do
  125.         if lines < maxLines then
  126.             local tMinutes = math.fmod (timeTable[2][i][1], 1) * 100/60 --minuter
  127.             local tHours = math.floor (timeTable[2][i][1])
  128.             local tTime = tHours + tMinutes --skapar en float med tiden
  129.             local sTime = ""
  130.            
  131.             if os.time() > tTime then
  132.                 --formattera tiden
  133.                 if math.floor (timeTable[2][i][1]) < 10 then
  134.                     sTime = sTime.."0"
  135.                 end
  136.                 sTime = sTime..timeTable[2][i][1]
  137.  
  138.                 term.setCursorPos(26,5+lines)
  139.                 local line = string.format("*%5s %2i %15s",
  140.                     sTime,
  141.                     timeTable[2][i][2],
  142.                     timeTable[2][i][3])
  143.                
  144.                 write(line)
  145.                 lines = lines + 1      
  146.             end
  147.         end
  148.     end
  149. end
  150.  
  151. function cPrint(msg,yPos)
  152.     term.setCursorPos((monitorX-string.len(msg))/2, yPos)
  153.     write(msg)
  154. end
  155.  
  156. function updateBoard()
  157.     while true do
  158.         local sTime = ""
  159.         term.setCursorPos(1,1)
  160.         term.clearLine()
  161.         if math.floor (os.time()) < 10 then
  162.             sTime = sTime.."0"
  163.         end
  164.             sTime = sTime..textutils.formatTime(os.time(), true)
  165.         cPrint(sTime,1)
  166.         writeInfo()
  167.         sleep(1)
  168.     end
  169. end
  170.  
  171. function writeHeader()
  172.     term.setCursorPos(1,2)
  173.     print("DEPARTURES               ARRIVALS\n Time   # Destination     Time   # From")
  174. end
  175.  
  176. function clearMonitor()
  177.     monitor.setBackgroundColor(colors.green)
  178.     monitor.setTextColor(colors.yellow)
  179.     monitor.clear()
  180.     term.setCursorPos(1,1)
  181. end
  182.  
  183. --[ INIT, MAIN ]--
  184. term.redirect(monitor)
  185.  
  186. clearMonitor()
  187. writeHeader()
  188. updateBoard()
  189.  
  190. -- [ END ]--
  191. term.restore()
Advertisement
Add Comment
Please, Sign In to add comment