Advertisement
christheboss894

Untitled

Nov 17th, 2020 (edited)
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 48.19 KB | None | 0 0
  1. --[===[
  2. Open Computer Requirements:
  3. RAM: At least 1 tier 3 memory chip
  4. Screen: Tier 3
  5. GPU: Tier 3
  6. Installing:
  7. pastebin get [-f] tVig6HZv <filepath>
  8. --]===]
  9.  
  10. --[===[
  11. Notes:
  12. On first time boot, press <F6> to enter the main program
  13. --]===]
  14.  
  15. --[===[
  16. Changelog:
  17. Version 1:
  18. Program created
  19. Version 1.1:
  20. Bug fixes
  21. Version 2:
  22. Multi-gate compatibility
  23. Address list
  24. Version 2.1:
  25. Addition of capacitor count and energy levels
  26. Shrunk buttons to add 3 more
  27. Version 2.2:
  28. Changed symbol glyph keybinds for parity with PoltixeTheDataatabase's program
  29. Version 2.3:
  30. Addition of energy required to dial for addresses in address list
  31. Version 2.4:
  32. Refined energy required to dial in address list for successful dials only
  33. Refined address book to use text file "addresses.sga" instead of global table variable
  34. Version 2.5:
  35. (Planned): Refine help page
  36. --]===]
  37.  
  38. local forced_exit = false
  39. local debug_mode = false
  40.  
  41. --Table *Conversion of characters to symbol strings*
  42. local points = {}
  43. points["q"] = {["MILKYWAY"]="Giza (POO)", ["PEGASUS"]="Subido (POO)", ["UNIVERSE"]="Glyph 17 (POO)"}
  44. points["w"] = {["MILKYWAY"]="Crater", ["PEGASUS"]="Aaxel", ["UNIVERSE"]="Glyph 1"}
  45. points["e"] = {["MILKYWAY"]="Virgo", ["PEGASUS"]="Abrin", ["UNIVERSE"]="Glyph 2"}
  46. points["r"] = {["MILKYWAY"]="Bootes", ["PEGASUS"]="Acjesis", ["UNIVERSE"]="Glyph 3"}
  47. points["t"] = {["MILKYWAY"]="Centaurus", ["PEGASUS"]="Aldeni", ["UNIVERSE"]="Glyph 4"}
  48. points["y"] = {["MILKYWAY"]="Libra", ["PEGASUS"]="Alura", ["UNIVERSE"]="Glyph 5"}
  49. points["u"] = {["MILKYWAY"]="Serpens Caput", ["PEGASUS"]="Amiwill", ["UNIVERSE"]="Glyph 6"}
  50. points["i"] = {["MILKYWAY"]="Norma", ["PEGASUS"]="Arami", ["UNIVERSE"]="Glyph 7"}
  51. points["o"] = {["MILKYWAY"]="Scorpius", ["PEGASUS"]="Avoniv", ["UNIVERSE"]="Glyph 8"}
  52. points["p"] = {["MILKYWAY"]="Corona Australis", ["PEGASUS"]="Baselai", ["UNIVERSE"]="Glyph 9"}
  53. points["["] = {["MILKYWAY"]="Scutum", ["PEGASUS"]="Bydo", ["UNIVERSE"]="Glyph 10"}
  54. points["]"] = {["MILKYWAY"]="Sagittarius", ["PEGASUS"]="Ca Po", ["UNIVERSE"]="Glyph 11"}
  55. points["\\"] = {["MILKYWAY"]="Aquila", ["PEGASUS"]="Danami", ["UNIVERSE"]="Glyph 12"}
  56. points["a"] = {["MILKYWAY"]="Microscopium", ["PEGASUS"]="Dawnre", ["UNIVERSE"]="Glyph 13"}
  57. points["s"] = {["MILKYWAY"]="Capricornus", ["PEGASUS"]="Ecrumig", ["UNIVERSE"]="Glyph 14"}
  58. points["d"] = {["MILKYWAY"]="Piscis Austrinus", ["PEGASUS"]="Elenami", ["UNIVERSE"]="Glyph 15"}
  59. points["f"] = {["MILKYWAY"]="Equuleus", ["PEGASUS"]="Gilltin", ["UNIVERSE"]="Glyph 16"}
  60. points["g"] = {["MILKYWAY"]="Aquarius", ["PEGASUS"]="Hacemill", ["UNIVERSE"]="Glyph 17"}
  61. points["h"] = {["MILKYWAY"]="Pegasus", ["PEGASUS"]="Hamlinto", ["UNIVERSE"]="Glyph 18"}
  62. points["j"] = {["MILKYWAY"]="Sculptor", ["PEGASUS"]="Illume", ["UNIVERSE"]="Glyph 19"}
  63. points["k"] = {["MILKYWAY"]="Pisces", ["PEGASUS"]="Laylox", ["UNIVERSE"]="Glyph 20"}
  64. points["l"] = {["MILKYWAY"]="Andromeda", ["PEGASUS"]="Lenchan", ["UNIVERSE"]="Glyph 21"}
  65. points[";"] = {["MILKYWAY"]="Triangulum", ["PEGASUS"]="Olavii", ["UNIVERSE"]="Glyph 22"}
  66. points["'"] = {["MILKYWAY"]="Aries", ["PEGASUS"]="Once el", ["UNIVERSE"]="Glyph 23"}
  67. points["z"] = {["MILKYWAY"]="Perseus", ["PEGASUS"]="Poco re", ["UNIVERSE"]="Glyph 24"}
  68. points["x"] = {["MILKYWAY"]="Cetus", ["PEGASUS"]="Ramnon", ["UNIVERSE"]="Glyph 25"}
  69. points["c"] = {["MILKYWAY"]="Taurus", ["PEGASUS"]="Recktic", ["UNIVERSE"]="Glyph 26"}
  70. points["v"] = {["MILKYWAY"]="Auriga", ["PEGASUS"]="Robandus", ["UNIVERSE"]="Glyph 27"}
  71. points["b"] = {["MILKYWAY"]="Eridanus", ["PEGASUS"]="Roehi", ["UNIVERSE"]="Glyph 28"}
  72. points["n"] = {["MILKYWAY"]="Orion", ["PEGASUS"]="Salma", ["UNIVERSE"]="Glyph 29"}
  73. points["m"] = {["MILKYWAY"]="Canis Minor", ["PEGASUS"]="Sandovi", ["UNIVERSE"]="Glyph 30"}
  74. points[","] = {["MILKYWAY"]="Monoceros", ["PEGASUS"]="Setas", ["UNIVERSE"]="Glyph 31"}
  75. points["."] = {["MILKYWAY"]="Gemini", ["PEGASUS"]="Sibbron", ["UNIVERSE"]="Glyph 32"}
  76. points["/"] = {["MILKYWAY"]="Hydra", ["PEGASUS"]="Tahnan", ["UNIVERSE"]="Glyph 33"}
  77. points["1"] = {["MILKYWAY"]="Lynx", ["PEGASUS"]="Zamilloz", ["UNIVERSE"]="Glyph 34"}
  78. points["2"] = {["MILKYWAY"]="Cancer", ["PEGASUS"]="Zeo", ["UNIVERSE"]="Glyph 35"}
  79. points["3"] = {["MILKYWAY"]="Sextans", ["PEGASUS"]=nil, ["UNIVERSE"]="Glyph 36"}
  80. points["4"] = {["MILKYWAY"]="Leo Minor", ["PEGASUS"]=nil, ["UNIVERSE"]=nil}
  81. points["5"] = {["MILKYWAY"]="Leo", ["PEGASUS"]=nil, ["UNIVERSE"]=nil}
  82.  
  83. --Table *Program keybinds*
  84. local keybinds = {}
  85. keybinds["Enter"] = "Dial"
  86. keybinds["F1"] = "Keybinds List"
  87. keybinds["F4"] = "Toggle Iris"
  88. keybinds["Shift"] = "Quit"
  89. keybinds["F3"] = "Recent Address List"
  90. keybinds["F5"] = "Sequence Compiler"
  91. keybinds["F6"] = "Dialer Help"
  92. keybinds["F7"] = "Switch Gate Type"
  93.  
  94. --Table *Stores chevron values [false=not engaged]*
  95. chevrons = {}
  96. chevrons[0] = false
  97. chevrons[1] = false
  98. chevrons[2] = false
  99. chevrons[3] = false
  100. chevrons[4] = false
  101. chevrons[5] = false
  102. chevrons[6] = false
  103. chevrons[7] = false
  104. chevrons[8] = false
  105.  
  106. --Table *Stores action buttons*
  107. local buttons = {}
  108.  
  109. --Table *Stores sequence compiler buttons*
  110. local symbol_buttons = {}
  111.  
  112. --Table *Stores old address buttons*
  113. local old_addr_buttons = {}
  114.  
  115. --Table *Stores confirm prompt buttons*
  116. local confirm_prompt_buttons = {}
  117.  
  118. --Table *Stores the address entered by user |zero-indexed|*
  119. local address = {}
  120.  
  121. --Import modules "I think there called modules in Lua"
  122. local os = require("os")
  123. local component = require("component")
  124. local keyboard = require("keyboard")
  125. local event = require("event")
  126. local sides = require("sides")
  127. local unicode = require("unicode")
  128. local fs = require("filesystem")
  129. --local rs = component.redstone
  130.  
  131. --Setup variables
  132. local gpu = component.gpu
  133. local sg = component.stargate
  134. local top = sides.top
  135.  
  136. --Setup numerical variables
  137. local w, h = gpu.getResolution()
  138. local initial, ispallet = gpu.getBackground()
  139. local vw = w / 100
  140. local vh = h / 100
  141. local index = 0
  142. local dial_index = 0
  143. local keybind_showKeybindsList = 59
  144. local keybind_toggleIris = 62
  145. local keybind_showOldAddresses = 61
  146. local keybind_showSequenceCompiler = 63
  147. local keybind_showHelp = 64
  148. local keybind_switchGateType = 65
  149.  
  150. --Setup boolean variables
  151. state = true
  152. dialing = false
  153. active = false
  154. sigterm = false
  155. failed = false
  156. inbound = false
  157. local iris = false
  158. local compiler_open = false
  159. local book_open = false
  160. local save_addr = true
  161. local confirm_open = false
  162. local confirm_response = nil
  163. local closed_fully = false
  164. local dhd_alert = false
  165.  
  166. --Setup byte variables
  167. local standard = 0x0024C0
  168.  
  169. --Setup string variables
  170. local fail_type = ""
  171. local idc = ""
  172. local gate_type = sg.getGateType()
  173.  
  174. --Setup code
  175. gpu.setDepth(8)
  176. if first == nil then
  177. first = false
  178. end
  179. if fs.exists("addresses.sga") == false then
  180. file = io.open("addresses.sga", "a")
  181. file:close()
  182. end
  183.  
  184. --Function *Clears the screen*
  185. function clear()
  186. os.execute("clear")
  187. end
  188.  
  189. --Function *Coverts table to number indxed table*
  190. function toOrderedTable(table)
  191. local out = {}
  192. for key, value in pairs(table) do
  193. if type(key) == "string" then
  194. out[string.byte(key)] = value
  195. elseif type(key) == "table" then
  196. out[len(key)] = value
  197. else
  198. out[key] = value
  199. end
  200. end
  201. return out
  202. end
  203.  
  204. --Function *Extension of toOrderedTable*
  205. function toFlooredOrderedTable(table)
  206. local out = {}
  207. local ordered = toOrderedTable(table)
  208. local smallest = getLeast(getKeys(ordered))
  209. local max = len(ordered)
  210. local i = 1
  211. while len(out) < max do
  212. out[i] = ordered[smallest]
  213. ordered[smallest] = nil
  214. smallest = getLeast(getKeys(ordered))
  215. i = i + 1
  216. end
  217. return out
  218. end
  219.  
  220. --Function *Returns table containing keys*
  221. function getKeys(table)
  222. local keys = {}
  223. local index = 0
  224. for k,v in pairs(table) do
  225. keys[index] = k
  226. index = index + 1
  227. end
  228. return keys
  229. end
  230.  
  231. --Function *Gets smallest number in table*
  232. function getLeast(table)
  233. local smallest = nil
  234. for k,v in pairs(table) do
  235. --print(smallest, v)
  236. if smallest == nil then
  237. smallest = v
  238. end
  239. if type(v) == "number" then
  240. if v < smallest then
  241. smallest = v
  242. end
  243. end
  244. end
  245. return smallest
  246. end
  247.  
  248. --Function *Splits string around delimiter*
  249. function split(string, delimiter, start_index)
  250. if #delimiter > 1 then
  251. error("[function<split>]: ParamError@delimiter -> Expected string of length 0 to 1, got "..#delimiter)
  252. else
  253. if start_index == nil then
  254. start_index = 0
  255. end
  256. local out = {}
  257. local index = start_index
  258. out[index] = ""
  259. for i=1,#string do
  260. local char = string:sub(i,i)
  261. if char == delimiter then
  262. index = index + 1
  263. out[index] = ""
  264. else
  265. out[index] = out[index]..char
  266. end
  267. end
  268. return out
  269. end
  270. end
  271.  
  272. --Function *Counts number of occurances of each element in a table*
  273. function count(table, element)
  274. local e_count = 0
  275. for k,v in pairs(table) do
  276. if v == element then
  277. e_count = e_count + 1
  278. end
  279. end
  280. return e_count
  281. end
  282.  
  283. --Function *Gets number of entries in table*
  284. function len(table)
  285. local count = 0
  286. for k,v in pairs(table) do
  287. count = count + 1
  288. end
  289. return count
  290. end
  291.  
  292. --Function *Fills a table with a value*
  293. function fill(table, value)
  294. for i,e in pairs(table) do
  295. table[i] = value
  296. end
  297. end
  298.  
  299. --Function *Returns index position of element in table*
  300. function indexof(table, value)
  301. for k,v in pairs(table) do
  302. if v == value then
  303. return k
  304. end
  305. end
  306. return -1
  307. end
  308.  
  309. --Function *Shallow comparison of tables*
  310. function isSame(t1, t2, start)
  311. start = start or 1
  312. if len(t1) ~= len(t2) then
  313. return false
  314. end
  315. local l = len(t1)
  316. for i=start,l do
  317. --print(t1[i], t2[i])
  318. if t1[i] ~= t2[i] then
  319. return false
  320. end
  321. end
  322. return true
  323. end
  324.  
  325. --Function *Converts degrees to radians*
  326. function toRadian(degrees)
  327. return degrees * (math.pi / 180)
  328. end
  329.  
  330. --Function *Rounds a number*
  331. function round(num, places)
  332. places = places or 1
  333. return math.floor(num*math.pow(10,places)+0.5) / math.pow(10,places)
  334. end
  335.  
  336. --Function *Returns key from key press*
  337. function parseKey()
  338. local event, a, b, c, d = event.pull("key_down")
  339. return unicode.char(b), keyboard.isControl(b), b, c, d
  340. end
  341.  
  342. --Function *Resets GPU to inital standards*
  343. function resetGpu()
  344. gpu.setBackground(0x000000)
  345. gpu.setForeground(0xFFFFFF)
  346. end
  347.  
  348. --Function *Creates/modifies a button*
  349. function createButton(buffer, name, x, y, w, h, border, text, onclick, ...)
  350. resetGpu()
  351. gpu.fill(x, y, w, h, " ")
  352. gpu.setBackground(border)
  353. gpu.fill(x, y, w, 2*vh, " ")
  354. gpu.fill(x, y + h, w + 0.75*vw, 2*vh, " ")
  355. gpu.fill(x, y, 1*vw, h, " ")
  356. gpu.fill(x + w, y, 1*vw, h, " ")
  357. resetGpu()
  358. gpu.set((x + w / 2) - (#text / 2), y + h / 2, text)
  359. buffer[name] = {["x"]=x, ["y"]=y, ["w"]=w, ["h"]=h, ["function"]=onclick, ["args"]={...}, ["text"]=text}
  360. end
  361.  
  362. --Function *Handles event listener errors*
  363. function threadHandler(event)
  364. prompt(0xFF0000, "Error", "An Error has Occured in Dialing Program")
  365. dialing = false
  366. sigterm = true
  367. end
  368.  
  369. --Function *Ignores event if function was defined*
  370. function ignoreIf(name, callback)
  371. if callback ~= nil then
  372. event.ignore(name, callback)
  373. return true
  374. else
  375. return false
  376. end
  377. end
  378.  
  379. --Function *Quits the program with certain clenup functions*
  380. function quit()
  381. clear()
  382. resetGpu()
  383. ignoreIf("stargate_spin_chevron_engaged", lockChevron)
  384. ignoreIf("touch", onScreenTouch)
  385. ignoreIf("key_down", onKeyPress)
  386. ignoreIf("stargate_close", closeGate)
  387. ignoreIf("stargate_wormhole_closed_fully", fullClose)
  388. ignoreIf("stargate_dhd_chevron_engaged", onDhdPress)
  389. ignoreIf("stargate_incoming_wormhole", inboundConnection)
  390. forced_exit = true
  391. os.exit()
  392. end
  393.  
  394. --Function *Draws a circle*
  395. function drawCircle(h, k, r, border, size, fill)
  396. if fill == nil then
  397. fill = initial
  398. end
  399. if border == nil then
  400. border = 0xFFFFFF
  401. end
  402. if size == nil then
  403. size = 1
  404. end
  405. gpu.setBackground(border)
  406. for theta=0,360 do
  407. local x = h + r * math.cos(toRadian(theta))
  408. local y = k + r * math.sin(toRadian(theta)) / (w / h)
  409. gpu.fill(round(x), round(y), size + 1.125*vw, size, " ")
  410. end
  411. end
  412.  
  413. --Function *Gets addresses from file*
  414. function getAddresses()
  415. local old = {}
  416. local file = io.open("addresses.sga", "r")
  417. local data = file:read("*all")
  418. data = data:sub(1, #data - 1)
  419. file:close()
  420. if data == "" then
  421. return {}
  422. end
  423. local data_table = split(data, "#", 1)
  424. for key, addr in ipairs(data_table) do
  425. local addr_data = split(addr, "~", 1)
  426. old[key] = {}
  427. for k, ind in ipairs(addr_data) do
  428. local pairs = split(ind, "=", 0)
  429. --print(pairs[0], pairs[1])
  430. old[key][pairs[0]] = pairs[1]
  431. end
  432. old[key]["chars_list"] = split(old[key]["chars_list"], " ", 1)
  433. end
  434. return old
  435. end
  436.  
  437. --Function *Saves addresses to book*
  438. function saveAddress()
  439. if save_addr == true then
  440. local char_list = ""
  441. local new_addr = ""
  442.  
  443. for k, char in ipairs(toFlooredOrderedTable(address)) do
  444. char_list = char_list..char.." "
  445. end
  446. char_list = char_list:sub(1, #char_list - 1)
  447.  
  448. new_addr = new_addr.."chars_list="..char_list.."~"
  449. new_addr = new_addr.."gate_type="..gate_type.."~"
  450. new_addr = new_addr.."success_state="..tostring(not failed).."#"
  451. local file = io.open("addresses.sga", "a")
  452. file:write(new_addr)
  453. file:close()
  454. end
  455. end
  456.  
  457. --Function *Deletes address from book*
  458. function deleteAddress(args)
  459. local res = confirm(0xFFB600, "Delete Address", "Delete this address from the book?", "Yes", "No")
  460. if res == true then
  461. local old = getAddresses()
  462. local addr = args[1]["chars_list"]
  463. local kept = {}
  464. for k, a in ipairs(old) do
  465. if isSame(a["chars_list"], addr, 1) == false then
  466. kept[len(kept) + 1] = a
  467. end
  468. end
  469. local out = ""
  470. for a, addr in ipairs(kept) do
  471. local chars = ""
  472. local address = ""
  473. for i, char in addr["chars_list"] do
  474. chars = chars..char.." "
  475. end
  476. chars = chars:sub(1, #chars - 1)
  477. address = address.."chars_list="..chars.."~"
  478. address = address.."gate_type="..addr["gate_type"].."~"
  479. address = address.."success_state="..addr["success_state"].."#"
  480. out = out..address
  481. end
  482. local file = io.open("addresses.sga", "w")
  483. file:write(out)
  484. file:close()
  485. end
  486. listOldAddresses()
  487. end
  488.  
  489. --Bound-Function *abort_button.onclick*
  490. function abort()
  491. if active == true then
  492. --sg.disengageGate()
  493. active = false
  494. elseif dialing == true then
  495. prompt(0xFFB600, "Gate Manual Override", "Override engaged", "Gate will shutdown on next chevron")
  496. sigterm = true
  497. elseif count(chevrons, false) < 9 then
  498. sg.disengageGate()
  499. else
  500. prompt(0xFF0000, "Gate is IDLE", "The stargate is idle", "and cannot be disengaged", true)
  501. end
  502. end
  503.  
  504. --Bound-Function *iris_button.onclick*
  505. function toggleIris()
  506. prompt(0xFF0000, "Component Error", "No iris system implemented", true)
  507. if iris == true then
  508. --sg.disengageIris()
  509. --createButton(buttons, "iris_button", 8*vw, 70*vh, 15*vw, 8*vh, 0xFF0000, "Open Iris", toggleIris)
  510. --iris = false
  511. else
  512. --sg.engageIris()
  513. --createButton(buttons, "iris_button", 8*vw, 70*vh, 15*vw, 8*vh, 0x00FF00, "Close Iris", toggleIris)
  514. --iris = true
  515. end
  516. --clear()
  517. --updateDisplay()
  518. end
  519.  
  520. --Bound-Function *symbol_button.onclick*
  521. function addSymbolToSequence(args_list)
  522. clear()
  523. listSequenceCompiler()
  524. local symbol = args_list[1]
  525. if symbol ~= -1 then
  526. if indexof(points, symbol) ~= -1 then
  527. local char = indexof(points, symbol)
  528. if count(address, char) >= 1 then
  529. prompt(0xFF0000, "Pre-Sequence Error", "Duplicate Keys", "Key \""..key.."\" is already listed", true)
  530. listSequenceCompiler()
  531. else
  532. address[index] = char
  533. index = index + 1
  534. local old_button = symbol_buttons[symbol[gate_type].."button"]
  535. 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)
  536. end
  537. else
  538. prompt(0xFF0000, "Pre-Sequence Error", "Unkown Symbol", "Symbol \""..symbol[gate_type].."\" is not recognized", true)
  539. listSequenceCompiler()
  540. end
  541. elseif index > 0 then
  542. index = index - 1
  543. local old = points[address[index]]
  544. address[index] = nil
  545. local old_button = symbol_buttons[old[gate_type].."button"]
  546. 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])
  547. end
  548. end
  549.  
  550. --Bound-Function *switch_button.onclick*
  551. function switchGate()
  552. sg = require("component").stargate
  553. index = 0
  554. address = {}
  555. if gate_type == "MILKYWAY" then
  556. points = p_points
  557. gate_type = "PEGASUS"
  558. prompt(0xFFb600, "Gate Alert", "Switched gate type to \"Pegasus\"", true)
  559. elseif gate_type == "PEGASUS" then
  560. points = u_points
  561. gate_type = "UNIVERSE"
  562. prompt(0xFFb600, "Gate Alert", "Switched gate type to \"Universe\"", true)
  563. elseif gate_type == "UNIVERSE" then
  564. points = mw_points
  565. gate_type = "MILKYWAY"
  566. prompt(0xFFb600, "Gate Alert", "Switched gate type to \"Milky Way\"", true)
  567. end
  568. end
  569.  
  570. --Bound-Function *old_address_button.onclick*
  571. function dialOldAddress(args_list)
  572. local addr = args_list[1]
  573. if addr["gate_type"] ~= gate_type then
  574. prompt(0xFF0000, "Gate Type Error", "Cannot use address", "Address gate type does not match", true)
  575. listOldAddresses()
  576. else
  577. for i,char in ipairs(addr["chars_list"]) do
  578. address[i - 1] = char
  579. index = i - 1
  580. end
  581. local symbol_list = {}
  582. for k, v in ipairs(toFlooredOrderedTable(address)) do
  583. point = points[v][gate_type]
  584. if point == "Giza (POO)" then
  585. point = "Point of Origin"
  586. elseif point == "Subido (POO)" then
  587. point = "Subido"
  588. elseif point == "Glyph 17 (POO)" then
  589. point = "Glyph 17"
  590. end
  591. symbol_list[k] = point
  592. end
  593. local req = nil
  594. if addr["success_state"] == "true" then
  595. req = tostring(sg.getEnergyRequiredToDial(symbol_list).open)
  596. else
  597. req = "No Lock"
  598. end
  599. local res = confirm(standard, "Address Selected", "Ready to Dial Address", "Confirm Sequence", "", "Required Power: "..req, "Confirm", "Deny")
  600. if res == true then
  601. save_addr = false
  602. beginDialSequence()
  603. save_addr = true
  604. else
  605. fill(address, nil)
  606. index = 0
  607. end
  608. listOldAddresses()
  609. end
  610. end
  611.  
  612. --Bound-Function *confirm_prompt_button.onclick*
  613. function setConfirmPromptState(args)
  614. confirm_response = args[1]
  615. end
  616.  
  617. --Function *Displays buttons "Panel on lower left"*
  618. function listActionPanel()
  619. resetGpu()
  620. gpu.setBackground(standard)
  621. gpu.fill(5*vw, 54*vh, 23*vw, 2*vh, " ")
  622. gpu.fill(5*vw, 95*vh, 23.5*vw, 2*vh, " ")
  623. gpu.fill(5*vw, 55*vh, 1*vw, 40*vh, " ")
  624. gpu.fill(28*vw, 55*vh, 1*vw, 40*vh, " ")
  625. createButton(buttons, "dial_button", 7*vw, 58*vh, 9*vw, 8*vh, 0x787878, "Dial", beginDialSequence)
  626. createButton(buttons, "switch_button", 17.5*vw, 58*vh, 8.5*vw, 8*vh, 0x787878, "Switch Gate", switchGate)
  627. if iris == true then
  628. createButton(buttons, "iris_button", 7*vw, 70*vh, 9*vw, 8*vh, 0x00FF00, "Open Iris", toggleIris)
  629. else
  630. createButton(buttons, "iris_button", 7*vw, 70*vh, 9*vw, 8*vh, 0xFF0000, "Close Iris", toggleIris)
  631. end
  632. createButton(buttons, "kb_button", 17.5*vw, 70*vh, 8.5*vw, 8*vh, 0x787878, "Keybinds", listKeyBinds)
  633. createButton(buttons, "abort_button", 7*vw, 82*vh, 9*vw, 8*vh, 0x787878, "Abort", abort)
  634. createButton(buttons, "quit_button", 17.5*vw, 82*vh, 8.5*vw, 8*vh, 0x787878, "Compiler", listSequenceCompiler)
  635. end
  636.  
  637. --Function *Displays chevron states "Panel on upper left"*
  638. function listChevronStates()
  639. resetGpu()
  640. gpu.setBackground(standard)
  641. gpu.fill(5*vw, 6*vh, 20*vw, 2*vh, " ")
  642. gpu.fill(5*vw, 46*vh, 21*vw, 2*vh, " ")
  643. gpu.fill(5*vw, 6*vh, 1*vw, 40*vh, " ")
  644. gpu.fill(25*vw, 6*vh, 1*vw, 40*vh, " ")
  645. y = 10
  646. for i=0,8 do
  647. local c = chevrons[i]
  648. if c == false then
  649. gpu.setBackground(0xFF0000)
  650. gpu.fill(16*vw, y*vh, 5*vw, 2*vh, " ")
  651. gpu.setBackground(0x787878)
  652. gpu.fill(10*vw, y*vh, 5*vw, 2*vh, " ")
  653. else
  654. gpu.setBackground(0x00FF00)
  655. gpu.fill(10*vw, y*vh, 5*vw, 2*vh, " ")
  656. gpu.setBackground(0x787878)
  657. gpu.fill(16*vw, y*vh, 5*vw, 2*vh, " ")
  658. end
  659. resetGpu()
  660. gpu.set(8*vw, y*vh, tostring(i+1))
  661. y = y + 4
  662. end
  663. end
  664.  
  665. --Function *Displays chevron symbols "Panel on right"*
  666. function listAddressBoxes()
  667. resetGpu()
  668. y = 6
  669. for a=0,8 do
  670. gpu.setBackground(standard)
  671. gpu.fill(80*vw, y*vh, 15*vw, 2*vh, " ")
  672. gpu.fill(80*vw, y*vh + 6*vh, 16*vw, 2*vh, " ")
  673. gpu.fill(80*vw, y*vh, 1*vw, 9*vh, " ")
  674. gpu.fill(95*vw, y*vh, 1*vw, 9*vh, " ")
  675. resetGpu()
  676. if dialing == true then
  677. if chevrons[a] ~= false then
  678. local str = chevrons[a]
  679. gpu.set(88*vw - #str / 2, y*vh + 2.5*vh, str)
  680. end
  681. else
  682. if address[a] ~= nil then
  683. local str = points[address[a]][gate_type]
  684. gpu.set(88*vw - #str / 2, y*vh + 2.5*vh, str)
  685. --gpu.set(88*vw - 1, y*vh + 2.5*vh, address[a])
  686. end
  687. end
  688. y = y + 10
  689. end
  690. end
  691.  
  692. function listStats()
  693. resetGpu()
  694. local stored = sg.getEnergyStored()
  695. local max = sg.getMaxEnergyStored()
  696. local cap_count = sg.getCapacitorsInstalled()
  697. local inc = 28*vw / max
  698. local units = inc * stored
  699. gpu.setBackground(standard)
  700. gpu.fill(30*vw, 64*vh, 45*vw, 2*vh, " ")
  701. gpu.fill(30*vw, 78*vh, 46*vw, 2*vh, " ")
  702. gpu.fill(30*vw, 64*vh, 1*vw, 14*vh, " ")
  703. gpu.fill(75*vw, 64*vh, 1*vw, 14*vh, " ")
  704. resetGpu()
  705. gpu.set(32*vw, 68*vh, "Capacitors: "..cap_count.."/3")
  706. gpu.set(44*vw, 68*vh, "[")
  707. local x = 45*vw
  708. for i=1,3 do
  709. if i <= cap_count then
  710. gpu.setBackground(0x00FF00)
  711. else
  712. gpu.setBackground(0xFF0000)
  713. end
  714. gpu.fill(x, 68*vh, 8*vw, 2*vh, " ")
  715. x = x + 10*vw
  716. end
  717. resetGpu()
  718. gpu.set(73.5*vw, 68*vh, "]")
  719. gpu.set(32*vw, 74*vh, "Energy:")
  720. gpu.set(38*vw, 75*vh, round((stored / max) * 100).."%")
  721. gpu.set(32*vw, 76*vh, stored.."/"..max)
  722. gpu.set(44*vw, 75*vh, "[")
  723. gpu.set(73.5*vw, 75*vh, "]")
  724. gpu.setBackground(0x787878)
  725. gpu.fill(45*vw, 75*vh, 28*vw, 2*vh, " ")
  726. gpu.setBackground(0x00FF00)
  727. gpu.fill(45*vw, 75*vh, units, 2*vh, " ")
  728. end
  729.  
  730. --Function *Displays IDC and stargate status*
  731. function listOutputs()
  732. resetGpu()
  733. gpu.setBackground(standard)
  734. gpu.fill(30*vw, 82*vh, 45*vw, 2*vh, " ")
  735. gpu.fill(30*vw, 95*vh, 46*vw, 2*vh, " ")
  736. gpu.fill(30*vw, 82*vh, 1*vw, 15*vh, " ")
  737. gpu.fill(75*vw, 82*vh, 1*vw, 15*vh, " ")
  738. resetGpu()
  739. local gate = ""
  740. if gate_type == "MILKYWAY" then
  741. gate = "Milky Way: "
  742. elseif gate_type == "PEGASUS" then
  743. gate = "Pegasus: "
  744. elseif gate_type == "UNIVERSE" then
  745. gate = "Universe: "
  746. end
  747. if dialing == false then
  748. if inbound == false and active == false then
  749. local idle = gate.."IDLE"
  750. gpu.set(50*vw - (#idle / 2), 86*vh, idle)
  751. elseif inbound == true then
  752. local inbound = gate.."INBOUND"
  753. gpu.set(50*vw - (#inbound / 2), 86*vh, inbound)
  754. elseif active == true then
  755. local locked = gate.."LOCKED"
  756. gpu.set(50*vw - (#locked / 2), 86*vh, locked)
  757. end
  758. else
  759. local active = gate.."ACTIVE"
  760. gpu.set(50*vw - (#active / 2), 86*vh, active)
  761. end
  762. gpu.set(35*vw, 90*vh, "Stargate IDC: ")
  763. if idc ~= nil then
  764. gpu.set(30*vw + (45*vw / 2) - (#idc / 2), 90*vh, idc)
  765. end
  766. end
  767.  
  768. --Function *Displays stargate*
  769. function listStargate()
  770. local ring_color = 0xA5A5A5
  771. local inner_color = 0x696969
  772. if gate_type == "UNIVERSE" then
  773. ring_color = 0x222222
  774. inner_color = 0x333333
  775. elseif gate_type == "PEGASUS" then
  776. ring_color = 0x222222
  777. inner_color = 0x33DBFF
  778. end
  779. drawCircle(50*vw, 32*vh, 18*vw, 0x0049FF, 1)
  780. drawCircle(50*vw, 32*vh, 16*vw, inner_color, 1)
  781. drawCircle(50*vw, 32*vh, 17*vw, ring_color, 1)
  782. drawCircle(50*vw, 32*vh, 15*vw, ring_color, 1)
  783. resetGpu()
  784. local final = indexof(address, "q")
  785. local chevs = {}
  786. local r = 16*vw
  787. local old = nil
  788. chevs[0] = 50
  789. chevs[1] = 10
  790. chevs[2] = 330
  791. chevs[3] = 210
  792. chevs[4] = 170
  793. chevs[5] = 130
  794. if len(address) <= 7 then
  795. chevs[6] = 90
  796. chevs[7] = 290
  797. chevs[8] = 250
  798. elseif len(address) == 8 then
  799. chevs[6] = 290
  800. chevs[7] = 90
  801. chevs[8] = 250
  802. elseif len(address) == 9 then
  803. chevs[6] = 290
  804. chevs[7] = 250
  805. chevs[8] = 90
  806. end
  807. for c=0,8 do
  808. chev = chevrons[c]
  809. local x = 49*vw + r * math.cos(toRadian(chevs[c]))
  810. local y = 30*vh + r * math.sin(toRadian(chevs[c]+180)) / 2
  811. if chev == false then
  812. gpu.setBackground(0xF2F2F2)
  813. else
  814. gpu.setBackground(0xFF0000)
  815. end
  816. gpu.fill(round(x), round(y), 4*vw, 6*vh, " ")
  817. end
  818. end
  819.  
  820. --Function *List symbol keybinds*
  821. function listKeyBinds()
  822. resetGpu()
  823. clear()
  824. gpu.set(50*vw - (#"AUNIS Dialing Program Keybinds (F1)" / 2), 6*vh, "AUNIS Dailing Program Keybinds (F1)")
  825. gpu.setBackground(standard)
  826. gpu.fill(0*vw, 2*vh, 100*vw, 2*vh, " ")
  827. gpu.fill(0*vw, 98*vh, 100*vw, 2*vh, " ")
  828. resetGpu()
  829. x = 10*vw
  830. y = 10*vh
  831. index = 0
  832. for char, pair in ipairs(toFlooredOrderedTable(points)) do
  833. local symbol = pair[gate_type]
  834. if symbol ~= nil then
  835. if symbol == "Point of Origin" then
  836. gpu.setForeground(0x00FF00)
  837. end
  838. gpu.set(x, y, "\""..char.."\": "..symbol)
  839. index = index + 1
  840. y = y + 5*vh
  841. if y >= 90*vh then
  842. y = 10*vh
  843. x = x + 20*vw
  844. end
  845. gpu.setForeground(0xFFFFFF)
  846. end
  847. end
  848. for key, action in pairs(keybinds) do
  849. if action == "Dial" then
  850. gpu.setForeground(0x0000FF)
  851. elseif action == "Quit" then
  852. gpu.setForeground(0xFF0000)
  853. else
  854. gpu.setForeground(0xAAAAAA)
  855. end
  856. gpu.set(x, y, "\""..key.."\": "..action)
  857. y = y + 5*vh
  858. if y >= 90*vh then
  859. y = 10*vh
  860. x = x + 20*vw
  861. end
  862. gpu.setForeground(0xFFFFFF)
  863. end
  864. resetGpu()
  865. local leave = "Press \"F1\" to Escape"
  866. gpu.set(50*vw - (#leave / 2), 95*vh, leave)
  867. local state = true
  868. while state == true do
  869. local key, is_control, raw, c = parseKey()
  870. if c == keybind_showKeybindsList then
  871. state = false
  872. end
  873. end
  874. resetGpu()
  875. end
  876.  
  877. --Function *List old addresses*
  878. function listOldAddresses()
  879. --book_open = true
  880. resetGpu()
  881. clear()
  882. local header = "Recent Address Book (F3)"
  883. gpu.set(50*vw - (#header / 2), 6*vh, header)
  884. local escape = "Press \"F3\" to Escape"
  885. gpu.set(50*vw - (#escape / 2), 95*vh, escape)
  886. gpu.setBackground(standard)
  887. gpu.fill(0*vw, 2*vh, 100*vw, 2*vh, " ")
  888. gpu.fill(0*vw, 98*vh, 100*vw, 2*vh, " ")
  889. resetGpu()
  890. local old_addresses = getAddresses()
  891. local max = len(old_addresses)
  892. x = 5*vw
  893. y = 10*vh
  894. local i = 0
  895. while x < 95*vh do
  896. resetGpu()
  897. local seg = len(old_addresses) - i
  898. local address = old_addresses[seg]
  899. if address == nil then
  900. break
  901. end
  902. local addr = ""
  903. for i,char in ipairs(address["chars_list"]) do
  904. addr = addr..char.." "
  905. end
  906. local color = 0xFFFFFF
  907. if address["gate_type"] ~= gate_type then
  908. color = 0x555555
  909. elseif address["success_state"] == "false" then
  910. color = 0xFF0000
  911. elseif address["success_state"] == "true" then
  912. color = 0x00FF00
  913. end
  914. createButton(old_addr_buttons, seg.."addr", x, y, 18.5*vw, 8*vh, color, "Address: "..addr, dialOldAddress, address)
  915. y = y + 12*vh
  916. if y >= 95*vh then
  917. x = x + 20*vw
  918. y = 10*vh
  919. end
  920. i = i + 1
  921. end
  922. if book_open == false then
  923. book_open = true
  924. local state = true
  925. while state == true and inbound == false do
  926. local key, is_control, raw, c = parseKey()
  927. if c == keybind_showOldAddresses then
  928. state = false
  929. end
  930. end
  931. book_open = false
  932. end
  933. end
  934.  
  935. --Function *Sequence compiler*
  936. function listSequenceCompiler()
  937. resetGpu()
  938. clear()
  939. gpu.setBackground(standard)
  940. gpu.fill(0*vw, 2*vh, 100*vw, 2*vh, " ")
  941. gpu.fill(0*vw, 98*vh, 100*vw, 2*vh, " ")
  942. resetGpu()
  943. gpu.set(50*vw - (#"Sequence Compiler (F5)" / 2), 6*vh, "Sequence Compiler (F5)")
  944. local y = 10*vh
  945. local x = 3*vw
  946. local ordered = toFlooredOrderedTable(points)
  947. for c,symbol in ipairs(ordered) do
  948. if symbol[gate_type] ~= nil then
  949. local bg = nil
  950. local char = indexof(points, symbol)
  951. if indexof(address, char) ~= -1 then
  952. bg = 0x00FF00
  953. else
  954. bg = 0x787878
  955. end
  956. createButton(symbol_buttons, symbol[gate_type].."button", x, y, 15*vw, 5*vh, bg, "("..char..") "..symbol[gate_type], addSymbolToSequence, symbol)
  957. y = y + 10*vh
  958. if y >= 90*vh then
  959. y = 10*vh
  960. x = x + 20*vw
  961. end
  962. end
  963. end
  964. createButton(symbol_buttons, "backspace_button", x, y, 15*vw, 5*vh, 0xFF0000, "Backspace", addSymbolToSequence, -1)
  965. if address[index - 1] == "q" and gate_type ~= "UNIVERSE" then
  966. prompt(standard, "Sequence Complete", "Sequence Entry Complete", "Press \"Enter\" to dial", false)
  967. end
  968. resetGpu()
  969. local leave = "Press \"F5\" to Escape"
  970. gpu.set(50*vw - (#leave / 2), 95*vh, leave)
  971. if compiler_open == false then
  972. compiler_open = true
  973. local state = true
  974. while state == true and inbound == false do
  975. local key, is_control, raw, c = parseKey()
  976. if c == keybind_showSequenceCompiler then
  977. state = false
  978. end
  979. end
  980. clear()
  981. updateDisplay()
  982. compiler_open = false
  983. end
  984. end
  985.  
  986. --Function *Shows help menu*
  987. function listHelp()
  988. resetGpu()
  989. clear()
  990. gpu.setBackground(standard)
  991. gpu.fill(0*vw, 2*vh, 100*vw, 2*vh, " ")
  992. gpu.fill(0*vw, 98*vh, 100*vw, 2*vh, " ")
  993. resetGpu()
  994. gpu.set(50*vw - (#"AUNIS Dialing Program Help (F6)" / 2), 6*vh, "AUNIS Dialing Program Help (F6)")
  995. 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"
  996. local link = "https://www.curseforge.com/minecraft/mc-mods/aunis"
  997. local y = 10*vh
  998. for num,line in ipairs(split(descrip, ";", 1)) do
  999. gpu.set(50*vw - (#line / 2), y, line)
  1000. y = y + 2*vh
  1001. end
  1002. gpu.setForeground(0x0000AA)
  1003. gpu.set(50*vw - (#link / 2), y+5*vh, link)
  1004. resetGpu()
  1005. gpu.set(50*vw - (#"Press \"F6\" to Escape" / 2), 95*vh, "Press \"F6\" to Escape")
  1006.  
  1007. gpu.setBackground(standard)
  1008. gpu.fill(5*vw, 30*vh, 30*vw, 2*vh, " ")
  1009. gpu.fill(5*vw, 58*vh, 31*vw, 2*vh, " ")
  1010. gpu.fill(5*vw, 30*vh, 1*vw, 28*vh, " ")
  1011. gpu.fill(35*vw, 30*vh, 1*vw, 28*vh, " ")
  1012. resetGpu()
  1013. gpu.set(20.5, 30*vh, "Home Screen Buttons")
  1014. gpu.set(7*vw, 34*vh, "[Dial] - Dials the gate")
  1015. gpu.set(7*vw, 38*vh, "[Close/Open Iris] - Togggles the gate iris")
  1016. gpu.set(7*vw, 42*vh, "[Abort] - Shutdown gate dialing")
  1017. gpu.set(7*vw, 46*vh, "[Switch] - Switch gate type")
  1018. gpu.set(7*vw, 50*vh, "[Keybinds] - Shows list of keybinds")
  1019. gpu.set(7*vw, 54*vh, "[Compiler] - Shows sequence compiler")
  1020.  
  1021.  
  1022. gpu.setBackground(standard)
  1023. gpu.fill(53*vw, 30*vh, 43*vw, 2*vh, " ")
  1024. gpu.fill(53*vw, 50*vh, 43.5*vw, 2*vh, " ")
  1025. gpu.fill(53*vw, 30*vh, 1*vw, 20*vh, " ")
  1026. gpu.fill(95*vw, 30*vh, 1*vw, 20*vh, " ")
  1027. resetGpu()
  1028. gpu.set(70*vw, 30*vh, "Dialing the Gate")
  1029. gpu.set(55*vw, 34*vh, "Using the keys or sequence compiler, enter a stargate address")
  1030. gpu.set(55*vw, 38*vh, "Once done, press enter to dial the gate")
  1031. gpu.set(55*vw, 42*vh, "The chevrons will lock into place and attempt to open the gate")
  1032. gpu.set(55*vw, 46*vh, "Press \"Space\" or the abort button anytime to cancel the dialer")
  1033.  
  1034. gpu.setBackground(standard)
  1035. gpu.fill(5*vw, 64*vh, 50*vw, 2*vh, " ")
  1036. gpu.fill(5*vw, 94*vh, 51*vw, 2*vh, " ")
  1037.  
  1038. gpu.set(7*vw, 68*vh, "")
  1039.  
  1040. resetGpu()
  1041. local state = true
  1042. while state == true and inbound == false do
  1043. local key, is_control, raw, c = parseKey()
  1044. if c == keybind_showHelp then
  1045. state = false
  1046. end
  1047. end
  1048. end
  1049.  
  1050. --Function *Master display update*
  1051. function updateDisplay()
  1052. resetGpu()
  1053. listActionPanel()
  1054. listChevronStates()
  1055. listAddressBoxes()
  1056. listOutputs()
  1057. listStats()
  1058. listStargate()
  1059. gpu.setBackground(standard)
  1060. gpu.fill(0*vw, 2*vh, 40*vw, 2*vh, " ")
  1061. gpu.fill(60*vw, 2*vh, 40*vw, 2*vh, " ")
  1062. gpu.fill(0*vw, 98*vh, 100*vw, 2*vh, " ")
  1063. resetGpu()
  1064. end
  1065.  
  1066. --Function *Displays the confirmation prompt*
  1067. function confirm(bg, header, ...)
  1068. local arg = {...}
  1069. resetGpu()
  1070. gpu.fill(20*vw, 10*vh, 60*vw, 50*vh, " ")
  1071. gpu.setBackground(bg)
  1072. gpu.fill(20*vw, 10*vh, 60*vw, 2*vh, " ")
  1073. gpu.fill(20*vw, 60*vh, 61*vw, 2*vh, " ")
  1074. gpu.fill(20*vw, 10*vh, 1*vw, 50*vh, " ")
  1075. gpu.fill(80*vw, 10*vh, 1*vw, 50*vh, " ")
  1076. gpu.fill(30*vw, 25*vh, 40*vw, 2*vh, " ")
  1077. resetGpu()
  1078. gpu.setForeground(bg)
  1079. gpu.set(50*vw - (#header / 2), 18*vh, header)
  1080. for i,m in pairs(arg) do
  1081. if type(m) == "string" and i < len(arg) - 1 then
  1082. gpu.set(50*vw - (#m / 2), 28*vh + (2*i*vh), m)
  1083. end
  1084. end
  1085. confirm_open = true
  1086. createButton(confirm_prompt_buttons, "yes_button", 34*vw, 46*vh, 12*vw, 8*vh, bg, arg[len(arg) - 1] or "Yes", setConfirmPromptState, true)
  1087. createButton(confirm_prompt_buttons, "no_button", 54*vw, 46*vh, 12*vw, 8*vh, bg, arg[len(arg)] or "No", setConfirmPromptState, false)
  1088. while confirm_response == nil do
  1089. os.sleep(0.1)
  1090. end
  1091. confirm_open = false
  1092. confirm_prompt_buttons = {}
  1093. local out = confirm_response
  1094. confirm_response = nil
  1095. return out
  1096. end
  1097.  
  1098. --Function *Displays the prompt*
  1099. function prompt(bg, header, ...)
  1100. local arg = {...}
  1101. local height = len(arg)
  1102. local blocking = arg[len(arg)]
  1103. if blocking ~= true then
  1104. blocking = false
  1105. end
  1106. resetGpu()
  1107. gpu.fill(20*vw, 10*vh, 60*vw, 50*vh, " ")
  1108. gpu.setBackground(bg)
  1109. gpu.fill(20*vw, 10*vh, 60*vw, 2*vh, " ")
  1110. gpu.fill(20*vw, 60*vh, 61*vw, 2*vh, " ")
  1111. gpu.fill(20*vw, 10*vh, 1*vw, 50*vh, " ")
  1112. gpu.fill(80*vw, 10*vh, 1*vw, 50*vh, " ")
  1113. gpu.fill(30*vw, 25*vh, 40*vw, 2*vh, " ")
  1114. resetGpu()
  1115. gpu.setForeground(bg)
  1116. gpu.set(50*vw - (#header / 2), 18*vh, header)
  1117. for i,m in pairs(arg) do
  1118. if type(m) == "string" then
  1119. gpu.set(50*vw - (#m / 2), 28*vh + (2*i*vh), m)
  1120. end
  1121. end
  1122. resetGpu()
  1123. if blocking == true then
  1124. gpu.setForeground(bg)
  1125. local escape = "Press \"Enter\" or \"Space\" to Escape"
  1126. gpu.set(50*vw - (#escape / 2), 56*vh, escape)
  1127. resetGpu()
  1128. local state = true
  1129. while state == true do
  1130. local key, is_control, raw = parseKey()
  1131. if raw == 13 or key == " " then
  1132. state = false
  1133. end
  1134. end
  1135. clear()
  1136. updateDisplay()
  1137. end
  1138. end
  1139.  
  1140. --Function *Dials symbol at index i*
  1141. function dial(i)
  1142. if address[i] == nil then
  1143. dialing = false
  1144. --Engage Gate
  1145. failed = true
  1146. event.ignore("stargate_spin_chevron_engaged", lockChevron)
  1147. if sgspin ~= nil then
  1148. event.cancel(sgspin)
  1149. end
  1150. return
  1151. end
  1152. local point = points[address[i]][gate_type]
  1153. if point == "Giza (POO)" then
  1154. sg.engageSymbol("Point of Origin")
  1155. elseif point == "Subido (POO)" then
  1156. sg.engageSymbol("Subido")
  1157. elseif point == "Glyph 17 (POO)" then
  1158. sg.engageSymbol("Glyph 17")
  1159. else
  1160. sg.engageSymbol(point)
  1161. end
  1162. end
  1163.  
  1164. --Callback *Callback function for stargate chevron locking*
  1165. function lockChevron(event, addr, caller, num, final_chevron, symbol)
  1166. if chevrons[num - 1] ~= false then
  1167. return
  1168. end
  1169. if gate_type == "UNIVERSE" and len(address) == num then
  1170. final_chevron = true
  1171. end
  1172. if gate_type == "MILKYWAY" or gate_type == "PEGASUS" then
  1173. os.sleep(0.5)
  1174. elseif gate_type == "UNIVERSE" and final_chevron == false and sigterm == false then
  1175. os.sleep(1)
  1176. end
  1177. chevrons[num - 1] = symbol
  1178. clear()
  1179. resetGpu()
  1180. updateDisplay()
  1181. if final_chevron == true or symbol == "Point of Origin" then
  1182. local status, name, descrip, state = sg.engageGate()
  1183. fail_type = state
  1184. if status == "stargate_engage" then
  1185. active = true
  1186. failed = false
  1187. else
  1188. active = false
  1189. failed = true
  1190. end
  1191. dialing = false
  1192. event.ignore("stargate_spin_chevron_engaged", lockChevron)
  1193. event.cancel(sgspin)
  1194. elseif sigterm == true then
  1195. dialing = false
  1196. failed = true
  1197. fail_type = "USER_MANUAL_OVERRIDE"
  1198. sg.engageGate()
  1199. event.ignore("stargate_spin_chevron_engaged", lockChevron)
  1200. if sgspin ~= nil then
  1201. event.cancel(sgspin)
  1202. end
  1203. elseif inbound == true then
  1204. dialing = false
  1205. event.ignore("stargate_spin_chevron_engaged", lockChevron)
  1206. if sgspin ~= nil then
  1207. event.cancel(sgspin)
  1208. end
  1209. else
  1210. dial(num)
  1211. end
  1212. end
  1213.  
  1214. --Callback *Callback for stargate inbound wormhole*
  1215. function inboundConnection(event, address, caller, address_size)
  1216. if dialing == true then
  1217. dialing = false
  1218. failed = false
  1219. active = false
  1220. end
  1221. inbound = true
  1222. beginInboundLoop(address_size)
  1223. end
  1224.  
  1225. --Callback *Callback for stargate dial failure*
  1226. function sequenceFailure(event, address, caller)
  1227. os.sleep(1)
  1228. --sg.engageGate()
  1229. dialing = false
  1230. failed = true
  1231. active = false
  1232. fail_type = "ADDRESS_MALFORMED"
  1233. event.ignore("stargate_spin_chevron_engaged", lockChevron)
  1234. if sgspin ~= nil then
  1235. event.cancel(sgspin)
  1236. end
  1237. fill(chevrons, false)
  1238. address = {}
  1239. index = 0
  1240. end
  1241.  
  1242. --Callback *Callback for unexpected gate close "For when the gate runs out of power"*
  1243. function closeGate(event, address, caller, reason)
  1244. active = false
  1245. inbound = false
  1246. dialing = false
  1247. if reason == "connection_lost" then
  1248. prompt(0xFF0000, "Stargate Error 499", "Connection to target gate terminated", true)
  1249. elseif reason == "out_of_power" then
  1250. prompt(0xFF0000, "Stargate Error 424", "Insufficient power to gate", true)
  1251. elseif reason == "command" then
  1252. prompt(0xFF0000, "Stargate Error 500", "Gate forcefully killed", true)
  1253. end
  1254. end
  1255.  
  1256. --Callback *Callback for matter stream transit*
  1257. function gateTravel(event, address, caller, inbound, player)
  1258. if inbound == false then
  1259. local time = 3
  1260. for a=1,time do
  1261. os.sleep(1)
  1262. end
  1263. active = false
  1264. --sg.disengageGate()
  1265. end
  1266. if inbound == true then
  1267. prompt(0xFF0000, "Warning", "Incoming traveller", true)
  1268. end
  1269. end
  1270.  
  1271. --Callback *Callback for gate wormhole close*
  1272. function fullClose(event, address, caller, initer)
  1273. closed_fully = true
  1274. end
  1275.  
  1276. --Callback *Callback for screen touch*
  1277. function onScreenTouch(event, address, x, y, button_number, player)
  1278. if compiler_open == true and confirm_open == false then
  1279. for id, button in pairs(symbol_buttons) do
  1280. if (x >= button["x"] and x <= button["x"] + button["w"]) and (y >= button["y"] and y <= button["y"] + button["h"]) then
  1281. local func = button["function"]
  1282. local args = button["args"]
  1283. if func ~= nil then
  1284. func(args)
  1285. else
  1286. print("No bound function")
  1287. end
  1288. end
  1289. end
  1290. elseif book_open == true and confirm_open == false then
  1291. for id, button in pairs(old_addr_buttons) do
  1292. if (x >= button.x and x <= button.x + button.w) and (y >= button.y and y <= button.y + button.h) then
  1293. if button_number == 0 then
  1294. local func = button["function"]
  1295. local args = button.args
  1296. if func ~= nil then
  1297. func(args)
  1298. else
  1299. print("No bound function")
  1300. end
  1301. elseif button_number == 1 then
  1302. deleteAddress(button.args)
  1303. end
  1304. end
  1305. end
  1306. elseif confirm_open == true then
  1307. for id, button in pairs(confirm_prompt_buttons) do
  1308. if (x >= button.x and x <= button.x + button.w) and (y >= button.y and y <= button.y + button.h) then
  1309. local func = button["function"]
  1310. local args = button.args
  1311. if func ~= nil then
  1312. func(args)
  1313. else
  1314. print("No bound function")
  1315. end
  1316. end
  1317. end
  1318. elseif confirm_open == false then
  1319. for id, button in pairs(buttons) do
  1320. if (x >= button.x and x <= button.x + button.w) and (y >= button.y and y <= button.y + button.h) then
  1321. local func = button["function"]
  1322. local args = button.args
  1323. if func ~= nil then
  1324. func(args)
  1325. else
  1326. print("No bound function")
  1327. end
  1328. end
  1329. end
  1330. end
  1331. end
  1332.  
  1333. --Callback *Callback for dhd key press*
  1334. function onDhdPress(event, caller, count, lock, name)
  1335. if dhd_alert == false then
  1336. dhd_alert = true
  1337. local res = confirm(0xFFB600, "Stargate Alert", "DHD key press detected", "", "Shutdown Gate?", "Yes", "No")
  1338. if res == true then
  1339. if sg.getGateStatus() == "open" then
  1340. sg.disengageGate()
  1341. else
  1342. sg.engageGate()
  1343. end
  1344. end
  1345. dhd_alert = false
  1346. clear()
  1347. updateDisplay()
  1348. end
  1349. end
  1350.  
  1351. --Callback *Callback for key press*
  1352. function onKeyPress(event, address, char, code, player)
  1353. char = unicode.char(char)
  1354. if active == true then
  1355. if char == " " then
  1356. active = false
  1357. --sg.disengageGate()
  1358. end
  1359. elseif dialing == true then
  1360. if char == " " or code == 28 then
  1361. prompt(0xFFB600, "Gate Manual Override", "Override engaged", "Gate will shutdown on next chevron")
  1362. sigterm = true
  1363. end
  1364. end
  1365. end
  1366.  
  1367. --Function *Halts the program until gate is idle*
  1368. function beginDialSequence()
  1369. if len(address) == 0 then
  1370. failed = true
  1371. fail_type = "NULL_ADDRESS"
  1372. else
  1373. beginDialLoop()
  1374. saveAddress()
  1375. end
  1376. if active == true then
  1377. beginActiveLoop()
  1378. elseif failed == true then
  1379. index = 0
  1380. fill(chevrons, false)
  1381. address = {}
  1382. if fail_type == "ADDRESS_MALFORMED" then
  1383. prompt(0xFF0000, "Sequence Failed", "The given sequnce", "did not lock", true)
  1384. elseif fail_type == "NOT_ENOUGH_POWER" then
  1385. prompt(0xFF0000, "Sequence Failed", "Not enough power to dial", true)
  1386. elseif fail_type == "BUSY" then
  1387. prompt(0xFF0000, "Sequence Failed", "Target gate is active", true)
  1388. elseif fail_type == "USER_MANUAL_OVERRIDE" then
  1389. prompt(0xFF0000, "Sequence Failed", "Stargate dialing sequence", "was manually terminated", true)
  1390. elseif fail_type == "NULL_ADDRESS" then
  1391. prompt(0xFF0000, "Sequence Error", "No sequence compiled", true)
  1392. else
  1393. prompt(0xFF0000, "Sequence Failed", "Unknown Stargate Error", "Error: ", fail_type, true)
  1394. end
  1395. end
  1396. address = {}
  1397. end
  1398.  
  1399. --Function *Halts the program until dialing is complete*
  1400. function beginDialLoop()
  1401. if dialing then
  1402. return false
  1403. end
  1404. if sgspin == nil then
  1405. local sgspin = event.listen("stargate_spin_chevron_engaged", lockChevron)
  1406. end
  1407. if sgfail == nil then
  1408. local sgfail = event.listen("stargate_failed", sequenceFailure)
  1409. end
  1410. dialing = true
  1411. dial(0)
  1412. clear()
  1413. updateDisplay()
  1414. while dialing do
  1415. os.sleep(0.1)
  1416. end
  1417. end
  1418.  
  1419. --Function *Halts the program until active gate is shutdown*
  1420. function beginActiveLoop()
  1421. --saveAddress()
  1422. if active == false or failed == true then
  1423. return false
  1424. end
  1425. updateDisplay()
  1426. prompt(0x00FF00, "Complete", "Sequence Locked; Press \"Space\" to Disengage", false)
  1427. --clear()
  1428. resetGpu()
  1429. while active == true do
  1430. os.sleep(0.1)
  1431. listStats()
  1432. end
  1433. sg.disengageGate()
  1434. resetGpu()
  1435. clear()
  1436. updateDisplay()
  1437. address = {}
  1438. fill(chevrons, false)
  1439. index = 0
  1440. resetGpu()
  1441. while closed_fully == false do
  1442. os.sleep(0.1)
  1443. end
  1444. end
  1445.  
  1446. --Function *Halts program until inbound gate is shutdown*
  1447. function beginInboundLoop(size)
  1448. clear()
  1449. if size ~= nil then
  1450. for i=1,size do
  1451. chevrons[i - 1] = true
  1452. end
  1453. end
  1454. updateDisplay()
  1455. prompt(0xFFB600, "Stargate Alert", "Inbound Wormhole", "Stargate dialed from "..size.." symbol address")
  1456. while inbound == true do
  1457. os.sleep(0.1)
  1458. end
  1459. sg.disengageGate()
  1460. clear()
  1461. updateDisplay()
  1462. fill(chevrons, false)
  1463. clear()
  1464. updateDisplay()
  1465. fully_closed = false
  1466. while full_closed == false do
  1467. os.sleep(0.1)
  1468. end
  1469. end
  1470.  
  1471. --Main code loop *Event listener creation*
  1472. clear()
  1473. --event.onError(threadHandler)
  1474. local sgin = event.listen("stargate_incoming_wormhole", inboundConnection)
  1475. local sgclose = event.listen("stargate_close", closeGate)
  1476. local screentouch = event.listen("touch", onScreenTouch)
  1477. local keypress = event.listen("key_down", onKeyPress)
  1478. local sgtravel = event.listen("stargate_traveler", gateTravel)
  1479. local sgfullclose = event.listen("stargate_wormhole_closed_fully", fullClose)
  1480. local dhdpress = event.listen("stargate_dhd_chevron_engaged", onDhdPress)
  1481.  
  1482. --Main code loop *Main loop*
  1483. function main()
  1484. --local res = confirm(0x00FF00, "Test", "Y/N", "Y", "N")
  1485. --print(res)
  1486. --os.sleep(3)
  1487. if sg.getGateStatus() ~= "not_merged" and sg.getGateStatus() ~= "idle" then
  1488. sg.disengageGate()
  1489. end
  1490. if first == false then
  1491. listHelp()
  1492. first = true
  1493. end
  1494. while state == true do
  1495. clear()
  1496. updateDisplay()
  1497. if address[index - 1] == "q" then
  1498. prompt(standard, "Sequence Complete", "Sequence Entry Complete", "Press \"Enter\" to dial", false)
  1499. end
  1500. local key, is_control, raw, c, d = parseKey()
  1501. if is_control == true then
  1502. if raw == 13 then
  1503. beginDialSequence()
  1504. elseif raw == 8 and index > 0 then
  1505. index = index - 1
  1506. address[index] = nil
  1507. elseif c == keybind_showKeybindsList then
  1508. listKeyBinds()
  1509. elseif c == keybind_toggleIris then
  1510. prompt(0xFF0000, "Component Failure", "No iris system implemented", true)
  1511. elseif c == 42 then
  1512. quit()
  1513. elseif c == keybind_showSequenceCompiler then
  1514. listSequenceCompiler()
  1515. elseif c == keybind_showOldAddresses then
  1516. listOldAddresses()
  1517. --prompt(0xFF0000, "Access Failure", "System WIP; Access Denied", "System Error 5", true)
  1518. elseif c == keybind_showHelp then
  1519. listHelp()
  1520. elseif c == keybind_switchGateType then
  1521. index = 0
  1522. address = {}
  1523. local new_gate_type
  1524. if gate_type == "MILKYWAY" then
  1525. new_gate_type = "PEGASUS"
  1526. prompt(0xFFb600, "Gate Alert", "Switched gate type to \"Pegasus\"", true)
  1527. elseif gate_type == "PEGASUS" then
  1528. new_gate_type = "UNIVERSE"
  1529. prompt(0xFFb600, "Gate Alert", "Switched gate type to \"Universe\"", true)
  1530. elseif gate_type == "UNIVERSE" then
  1531. new_gate_type = "MILKYWAY"
  1532. prompt(0xFFb600, "Gate Alert", "Switched gate type to \"Milky Way\"", true)
  1533. end
  1534. sg = require("component").stargate
  1535. local new = sg.getGateType()
  1536. if new_gate_type ~= new then
  1537. local res = confirm(0xFFB600, "Unequal Gate Type Alert", "The selected gate type does", "not match the selected gate", "", "Keep Changes?", "Yes", "No")
  1538. if res == true then
  1539. if gate_type == "MILKYWAY" then
  1540. gate_type = "PEGASUS"
  1541. --points = p_points
  1542. elseif gate_type == "PEGASUS" then
  1543. gate_type = "UNIVERSE"
  1544. --points = u_points
  1545. elseif gate_type == "UNIVERSE" then
  1546. gate_type = "MILKYWAY"
  1547. --points = mw_points
  1548. end
  1549. else
  1550. gate_type = new
  1551. end
  1552. else
  1553. gate_type = new_gate_type
  1554. end
  1555. end
  1556. else
  1557. if len(address) == 9 then
  1558. prompt(0xFF0000, "Pre-Sequence Error", "Address Full", "Cannot append symbol to list", true)
  1559. elseif points[key] ~= nil and points[key][gate_type] ~= nil then
  1560. if count(address, key) >= 1 then
  1561. prompt(0xFF0000, "Pre-Sequence Error", "Duplicate Keys", "Key \""..key.."\" is already listed", true)
  1562. else
  1563. if indexof(address, "q") ~= -1 then
  1564. prompt(0xFFb600, "Pre-Sequence Alert", "\"Point of Origin\" already listed", true)
  1565. end
  1566. address[index] = key
  1567. index = index + 1
  1568. end
  1569. else
  1570. prompt(0xFF0000, "Pre-Sequence Error", "Unkown Key", "Key \""..key.."\" is not recognized", true)
  1571. end
  1572. end
  1573. end
  1574.  
  1575. quit()
  1576.  
  1577. end
  1578.  
  1579. --Error handling
  1580. if debug_mode == false then
  1581. local p_res, error = pcall(main)
  1582. if p_res == false and forced_exit == false then
  1583. prompt(0xFF0000, "Critical Error", "The program has encountered an unexpected error", true)
  1584. --[=====[
  1585. if dialing == true then
  1586. local res = sg.engageGate()
  1587. if res ~= nil then
  1588. os.sleep(3)
  1589. sg.disengageGate()
  1590. end
  1591. elseif active == true then
  1592. sg.disengageGate()
  1593. end
  1594. --]=====]
  1595. quit()
  1596. end
  1597. else
  1598. main()
  1599. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement