Repository navigation
Expand file tree
/
Copy pathsg.lua
More file actions
193 lines (171 loc) · 5.27 KB
/
Copy pathsg.lua
File metadata and controls
193 lines (171 loc) · 5.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
if not os.bios then error("System Failed (No Bios)") end
if os.bios() ~= "SeaTECH Bios 1.4" then
shell.run("clear")
print("BIOS: Bios Version is not Compatible with SG")
print("BIOS: It may have some errors!")
print("BIOS: Please have attention of it!")
sleep(2)
shell.run("clear")
end
BASE_DIR = shell.dir()
SGControl = {}
StargateScreen = {}
SGControl.Args = { ... }
SG_ADDRESS = ""
SGControl.Version = "v1.5"
SGControl.SystemIP = ""
SGControl.DeviceIP = ""
SGControl.Minimized = false
SGControl.Menu = {}
SGControl.Touch = {}
SGControl.Hooks = {}
SGControl.Exit = false
SGControl.Mods = {}
SGControl.ExitError = ""
StargateScreen.Mode = "list"
StargateScreen.Modes = {}
SGControl.User = {}
shell.run("clear")
-- Normal Gui
function SGControl.addStargate( address, name )
if address == nil then error("Java.Lang.Function.Input(0x0001)") end
if name == nil then error("Java.Lang.Function.Input(0x0001") end
local f = fs.open( BASE_DIR .. ".sg_" .. address, "w")
f.write( name )
f.close()
return true
end
function SGControl.listStargates()
local f = fs.list(BASE_DIR)
local sgList = {}
for i=1, #f do
if string.sub(f[i], 1, 4) == ".sg_" then
table.insert( sgList, string.sub(f[i], 5))
end
end
return sgList
end
function SGControl.getSGName( address )
if fs.exists(BASE_DIR .. ".sg_" .. address) == true then
local f = fs.open( BASE_DIR .. ".sg_"..address, "r")
local x = f.readAll()
f.close()
return x
else
return "None"
end
end
function SGControl.removeSG( address )
fs.delete( ".sg_" .. address )
end
function SGControl.addExternalMod( fileName )
table.insert(SGControl.Mods, fileName)
shell.run(fileName)
end
function SGControl.addTouch( ex, rx, ey, func, Table)
if Table == nil then Table = SGControl.Touch end
for i=1, #Table do
if Table[i].y == ey and Table[i].x == ex and Table[i].ax == rx then
return false
end
end
table.insert(Table, {x = ex, ax = rx, y = ey, funct = func} )
end
function SGControl.revertBoolean( bool )
if bool == true then return false else return true end
end
function SGControl.getDate()
local h = http.get("http://sealife.top-web.info/cc/timec.php")
local x = h.readAll()
h.close()
return x
end
function SGControl.addLog( file, string )
if file == nil then return end
if string == nil then return end
local f = fs.open( file, "a")
if f == nil then return end
f.writeLine( SGControl.getDate() ..": ".. string )
f.close()
end
function StargateScreen.Header()
term.setCursorPos(1, 1)
term.setBackgroundColor( colors.orange )
term.clearLine()
term.setTextColor( colors.black )
write("_ x")
term.cprint("Stargate Control " .. SG_ADDRESS)
SGControl.addTouch( 3, 3, 1, function() SGControl.Exit = true end)
end
function StargateScreen.Menu()
term.setBackgroundColor( colors.lightGray )
term.setTextColor( colors.black )
term.clearLine()
write(" ")
local x, y = term.getCursorPos()
for i=1, #SGControl.Menu do
local x, _ = term.getCursorPos()
term.setCursorPos( x, y)
SGControl.addTouch( x, x+string.len(SGControl.Menu[i].name), y, SGControl.Menu[i].funct )
write( SGControl.Menu[i].name .. " ")
end
term.setCursorPos(1, y+1 )
end
-- Function Extensions
function StargateScreen.SetContent( content )
StargateScreen.Mode = content
end
function StargateScreen.resetColor()
term.setTextColor( colors.white )
term.setBackgroundColor( colors.black )
end
function StargateScreen.CheckBox(x, y, state)
term.setCursorPos(x, y)
if state == false then
term.setBackgroundColor( colors.red )
else
term.setBackgroundColor( colors.gray )
end
write(" ")
if state == true then
term.setBackgroundColor( colors.green )
else
term.setBackgroundColor( colors.gray )
end
write(" ")
StargateScreen.resetColor()
end
if fs.exists("sg_screens.lua") then shell.run("sg_screens.lua") else error("sg_screens.lua failed to load!") end
if fs.exists("sg_hooks.lua") then shell.run("sg_hooks.lua") else error("sg_hooks.lua failed to load!") end
if fs.exists("sg_mod.lua") then shell.run("sg_mod.lua") end
if peripheral.find("stargate", true, true) == nil then error("No Stargate in NW") end
-- Test if OpenPeripheral is fully Compatible with this Script:
local SG = peripheral.find("stargate", true, true )
if SG.getFuelLevel == nil then error("Function Failed: 1") end
if SG.isValidAddress == nil then error("Function Failed: 2") end
if SG.getHomeAddress == nil then error("Function Failed: 3") end
if SG.disconnect == nil then error("Function Failed: 4") end
if SG.connect == nil then error("Function Failed: 5") end
if SG.isDHDConnected == nil then error("Function Failed: 6") end
if SG.isConnected == nil then error("Function Failed: 7") end
if SG.isInitiator == nil then error("Function Failed: 8") end
if SG.getLockedChevronCount == nil then error("Function Failed: 9") end
SGControl.SystemIP = term.getIP()
SG_ADDRESS = SG.getHomeAddress()
function SGControl.Screen()
while true do
shell.run("clear")
StargateScreen.Header()
StargateScreen.Menu()
StargateScreen.resetColor()
if StargateScreen.Modes[ StargateScreen.Mode ] == nil then
term.xyprint(3, 5, "SG ERROR: No StargateSCREEN Available!")
else
StargateScreen.Modes[ StargateScreen.Mode ]()
end
sleep(0.6)
end
end
parallel.waitForAny(SGControl.Screen, unpack(SGControl.Hooks) )
if SGControl.ExitError ~= "" then error( SGControl.ExitError ) end
shell.run("clear")