-- http://cdn.clearbackblast.com/dcs/cc/gate_dialer.lua local basalt = require("basalt") -- Get the main frame (your window) local main = basalt.getMainFrame() :setBackground(colors.black) function resetGate(gate) gate.disconnectStargate() end function dialGateFast(gate, address) for _, symbol in pairs(address) do gate.engageSymbol(symbol) end end function dialGateSlow(gate, address) local timing = 0.75 for id, symbol in pairs(address) do rotateGate(gate, symbol) while (not gate.isCurrentSymbol(symbol)) do sleep(0) end sleep(0.4) gate.openChevron() sleep(timing) gate.encodeChevron() sleep(id ~= #address and timing or 0) gate.closeChevron() sleep(id ~= #address and timing or 0) end end function dialGate(gate, address, fast) if fast then dialGateFast(gate, address) else dialGateSlow(gate, address) end end function rotateGate(gate, symbol) local current_s = gate.getCurrentSymbol() local next_s = symbol local total = 40 local direction = ((next_s - current_s) % total) > (total / 2) if direction then gate.rotateClockwise(symbol) else gate.rotateAntiClockwise(symbol) end end address = {} gate = peripheral.find("crystal_interface") main:addDropdown({ dropdownHeight = 10, items = { { text = 'Abydos', callback = function() address = {26, 6, 14, 31, 11, 29, 0} end }, { text = 'Chulak', callback = function() address = {8, 1, 22, 14, 36, 19, 0} end }, { text = 'Cavum Tenebrae', callback = function() address = {18, 7, 3, 36, 25, 15, 0} end }, { text = 'Lost City', callback = function() address = {20, 22, 21, 10, 35, 6, 0} end }, { text = 'Mining', callback = function() address = {21, 31, 4, 13, 38, 11, 0} end }, { text = 'The End', callback = function() address = {13, 24, 2, 19, 3, 30, 0} end }, { text = 'Glacio', callback = function() address = {26, 20, 4, 36, 9, 27, 0} end }, { text = 'The Aether', callback = function() address = {37, 2, 27, 15, 22, 29, 0} end }, { text = 'Twilight Forest', callback = function() address = {17, 26, 5, 1, 9, 12, 0} end }, { text = 'Reality Marble', callback = function() address = {29, 17, 31, 21, 32, 16, 0} end }, { text = 'Blood Magic Dungeon', callback = function() address = {21, 12, 1, 32, 27, 6, 0} end }, { text = 'Everdawn', callback = function() address = {13, 35, 3, 38, 7, 29, 0} end }, { text = 'Everbright', callback = function() address = {38, 27, 10, 26, 34, 9, 0} end }, { text = 'The Other', callback = function() address = {22, 25, 3, 33, 2, 31, 0} end }, { text = 'The Beyond', callback = function() address = {29, 17, 18, 12, 21, 1, 0} end }, } }) :setPosition(2, 2) :setSize('{parent.width - 2}', 1) main:addButton() :setText("Dial") :setBackground(colors.gray) :setForeground(colors.white) :setPosition(2, 4) :setSize('{parent.width - 2}', 1) :onClick(function() resetGate(gate) dialGate(gate, address, true) end) main:addButton() :setText("Dial (Slow)") :setBackground(colors.gray) :setForeground(colors.white) :setPosition(2, 6) :setSize('{parent.width - 2}', 1) :onClick(function() resetGate(gate) dialGate(gate, address, false) end) main:addButton() :setText("Disconnect") :setBackground(colors.gray) :setForeground(colors.white) :setPosition(2, 8) :setSize('{parent.width - 2}', 1) :onClick(function() resetGate(gate) end) main:addButton() :setText("Open") :setBackground(colors.green) :setForeground(colors.white) :setPosition(2, 10) :setSize('{(parent.width - 2) / 2 - 1}', 1) :onClick(function() gate.openIris() end) main:addButton() :setText("Close") :setBackground(colors.red) :setForeground(colors.white) :setPosition('{(parent.width - 2) / 2 + 2 + 1}', 10) :setSize('{(parent.width - 2) / 2 - 1}', 1) :onClick(function() gate.closeIris() end) function onTransceiverMessage(obj, freq, code, matched) if matched then if gate.getIrisProgressPercentage() > 0 then gate.openIris() else gate.closeIris() end end end function onIncomingWormhole(obj, address) gate.closeIris() end basalt.schedule(function() while true do local event = {os.pullEvent()} local eventName = event[1] if eventName == "transceiver_transmission_received" then onTransceiverMessage(table.unpack(event, 2)) elseif eventName == "stargate_incoming_wormhole" then onIncomingWormhole(table.unpack(event, 2)) end end end) -- Start Basalt basalt.run()