Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[===[
- Open Computer Requirements:
- RAM: At least 1 tier 3 memory chip
- Screen: Tier 3
- GPU: Tier 3
- Installing:
- pastebin get [-f] tVig6HZv <filepath>
- --]===]
- --[===[
- Notes:
- On first time boot, press <F6> to enter the main program
- --]===]
- --[===[
- Changelog:
- Version 1:
- Program created
- Version 1.1:
- Bug fixes
- Version 2:
- Multi-gate compatibility
- Address list
- Version 2.1:
- Addition of capacitor count and energy levels
- Shrunk buttons to add 3 more
- Version 2.2:
- Changed symbol glyph keybinds for parity with PoltixeTheDataatabase's program
- Version 2.3:
- Addition of energy required to dial for addresses in address list
- Version 2.4:
- Refined energy required to dial in address list for successful dials only
- Refined address book to use text file "addresses.sga" instead of global table variable
- Version 2.5:
- (Planned): Refine help page
- --]===]
- local forced_exit = false
- local debug_mode = false
- --Table *Conversion of characters to symbol strings*
- local points = {}
- points["q"] = {["MILKYWAY"]="Giza (POO)", ["PEGASUS"]="Subido (POO)", ["UNIVERSE"]="Glyph 17 (POO)"}
- points["w"] = {["MILKYWAY"]="Crater", ["PEGASUS"]="Aaxel", ["UNIVERSE"]="Glyph 1"}
- points["e"] = {["MILKYWAY"]="Virgo", ["PEGASUS"]="Abrin", ["UNIVERSE"]="Glyph 2"}
- points["r"] = {["MILKYWAY"]="Bootes", ["PEGASUS"]="Acjesis", ["UNIVERSE"]="Glyph 3"}
- points["t"] = {["MILKYWAY"]="Centaurus", ["PEGASUS"]="Aldeni", ["UNIVERSE"]="Glyph 4"}
- points["y"] = {["MILKYWAY"]="Libra", ["PEGASUS"]="Alura", ["UNIVERSE"]="Glyph 5"}
- points["u"] = {["MILKYWAY"]="Serpens Caput", ["PEGASUS"]="Amiwill", ["UNIVERSE"]="Glyph 6"}
- points["i"] = {["MILKYWAY"]="Norma", ["PEGASUS"]="Arami", ["UNIVERSE"]="Glyph 7"}
- points["o"] = {["MILKYWAY"]="Scorpius", ["PEGASUS"]="Avoniv", ["UNIVERSE"]="Glyph 8"}
- points["p"] = {["MILKYWAY"]="Corona Australis", ["PEGASUS"]="Baselai", ["UNIVERSE"]="Glyph 9"}
- points["["] = {["MILKYWAY"]="Scutum", ["PEGASUS"]="Bydo", ["UNIVERSE"]="Glyph 10"}
- points["]"] = {["MILKYWAY"]="Sagittarius", ["PEGASUS"]="Ca Po", ["UNIVERSE"]="Glyph 11"}
- points["\\"] = {["MILKYWAY"]="Aquila", ["PEGASUS"]="Danami", ["UNIVERSE"]="Glyph 12"}
- points["a"] = {["MILKYWAY"]="Microscopium", ["PEGASUS"]="Dawnre", ["UNIVERSE"]="Glyph 13"}
- points["s"] = {["MILKYWAY"]="Capricornus", ["PEGASUS"]="Ecrumig", ["UNIVERSE"]="Glyph 14"}
- points["d"] = {["MILKYWAY"]="Piscis Austrinus", ["PEGASUS"]="Elenami", ["UNIVERSE"]="Glyph 15"}
- points["f"] = {["MILKYWAY"]="Equuleus", ["PEGASUS"]="Gilltin", ["UNIVERSE"]="Glyph 16"}
- points["g"] = {["MILKYWAY"]="Aquarius", ["PEGASUS"]="Hacemill", ["UNIVERSE"]="Glyph 17"}
- points["h"] = {["MILKYWAY"]="Pegasus", ["PEGASUS"]="Hamlinto", ["UNIVERSE"]="Glyph 18"}
- points["j"] = {["MILKYWAY"]="Sculptor", ["PEGASUS"]="Illume", ["UNIVERSE"]="Glyph 19"}
- points["k"] = {["MILKYWAY"]="Pisces", ["PEGASUS"]="Laylox", ["UNIVERSE"]="Glyph 20"}
- points["l"] = {["MILKYWAY"]="Andromeda", ["PEGASUS"]="Lenchan", ["UNIVERSE"]="Glyph 21"}
- points[";"] = {["MILKYWAY"]="Triangulum", ["PEGASUS"]="Olavii", ["UNIVERSE"]="Glyph 22"}
- points["'"] = {["MILKYWAY"]="Aries", ["PEGASUS"]="Once el", ["UNIVERSE"]="Glyph 23"}
- points["z"] = {["MILKYWAY"]="Perseus", ["PEGASUS"]="Poco re", ["UNIVERSE"]="Glyph 24"}
- points["x"] = {["MILKYWAY"]="Cetus", ["PEGASUS"]="Ramnon", ["UNIVERSE"]="Glyph 25"}
- points["c"] = {["MILKYWAY"]="Taurus", ["PEGASUS"]="Recktic", ["UNIVERSE"]="Glyph 26"}
- points["v"] = {["MILKYWAY"]="Auriga", ["PEGASUS"]="Robandus", ["UNIVERSE"]="Glyph 27"}
- points["b"] = {["MILKYWAY"]="Eridanus", ["PEGASUS"]="Roehi", ["UNIVERSE"]="Glyph 28"}
- points["n"] = {["MILKYWAY"]="Orion", ["PEGASUS"]="Salma", ["UNIVERSE"]="Glyph 29"}
- points["m"] = {["MILKYWAY"]="Canis Minor", ["PEGASUS"]="Sandovi", ["UNIVERSE"]="Glyph 30"}
- points[","] = {["MILKYWAY"]="Monoceros", ["PEGASUS"]="Setas", ["UNIVERSE"]="Glyph 31"}
- points["."] = {["MILKYWAY"]="Gemini", ["PEGASUS"]="Sibbron", ["UNIVERSE"]="Glyph 32"}
- points["/"] = {["MILKYWAY"]="Hydra", ["PEGASUS"]="Tahnan", ["UNIVERSE"]="Glyph 33"}
- points["1"] = {["MILKYWAY"]="Lynx", ["PEGASUS"]="Zamilloz", ["UNIVERSE"]="Glyph 34"}
- points["2"] = {["MILKYWAY"]="Cancer", ["PEGASUS"]="Zeo", ["UNIVERSE"]="Glyph 35"}
- points["3"] = {["MILKYWAY"]="Sextans", ["PEGASUS"]=nil, ["UNIVERSE"]="Glyph 36"}
- points["4"] = {["MILKYWAY"]="Leo Minor", ["PEGASUS"]=nil, ["UNIVERSE"]=nil}
- points["5"] = {["MILKYWAY"]="Leo", ["PEGASUS"]=nil, ["UNIVERSE"]=nil}
- --Table *Program keybinds*
- local keybinds = {}
- keybinds["Enter"] = "Dial"
- keybinds["F1"] = "Keybinds List"
- keybinds["F4"] = "Toggle Iris"
- keybinds["Shift"] = "Quit"
- keybinds["F3"] = "Recent Address List"
- keybinds["F5"] = "Sequence Compiler"
- keybinds["F6"] = "Dialer Help"
- keybinds["F7"] = "Switch Gate Type"
- --Table *Stores chevron values [false=not engaged]*
- chevrons = {}
- chevrons[0] = false
- chevrons[1] = false
- chevrons[2] = false
- chevrons[3] = false
- chevrons[4] = false
- chevrons[5] = false
- chevrons[6] = false
- chevrons[7] = false
- chevrons[8] = false
- --Table *Stores action buttons*
- local buttons = {}
- --Table *Stores sequence compiler buttons*
- local symbol_buttons = {}
- --Table *Stores old address buttons*
- local old_addr_buttons = {}
- --Table *Stores confirm prompt buttons*
- local confirm_prompt_buttons = {}
- --Table *Stores the address entered by user |zero-indexed|*
- local address = {}
- --Import modules "I think there called modules in Lua"
- local os = require("os")
- local component = require("component")
- local keyboard = require("keyboard")
- local event = require("event")
- local sides = require("sides")
- local unicode = require("unicode")
- local fs = require("filesystem")
- --local rs = component.redstone
- --Setup variables
- local gpu = component.gpu
- local sg = component.stargate
- local top = sides.top
- --Setup numerical variables
- local w, h = gpu.getResolution()
- local initial, ispallet = gpu.getBackground()
- local vw = w / 100
- local vh = h / 100
- local index = 0
- local dial_index = 0
- local keybind_showKeybindsList = 59
- local keybind_toggleIris = 62
- local keybind_showOldAddresses = 61
- local keybind_showSequenceCompiler = 63
- local keybind_showHelp = 64
- local keybind_switchGateType = 65
- --Setup boolean variables
- state = true
- dialing = false
- active = false
- sigterm = false
- failed = false
- inbound = false
- local iris = false
- local compiler_open = false
- local book_open = false
- local save_addr = true
- local confirm_open = false
- local confirm_response = nil
- local closed_fully = false
- local dhd_alert = false
- --Setup byte variables
- local standard = 0x0024C0
- --Setup string variables
- local fail_type = ""
- local idc = ""
- local gate_type = sg.getGateType()
- --Setup code
- gpu.setDepth(8)
- if first == nil then
- first = false
- end
- if fs.exists("addresses.sga") == false then
- file = io.open("addresses.sga", "a")
- file:close()
- end
- --Function *Clears the screen*
- function clear()
- os.execute("clear")
- end
- --Function *Coverts table to number indxed table*
- function toOrderedTable(table)
- local out = {}
- for key, value in pairs(table) do
- if type(key) == "string" then
- out[string.byte(key)] = value
- elseif type(key) == "table" then
- out[len(key)] = value
- else
- out[key] = value
- end
- end
- return out
- end
- --Function *Extension of toOrderedTable*
- function toFlooredOrderedTable(table)
- local out = {}
- local ordered = toOrderedTable(table)
- local smallest = getLeast(getKeys(ordered))
- local max = len(ordered)
- local i = 1
- while len(out) < max do
- out[i] = ordered[smallest]
- ordered[smallest] = nil
- smallest = getLeast(getKeys(ordered))
- i = i + 1
- end
- return out
- end
- --Function *Returns table containing keys*
- function getKeys(table)
- local keys = {}
- local index = 0
- for k,v in pairs(table) do
- keys[index] = k
- index = index + 1
- end
- return keys
- end
- --Function *Gets smallest number in table*
- function getLeast(table)
- local smallest = nil
- for k,v in pairs(table) do
- --print(smallest, v)
- if smallest == nil then
- smallest = v
- end
- if type(v) == "number" then
- if v < smallest then
- smallest = v
- end
- end
- end
- return smallest
- end
- --Function *Splits string around delimiter*
- function split(string, delimiter, start_index)
- if #delimiter > 1 then
- error("[function<split>]: ParamError@delimiter -> Expected string of length 0 to 1, got "..#delimiter)
- else
- if start_index == nil then
- start_index = 0
- end
- local out = {}
- local index = start_index
- out[index] = ""
- for i=1,#string do
- local char = string:sub(i,i)
- if char == delimiter then
- index = index + 1
- out[index] = ""
- else
- out[index] = out[index]..char
- end
- end
- return out
- end
- end
- --Function *Counts number of occurances of each element in a table*
- function count(table, element)
- local e_count = 0
- for k,v in pairs(table) do
- if v == element then
- e_count = e_count + 1
- end
- end
- return e_count
- end
- --Function *Gets number of entries in table*
- function len(table)
- local count = 0
- for k,v in pairs(table) do
- count = count + 1
- end
- return count
- end
- --Function *Fills a table with a value*
- function fill(table, value)
- for i,e in pairs(table) do
- table[i] = value
- end
- end
- --Function *Returns index position of element in table*
- function indexof(table, value)
- for k,v in pairs(table) do
- if v == value then
- return k
- end
- end
- return -1
- end
- --Function *Shallow comparison of tables*
- function isSame(t1, t2, start)
- start = start or 1
- if len(t1) ~= len(t2) then
- return false
- end
- local l = len(t1)
- for i=start,l do
- --print(t1[i], t2[i])
- if t1[i] ~= t2[i] then
- return false
- end
- end
- return true
- end
- --Function *Converts degrees to radians*
- function toRadian(degrees)
- return degrees * (math.pi / 180)
- end
- --Function *Rounds a number*
- function round(num, places)
- places = places or 1
- return math.floor(num*math.pow(10,places)+0.5) / math.pow(10,places)
- end
- --Function *Returns key from key press*
- function parseKey()
- local event, a, b, c, d = event.pull("key_down")
- return unicode.char(b), keyboard.isControl(b), b, c, d
- end
- --Function *Resets GPU to inital standards*
- function resetGpu()
- gpu.setBackground(0x000000)
- gpu.setForeground(0xFFFFFF)
- end
- --Function *Creates/modifies a button*
- function createButton(buffer, name, x, y, w, h, border, text, onclick, ...)
- resetGpu()
- gpu.fill(x, y, w, h, " ")
- gpu.setBackground(border)
- gpu.fill(x, y, w, 2*vh, " ")
- gpu.fill(x, y + h, w + 0.75*vw, 2*vh, " ")
- gpu.fill(x, y, 1*vw, h, " ")
- gpu.fill(x + w, y, 1*vw, h, " ")
- resetGpu()
- gpu.set((x + w / 2) - (#text / 2), y + h / 2, text)
- buffer[name] = {["x"]=x, ["y"]=y, ["w"]=w, ["h"]=h, ["function"]=onclick, ["args"]={...}, ["text"]=text}
- end
- --Function *Handles event listener errors*
- function threadHandler(event)
- prompt(0xFF0000, "Error", "An Error has Occured in Dialing Program")
- dialing = false
- sigterm = true
- end
- --Function *Ignores event if function was defined*
- function ignoreIf(name, callback)
- if callback ~= nil then
- event.ignore(name, callback)
- return true
- else
- return false
- end
- end
- --Function *Quits the program with certain clenup functions*
- function quit()
- clear()
- resetGpu()
- ignoreIf("stargate_spin_chevron_engaged", lockChevron)
- ignoreIf("touch", onScreenTouch)
- ignoreIf("key_down", onKeyPress)
- ignoreIf("stargate_close", closeGate)
- ignoreIf("stargate_wormhole_closed_fully", fullClose)
- ignoreIf("stargate_dhd_chevron_engaged", onDhdPress)
- ignoreIf("stargate_incoming_wormhole", inboundConnection)
- forced_exit = true
- os.exit()
- end
- --Function *Draws a circle*
- function drawCircle(h, k, r, border, size, fill)
- if fill == nil then
- fill = initial
- end
- if border == nil then
- border = 0xFFFFFF
- end
- if size == nil then
- size = 1
- end
- gpu.setBackground(border)
- for theta=0,360 do
- local x = h + r * math.cos(toRadian(theta))
- local y = k + r * math.sin(toRadian(theta)) / (w / h)
- gpu.fill(round(x), round(y), size + 1.125*vw, size, " ")
- end
- end
- --Function *Gets addresses from file*
- function getAddresses()
- local old = {}
- local file = io.open("addresses.sga", "r")
- local data = file:read("*all")
- data = data:sub(1, #data - 1)
- file:close()
- if data == "" then
- return {}
- end
- local data_table = split(data, "#", 1)
- for key, addr in ipairs(data_table) do
- local addr_data = split(addr, "~", 1)
- old[key] = {}
- for k, ind in ipairs(addr_data) do
- local pairs = split(ind, "=", 0)
- --print(pairs[0], pairs[1])
- old[key][pairs[0]] = pairs[1]
- end
- old[key]["chars_list"] = split(old[key]["chars_list"], " ", 1)
- end
- return old
- end
- --Function *Saves addresses to book*
- function saveAddress()
- if save_addr == true then
- local char_list = ""
- local new_addr = ""
- for k, char in ipairs(toFlooredOrderedTable(address)) do
- char_list = char_list..char.." "
- end
- char_list = char_list:sub(1, #char_list - 1)
- new_addr = new_addr.."chars_list="..char_list.."~"
- new_addr = new_addr.."gate_type="..gate_type.."~"
- new_addr = new_addr.."success_state="..tostring(not failed).."#"
- local file = io.open("addresses.sga", "a")
- file:write(new_addr)
- file:close()
- end
- end
- --Function *Deletes address from book*
- function deleteAddress(args)
- local res = confirm(0xFFB600, "Delete Address", "Delete this address from the book?", "Yes", "No")
- if res == true then
- local old = getAddresses()
- local addr = args[1]["chars_list"]
- local kept = {}
- for k, a in ipairs(old) do
- if isSame(a["chars_list"], addr, 1) == false then
- kept[len(kept) + 1] = a
- end
- end
- local out = ""
- for a, addr in ipairs(kept) do
- local chars = ""
- local address = ""
- for i, char in addr["chars_list"] do
- chars = chars..char.." "
- end
- chars = chars:sub(1, #chars - 1)
- address = address.."chars_list="..chars.."~"
- address = address.."gate_type="..addr["gate_type"].."~"
- address = address.."success_state="..addr["success_state"].."#"
- out = out..address
- end
- local file = io.open("addresses.sga", "w")
- file:write(out)
- file:close()
- end
- listOldAddresses()
- end
- --Bound-Function *abort_button.onclick*
- function abort()
- if active == true then
- --sg.disengageGate()
- active = false
- elseif dialing == true then
- prompt(0xFFB600, "Gate Manual Override", "Override engaged", "Gate will shutdown on next chevron")
- sigterm = true
- elseif count(chevrons, false) < 9 then
- sg.disengageGate()
- else
- prompt(0xFF0000, "Gate is IDLE", "The stargate is idle", "and cannot be disengaged", true)
- end
- end
- --Bound-Function *iris_button.onclick*
- function toggleIris()
- boolean Beamer = sg.isActive;
- if (Beamer == true)
- Beamer = false;
- else
- Beamer = true;
- end
- createButton(buttons, "beamer_button", 8*vw, 70*vh, 15*vw, 8*vh, 0xFF0000, "Toggle Beamer", toggleIris)
- sg.setActive(Beamer)
- clear()
- updateDisplay()
- end
- --Bound-Function *symbol_button.onclick*
- function addSymbolToSequence(args_list)
- clear()
- listSequenceCompiler()
- local symbol = args_list[1]
- if symbol ~= -1 then
- if indexof(points, symbol) ~= -1 then
- local char = indexof(points, symbol)
- if count(address, char) >= 1 then
- prompt(0xFF0000, "Pre-Sequence Error", "Duplicate Keys", "Key \""..key.."\" is already listed", true)
- listSequenceCompiler()
- else
- address[index] = char
- index = index + 1
- local old_button = symbol_buttons[symbol[gate_type].."button"]
- createButton(symbol_buttons, symbol[gate_type].."button", old_button.x, old_button.y, old_button.w, old_button.h, 0x00FF00, "("..indexof(points, symbol)..") "..symbol[gate_type], addSymbolToSequence, old)
- end
- else
- prompt(0xFF0000, "Pre-Sequence Error", "Unkown Symbol", "Symbol \""..symbol[gate_type].."\" is not recognized", true)
- listSequenceCompiler()
- end
- elseif index > 0 then
- index = index - 1
- local old = points[address[index]]
- address[index] = nil
- local old_button = symbol_buttons[old[gate_type].."button"]
- createButton(symbol_buttons, old[gate_type].."button", old_button.x, old_button.y, old_button.w, old_button.h, 0x787878,"("..indexof(points, old)..") "..old[gate_type], addSymbolToSequence, old[gate_type])
- end
- end
- --Bound-Function *switch_button.onclick*
- function switchGate()
- sg = require("component").stargate
- index = 0
- address = {}
- if gate_type == "MILKYWAY" then
- points = p_points
- gate_type = "PEGASUS"
- prompt(0xFFb600, "Gate Alert", "Switched gate type to \"Pegasus\"", true)
- elseif gate_type == "PEGASUS" then
- points = u_points
- gate_type = "UNIVERSE"
- prompt(0xFFb600, "Gate Alert", "Switched gate type to \"Universe\"", true)
- elseif gate_type == "UNIVERSE" then
- points = mw_points
- gate_type = "MILKYWAY"
- prompt(0xFFb600, "Gate Alert", "Switched gate type to \"Milky Way\"", true)
- end
- end
- --Bound-Function *old_address_button.onclick*
- function dialOldAddress(args_list)
- local addr = args_list[1]
- if addr["gate_type"] ~= gate_type then
- prompt(0xFF0000, "Gate Type Error", "Cannot use address", "Address gate type does not match", true)
- listOldAddresses()
- else
- for i,char in ipairs(addr["chars_list"]) do
- address[i - 1] = char
- index = i - 1
- end
- local symbol_list = {}
- for k, v in ipairs(toFlooredOrderedTable(address)) do
- point = points[v][gate_type]
- if point == "Giza (POO)" then
- point = "Point of Origin"
- elseif point == "Subido (POO)" then
- point = "Subido"
- elseif point == "Glyph 17 (POO)" then
- point = "Glyph 17"
- end
- symbol_list[k] = point
- end
- local req = nil
- if addr["success_state"] == "true" then
- req = tostring(sg.getEnergyRequiredToDial(symbol_list).open)
- else
- req = "No Lock"
- end
- local res = confirm(standard, "Address Selected", "Ready to Dial Address", "Confirm Sequence", "", "Required Power: "..req, "Confirm", "Deny")
- if res == true then
- save_addr = false
- beginDialSequence()
- save_addr = true
- else
- fill(address, nil)
- index = 0
- end
- listOldAddresses()
- end
- end
- --Bound-Function *confirm_prompt_button.onclick*
- function setConfirmPromptState(args)
- confirm_response = args[1]
- end
- --Function *Displays buttons "Panel on lower left"*
- function listActionPanel()
- resetGpu()
- gpu.setBackground(standard)
- gpu.fill(5*vw, 54*vh, 23*vw, 2*vh, " ")
- gpu.fill(5*vw, 95*vh, 23.5*vw, 2*vh, " ")
- gpu.fill(5*vw, 55*vh, 1*vw, 40*vh, " ")
- gpu.fill(28*vw, 55*vh, 1*vw, 40*vh, " ")
- createButton(buttons, "dial_button", 7*vw, 58*vh, 9*vw, 8*vh, 0x787878, "Dial", beginDialSequence)
- createButton(buttons, "switch_button", 17.5*vw, 58*vh, 8.5*vw, 8*vh, 0x787878, "Switch Gate", switchGate)
- createButton(buttons, "beamer_button", 7*vw, 70*vh, 9*vw, 8*vh, 0x00FF00, "Toggle Beamer", toggleIris)
- createButton(buttons, "kb_button", 17.5*vw, 70*vh, 8.5*vw, 8*vh, 0x787878, "Keybinds", listKeyBinds)
- createButton(buttons, "abort_button", 7*vw, 82*vh, 9*vw, 8*vh, 0x787878, "Abort", abort)
- createButton(buttons, "quit_button", 17.5*vw, 82*vh, 8.5*vw, 8*vh, 0x787878, "Compiler", listSequenceCompiler)
- end
- --Function *Displays chevron states "Panel on upper left"*
- function listChevronStates()
- resetGpu()
- gpu.setBackground(standard)
- gpu.fill(5*vw, 6*vh, 20*vw, 2*vh, " ")
- gpu.fill(5*vw, 46*vh, 21*vw, 2*vh, " ")
- gpu.fill(5*vw, 6*vh, 1*vw, 40*vh, " ")
- gpu.fill(25*vw, 6*vh, 1*vw, 40*vh, " ")
- y = 10
- for i=0,8 do
- local c = chevrons[i]
- if c == false then
- gpu.setBackground(0xFF0000)
- gpu.fill(16*vw, y*vh, 5*vw, 2*vh, " ")
- gpu.setBackground(0x787878)
- gpu.fill(10*vw, y*vh, 5*vw, 2*vh, " ")
- else
- gpu.setBackground(0x00FF00)
- gpu.fill(10*vw, y*vh, 5*vw, 2*vh, " ")
- gpu.setBackground(0x787878)
- gpu.fill(16*vw, y*vh, 5*vw, 2*vh, " ")
- end
- resetGpu()
- gpu.set(8*vw, y*vh, tostring(i+1))
- y = y + 4
- end
- end
- --Function *Displays chevron symbols "Panel on right"*
- function listAddressBoxes()
- resetGpu()
- y = 6
- for a=0,8 do
- gpu.setBackground(standard)
- gpu.fill(80*vw, y*vh, 15*vw, 2*vh, " ")
- gpu.fill(80*vw, y*vh + 6*vh, 16*vw, 2*vh, " ")
- gpu.fill(80*vw, y*vh, 1*vw, 9*vh, " ")
- gpu.fill(95*vw, y*vh, 1*vw, 9*vh, " ")
- resetGpu()
- if dialing == true then
- if chevrons[a] ~= false then
- local str = chevrons[a]
- gpu.set(88*vw - #str / 2, y*vh + 2.5*vh, str)
- end
- else
- if address[a] ~= nil then
- local str = points[address[a]][gate_type]
- gpu.set(88*vw - #str / 2, y*vh + 2.5*vh, str)
- --gpu.set(88*vw - 1, y*vh + 2.5*vh, address[a])
- end
- end
- y = y + 10
- end
- end
- function listStats()
- resetGpu()
- local stored = sg.getEnergyStored()
- local max = sg.getMaxEnergyStored()
- local cap_count = sg.getCapacitorsInstalled()
- local inc = 28*vw / max
- local units = inc * stored
- gpu.setBackground(standard)
- gpu.fill(30*vw, 64*vh, 45*vw, 2*vh, " ")
- gpu.fill(30*vw, 78*vh, 46*vw, 2*vh, " ")
- gpu.fill(30*vw, 64*vh, 1*vw, 14*vh, " ")
- gpu.fill(75*vw, 64*vh, 1*vw, 14*vh, " ")
- resetGpu()
- gpu.set(32*vw, 68*vh, "Capacitors: "..cap_count.."/3")
- gpu.set(44*vw, 68*vh, "[")
- local x = 45*vw
- for i=1,3 do
- if i <= cap_count then
- gpu.setBackground(0x00FF00)
- else
- gpu.setBackground(0xFF0000)
- end
- gpu.fill(x, 68*vh, 8*vw, 2*vh, " ")
- x = x + 10*vw
- end
- resetGpu()
- gpu.set(73.5*vw, 68*vh, "]")
- gpu.set(32*vw, 74*vh, "Energy:")
- gpu.set(38*vw, 75*vh, round((stored / max) * 100).."%")
- gpu.set(32*vw, 76*vh, stored.."/"..max)
- gpu.set(44*vw, 75*vh, "[")
- gpu.set(73.5*vw, 75*vh, "]")
- gpu.setBackground(0x787878)
- gpu.fill(45*vw, 75*vh, 28*vw, 2*vh, " ")
- gpu.setBackground(0x00FF00)
- gpu.fill(45*vw, 75*vh, units, 2*vh, " ")
- end
- --Function *Displays IDC and stargate status*
- function listOutputs()
- resetGpu()
- gpu.setBackground(standard)
- gpu.fill(30*vw, 82*vh, 45*vw, 2*vh, " ")
- gpu.fill(30*vw, 95*vh, 46*vw, 2*vh, " ")
- gpu.fill(30*vw, 82*vh, 1*vw, 15*vh, " ")
- gpu.fill(75*vw, 82*vh, 1*vw, 15*vh, " ")
- resetGpu()
- local gate = ""
- if gate_type == "MILKYWAY" then
- gate = "Milky Way: "
- elseif gate_type == "PEGASUS" then
- gate = "Pegasus: "
- elseif gate_type == "UNIVERSE" then
- gate = "Universe: "
- end
- if dialing == false then
- if inbound == false and active == false then
- local idle = gate.."IDLE"
- gpu.set(50*vw - (#idle / 2), 86*vh, idle)
- elseif inbound == true then
- local inbound = gate.."INBOUND"
- gpu.set(50*vw - (#inbound / 2), 86*vh, inbound)
- elseif active == true then
- local locked = gate.."LOCKED"
- gpu.set(50*vw - (#locked / 2), 86*vh, locked)
- end
- else
- local active = gate.."ACTIVE"
- gpu.set(50*vw - (#active / 2), 86*vh, active)
- end
- gpu.set(35*vw, 90*vh, "Stargate IDC: ")
- if idc ~= nil then
- gpu.set(30*vw + (45*vw / 2) - (#idc / 2), 90*vh, idc)
- end
- end
- --Function *Displays stargate*
- function listStargate()
- local ring_color = 0xA5A5A5
- local inner_color = 0x696969
- if gate_type == "UNIVERSE" then
- ring_color = 0x222222
- inner_color = 0x333333
- elseif gate_type == "PEGASUS" then
- ring_color = 0x222222
- inner_color = 0x33DBFF
- end
- drawCircle(50*vw, 32*vh, 18*vw, 0x0049FF, 1)
- drawCircle(50*vw, 32*vh, 16*vw, inner_color, 1)
- drawCircle(50*vw, 32*vh, 17*vw, ring_color, 1)
- drawCircle(50*vw, 32*vh, 15*vw, ring_color, 1)
- resetGpu()
- local final = indexof(address, "q")
- local chevs = {}
- local r = 16*vw
- local old = nil
- chevs[0] = 50
- chevs[1] = 10
- chevs[2] = 330
- chevs[3] = 210
- chevs[4] = 170
- chevs[5] = 130
- if len(address) <= 7 then
- chevs[6] = 90
- chevs[7] = 290
- chevs[8] = 250
- elseif len(address) == 8 then
- chevs[6] = 290
- chevs[7] = 90
- chevs[8] = 250
- elseif len(address) == 9 then
- chevs[6] = 290
- chevs[7] = 250
- chevs[8] = 90
- end
- for c=0,8 do
- chev = chevrons[c]
- local x = 49*vw + r * math.cos(toRadian(chevs[c]))
- local y = 30*vh + r * math.sin(toRadian(chevs[c]+180)) / 2
- if chev == false then
- gpu.setBackground(0xF2F2F2)
- else
- gpu.setBackground(0xFF0000)
- end
- gpu.fill(round(x), round(y), 4*vw, 6*vh, " ")
- end
- end
- --Function *List symbol keybinds*
- function listKeyBinds()
- resetGpu()
- clear()
- gpu.set(50*vw - (#"AUNIS Dialing Program Keybinds (F1)" / 2), 6*vh, "AUNIS Dailing Program Keybinds (F1)")
- gpu.setBackground(standard)
- gpu.fill(0*vw, 2*vh, 100*vw, 2*vh, " ")
- gpu.fill(0*vw, 98*vh, 100*vw, 2*vh, " ")
- resetGpu()
- x = 10*vw
- y = 10*vh
- index = 0
- for char, pair in ipairs(toFlooredOrderedTable(points)) do
- local symbol = pair[gate_type]
- if symbol ~= nil then
- if symbol == "Point of Origin" then
- gpu.setForeground(0x00FF00)
- end
- gpu.set(x, y, "\""..char.."\": "..symbol)
- index = index + 1
- y = y + 5*vh
- if y >= 90*vh then
- y = 10*vh
- x = x + 20*vw
- end
- gpu.setForeground(0xFFFFFF)
- end
- end
- for key, action in pairs(keybinds) do
- if action == "Dial" then
- gpu.setForeground(0x0000FF)
- elseif action == "Quit" then
- gpu.setForeground(0xFF0000)
- else
- gpu.setForeground(0xAAAAAA)
- end
- gpu.set(x, y, "\""..key.."\": "..action)
- y = y + 5*vh
- if y >= 90*vh then
- y = 10*vh
- x = x + 20*vw
- end
- gpu.setForeground(0xFFFFFF)
- end
- resetGpu()
- local leave = "Press \"F1\" to Escape"
- gpu.set(50*vw - (#leave / 2), 95*vh, leave)
- local state = true
- while state == true do
- local key, is_control, raw, c = parseKey()
- if c == keybind_showKeybindsList then
- state = false
- end
- end
- resetGpu()
- end
- --Function *List old addresses*
- function listOldAddresses()
- --book_open = true
- resetGpu()
- clear()
- local header = "Recent Address Book (F3)"
- gpu.set(50*vw - (#header / 2), 6*vh, header)
- local escape = "Press \"F3\" to Escape"
- gpu.set(50*vw - (#escape / 2), 95*vh, escape)
- gpu.setBackground(standard)
- gpu.fill(0*vw, 2*vh, 100*vw, 2*vh, " ")
- gpu.fill(0*vw, 98*vh, 100*vw, 2*vh, " ")
- resetGpu()
- local old_addresses = getAddresses()
- local max = len(old_addresses)
- x = 5*vw
- y = 10*vh
- local i = 0
- while x < 95*vh do
- resetGpu()
- local seg = len(old_addresses) - i
- local address = old_addresses[seg]
- if address == nil then
- break
- end
- local addr = ""
- for i,char in ipairs(address["chars_list"]) do
- addr = addr..char.." "
- end
- local color = 0xFFFFFF
- if address["gate_type"] ~= gate_type then
- color = 0x555555
- elseif address["success_state"] == "false" then
- color = 0xFF0000
- elseif address["success_state"] == "true" then
- color = 0x00FF00
- end
- createButton(old_addr_buttons, seg.."addr", x, y, 18.5*vw, 8*vh, color, "Address: "..addr, dialOldAddress, address)
- y = y + 12*vh
- if y >= 95*vh then
- x = x + 20*vw
- y = 10*vh
- end
- i = i + 1
- end
- if book_open == false then
- book_open = true
- local state = true
- while state == true and inbound == false do
- local key, is_control, raw, c = parseKey()
- if c == keybind_showOldAddresses then
- state = false
- end
- end
- book_open = false
- end
- end
- --Function *Sequence compiler*
- function listSequenceCompiler()
- resetGpu()
- clear()
- gpu.setBackground(standard)
- gpu.fill(0*vw, 2*vh, 100*vw, 2*vh, " ")
- gpu.fill(0*vw, 98*vh, 100*vw, 2*vh, " ")
- resetGpu()
- gpu.set(50*vw - (#"Sequence Compiler (F5)" / 2), 6*vh, "Sequence Compiler (F5)")
- local y = 10*vh
- local x = 3*vw
- local ordered = toFlooredOrderedTable(points)
- for c,symbol in ipairs(ordered) do
- if symbol[gate_type] ~= nil then
- local bg = nil
- local char = indexof(points, symbol)
- if indexof(address, char) ~= -1 then
- bg = 0x00FF00
- else
- bg = 0x787878
- end
- createButton(symbol_buttons, symbol[gate_type].."button", x, y, 15*vw, 5*vh, bg, "("..char..") "..symbol[gate_type], addSymbolToSequence, symbol)
- y = y + 10*vh
- if y >= 90*vh then
- y = 10*vh
- x = x + 20*vw
- end
- end
- end
- createButton(symbol_buttons, "backspace_button", x, y, 15*vw, 5*vh, 0xFF0000, "Backspace", addSymbolToSequence, -1)
- if address[index - 1] == "q" and gate_type ~= "UNIVERSE" then
- prompt(standard, "Sequence Complete", "Sequence Entry Complete", "Press \"Enter\" to dial", false)
- end
- resetGpu()
- local leave = "Press \"F5\" to Escape"
- gpu.set(50*vw - (#leave / 2), 95*vh, leave)
- if compiler_open == false then
- compiler_open = true
- local state = true
- while state == true and inbound == false do
- local key, is_control, raw, c = parseKey()
- if c == keybind_showSequenceCompiler then
- state = false
- end
- end
- clear()
- updateDisplay()
- compiler_open = false
- end
- end
- --Function *Shows help menu*
- function listHelp()
- resetGpu()
- clear()
- gpu.setBackground(standard)
- gpu.fill(0*vw, 2*vh, 100*vw, 2*vh, " ")
- gpu.fill(0*vw, 98*vh, 100*vw, 2*vh, " ")
- resetGpu()
- gpu.set(50*vw - (#"AUNIS Dialing Program Help (F6)" / 2), 6*vh, "AUNIS Dialing Program Help (F6)")
- local descrip = "This AUNIS Mod dialing program is designed to dial the stargates;from the AUNIS mod (Link below).;This program converts symbols into single characters for dialing.;See all keybinds by pressing F1"
- local link = "https://www.curseforge.com/minecraft/mc-mods/aunis"
- local y = 10*vh
- for num,line in ipairs(split(descrip, ";", 1)) do
- gpu.set(50*vw - (#line / 2), y, line)
- y = y + 2*vh
- end
- gpu.setForeground(0x0000AA)
- gpu.set(50*vw - (#link / 2), y+5*vh, link)
- resetGpu()
- gpu.set(50*vw - (#"Press \"F6\" to Escape" / 2), 95*vh, "Press \"F6\" to Escape")
- gpu.setBackground(standard)
- gpu.fill(5*vw, 30*vh, 30*vw, 2*vh, " ")
- gpu.fill(5*vw, 58*vh, 31*vw, 2*vh, " ")
- gpu.fill(5*vw, 30*vh, 1*vw, 28*vh, " ")
- gpu.fill(35*vw, 30*vh, 1*vw, 28*vh, " ")
- resetGpu()
- gpu.set(20.5, 30*vh, "Home Screen Buttons")
- gpu.set(7*vw, 34*vh, "[Dial] - Dials the gate")
- gpu.set(7*vw, 38*vh, "[Toggle Beamer] - Togggles the gate beamer")
- gpu.set(7*vw, 42*vh, "[Abort] - Shutdown gate dialing")
- gpu.set(7*vw, 46*vh, "[Switch] - Switch gate type")
- gpu.set(7*vw, 50*vh, "[Keybinds] - Shows list of keybinds")
- gpu.set(7*vw, 54*vh, "[Compiler] - Shows sequence compiler")
- gpu.setBackground(standard)
- gpu.fill(53*vw, 30*vh, 43*vw, 2*vh, " ")
- gpu.fill(53*vw, 50*vh, 43.5*vw, 2*vh, " ")
- gpu.fill(53*vw, 30*vh, 1*vw, 20*vh, " ")
- gpu.fill(95*vw, 30*vh, 1*vw, 20*vh, " ")
- resetGpu()
- gpu.set(70*vw, 30*vh, "Dialing the Gate")
- gpu.set(55*vw, 34*vh, "Using the keys or sequence compiler, enter a stargate address")
- gpu.set(55*vw, 38*vh, "Once done, press enter to dial the gate")
- gpu.set(55*vw, 42*vh, "The chevrons will lock into place and attempt to open the gate")
- gpu.set(55*vw, 46*vh, "Press \"Space\" or the abort button anytime to cancel the dialer")
- gpu.setBackground(standard)
- gpu.fill(5*vw, 64*vh, 50*vw, 2*vh, " ")
- gpu.fill(5*vw, 94*vh, 51*vw, 2*vh, " ")
- gpu.set(7*vw, 68*vh, "")
- resetGpu()
- local state = true
- while state == true and inbound == false do
- local key, is_control, raw, c = parseKey()
- if c == keybind_showHelp then
- state = false
- end
- end
- end
- --Function *Master display update*
- function updateDisplay()
- resetGpu()
- listActionPanel()
- listChevronStates()
- listAddressBoxes()
- listOutputs()
- listStats()
- listStargate()
- gpu.setBackground(standard)
- gpu.fill(0*vw, 2*vh, 40*vw, 2*vh, " ")
- gpu.fill(60*vw, 2*vh, 40*vw, 2*vh, " ")
- gpu.fill(0*vw, 98*vh, 100*vw, 2*vh, " ")
- resetGpu()
- end
- --Function *Displays the confirmation prompt*
- function confirm(bg, header, ...)
- local arg = {...}
- resetGpu()
- gpu.fill(20*vw, 10*vh, 60*vw, 50*vh, " ")
- gpu.setBackground(bg)
- gpu.fill(20*vw, 10*vh, 60*vw, 2*vh, " ")
- gpu.fill(20*vw, 60*vh, 61*vw, 2*vh, " ")
- gpu.fill(20*vw, 10*vh, 1*vw, 50*vh, " ")
- gpu.fill(80*vw, 10*vh, 1*vw, 50*vh, " ")
- gpu.fill(30*vw, 25*vh, 40*vw, 2*vh, " ")
- resetGpu()
- gpu.setForeground(bg)
- gpu.set(50*vw - (#header / 2), 18*vh, header)
- for i,m in pairs(arg) do
- if type(m) == "string" and i < len(arg) - 1 then
- gpu.set(50*vw - (#m / 2), 28*vh + (2*i*vh), m)
- end
- end
- confirm_open = true
- createButton(confirm_prompt_buttons, "yes_button", 34*vw, 46*vh, 12*vw, 8*vh, bg, arg[len(arg) - 1] or "Yes", setConfirmPromptState, true)
- createButton(confirm_prompt_buttons, "no_button", 54*vw, 46*vh, 12*vw, 8*vh, bg, arg[len(arg)] or "No", setConfirmPromptState, false)
- while confirm_response == nil do
- os.sleep(0.1)
- end
- confirm_open = false
- confirm_prompt_buttons = {}
- local out = confirm_response
- confirm_response = nil
- return out
- end
- --Function *Displays the prompt*
- function prompt(bg, header, ...)
- local arg = {...}
- local height = len(arg)
- local blocking = arg[len(arg)]
- if blocking ~= true then
- blocking = false
- end
- resetGpu()
- gpu.fill(20*vw, 10*vh, 60*vw, 50*vh, " ")
- gpu.setBackground(bg)
- gpu.fill(20*vw, 10*vh, 60*vw, 2*vh, " ")
- gpu.fill(20*vw, 60*vh, 61*vw, 2*vh, " ")
- gpu.fill(20*vw, 10*vh, 1*vw, 50*vh, " ")
- gpu.fill(80*vw, 10*vh, 1*vw, 50*vh, " ")
- gpu.fill(30*vw, 25*vh, 40*vw, 2*vh, " ")
- resetGpu()
- gpu.setForeground(bg)
- gpu.set(50*vw - (#header / 2), 18*vh, header)
- for i,m in pairs(arg) do
- if type(m) == "string" then
- gpu.set(50*vw - (#m / 2), 28*vh + (2*i*vh), m)
- end
- end
- resetGpu()
- if blocking == true then
- gpu.setForeground(bg)
- local escape = "Press \"Enter\" or \"Space\" to Escape"
- gpu.set(50*vw - (#escape / 2), 56*vh, escape)
- resetGpu()
- local state = true
- while state == true do
- local key, is_control, raw = parseKey()
- if raw == 13 or key == " " then
- state = false
- end
- end
- clear()
- updateDisplay()
- end
- end
- --Function *Dials symbol at index i*
- function dial(i)
- if address[i] == nil then
- dialing = false
- --Engage Gate
- failed = true
- event.ignore("stargate_spin_chevron_engaged", lockChevron)
- if sgspin ~= nil then
- event.cancel(sgspin)
- end
- return
- end
- local point = points[address[i]][gate_type]
- if point == "Giza (POO)" then
- sg.engageSymbol("Point of Origin")
- elseif point == "Subido (POO)" then
- sg.engageSymbol("Subido")
- elseif point == "Glyph 17 (POO)" then
- sg.engageSymbol("Glyph 17")
- else
- sg.engageSymbol(point)
- end
- end
- --Callback *Callback function for stargate chevron locking*
- function lockChevron(event, addr, caller, num, final_chevron, symbol)
- if chevrons[num - 1] ~= false then
- return
- end
- if gate_type == "UNIVERSE" and len(address) == num then
- final_chevron = true
- end
- if gate_type == "MILKYWAY" or gate_type == "PEGASUS" then
- os.sleep(0.5)
- elseif gate_type == "UNIVERSE" and final_chevron == false and sigterm == false then
- os.sleep(1)
- end
- chevrons[num - 1] = symbol
- clear()
- resetGpu()
- updateDisplay()
- if final_chevron == true or symbol == "Point of Origin" then
- local status, name, descrip, state = sg.engageGate()
- fail_type = state
- if status == "stargate_engage" then
- active = true
- failed = false
- else
- active = false
- failed = true
- end
- dialing = false
- event.ignore("stargate_spin_chevron_engaged", lockChevron)
- event.cancel(sgspin)
- elseif sigterm == true then
- dialing = false
- failed = true
- fail_type = "USER_MANUAL_OVERRIDE"
- sg.engageGate()
- event.ignore("stargate_spin_chevron_engaged", lockChevron)
- if sgspin ~= nil then
- event.cancel(sgspin)
- end
- elseif inbound == true then
- dialing = false
- event.ignore("stargate_spin_chevron_engaged", lockChevron)
- if sgspin ~= nil then
- event.cancel(sgspin)
- end
- else
- dial(num)
- end
- end
- --Callback *Callback for stargate inbound wormhole*
- function inboundConnection(event, address, caller, address_size)
- if dialing == true then
- dialing = false
- failed = false
- active = false
- end
- inbound = true
- beginInboundLoop(address_size)
- end
- --Callback *Callback for stargate dial failure*
- function sequenceFailure(event, address, caller)
- os.sleep(1)
- --sg.engageGate()
- dialing = false
- failed = true
- active = false
- fail_type = "ADDRESS_MALFORMED"
- event.ignore("stargate_spin_chevron_engaged", lockChevron)
- if sgspin ~= nil then
- event.cancel(sgspin)
- end
- fill(chevrons, false)
- address = {}
- index = 0
- end
- --Callback *Callback for unexpected gate close "For when the gate runs out of power"*
- function closeGate(event, address, caller, reason)
- active = false
- inbound = false
- dialing = false
- if reason == "connection_lost" then
- prompt(0xFF0000, "Stargate Error 499", "Connection to target gate terminated", true)
- elseif reason == "out_of_power" then
- prompt(0xFF0000, "Stargate Error 424", "Insufficient power to gate", true)
- elseif reason == "command" then
- prompt(0xFF0000, "Stargate Error 500", "Gate forcefully killed", true)
- end
- end
- --Callback *Callback for matter stream transit*
- function gateTravel(event, address, caller, inbound, player)
- if inbound == false then
- local time = 3
- for a=1,time do
- os.sleep(1)
- end
- active = false
- --sg.disengageGate()
- end
- if inbound == true then
- prompt(0xFF0000, "Warning", "Incoming traveller", true)
- end
- end
- --Callback *Callback for gate wormhole close*
- function fullClose(event, address, caller, initer)
- closed_fully = true
- end
- --Callback *Callback for screen touch*
- function onScreenTouch(event, address, x, y, button_number, player)
- if compiler_open == true and confirm_open == false then
- for id, button in pairs(symbol_buttons) do
- if (x >= button["x"] and x <= button["x"] + button["w"]) and (y >= button["y"] and y <= button["y"] + button["h"]) then
- local func = button["function"]
- local args = button["args"]
- if func ~= nil then
- func(args)
- else
- print("No bound function")
- end
- end
- end
- elseif book_open == true and confirm_open == false then
- for id, button in pairs(old_addr_buttons) do
- if (x >= button.x and x <= button.x + button.w) and (y >= button.y and y <= button.y + button.h) then
- if button_number == 0 then
- local func = button["function"]
- local args = button.args
- if func ~= nil then
- func(args)
- else
- print("No bound function")
- end
- elseif button_number == 1 then
- deleteAddress(button.args)
- end
- end
- end
- elseif confirm_open == true then
- for id, button in pairs(confirm_prompt_buttons) do
- if (x >= button.x and x <= button.x + button.w) and (y >= button.y and y <= button.y + button.h) then
- local func = button["function"]
- local args = button.args
- if func ~= nil then
- func(args)
- else
- print("No bound function")
- end
- end
- end
- elseif confirm_open == false then
- for id, button in pairs(buttons) do
- if (x >= button.x and x <= button.x + button.w) and (y >= button.y and y <= button.y + button.h) then
- local func = button["function"]
- local args = button.args
- if func ~= nil then
- func(args)
- else
- print("No bound function")
- end
- end
- end
- end
- end
- --Callback *Callback for dhd key press*
- function onDhdPress(event, caller, count, lock, name)
- if dhd_alert == false then
- dhd_alert = true
- local res = confirm(0xFFB600, "Stargate Alert", "DHD key press detected", "", "Shutdown Gate?", "Yes", "No")
- if res == true then
- if sg.getGateStatus() == "open" then
- sg.disengageGate()
- else
- sg.engageGate()
- end
- end
- dhd_alert = false
- clear()
- updateDisplay()
- end
- end
- --Callback *Callback for key press*
- function onKeyPress(event, address, char, code, player)
- char = unicode.char(char)
- if active == true then
- if char == " " then
- active = false
- --sg.disengageGate()
- end
- elseif dialing == true then
- if char == " " or code == 28 then
- prompt(0xFFB600, "Gate Manual Override", "Override engaged", "Gate will shutdown on next chevron")
- sigterm = true
- end
- end
- end
- --Function *Halts the program until gate is idle*
- function beginDialSequence()
- if len(address) == 0 then
- failed = true
- fail_type = "NULL_ADDRESS"
- else
- beginDialLoop()
- saveAddress()
- end
- if active == true then
- beginActiveLoop()
- elseif failed == true then
- index = 0
- fill(chevrons, false)
- address = {}
- if fail_type == "ADDRESS_MALFORMED" then
- prompt(0xFF0000, "Sequence Failed", "The given sequnce", "did not lock", true)
- elseif fail_type == "NOT_ENOUGH_POWER" then
- prompt(0xFF0000, "Sequence Failed", "Not enough power to dial", true)
- elseif fail_type == "BUSY" then
- prompt(0xFF0000, "Sequence Failed", "Target gate is active", true)
- elseif fail_type == "USER_MANUAL_OVERRIDE" then
- prompt(0xFF0000, "Sequence Failed", "Stargate dialing sequence", "was manually terminated", true)
- elseif fail_type == "NULL_ADDRESS" then
- prompt(0xFF0000, "Sequence Error", "No sequence compiled", true)
- else
- prompt(0xFF0000, "Sequence Failed", "Unknown Stargate Error", "Error: ", fail_type, true)
- end
- end
- address = {}
- end
- --Function *Halts the program until dialing is complete*
- function beginDialLoop()
- if dialing then
- return false
- end
- if sgspin == nil then
- local sgspin = event.listen("stargate_spin_chevron_engaged", lockChevron)
- end
- if sgfail == nil then
- local sgfail = event.listen("stargate_failed", sequenceFailure)
- end
- dialing = true
- dial(0)
- clear()
- updateDisplay()
- while dialing do
- os.sleep(0.1)
- end
- end
- --Function *Halts the program until active gate is shutdown*
- function beginActiveLoop()
- --saveAddress()
- if active == false or failed == true then
- return false
- end
- updateDisplay()
- prompt(0x00FF00, "Complete", "Sequence Locked; Press \"Space\" to Disengage", false)
- --clear()
- resetGpu()
- while active == true do
- os.sleep(0.1)
- listStats()
- end
- sg.disengageGate()
- resetGpu()
- clear()
- updateDisplay()
- address = {}
- fill(chevrons, false)
- index = 0
- resetGpu()
- while closed_fully == false do
- os.sleep(0.1)
- end
- end
- --Function *Halts program until inbound gate is shutdown*
- function beginInboundLoop(size)
- clear()
- if size ~= nil then
- for i=1,size do
- chevrons[i - 1] = true
- end
- end
- updateDisplay()
- prompt(0xFFB600, "Stargate Alert", "Inbound Wormhole", "Stargate dialed from "..size.." symbol address")
- while inbound == true do
- os.sleep(0.1)
- end
- sg.disengageGate()
- clear()
- updateDisplay()
- fill(chevrons, false)
- clear()
- updateDisplay()
- fully_closed = false
- while full_closed == false do
- os.sleep(0.1)
- end
- end
- --Main code loop *Event listener creation*
- clear()
- --event.onError(threadHandler)
- local sgin = event.listen("stargate_incoming_wormhole", inboundConnection)
- local sgclose = event.listen("stargate_close", closeGate)
- local screentouch = event.listen("touch", onScreenTouch)
- local keypress = event.listen("key_down", onKeyPress)
- local sgtravel = event.listen("stargate_traveler", gateTravel)
- local sgfullclose = event.listen("stargate_wormhole_closed_fully", fullClose)
- local dhdpress = event.listen("stargate_dhd_chevron_engaged", onDhdPress)
- --Main code loop *Main loop*
- function main()
- --local res = confirm(0x00FF00, "Test", "Y/N", "Y", "N")
- --print(res)
- --os.sleep(3)
- if sg.getGateStatus() ~= "not_merged" and sg.getGateStatus() ~= "idle" then
- sg.disengageGate()
- end
- if first == false then
- listHelp()
- first = true
- end
- while state == true do
- clear()
- updateDisplay()
- if address[index - 1] == "q" then
- prompt(standard, "Sequence Complete", "Sequence Entry Complete", "Press \"Enter\" to dial", false)
- end
- local key, is_control, raw, c, d = parseKey()
- if is_control == true then
- if raw == 13 then
- beginDialSequence()
- elseif raw == 8 and index > 0 then
- index = index - 1
- address[index] = nil
- elseif c == keybind_showKeybindsList then
- listKeyBinds()
- elseif c == keybind_toggleIris then
- prompt(0xFF0000, "Component Failure", "No iris system implemented", true)
- elseif c == 42 then
- quit()
- elseif c == keybind_showSequenceCompiler then
- listSequenceCompiler()
- elseif c == keybind_showOldAddresses then
- listOldAddresses()
- --prompt(0xFF0000, "Access Failure", "System WIP; Access Denied", "System Error 5", true)
- elseif c == keybind_showHelp then
- listHelp()
- elseif c == keybind_switchGateType then
- index = 0
- address = {}
- local new_gate_type
- if gate_type == "MILKYWAY" then
- new_gate_type = "PEGASUS"
- prompt(0xFFb600, "Gate Alert", "Switched gate type to \"Pegasus\"", true)
- elseif gate_type == "PEGASUS" then
- new_gate_type = "UNIVERSE"
- prompt(0xFFb600, "Gate Alert", "Switched gate type to \"Universe\"", true)
- elseif gate_type == "UNIVERSE" then
- new_gate_type = "MILKYWAY"
- prompt(0xFFb600, "Gate Alert", "Switched gate type to \"Milky Way\"", true)
- end
- sg = require("component").stargate
- local new = sg.getGateType()
- if new_gate_type ~= new then
- local res = confirm(0xFFB600, "Unequal Gate Type Alert", "The selected gate type does", "not match the selected gate", "", "Keep Changes?", "Yes", "No")
- if res == true then
- if gate_type == "MILKYWAY" then
- gate_type = "PEGASUS"
- --points = p_points
- elseif gate_type == "PEGASUS" then
- gate_type = "UNIVERSE"
- --points = u_points
- elseif gate_type == "UNIVERSE" then
- gate_type = "MILKYWAY"
- --points = mw_points
- end
- else
- gate_type = new
- end
- else
- gate_type = new_gate_type
- end
- end
- else
- if len(address) == 9 then
- prompt(0xFF0000, "Pre-Sequence Error", "Address Full", "Cannot append symbol to list", true)
- elseif points[key] ~= nil and points[key][gate_type] ~= nil then
- if count(address, key) >= 1 then
- prompt(0xFF0000, "Pre-Sequence Error", "Duplicate Keys", "Key \""..key.."\" is already listed", true)
- else
- if indexof(address, "q") ~= -1 then
- prompt(0xFFb600, "Pre-Sequence Alert", "\"Point of Origin\" already listed", true)
- end
- address[index] = key
- index = index + 1
- end
- else
- prompt(0xFF0000, "Pre-Sequence Error", "Unkown Key", "Key \""..key.."\" is not recognized", true)
- end
- end
- end
- quit()
- end
- --Error handling
- if debug_mode == false then
- local p_res, error = pcall(main)
- if p_res == false and forced_exit == false then
- prompt(0xFF0000, "Critical Error", "The program has encountered an unexpected error", true)
- --[=====[
- if dialing == true then
- local res = sg.engageGate()
- if res ~= nil then
- os.sleep(3)
- sg.disengageGate()
- end
- elseif active == true then
- sg.disengageGate()
- end
- --]=====]
- quit()
- end
- else
- main()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement