local function channelList() channels = { [1] = "controller", [12] = "foresta builders", [13] = "foresta warehouse left", [14] = "foresta requests", [15] = "foresta warehouse right", [16] = "create rotation", [17] = "test1", [19] = "jeri pocket", [20] = "foresta info", [21] = "brookhaven wh1", [22] = "brookhaven builders", [23] = "brookhaven requests", [25] = "brookhaven wh2", [27] = "ae2 control", [28] = "brookhaven info" } return(channels) end local function uncraftables() uncraftables = {"domum_ornamentum", "mahoutsukai", "justdirethings"} return(uncraftables) end local function getID(computer) channels = channelList() local channel = 0 for id, name in pairs(channels) do if(name == computer) then channel = id end end return(channel) end local function getFunction(needID) channels = channelList() local purpose = " " for id, name in pairs(channels) do if(needID == id) then purpose = name end end return(purpose) end local function setMenuBar(monitor) navSpacing = " " backWriting = " < BACK " nextWriting = " NEXT > " homeWriting = " HOME " homeSpacing = " " maxX, maxY = monitor.getSize() startY = maxY - 3 for test = 1, maxX do monitor.setBackgroundColor(colors.white) monitor.setCursorPos(test, startY) monitor.write(" ") end startX = 1 startY = maxY - 2 monitor.setCursorPos(startX, startY) monitor.setBackgroundColor(colors.red) monitor.write(navSpacing) monitor.setCursorPos(startX, startY + 1) monitor.write(backWriting) monitor.setCursorPos(startX, startY + 2) monitor.write(navSpacing) startX = maxX - 7 monitor.setCursorPos(startX, startY) monitor.setBackgroundColor(colors.lime) monitor.write(navSpacing) monitor.setCursorPos(startX, startY + 1) monitor.write(nextWriting) monitor.setCursorPos(startX, startY + 2) monitor.write(navSpacing) startX = (maxX / 2) - 2 monitor.setCursorPos(startX, startY) monitor.setBackgroundColor(colors.lightBlue) monitor.write(homeSpacing) monitor.setCursorPos(startX, startY + 1) monitor.write(homeWriting) monitor.setCursorPos(startX, startY + 2) monitor.write(homeSpacing) end local function setDblMenuBar(monitor) monitor.setBackgroundColor(colors.black) monitor.clear() navSpacing = " " backWriting = " < BACK " nextWriting = " NEXT > " homeWriting = " HOME " homeSpacing = " " maxX, maxY = monitor.getSize() startY = 1 startX = 1 midY = 1 topSpacing = 0 bottomSpacing = 0 if (maxY % 2 == 0) then midY = maxY / 2 bottomSpacing = maxY / 2 topSpacing = bottomSpacing - 1 else midY = math.floor(maxY / 2) + 1 bottomSpacing = math.floor(maxY / 2) topSpacing = bottomSpacing end for a = 1, topSpacing do monitor.setCursorPos(startX, a) monitor.setBackgroundColor(colors.red) monitor.write(navSpacing) end monitor.setCursorPos(startX, midY) monitor.setBackgroundColor(colors.red) monitor.write(backWriting) for a = 1, bottomSpacing do monitor.setCursorPos(startX, a + midY) monitor.setBackgroundColor(colors.red) monitor.write(navSpacing) end startX = maxX - 7 for a = 1, topSpacing do monitor.setCursorPos(startX, a) monitor.setBackgroundColor(colors.lime) monitor.write(navSpacing) end monitor.setCursorPos(startX, midY) monitor.setBackgroundColor(colors.lime) monitor.write(nextWriting) for a = 1, bottomSpacing do monitor.setCursorPos(startX, a + midY) monitor.setBackgroundColor(colors.lime) monitor.write(navSpacing) end startX = (maxX / 2) - 2 for a = 1, topSpacing do monitor.setCursorPos(startX, a) monitor.setBackgroundColor(colors.lightBlue) monitor.write(homeSpacing) end monitor.setCursorPos(startX, midY) monitor.setBackgroundColor(colors.lightBlue) monitor.write(homeWriting) for a = 1, bottomSpacing do monitor.setCursorPos(startX, a + midY) monitor.setBackgroundColor(colors.lightBlue) monitor.write(homeSpacing) end end local function oneScreenMenu(monitor) monitor.setTextScale(0.6) monitor.setCursorPos(1, 1) monitor.setBackgroundColor(colors.black) monitor.clear() backWindow = window.create(monitor, 1, 1, 7, 5) backWindow.setBackgroundColor(colors.red) backWindow.clear() backWindow.setCursorPos(2, 3) backWindow.write("BACK") nextWindow = window.create(monitor, 9, 1, 7, 5) nextWindow.setBackgroundColor(colors.green) nextWindow.clear() nextWindow.setCursorPos(3, 3) nextWindow.write("NEXT") homeWindow = window.create(monitor, 1, 7, 15, 4) homeWindow.setBackgroundColor(colors.lightBlue) homeWindow.clear() homeWindow.setCursorPos(7, 3) homeWindow.write("HOME") end local function printTable(t) local printTable_cache = {} local function sub_printTable(t, indent) if (printTable_cache[tostring(t)]) then print(indent .. "*" .. tostring(t)) else printTable_cache[tostring(t)] = true if (type(t) == "table") then for pos, val in pairs(t) do if (type(val) == "table") then print(indent .. "[" .. pos .. "] => " .. tostring(t) .. " {") sub_printTable(val, indent .. string.rep(" ", string.len(pos) + 8)) print(indent .. string.rep(" ", string.len(pos) + 6) .. "}") elseif (type(val) == "string") then print(indent .. "[" .. pos .. "'] => '" .. val .. "'") else print(indent .. "[" .. pos .. "] => " .. tostring(val)) end end else print(indent .. tostring(t)) end end end if (type(t) == "table") then print(tostring(t)) end sub_printTable(t, "") end local function writeTable(t, file) bfile = fs.open(file, "w+") local printTable_cache = {} local function sub_printTable(t, indent) if (printTable_cache[tostring(t)]) then bfile.write(indent .. "*" .. tostring(t) .. "\n") else printTable_cache[tostring(t)] = true if (type(t) == "table") then for pos, val in pairs(t) do if (type(val) == "table") then bfile.write(indent .. "[" .. pos .. "] => " .. tostring(t) .. " {" .. "\n") sub_printTable(val, indent .. string.rep(" ", string.len(pos) + 8)) bfile.write(indent .. string.rep(" ", string.len(pos) + 6) .. "}" .. "\n") elseif (type(val) == "string") then bfile.write(indent .. "[" .. pos .. "'] => '" .. val .. "'" .. "\n") else bfile.write(indent .. "[" .. pos .. "] => " .. tostring(val) .. "\n") end end else bfile.write(indent .. tostring(t) .. "\n") end end end if (type(t) == "table") then bfile.write(tostring(t) .. "\n") end sub_printTable(t, "") bfile.close() end function table_contains(tbl, x) found = false for _, v in pairs(tbl) do if v == x then found = true end end return found end function comma_value(amount) local formatted = amount while true do formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2') if (k==0) then break end end return formatted end function pctFormat(number) return (string.format("%.2f%%", number)) end function sortTable(t) keys = {} newTable = {} for key in pairs(t) do table.insert(keys, key) end table.sort(keys) for _, key in ipairs(keys) do print(key, t[key]) end end return {channelList = channelList, getID = getID, getFunction = getFunction, uncraftables = uncraftables, setMenuBar = setMenuBar, printTable = printTable, writeTable = writeTable, table_contains = table_contains, oneScreenMenu = oneScreenMenu, comma_value = comma_value, pctFormat = pctFormat, setDblMenuBar = setDblMenuBar, sortTable = sortTable}