Advertisement
christheboss894

Untitled

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