Advertisement
christheboss894

Untitled

Nov 17th, 2020
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 47.91 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. boolean Beamer = component.beamer.isActive;
  507. if (Beamer == true)
  508. Beamer = false;
  509. else
  510. Beamer = true;
  511. end
  512. createButton(buttons, "beamer_button", 8*vw, 70*vh, 15*vw, 8*vh, 0xFF0000, "Toggle Beamer", toggleIris)
  513. component.beamer.setActive(Beamer)
  514. clear()
  515. updateDisplay()
  516. end
  517.  
  518. --Bound-Function *symbol_button.onclick*
  519. function addSymbolToSequence(args_list)
  520. clear()
  521. listSequenceCompiler()
  522. local symbol = args_list[1]
  523. if symbol ~= -1 then
  524. if indexof(points, symbol) ~= -1 then
  525. local char = indexof(points, symbol)
  526. if count(address, char) >= 1 then
  527. prompt(0xFF0000, "Pre-Sequence Error", "Duplicate Keys", "Key \""..key.."\" is already listed", true)
  528. listSequenceCompiler()
  529. else
  530. address[index] = char
  531. index = index + 1
  532. local old_button = symbol_buttons[symbol[gate_type].."button"]
  533. 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)
  534. end
  535. else
  536. prompt(0xFF0000, "Pre-Sequence Error", "Unkown Symbol", "Symbol \""..symbol[gate_type].."\" is not recognized", true)
  537. listSequenceCompiler()
  538. end
  539. elseif index > 0 then
  540. index = index - 1
  541. local old = points[address[index]]
  542. address[index] = nil
  543. local old_button = symbol_buttons[old[gate_type].."button"]
  544. 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])
  545. end
  546. end
  547.  
  548. --Bound-Function *switch_button.onclick*
  549. function switchGate()
  550. sg = require("component").stargate
  551. index = 0
  552. address = {}
  553. if gate_type == "MILKYWAY" then
  554. points = p_points
  555. gate_type = "PEGASUS"
  556. prompt(0xFFb600, "Gate Alert", "Switched gate type to \"Pegasus\"", true)
  557. elseif gate_type == "PEGASUS" then
  558. points = u_points
  559. gate_type = "UNIVERSE"
  560. prompt(0xFFb600, "Gate Alert", "Switched gate type to \"Universe\"", true)
  561. elseif gate_type == "UNIVERSE" then
  562. points = mw_points
  563. gate_type = "MILKYWAY"
  564. prompt(0xFFb600, "Gate Alert", "Switched gate type to \"Milky Way\"", true)
  565. end
  566. end
  567.  
  568. --Bound-Function *old_address_button.onclick*
  569. function dialOldAddress(args_list)
  570. local addr = args_list[1]
  571. if addr["gate_type"] ~= gate_type then
  572. prompt(0xFF0000, "Gate Type Error", "Cannot use address", "Address gate type does not match", true)
  573. listOldAddresses()
  574. else
  575. for i,char in ipairs(addr["chars_list"]) do
  576. address[i - 1] = char
  577. index = i - 1
  578. end
  579. local symbol_list = {}
  580. for k, v in ipairs(toFlooredOrderedTable(address)) do
  581. point = points[v][gate_type]
  582. if point == "Giza (POO)" then
  583. point = "Point of Origin"
  584. elseif point == "Subido (POO)" then
  585. point = "Subido"
  586. elseif point == "Glyph 17 (POO)" then
  587. point = "Glyph 17"
  588. end
  589. symbol_list[k] = point
  590. end
  591. local req = nil
  592. if addr["success_state"] == "true" then
  593. req = tostring(sg.getEnergyRequiredToDial(symbol_list).open)
  594. else
  595. req = "No Lock"
  596. end
  597. local res = confirm(standard, "Address Selected", "Ready to Dial Address", "Confirm Sequence", "", "Required Power: "..req, "Confirm", "Deny")
  598. if res == true then
  599. save_addr = false
  600. beginDialSequence()
  601. save_addr = true
  602. else
  603. fill(address, nil)
  604. index = 0
  605. end
  606. listOldAddresses()
  607. end
  608. end
  609.  
  610. --Bound-Function *confirm_prompt_button.onclick*
  611. function setConfirmPromptState(args)
  612. confirm_response = args[1]
  613. end
  614.  
  615. --Function *Displays buttons "Panel on lower left"*
  616. function listActionPanel()
  617. resetGpu()
  618. gpu.setBackground(standard)
  619. gpu.fill(5*vw, 54*vh, 23*vw, 2*vh, " ")
  620. gpu.fill(5*vw, 95*vh, 23.5*vw, 2*vh, " ")
  621. gpu.fill(5*vw, 55*vh, 1*vw, 40*vh, " ")
  622. gpu.fill(28*vw, 55*vh, 1*vw, 40*vh, " ")
  623. createButton(buttons, "dial_button", 7*vw, 58*vh, 9*vw, 8*vh, 0x787878, "Dial", beginDialSequence)
  624. createButton(buttons, "switch_button", 17.5*vw, 58*vh, 8.5*vw, 8*vh, 0x787878, "Switch Gate", switchGate)
  625. createButton(buttons, "beamer_button", 7*vw, 70*vh, 9*vw, 8*vh, 0x00FF00, "Toggle Beamer", toggleIris)
  626. createButton(buttons, "kb_button", 17.5*vw, 70*vh, 8.5*vw, 8*vh, 0x787878, "Keybinds", listKeyBinds)
  627. createButton(buttons, "abort_button", 7*vw, 82*vh, 9*vw, 8*vh, 0x787878, "Abort", abort)
  628. createButton(buttons, "quit_button", 17.5*vw, 82*vh, 8.5*vw, 8*vh, 0x787878, "Compiler", listSequenceCompiler)
  629. end
  630.  
  631. --Function *Displays chevron states "Panel on upper left"*
  632. function listChevronStates()
  633. resetGpu()
  634. gpu.setBackground(standard)
  635. gpu.fill(5*vw, 6*vh, 20*vw, 2*vh, " ")
  636. gpu.fill(5*vw, 46*vh, 21*vw, 2*vh, " ")
  637. gpu.fill(5*vw, 6*vh, 1*vw, 40*vh, " ")
  638. gpu.fill(25*vw, 6*vh, 1*vw, 40*vh, " ")
  639. y = 10
  640. for i=0,8 do
  641. local c = chevrons[i]
  642. if c == false then
  643. gpu.setBackground(0xFF0000)
  644. gpu.fill(16*vw, y*vh, 5*vw, 2*vh, " ")
  645. gpu.setBackground(0x787878)
  646. gpu.fill(10*vw, y*vh, 5*vw, 2*vh, " ")
  647. else
  648. gpu.setBackground(0x00FF00)
  649. gpu.fill(10*vw, y*vh, 5*vw, 2*vh, " ")
  650. gpu.setBackground(0x787878)
  651. gpu.fill(16*vw, y*vh, 5*vw, 2*vh, " ")
  652. end
  653. resetGpu()
  654. gpu.set(8*vw, y*vh, tostring(i+1))
  655. y = y + 4
  656. end
  657. end
  658.  
  659. --Function *Displays chevron symbols "Panel on right"*
  660. function listAddressBoxes()
  661. resetGpu()
  662. y = 6
  663. for a=0,8 do
  664. gpu.setBackground(standard)
  665. gpu.fill(80*vw, y*vh, 15*vw, 2*vh, " ")
  666. gpu.fill(80*vw, y*vh + 6*vh, 16*vw, 2*vh, " ")
  667. gpu.fill(80*vw, y*vh, 1*vw, 9*vh, " ")
  668. gpu.fill(95*vw, y*vh, 1*vw, 9*vh, " ")
  669. resetGpu()
  670. if dialing == true then
  671. if chevrons[a] ~= false then
  672. local str = chevrons[a]
  673. gpu.set(88*vw - #str / 2, y*vh + 2.5*vh, str)
  674. end
  675. else
  676. if address[a] ~= nil then
  677. local str = points[address[a]][gate_type]
  678. gpu.set(88*vw - #str / 2, y*vh + 2.5*vh, str)
  679. --gpu.set(88*vw - 1, y*vh + 2.5*vh, address[a])
  680. end
  681. end
  682. y = y + 10
  683. end
  684. end
  685.  
  686. function listStats()
  687. resetGpu()
  688. local stored = sg.getEnergyStored()
  689. local max = sg.getMaxEnergyStored()
  690. local cap_count = sg.getCapacitorsInstalled()
  691. local inc = 28*vw / max
  692. local units = inc * stored
  693. gpu.setBackground(standard)
  694. gpu.fill(30*vw, 64*vh, 45*vw, 2*vh, " ")
  695. gpu.fill(30*vw, 78*vh, 46*vw, 2*vh, " ")
  696. gpu.fill(30*vw, 64*vh, 1*vw, 14*vh, " ")
  697. gpu.fill(75*vw, 64*vh, 1*vw, 14*vh, " ")
  698. resetGpu()
  699. gpu.set(32*vw, 68*vh, "Capacitors: "..cap_count.."/3")
  700. gpu.set(44*vw, 68*vh, "[")
  701. local x = 45*vw
  702. for i=1,3 do
  703. if i <= cap_count then
  704. gpu.setBackground(0x00FF00)
  705. else
  706. gpu.setBackground(0xFF0000)
  707. end
  708. gpu.fill(x, 68*vh, 8*vw, 2*vh, " ")
  709. x = x + 10*vw
  710. end
  711. resetGpu()
  712. gpu.set(73.5*vw, 68*vh, "]")
  713. gpu.set(32*vw, 74*vh, "Energy:")
  714. gpu.set(38*vw, 75*vh, round((stored / max) * 100).."%")
  715. gpu.set(32*vw, 76*vh, stored.."/"..max)
  716. gpu.set(44*vw, 75*vh, "[")
  717. gpu.set(73.5*vw, 75*vh, "]")
  718. gpu.setBackground(0x787878)
  719. gpu.fill(45*vw, 75*vh, 28*vw, 2*vh, " ")
  720. gpu.setBackground(0x00FF00)
  721. gpu.fill(45*vw, 75*vh, units, 2*vh, " ")
  722. end
  723.  
  724. --Function *Displays IDC and stargate status*
  725. function listOutputs()
  726. resetGpu()
  727. gpu.setBackground(standard)
  728. gpu.fill(30*vw, 82*vh, 45*vw, 2*vh, " ")
  729. gpu.fill(30*vw, 95*vh, 46*vw, 2*vh, " ")
  730. gpu.fill(30*vw, 82*vh, 1*vw, 15*vh, " ")
  731. gpu.fill(75*vw, 82*vh, 1*vw, 15*vh, " ")
  732. resetGpu()
  733. local gate = ""
  734. if gate_type == "MILKYWAY" then
  735. gate = "Milky Way: "
  736. elseif gate_type == "PEGASUS" then
  737. gate = "Pegasus: "
  738. elseif gate_type == "UNIVERSE" then
  739. gate = "Universe: "
  740. end
  741. if dialing == false then
  742. if inbound == false and active == false then
  743. local idle = gate.."IDLE"
  744. gpu.set(50*vw - (#idle / 2), 86*vh, idle)
  745. elseif inbound == true then
  746. local inbound = gate.."INBOUND"
  747. gpu.set(50*vw - (#inbound / 2), 86*vh, inbound)
  748. elseif active == true then
  749. local locked = gate.."LOCKED"
  750. gpu.set(50*vw - (#locked / 2), 86*vh, locked)
  751. end
  752. else
  753. local active = gate.."ACTIVE"
  754. gpu.set(50*vw - (#active / 2), 86*vh, active)
  755. end
  756. gpu.set(35*vw, 90*vh, "Stargate IDC: ")
  757. if idc ~= nil then
  758. gpu.set(30*vw + (45*vw / 2) - (#idc / 2), 90*vh, idc)
  759. end
  760. end
  761.  
  762. --Function *Displays stargate*
  763. function listStargate()
  764. local ring_color = 0xA5A5A5
  765. local inner_color = 0x696969
  766. if gate_type == "UNIVERSE" then
  767. ring_color = 0x222222
  768. inner_color = 0x333333
  769. elseif gate_type == "PEGASUS" then
  770. ring_color = 0x222222
  771. inner_color = 0x33DBFF
  772. end
  773. drawCircle(50*vw, 32*vh, 18*vw, 0x0049FF, 1)
  774. drawCircle(50*vw, 32*vh, 16*vw, inner_color, 1)
  775. drawCircle(50*vw, 32*vh, 17*vw, ring_color, 1)
  776. drawCircle(50*vw, 32*vh, 15*vw, ring_color, 1)
  777. resetGpu()
  778. local final = indexof(address, "q")
  779. local chevs = {}
  780. local r = 16*vw
  781. local old = nil
  782. chevs[0] = 50
  783. chevs[1] = 10
  784. chevs[2] = 330
  785. chevs[3] = 210
  786. chevs[4] = 170
  787. chevs[5] = 130
  788. if len(address) <= 7 then
  789. chevs[6] = 90
  790. chevs[7] = 290
  791. chevs[8] = 250
  792. elseif len(address) == 8 then
  793. chevs[6] = 290
  794. chevs[7] = 90
  795. chevs[8] = 250
  796. elseif len(address) == 9 then
  797. chevs[6] = 290
  798. chevs[7] = 250
  799. chevs[8] = 90
  800. end
  801. for c=0,8 do
  802. chev = chevrons[c]
  803. local x = 49*vw + r * math.cos(toRadian(chevs[c]))
  804. local y = 30*vh + r * math.sin(toRadian(chevs[c]+180)) / 2
  805. if chev == false then
  806. gpu.setBackground(0xF2F2F2)
  807. else
  808. gpu.setBackground(0xFF0000)
  809. end
  810. gpu.fill(round(x), round(y), 4*vw, 6*vh, " ")
  811. end
  812. end
  813.  
  814. --Function *List symbol keybinds*
  815. function listKeyBinds()
  816. resetGpu()
  817. clear()
  818. gpu.set(50*vw - (#"AUNIS Dialing Program Keybinds (F1)" / 2), 6*vh, "AUNIS Dailing Program Keybinds (F1)")
  819. gpu.setBackground(standard)
  820. gpu.fill(0*vw, 2*vh, 100*vw, 2*vh, " ")
  821. gpu.fill(0*vw, 98*vh, 100*vw, 2*vh, " ")
  822. resetGpu()
  823. x = 10*vw
  824. y = 10*vh
  825. index = 0
  826. for char, pair in ipairs(toFlooredOrderedTable(points)) do
  827. local symbol = pair[gate_type]
  828. if symbol ~= nil then
  829. if symbol == "Point of Origin" then
  830. gpu.setForeground(0x00FF00)
  831. end
  832. gpu.set(x, y, "\""..char.."\": "..symbol)
  833. index = index + 1
  834. y = y + 5*vh
  835. if y >= 90*vh then
  836. y = 10*vh
  837. x = x + 20*vw
  838. end
  839. gpu.setForeground(0xFFFFFF)
  840. end
  841. end
  842. for key, action in pairs(keybinds) do
  843. if action == "Dial" then
  844. gpu.setForeground(0x0000FF)
  845. elseif action == "Quit" then
  846. gpu.setForeground(0xFF0000)
  847. else
  848. gpu.setForeground(0xAAAAAA)
  849. end
  850. gpu.set(x, y, "\""..key.."\": "..action)
  851. y = y + 5*vh
  852. if y >= 90*vh then
  853. y = 10*vh
  854. x = x + 20*vw
  855. end
  856. gpu.setForeground(0xFFFFFF)
  857. end
  858. resetGpu()
  859. local leave = "Press \"F1\" to Escape"
  860. gpu.set(50*vw - (#leave / 2), 95*vh, leave)
  861. local state = true
  862. while state == true do
  863. local key, is_control, raw, c = parseKey()
  864. if c == keybind_showKeybindsList then
  865. state = false
  866. end
  867. end
  868. resetGpu()
  869. end
  870.  
  871. --Function *List old addresses*
  872. function listOldAddresses()
  873. --book_open = true
  874. resetGpu()
  875. clear()
  876. local header = "Recent Address Book (F3)"
  877. gpu.set(50*vw - (#header / 2), 6*vh, header)
  878. local escape = "Press \"F3\" to Escape"
  879. gpu.set(50*vw - (#escape / 2), 95*vh, escape)
  880. gpu.setBackground(standard)
  881. gpu.fill(0*vw, 2*vh, 100*vw, 2*vh, " ")
  882. gpu.fill(0*vw, 98*vh, 100*vw, 2*vh, " ")
  883. resetGpu()
  884. local old_addresses = getAddresses()
  885. local max = len(old_addresses)
  886. x = 5*vw
  887. y = 10*vh
  888. local i = 0
  889. while x < 95*vh do
  890. resetGpu()
  891. local seg = len(old_addresses) - i
  892. local address = old_addresses[seg]
  893. if address == nil then
  894. break
  895. end
  896. local addr = ""
  897. for i,char in ipairs(address["chars_list"]) do
  898. addr = addr..char.." "
  899. end
  900. local color = 0xFFFFFF
  901. if address["gate_type"] ~= gate_type then
  902. color = 0x555555
  903. elseif address["success_state"] == "false" then
  904. color = 0xFF0000
  905. elseif address["success_state"] == "true" then
  906. color = 0x00FF00
  907. end
  908. createButton(old_addr_buttons, seg.."addr", x, y, 18.5*vw, 8*vh, color, "Address: "..addr, dialOldAddress, address)
  909. y = y + 12*vh
  910. if y >= 95*vh then
  911. x = x + 20*vw
  912. y = 10*vh
  913. end
  914. i = i + 1
  915. end
  916. if book_open == false then
  917. book_open = true
  918. local state = true
  919. while state == true and inbound == false do
  920. local key, is_control, raw, c = parseKey()
  921. if c == keybind_showOldAddresses then
  922. state = false
  923. end
  924. end
  925. book_open = false
  926. end
  927. end
  928.  
  929. --Function *Sequence compiler*
  930. function listSequenceCompiler()
  931. resetGpu()
  932. clear()
  933. gpu.setBackground(standard)
  934. gpu.fill(0*vw, 2*vh, 100*vw, 2*vh, " ")
  935. gpu.fill(0*vw, 98*vh, 100*vw, 2*vh, " ")
  936. resetGpu()
  937. gpu.set(50*vw - (#"Sequence Compiler (F5)" / 2), 6*vh, "Sequence Compiler (F5)")
  938. local y = 10*vh
  939. local x = 3*vw
  940. local ordered = toFlooredOrderedTable(points)
  941. for c,symbol in ipairs(ordered) do
  942. if symbol[gate_type] ~= nil then
  943. local bg = nil
  944. local char = indexof(points, symbol)
  945. if indexof(address, char) ~= -1 then
  946. bg = 0x00FF00
  947. else
  948. bg = 0x787878
  949. end
  950. createButton(symbol_buttons, symbol[gate_type].."button", x, y, 15*vw, 5*vh, bg, "("..char..") "..symbol[gate_type], addSymbolToSequence, symbol)
  951. y = y + 10*vh
  952. if y >= 90*vh then
  953. y = 10*vh
  954. x = x + 20*vw
  955. end
  956. end
  957. end
  958. createButton(symbol_buttons, "backspace_button", x, y, 15*vw, 5*vh, 0xFF0000, "Backspace", addSymbolToSequence, -1)
  959. if address[index - 1] == "q" and gate_type ~= "UNIVERSE" then
  960. prompt(standard, "Sequence Complete", "Sequence Entry Complete", "Press \"Enter\" to dial", false)
  961. end
  962. resetGpu()
  963. local leave = "Press \"F5\" to Escape"
  964. gpu.set(50*vw - (#leave / 2), 95*vh, leave)
  965. if compiler_open == false then
  966. compiler_open = true
  967. local state = true
  968. while state == true and inbound == false do
  969. local key, is_control, raw, c = parseKey()
  970. if c == keybind_showSequenceCompiler then
  971. state = false
  972. end
  973. end
  974. clear()
  975. updateDisplay()
  976. compiler_open = false
  977. end
  978. end
  979.  
  980. --Function *Shows help menu*
  981. function listHelp()
  982. resetGpu()
  983. clear()
  984. gpu.setBackground(standard)
  985. gpu.fill(0*vw, 2*vh, 100*vw, 2*vh, " ")
  986. gpu.fill(0*vw, 98*vh, 100*vw, 2*vh, " ")
  987. resetGpu()
  988. gpu.set(50*vw - (#"AUNIS Dialing Program Help (F6)" / 2), 6*vh, "AUNIS Dialing Program Help (F6)")
  989. 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"
  990. local link = "https://www.curseforge.com/minecraft/mc-mods/aunis"
  991. local y = 10*vh
  992. for num,line in ipairs(split(descrip, ";", 1)) do
  993. gpu.set(50*vw - (#line / 2), y, line)
  994. y = y + 2*vh
  995. end
  996. gpu.setForeground(0x0000AA)
  997. gpu.set(50*vw - (#link / 2), y+5*vh, link)
  998. resetGpu()
  999. gpu.set(50*vw - (#"Press \"F6\" to Escape" / 2), 95*vh, "Press \"F6\" to Escape")
  1000.  
  1001. gpu.setBackground(standard)
  1002. gpu.fill(5*vw, 30*vh, 30*vw, 2*vh, " ")
  1003. gpu.fill(5*vw, 58*vh, 31*vw, 2*vh, " ")
  1004. gpu.fill(5*vw, 30*vh, 1*vw, 28*vh, " ")
  1005. gpu.fill(35*vw, 30*vh, 1*vw, 28*vh, " ")
  1006. resetGpu()
  1007. gpu.set(20.5, 30*vh, "Home Screen Buttons")
  1008. gpu.set(7*vw, 34*vh, "[Dial] - Dials the gate")
  1009. gpu.set(7*vw, 38*vh, "[Toggle Beamer] - Togggles the gate beamer")
  1010. gpu.set(7*vw, 42*vh, "[Abort] - Shutdown gate dialing")
  1011. gpu.set(7*vw, 46*vh, "[Switch] - Switch gate type")
  1012. gpu.set(7*vw, 50*vh, "[Keybinds] - Shows list of keybinds")
  1013. gpu.set(7*vw, 54*vh, "[Compiler] - Shows sequence compiler")
  1014.  
  1015.  
  1016. gpu.setBackground(standard)
  1017. gpu.fill(53*vw, 30*vh, 43*vw, 2*vh, " ")
  1018. gpu.fill(53*vw, 50*vh, 43.5*vw, 2*vh, " ")
  1019. gpu.fill(53*vw, 30*vh, 1*vw, 20*vh, " ")
  1020. gpu.fill(95*vw, 30*vh, 1*vw, 20*vh, " ")
  1021. resetGpu()
  1022. gpu.set(70*vw, 30*vh, "Dialing the Gate")
  1023. gpu.set(55*vw, 34*vh, "Using the keys or sequence compiler, enter a stargate address")
  1024. gpu.set(55*vw, 38*vh, "Once done, press enter to dial the gate")
  1025. gpu.set(55*vw, 42*vh, "The chevrons will lock into place and attempt to open the gate")
  1026. gpu.set(55*vw, 46*vh, "Press \"Space\" or the abort button anytime to cancel the dialer")
  1027.  
  1028. gpu.setBackground(standard)
  1029. gpu.fill(5*vw, 64*vh, 50*vw, 2*vh, " ")
  1030. gpu.fill(5*vw, 94*vh, 51*vw, 2*vh, " ")
  1031.  
  1032. gpu.set(7*vw, 68*vh, "")
  1033.  
  1034. resetGpu()
  1035. local state = true
  1036. while state == true and inbound == false do
  1037. local key, is_control, raw, c = parseKey()
  1038. if c == keybind_showHelp then
  1039. state = false
  1040. end
  1041. end
  1042. end
  1043.  
  1044. --Function *Master display update*
  1045. function updateDisplay()
  1046. resetGpu()
  1047. listActionPanel()
  1048. listChevronStates()
  1049. listAddressBoxes()
  1050. listOutputs()
  1051. listStats()
  1052. listStargate()
  1053. gpu.setBackground(standard)
  1054. gpu.fill(0*vw, 2*vh, 40*vw, 2*vh, " ")
  1055. gpu.fill(60*vw, 2*vh, 40*vw, 2*vh, " ")
  1056. gpu.fill(0*vw, 98*vh, 100*vw, 2*vh, " ")
  1057. resetGpu()
  1058. end
  1059.  
  1060. --Function *Displays the confirmation prompt*
  1061. function confirm(bg, header, ...)
  1062. local arg = {...}
  1063. resetGpu()
  1064. gpu.fill(20*vw, 10*vh, 60*vw, 50*vh, " ")
  1065. gpu.setBackground(bg)
  1066. gpu.fill(20*vw, 10*vh, 60*vw, 2*vh, " ")
  1067. gpu.fill(20*vw, 60*vh, 61*vw, 2*vh, " ")
  1068. gpu.fill(20*vw, 10*vh, 1*vw, 50*vh, " ")
  1069. gpu.fill(80*vw, 10*vh, 1*vw, 50*vh, " ")
  1070. gpu.fill(30*vw, 25*vh, 40*vw, 2*vh, " ")
  1071. resetGpu()
  1072. gpu.setForeground(bg)
  1073. gpu.set(50*vw - (#header / 2), 18*vh, header)
  1074. for i,m in pairs(arg) do
  1075. if type(m) == "string" and i < len(arg) - 1 then
  1076. gpu.set(50*vw - (#m / 2), 28*vh + (2*i*vh), m)
  1077. end
  1078. end
  1079. confirm_open = true
  1080. createButton(confirm_prompt_buttons, "yes_button", 34*vw, 46*vh, 12*vw, 8*vh, bg, arg[len(arg) - 1] or "Yes", setConfirmPromptState, true)
  1081. createButton(confirm_prompt_buttons, "no_button", 54*vw, 46*vh, 12*vw, 8*vh, bg, arg[len(arg)] or "No", setConfirmPromptState, false)
  1082. while confirm_response == nil do
  1083. os.sleep(0.1)
  1084. end
  1085. confirm_open = false
  1086. confirm_prompt_buttons = {}
  1087. local out = confirm_response
  1088. confirm_response = nil
  1089. return out
  1090. end
  1091.  
  1092. --Function *Displays the prompt*
  1093. function prompt(bg, header, ...)
  1094. local arg = {...}
  1095. local height = len(arg)
  1096. local blocking = arg[len(arg)]
  1097. if blocking ~= true then
  1098. blocking = false
  1099. end
  1100. resetGpu()
  1101. gpu.fill(20*vw, 10*vh, 60*vw, 50*vh, " ")
  1102. gpu.setBackground(bg)
  1103. gpu.fill(20*vw, 10*vh, 60*vw, 2*vh, " ")
  1104. gpu.fill(20*vw, 60*vh, 61*vw, 2*vh, " ")
  1105. gpu.fill(20*vw, 10*vh, 1*vw, 50*vh, " ")
  1106. gpu.fill(80*vw, 10*vh, 1*vw, 50*vh, " ")
  1107. gpu.fill(30*vw, 25*vh, 40*vw, 2*vh, " ")
  1108. resetGpu()
  1109. gpu.setForeground(bg)
  1110. gpu.set(50*vw - (#header / 2), 18*vh, header)
  1111. for i,m in pairs(arg) do
  1112. if type(m) == "string" then
  1113. gpu.set(50*vw - (#m / 2), 28*vh + (2*i*vh), m)
  1114. end
  1115. end
  1116. resetGpu()
  1117. if blocking == true then
  1118. gpu.setForeground(bg)
  1119. local escape = "Press \"Enter\" or \"Space\" to Escape"
  1120. gpu.set(50*vw - (#escape / 2), 56*vh, escape)
  1121. resetGpu()
  1122. local state = true
  1123. while state == true do
  1124. local key, is_control, raw = parseKey()
  1125. if raw == 13 or key == " " then
  1126. state = false
  1127. end
  1128. end
  1129. clear()
  1130. updateDisplay()
  1131. end
  1132. end
  1133.  
  1134. --Function *Dials symbol at index i*
  1135. function dial(i)
  1136. if address[i] == nil then
  1137. dialing = false
  1138. --Engage Gate
  1139. failed = true
  1140. event.ignore("stargate_spin_chevron_engaged", lockChevron)
  1141. if sgspin ~= nil then
  1142. event.cancel(sgspin)
  1143. end
  1144. return
  1145. end
  1146. local point = points[address[i]][gate_type]
  1147. if point == "Giza (POO)" then
  1148. sg.engageSymbol("Point of Origin")
  1149. elseif point == "Subido (POO)" then
  1150. sg.engageSymbol("Subido")
  1151. elseif point == "Glyph 17 (POO)" then
  1152. sg.engageSymbol("Glyph 17")
  1153. else
  1154. sg.engageSymbol(point)
  1155. end
  1156. end
  1157.  
  1158. --Callback *Callback function for stargate chevron locking*
  1159. function lockChevron(event, addr, caller, num, final_chevron, symbol)
  1160. if chevrons[num - 1] ~= false then
  1161. return
  1162. end
  1163. if gate_type == "UNIVERSE" and len(address) == num then
  1164. final_chevron = true
  1165. end
  1166. if gate_type == "MILKYWAY" or gate_type == "PEGASUS" then
  1167. os.sleep(0.5)
  1168. elseif gate_type == "UNIVERSE" and final_chevron == false and sigterm == false then
  1169. os.sleep(1)
  1170. end
  1171. chevrons[num - 1] = symbol
  1172. clear()
  1173. resetGpu()
  1174. updateDisplay()
  1175. if final_chevron == true or symbol == "Point of Origin" then
  1176. local status, name, descrip, state = sg.engageGate()
  1177. fail_type = state
  1178. if status == "stargate_engage" then
  1179. active = true
  1180. failed = false
  1181. else
  1182. active = false
  1183. failed = true
  1184. end
  1185. dialing = false
  1186. event.ignore("stargate_spin_chevron_engaged", lockChevron)
  1187. event.cancel(sgspin)
  1188. elseif sigterm == true then
  1189. dialing = false
  1190. failed = true
  1191. fail_type = "USER_MANUAL_OVERRIDE"
  1192. sg.engageGate()
  1193. event.ignore("stargate_spin_chevron_engaged", lockChevron)
  1194. if sgspin ~= nil then
  1195. event.cancel(sgspin)
  1196. end
  1197. elseif inbound == true then
  1198. dialing = false
  1199. event.ignore("stargate_spin_chevron_engaged", lockChevron)
  1200. if sgspin ~= nil then
  1201. event.cancel(sgspin)
  1202. end
  1203. else
  1204. dial(num)
  1205. end
  1206. end
  1207.  
  1208. --Callback *Callback for stargate inbound wormhole*
  1209. function inboundConnection(event, address, caller, address_size)
  1210. if dialing == true then
  1211. dialing = false
  1212. failed = false
  1213. active = false
  1214. end
  1215. inbound = true
  1216. beginInboundLoop(address_size)
  1217. end
  1218.  
  1219. --Callback *Callback for stargate dial failure*
  1220. function sequenceFailure(event, address, caller)
  1221. os.sleep(1)
  1222. --sg.engageGate()
  1223. dialing = false
  1224. failed = true
  1225. active = false
  1226. fail_type = "ADDRESS_MALFORMED"
  1227. event.ignore("stargate_spin_chevron_engaged", lockChevron)
  1228. if sgspin ~= nil then
  1229. event.cancel(sgspin)
  1230. end
  1231. fill(chevrons, false)
  1232. address = {}
  1233. index = 0
  1234. end
  1235.  
  1236. --Callback *Callback for unexpected gate close "For when the gate runs out of power"*
  1237. function closeGate(event, address, caller, reason)
  1238. active = false
  1239. inbound = false
  1240. dialing = false
  1241. if reason == "connection_lost" then
  1242. prompt(0xFF0000, "Stargate Error 499", "Connection to target gate terminated", true)
  1243. elseif reason == "out_of_power" then
  1244. prompt(0xFF0000, "Stargate Error 424", "Insufficient power to gate", true)
  1245. elseif reason == "command" then
  1246. prompt(0xFF0000, "Stargate Error 500", "Gate forcefully killed", true)
  1247. end
  1248. end
  1249.  
  1250. --Callback *Callback for matter stream transit*
  1251. function gateTravel(event, address, caller, inbound, player)
  1252. if inbound == false then
  1253. local time = 3
  1254. for a=1,time do
  1255. os.sleep(1)
  1256. end
  1257. active = false
  1258. --sg.disengageGate()
  1259. end
  1260. if inbound == true then
  1261. prompt(0xFF0000, "Warning", "Incoming traveller", true)
  1262. end
  1263. end
  1264.  
  1265. --Callback *Callback for gate wormhole close*
  1266. function fullClose(event, address, caller, initer)
  1267. closed_fully = true
  1268. end
  1269.  
  1270. --Callback *Callback for screen touch*
  1271. function onScreenTouch(event, address, x, y, button_number, player)
  1272. if compiler_open == true and confirm_open == false then
  1273. for id, button in pairs(symbol_buttons) do
  1274. if (x >= button["x"] and x <= button["x"] + button["w"]) and (y >= button["y"] and y <= button["y"] + button["h"]) then
  1275. local func = button["function"]
  1276. local args = button["args"]
  1277. if func ~= nil then
  1278. func(args)
  1279. else
  1280. print("No bound function")
  1281. end
  1282. end
  1283. end
  1284. elseif book_open == true and confirm_open == false then
  1285. for id, button in pairs(old_addr_buttons) do
  1286. if (x >= button.x and x <= button.x + button.w) and (y >= button.y and y <= button.y + button.h) then
  1287. if button_number == 0 then
  1288. local func = button["function"]
  1289. local args = button.args
  1290. if func ~= nil then
  1291. func(args)
  1292. else
  1293. print("No bound function")
  1294. end
  1295. elseif button_number == 1 then
  1296. deleteAddress(button.args)
  1297. end
  1298. end
  1299. end
  1300. elseif confirm_open == true then
  1301. for id, button in pairs(confirm_prompt_buttons) do
  1302. if (x >= button.x and x <= button.x + button.w) and (y >= button.y and y <= button.y + button.h) then
  1303. local func = button["function"]
  1304. local args = button.args
  1305. if func ~= nil then
  1306. func(args)
  1307. else
  1308. print("No bound function")
  1309. end
  1310. end
  1311. end
  1312. elseif confirm_open == false then
  1313. for id, button in pairs(buttons) do
  1314. if (x >= button.x and x <= button.x + button.w) and (y >= button.y and y <= button.y + button.h) then
  1315. local func = button["function"]
  1316. local args = button.args
  1317. if func ~= nil then
  1318. func(args)
  1319. else
  1320. print("No bound function")
  1321. end
  1322. end
  1323. end
  1324. end
  1325. end
  1326.  
  1327. --Callback *Callback for dhd key press*
  1328. function onDhdPress(event, caller, count, lock, name)
  1329. if dhd_alert == false then
  1330. dhd_alert = true
  1331. local res = confirm(0xFFB600, "Stargate Alert", "DHD key press detected", "", "Shutdown Gate?", "Yes", "No")
  1332. if res == true then
  1333. if sg.getGateStatus() == "open" then
  1334. sg.disengageGate()
  1335. else
  1336. sg.engageGate()
  1337. end
  1338. end
  1339. dhd_alert = false
  1340. clear()
  1341. updateDisplay()
  1342. end
  1343. end
  1344.  
  1345. --Callback *Callback for key press*
  1346. function onKeyPress(event, address, char, code, player)
  1347. char = unicode.char(char)
  1348. if active == true then
  1349. if char == " " then
  1350. active = false
  1351. --sg.disengageGate()
  1352. end
  1353. elseif dialing == true then
  1354. if char == " " or code == 28 then
  1355. prompt(0xFFB600, "Gate Manual Override", "Override engaged", "Gate will shutdown on next chevron")
  1356. sigterm = true
  1357. end
  1358. end
  1359. end
  1360.  
  1361. --Function *Halts the program until gate is idle*
  1362. function beginDialSequence()
  1363. if len(address) == 0 then
  1364. failed = true
  1365. fail_type = "NULL_ADDRESS"
  1366. else
  1367. beginDialLoop()
  1368. saveAddress()
  1369. end
  1370. if active == true then
  1371. beginActiveLoop()
  1372. elseif failed == true then
  1373. index = 0
  1374. fill(chevrons, false)
  1375. address = {}
  1376. if fail_type == "ADDRESS_MALFORMED" then
  1377. prompt(0xFF0000, "Sequence Failed", "The given sequnce", "did not lock", true)
  1378. elseif fail_type == "NOT_ENOUGH_POWER" then
  1379. prompt(0xFF0000, "Sequence Failed", "Not enough power to dial", true)
  1380. elseif fail_type == "BUSY" then
  1381. prompt(0xFF0000, "Sequence Failed", "Target gate is active", true)
  1382. elseif fail_type == "USER_MANUAL_OVERRIDE" then
  1383. prompt(0xFF0000, "Sequence Failed", "Stargate dialing sequence", "was manually terminated", true)
  1384. elseif fail_type == "NULL_ADDRESS" then
  1385. prompt(0xFF0000, "Sequence Error", "No sequence compiled", true)
  1386. else
  1387. prompt(0xFF0000, "Sequence Failed", "Unknown Stargate Error", "Error: ", fail_type, true)
  1388. end
  1389. end
  1390. address = {}
  1391. end
  1392.  
  1393. --Function *Halts the program until dialing is complete*
  1394. function beginDialLoop()
  1395. if dialing then
  1396. return false
  1397. end
  1398. if sgspin == nil then
  1399. local sgspin = event.listen("stargate_spin_chevron_engaged", lockChevron)
  1400. end
  1401. if sgfail == nil then
  1402. local sgfail = event.listen("stargate_failed", sequenceFailure)
  1403. end
  1404. dialing = true
  1405. dial(0)
  1406. clear()
  1407. updateDisplay()
  1408. while dialing do
  1409. os.sleep(0.1)
  1410. end
  1411. end
  1412.  
  1413. --Function *Halts the program until active gate is shutdown*
  1414. function beginActiveLoop()
  1415. --saveAddress()
  1416. if active == false or failed == true then
  1417. return false
  1418. end
  1419. updateDisplay()
  1420. prompt(0x00FF00, "Complete", "Sequence Locked; Press \"Space\" to Disengage", false)
  1421. --clear()
  1422. resetGpu()
  1423. while active == true do
  1424. os.sleep(0.1)
  1425. listStats()
  1426. end
  1427. sg.disengageGate()
  1428. resetGpu()
  1429. clear()
  1430. updateDisplay()
  1431. address = {}
  1432. fill(chevrons, false)
  1433. index = 0
  1434. resetGpu()
  1435. while closed_fully == false do
  1436. os.sleep(0.1)
  1437. end
  1438. end
  1439.  
  1440. --Function *Halts program until inbound gate is shutdown*
  1441. function beginInboundLoop(size)
  1442. clear()
  1443. if size ~= nil then
  1444. for i=1,size do
  1445. chevrons[i - 1] = true
  1446. end
  1447. end
  1448. updateDisplay()
  1449. prompt(0xFFB600, "Stargate Alert", "Inbound Wormhole", "Stargate dialed from "..size.." symbol address")
  1450. while inbound == true do
  1451. os.sleep(0.1)
  1452. end
  1453. sg.disengageGate()
  1454. clear()
  1455. updateDisplay()
  1456. fill(chevrons, false)
  1457. clear()
  1458. updateDisplay()
  1459. fully_closed = false
  1460. while full_closed == false do
  1461. os.sleep(0.1)
  1462. end
  1463. end
  1464.  
  1465. --Main code loop *Event listener creation*
  1466. clear()
  1467. --event.onError(threadHandler)
  1468. local sgin = event.listen("stargate_incoming_wormhole", inboundConnection)
  1469. local sgclose = event.listen("stargate_close", closeGate)
  1470. local screentouch = event.listen("touch", onScreenTouch)
  1471. local keypress = event.listen("key_down", onKeyPress)
  1472. local sgtravel = event.listen("stargate_traveler", gateTravel)
  1473. local sgfullclose = event.listen("stargate_wormhole_closed_fully", fullClose)
  1474. local dhdpress = event.listen("stargate_dhd_chevron_engaged", onDhdPress)
  1475.  
  1476. --Main code loop *Main loop*
  1477. function main()
  1478. --local res = confirm(0x00FF00, "Test", "Y/N", "Y", "N")
  1479. --print(res)
  1480. --os.sleep(3)
  1481. if sg.getGateStatus() ~= "not_merged" and sg.getGateStatus() ~= "idle" then
  1482. sg.disengageGate()
  1483. end
  1484. if first == false then
  1485. listHelp()
  1486. first = true
  1487. end
  1488. while state == true do
  1489. clear()
  1490. updateDisplay()
  1491. if address[index - 1] == "q" then
  1492. prompt(standard, "Sequence Complete", "Sequence Entry Complete", "Press \"Enter\" to dial", false)
  1493. end
  1494. local key, is_control, raw, c, d = parseKey()
  1495. if is_control == true then
  1496. if raw == 13 then
  1497. beginDialSequence()
  1498. elseif raw == 8 and index > 0 then
  1499. index = index - 1
  1500. address[index] = nil
  1501. elseif c == keybind_showKeybindsList then
  1502. listKeyBinds()
  1503. elseif c == keybind_toggleIris then
  1504. prompt(0xFF0000, "Component Failure", "No iris system implemented", true)
  1505. elseif c == 42 then
  1506. quit()
  1507. elseif c == keybind_showSequenceCompiler then
  1508. listSequenceCompiler()
  1509. elseif c == keybind_showOldAddresses then
  1510. listOldAddresses()
  1511. --prompt(0xFF0000, "Access Failure", "System WIP; Access Denied", "System Error 5", true)
  1512. elseif c == keybind_showHelp then
  1513. listHelp()
  1514. elseif c == keybind_switchGateType then
  1515. index = 0
  1516. address = {}
  1517. local new_gate_type
  1518. if gate_type == "MILKYWAY" then
  1519. new_gate_type = "PEGASUS"
  1520. prompt(0xFFb600, "Gate Alert", "Switched gate type to \"Pegasus\"", true)
  1521. elseif gate_type == "PEGASUS" then
  1522. new_gate_type = "UNIVERSE"
  1523. prompt(0xFFb600, "Gate Alert", "Switched gate type to \"Universe\"", true)
  1524. elseif gate_type == "UNIVERSE" then
  1525. new_gate_type = "MILKYWAY"
  1526. prompt(0xFFb600, "Gate Alert", "Switched gate type to \"Milky Way\"", true)
  1527. end
  1528. sg = require("component").stargate
  1529. local new = sg.getGateType()
  1530. if new_gate_type ~= new then
  1531. local res = confirm(0xFFB600, "Unequal Gate Type Alert", "The selected gate type does", "not match the selected gate", "", "Keep Changes?", "Yes", "No")
  1532. if res == true then
  1533. if gate_type == "MILKYWAY" then
  1534. gate_type = "PEGASUS"
  1535. --points = p_points
  1536. elseif gate_type == "PEGASUS" then
  1537. gate_type = "UNIVERSE"
  1538. --points = u_points
  1539. elseif gate_type == "UNIVERSE" then
  1540. gate_type = "MILKYWAY"
  1541. --points = mw_points
  1542. end
  1543. else
  1544. gate_type = new
  1545. end
  1546. else
  1547. gate_type = new_gate_type
  1548. end
  1549. end
  1550. else
  1551. if len(address) == 9 then
  1552. prompt(0xFF0000, "Pre-Sequence Error", "Address Full", "Cannot append symbol to list", true)
  1553. elseif points[key] ~= nil and points[key][gate_type] ~= nil then
  1554. if count(address, key) >= 1 then
  1555. prompt(0xFF0000, "Pre-Sequence Error", "Duplicate Keys", "Key \""..key.."\" is already listed", true)
  1556. else
  1557. if indexof(address, "q") ~= -1 then
  1558. prompt(0xFFb600, "Pre-Sequence Alert", "\"Point of Origin\" already listed", true)
  1559. end
  1560. address[index] = key
  1561. index = index + 1
  1562. end
  1563. else
  1564. prompt(0xFF0000, "Pre-Sequence Error", "Unkown Key", "Key \""..key.."\" is not recognized", true)
  1565. end
  1566. end
  1567. end
  1568.  
  1569. quit()
  1570.  
  1571. end
  1572.  
  1573. --Error handling
  1574. if debug_mode == false then
  1575. local p_res, error = pcall(main)
  1576. if p_res == false and forced_exit == false then
  1577. prompt(0xFF0000, "Critical Error", "The program has encountered an unexpected error", true)
  1578. --[=====[
  1579. if dialing == true then
  1580. local res = sg.engageGate()
  1581. if res ~= nil then
  1582. os.sleep(3)
  1583. sg.disengageGate()
  1584. end
  1585. elseif active == true then
  1586. sg.disengageGate()
  1587. end
  1588. --]=====]
  1589. quit()
  1590. end
  1591. else
  1592. main()
  1593. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement