Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- (C) 2022 FoxInvest
- menu = {}
- scambi = {}
- semafori = {}
- scambiPos = {}
- scambiName = {}
- scambiStatus = {}
- semaforiPos = {}
- semaforiName = {}
- semaforiStatus = {}
- function clearAllTables()
- menu = {}
- scambi = {}
- semafori = {}
- scambiPos = {}
- scambiName = {}
- scambiStatus = {}
- semaforiPos = {}
- semaforiName = {}
- semaforiStatus = {}
- end
- function setMenu(tratte)
- local colori = {"gray", "lightGray", "gray", "lightGray", "gray", "lightGray"}
- term.setCursorPos(1, 1)
- for i, v in pairs(tratte) do
- local cursorX, cursorY = term.getCursorPos()
- term.setBackgroundColor(colors[colori[i]])
- term.setTextColor(colors.white)
- term.write(v)
- table.insert(menu, cursorX .. "," .. cursorX + #v)
- end
- end
- function split(s, delimiter)
- result = {}
- for match in (s..delimiter):gmatch("(.-)"..delimiter) do
- table.insert(result, match)
- end
- return result
- end
- function scambio(x, y, type, color)
- local scambio = {}
- table.insert(scambio, color)
- table.insert(scambio, x)
- table.insert(scambio, y)
- table.insert(scambio, type)
- table.insert(scambi, scambio)
- table.insert(scambiPos, x .. "," .. y)
- table.insert(scambiName, color)
- table.insert(scambiStatus, "false")
- end
- function semaforo(x, y, color)
- local semaforo = {}
- table.insert(semaforo, color)
- table.insert(semaforo, x)
- table.insert(semaforo, y)
- table.insert(semafori, semaforo)
- table.insert(semaforiPos, x .. "," .. y)
- table.insert(semaforiName, color)
- table.insert(semaforiStatus, "true")
- end
- function getSemaforoPosByName(color)
- return semaforiPos[getSemaforoNumberInArray(color)]
- end
- function getSemaforoNameByPos(x, y)
- for i, v in pairs(semaforiPos) do
- if (x .. "," .. y == v) then
- return semaforiName[i]
- end
- end
- return nil
- end
- function getSemaforoStatus(color)
- return semaforiStatus[getSemaforoNumberInArray(color)]
- end
- function getScambioPosByName(color)
- return scambiPos[getSegnaleNumberInArray(color)]
- end
- function getScambioTypeByName(color)
- return scambi[getSegnaleNumberInArray(color)][4]
- end
- function getScambioNameByPos(x, y)
- for i, v in pairs(scambiPos) do
- if (x .. "," .. y == v) then
- return scambiName[i]
- end
- end
- return nil
- end
- function viewScambi()
- for i, v in pairs(scambiName) do
- local dim = split(scambiPos[i], ",")
- local type = getScambioTypeByName(v)
- term.setCursorPos(tonumber(dim[1]), tonumber(dim[2]))
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- if isScambioDeviato(v) == "true" then
- term.write(type)
- else
- term.write("-")
- end
- end
- end
- function viewSemafori()
- for i, v in pairs(semaforiName) do
- local dim = split(semaforiPos[i], ",")
- term.setCursorPos(tonumber(dim[1]), tonumber(dim[2]))
- term.setTextColor(colors.white)
- if getSemaforoStatus(v) == "true" then
- term.setBackgroundColor(colors.green)
- term.write(" ")
- else
- term.setBackgroundColor(colors.red)
- term.write(" ")
- end
- end
- end
- function isScambioDeviato(color)
- return scambiStatus[getSegnaleNumberInArray(color)]
- end
- function getSegnaleNumberInArray(color)
- for i, v in pairs(scambiName) do
- if v == color then
- return i
- end
- end
- return false
- end
- function getSemaforoNumberInArray(color)
- for i, v in pairs(semaforiName) do
- if v == color then
- return i
- end
- end
- return false
- end
- function setScambio(color)
- local pos = split(getScambioPosByName(color), ',')
- term.setCursorPos(tonumber(pos[1]), tonumber(pos[2]))
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- local number = getSegnaleNumberInArray(color)
- if isScambioDeviato(color) == "true" then
- scambiStatus[number] = "false"
- else
- scambiStatus[number] = "true"
- end
- local actNumber = 0
- for i, v in pairs(scambiStatus) do
- if v == "true" then
- actNumber = actNumber + colors[scambiName[i]]
- end
- end
- rs.setBundledOutput("bottom", actNumber)
- end
- function setSemaforo(color)
- local pos = split(getSemaforoPosByName(color), ',')
- term.setCursorPos(tonumber(pos[1]), tonumber(pos[2]))
- term.setTextColor(colors.white)
- local number = getSemaforoNumberInArray(color)
- if getSemaforoStatus(color) == "true" then
- semaforiStatus[number] = "false"
- else
- semaforiStatus[number] = "true"
- end
- local actNumber = 0
- for i, v in pairs(semaforiStatus) do
- if v == "false" then
- actNumber = actNumber + colors[semaforiName[i]]
- end
- end
- rs.setBundledOutput("right", actNumber)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement