Advertisement
FoxWorn3365

RFI - SCTF Funzioni

Jul 20th, 2022 (edited)
961
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- (C) 2022 FoxInvest
  2. menu = {}
  3. scambi = {}
  4. semafori = {}
  5. scambiPos = {}
  6. scambiName = {}
  7. scambiStatus = {}
  8. semaforiPos = {}
  9. semaforiName = {}
  10. semaforiStatus = {}
  11.  
  12. function clearAllTables()
  13.   menu = {}
  14.   scambi = {}
  15.   semafori = {}
  16.   scambiPos = {}
  17.   scambiName = {}
  18.   scambiStatus = {}
  19.   semaforiPos = {}
  20.   semaforiName = {}
  21.   semaforiStatus = {}
  22. end
  23.  
  24. function setMenu(tratte)
  25.   local colori = {"gray", "lightGray", "gray", "lightGray", "gray", "lightGray"}
  26.   term.setCursorPos(1, 1)
  27.   for i, v in pairs(tratte) do
  28.     local cursorX, cursorY = term.getCursorPos()
  29.     term.setBackgroundColor(colors[colori[i]])
  30.     term.setTextColor(colors.white)
  31.     term.write(v)
  32.     table.insert(menu, cursorX .. "," .. cursorX + #v)
  33.   end
  34. end
  35.  
  36. function split(s, delimiter)
  37.   result = {}
  38.   for match in (s..delimiter):gmatch("(.-)"..delimiter) do
  39.     table.insert(result, match)
  40.   end
  41.   return result
  42. end
  43.  
  44. function scambio(x, y, type, color)
  45.   local scambio = {}
  46.   table.insert(scambio, color)
  47.   table.insert(scambio, x)
  48.   table.insert(scambio, y)
  49.   table.insert(scambio, type)
  50.   table.insert(scambi, scambio)
  51.   table.insert(scambiPos, x .. "," .. y)
  52.   table.insert(scambiName, color)
  53.   table.insert(scambiStatus, "false")
  54. end
  55.  
  56. function semaforo(x, y, color)
  57.   local semaforo = {}
  58.   table.insert(semaforo, color)
  59.   table.insert(semaforo, x)
  60.   table.insert(semaforo, y)
  61.   table.insert(semafori, semaforo)
  62.   table.insert(semaforiPos, x .. "," .. y)
  63.   table.insert(semaforiName, color)
  64.   table.insert(semaforiStatus, "true")
  65. end
  66.  
  67. function getSemaforoPosByName(color)
  68.   return semaforiPos[getSemaforoNumberInArray(color)]
  69. end
  70.  
  71. function getSemaforoNameByPos(x, y)
  72.   for i, v in pairs(semaforiPos) do
  73.     if (x .. "," .. y == v) then
  74.       return semaforiName[i]
  75.     end
  76.   end
  77.   return nil
  78. end
  79.  
  80. function getSemaforoStatus(color)
  81.   return semaforiStatus[getSemaforoNumberInArray(color)]
  82. end
  83.  
  84. function getScambioPosByName(color)
  85.   return scambiPos[getSegnaleNumberInArray(color)]
  86. end
  87.  
  88. function getScambioTypeByName(color)
  89.   return scambi[getSegnaleNumberInArray(color)][4]
  90. end
  91.  
  92. function getScambioNameByPos(x, y)
  93.   for i, v in pairs(scambiPos) do
  94.     if (x .. "," .. y == v) then
  95.       return scambiName[i]
  96.     end
  97.   end
  98.   return nil
  99. end
  100.  
  101. function viewScambi()
  102.   for i, v in pairs(scambiName) do
  103.     local dim = split(scambiPos[i], ",")
  104.     local type = getScambioTypeByName(v)
  105.     term.setCursorPos(tonumber(dim[1]), tonumber(dim[2]))
  106.     term.setTextColor(colors.white)
  107.     term.setBackgroundColor(colors.black)
  108.     if isScambioDeviato(v) == "true" then
  109.       term.write(type)
  110.     else
  111.       term.write("-")
  112.     end
  113.   end
  114. end
  115.  
  116. function viewSemafori()
  117.   for i, v in pairs(semaforiName) do
  118.     local dim = split(semaforiPos[i], ",")
  119.     term.setCursorPos(tonumber(dim[1]), tonumber(dim[2]))
  120.     term.setTextColor(colors.white)
  121.     if getSemaforoStatus(v) == "true" then
  122.       term.setBackgroundColor(colors.green)
  123.       term.write(" ")
  124.     else
  125.       term.setBackgroundColor(colors.red)
  126.       term.write(" ")
  127.     end
  128.   end
  129. end
  130.  
  131. function isScambioDeviato(color)
  132.   return scambiStatus[getSegnaleNumberInArray(color)]
  133. end
  134.  
  135. function getSegnaleNumberInArray(color)
  136.   for i, v in pairs(scambiName) do
  137.     if v == color then
  138.       return i
  139.     end
  140.   end
  141.   return false
  142. end
  143.  
  144. function getSemaforoNumberInArray(color)
  145.   for i, v in pairs(semaforiName) do
  146.     if v == color then
  147.       return i
  148.     end
  149.   end
  150.   return false
  151. end
  152.  
  153. function setScambio(color)
  154.   local pos = split(getScambioPosByName(color), ',')
  155.   term.setCursorPos(tonumber(pos[1]), tonumber(pos[2]))
  156.   term.setTextColor(colors.white)
  157.   term.setBackgroundColor(colors.black)
  158.   local number = getSegnaleNumberInArray(color)
  159.   if isScambioDeviato(color) == "true" then
  160.     scambiStatus[number] = "false"
  161.   else
  162.     scambiStatus[number] = "true"
  163.   end
  164.   local actNumber = 0
  165.   for i, v in pairs(scambiStatus) do
  166.     if v == "true" then
  167.       actNumber = actNumber + colors[scambiName[i]]
  168.     end
  169.   end
  170.   rs.setBundledOutput("bottom", actNumber)
  171. end
  172.  
  173. function setSemaforo(color)
  174.   local pos = split(getSemaforoPosByName(color), ',')
  175.   term.setCursorPos(tonumber(pos[1]), tonumber(pos[2]))
  176.   term.setTextColor(colors.white)
  177.   local number = getSemaforoNumberInArray(color)
  178.   if getSemaforoStatus(color) == "true" then
  179.     semaforiStatus[number] = "false"
  180.   else
  181.     semaforiStatus[number] = "true"
  182.   end
  183.   local actNumber = 0
  184.   for i, v in pairs(semaforiStatus) do
  185.     if v == "false" then
  186.       actNumber = actNumber + colors[semaforiName[i]]
  187.     end
  188.   end
  189.   rs.setBundledOutput("right", actNumber)
  190. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement