SHOW:
|
|
- or go back to the newest paste.
1 | - | --[[ |
1 | + | -- 'Map' by EldidiStroyrr (LDDestroier) |
2 | - | 'Map' (GPS Minimap) by EldidiStroyrr (LDDestroier) |
2 | + | -- This program can be copied, and it can be modified, but it |
3 | -- can NOT be copied, modified slightly, and then claimed as your own. | |
4 | - | Get with |
4 | + | -- You must give me, EldidiStroyrr, credit for the creation and |
5 | - | pastebin get KJ4t2DM9 map |
5 | + | -- only reference yourself as some guy who changed a bit. |
6 | - | or |
6 | + | |
7 | - | std pb KJ4t2DM9 map |
7 | + | parentDir = "/" .. fs.getDir(shell.getRunningProgram()) |
8 | - | std ld map map |
8 | + | waypointFile = "/" .. fs.combine(parentDir, ".waypoints") |
9 | mapConfigFile = "/" .. fs.combine(parentDir, "/.map_conf") | |
10 | - | This is a beta release. You fool! |
10 | + | |
11 | - | --]] |
11 | + | local mapVersion = "1.3" --Version of Map. Must be string. |
12 | if string.sub(shell.dir(), 1, 4) == "rom/" or shell.dir() == "rom" then | |
13 | - | local mapRelease = "beta" |
13 | + | waypointFile = ("/.waypoints") |
14 | - | local pastebinIDList = { |
14 | + | mapConfigFile = ("/.map_conf") |
15 | - | main = "x9ajKSc0", |
15 | + | |
16 | - | beta = "KJ4t2DM9", |
16 | + | |
17 | function updateMapProgram() | |
18 | - | mapVersion = "1.3.9 Beta" --Version of Map. Must be string. |
18 | + | local mapName = shell.getRunningProgram() |
19 | local updateFile = http.get("http://pastebin.com/raw.php?i=x9ajKSc0").readAll() | |
20 | - | os.pullEvent = os.pullEventRaw |
20 | + | |
21 | - | local parentDir = fs.combine("",fs.getDir(shell.getRunningProgram())) |
21 | + | |
22 | - | local configDir = fs.combine(parentDir,".map") |
22 | + | |
23 | - | if not fs.isDir(configDir) then |
23 | + | |
24 | - | if fs.exists(configDir) then fs.delete(configDir) end |
24 | + | |
25 | - | fs.makeDir(configDir) |
25 | + | |
26 | scr_x, scr_y = term.getSize() | |
27 | - | if fs.isReadOnly(shell.resolve(shell.getRunningProgram())) then --In case Map is located in a write-protected directory. |
27 | + | |
28 | - | waypointDir = fs.combine(fs.getName(configDir),"waypoints") |
28 | + | |
29 | - | mapConfigFile = fs.combine(fs.getName(configDir),"config") |
29 | + | |
30 | - | pathDir = fs.combine(fs.getName(configDir),"paths") |
30 | + | |
31 | fs.delete(mapConfigFile) | |
32 | - | waypointDir = "/" .. fs.combine(configDir, "waypoints") |
32 | + | |
33 | - | mapConfigFile = "/" .. fs.combine(configDir, "config") |
33 | + | |
34 | - | pathDir = fs.combine(configDir,"paths") |
34 | + | |
35 | end | |
36 | - | if not fs.exists(waypointDir) then fs.makeDir(waypointDir) end |
36 | + | |
37 | - | if not fs.exists(pathDir) then fs.makeDir(pathDir) end |
37 | + | |
38 | - | defaultWaypointFile = "waypoints" --The name of the waypoint file that is written to. |
38 | + | if fs.exists(waypointFile) then |
39 | - | mapNetworkWaypointsFile = fs.combine(waypointDir,"networkPoints") |
39 | + | fs.delete(waypointFile) |
40 | - | local mapName |
40 | + | |
41 | - | function updateMapProgram(url) |
41 | + | |
42 | - | if not fs.isReadOnly(shell.resolve(shell.getRunningProgram())) then |
42 | + | |
43 | - | mapName = fs.combine("",shell.getRunningProgram()) |
43 | + | |
44 | return | |
45 | - | mapName = shell.getRunningProgram() |
45 | + | |
46 | write("Updating " .. shell.getRunningProgram() .. "...") | |
47 | - | local updateFile |
47 | + | |
48 | - | if url then |
48 | + | local fileSize = updateMapProgram() |
49 | - | updateFile = http.get(url) |
49 | + | |
50 | return true | |
51 | - | updateFile = http.get("http://pastebin.com/raw.php?i=" .. pastebinIDList[mapRelease]) |
51 | + | |
52 | if tArg[1] ~= "mon" then | |
53 | - | if updateFile then |
53 | + | |
54 | - | updateFile = updateFile.readAll() |
54 | + | |
55 | end | |
56 | - | error("Could not connect.") |
56 | + | mapColors = { |
57 | colors.gray, --Background color | |
58 | colors.white, --Border color | |
59 | colors.yellow, --Waypoint color | |
60 | colors.red, --Off-screen waypoint text color | |
61 | colors.lightBlue, --Player color | |
62 | colors.black, --Command screen text color | |
63 | colors.lightGray, --Command screen background color | |
64 | - | function setColormode() |
64 | + | colors.red --Background color if not connected to a GPS server |
65 | - | if term.isColor() and colorLimit >= 2 then |
65 | + | |
66 | - | colormode = true |
66 | + | |
67 | - | grayAllowed = true |
67 | + | directionSensitivity = 0.6 |
68 | mapCorners = { --Top left corner, bottom right corner | |
69 | - | colormode = false |
69 | + | { |
70 | - | if _VERSION and colorLimit == 1 then |
70 | + | 2, |
71 | - | grayAllowed = true |
71 | + | 2, |
72 | }, | |
73 | - | grayAllowed = false |
73 | + | { |
74 | scr_x - 1, | |
75 | scr_y - 6, | |
76 | } | |
77 | } | |
78 | - | local nothing = false |
78 | + | corner1 = mapCorners[1] |
79 | corner2 = mapCorners[2] | |
80 | midPoint = { | |
81 | math.floor((corner1[1] + corner2[1]) / 2), | |
82 | math.floor((corner1[2] + corner2[2]) / 2) | |
83 | } | |
84 | mapDimensions = { | |
85 | corner2[1] - corner1[1], | |
86 | corner2[2] - corner1[2] | |
87 | } | |
88 | - | fakeX = nil |
88 | + | |
89 | - | fakeY = nil |
89 | + | if term.isColor() then |
90 | - | fakeZ = nil |
90 | + | colormode = true |
91 | - | fakeDir = nil |
91 | + | |
92 | colormode = false | |
93 | end | |
94 | - | if fs.exists(waypointDir) then |
94 | + | |
95 | - | fs.delete(waypointDir) |
95 | + | isConnected = true |
96 | arrows = { | |
97 | ">", | |
98 | "v", | |
99 | "<", | |
100 | "^" | |
101 | - | elseif tArg[1] == "oc" then |
101 | + | |
102 | - | shell.run("edit "..mapConfigFile) |
102 | + | |
103 | - | print("Config updated.") |
103 | + | |
104 | ||
105 | - | elseif tArg[1] == "nothing" then |
105 | + | function getConfig() |
106 | - | nothing = true |
106 | + | if not fs.exists(waypointFile) then |
107 | file = fs.open(waypointFile, "w") | |
108 | - | local file = tArg[2] |
108 | + | file.write({}) |
109 | - | local updateURL |
109 | + | |
110 | - | if not tArg[2] then |
110 | + | |
111 | - | file = "beta" |
111 | + | file = fs.open(waypointFile, "r") |
112 | - | updateURL = pastebinIDList[file] |
112 | + | contents = file.readAll() |
113 | contents = textutils.unserialize(contents) | |
114 | - | if pastebinIDList[file] then |
114 | + | |
115 | - | updateURL = pastebinIDList[file] |
115 | + | |
116 | for a = 1, #contents do | |
117 | - | print("Invalid update source.") |
117 | + | table.insert(waypoints, contents[a]) |
118 | - | return false |
118 | + | |
119 | ||
120 | if not fs.exists(mapConfigFile) then | |
121 | file = fs.open(mapConfigFile, "w") | |
122 | file.writeLine("-" .. "- Do not break the format of this config.") | |
123 | - | local fileSize = updateMapProgram("http://pastebin.com/raw.php?i=" .. updateURL) |
123 | + | file.writeLine("-" .. "- This is for Eldidi's Map. Do 'map cc' to fix broken config.") |
124 | file.writeLine("spoofMode = false -" .. "-boolean, set true if testing program in emulator. Replaces gps movement detection with arrow keys. Default: false") | |
125 | - | write("Updated from "..mapVersion) |
125 | + | file.writeLine("scaleFactor = 0.25 -" .. "-number, the zoom factor for the minimap. Lower means wider range. Does not affect GPS range. Default: 0.25") |
126 | - | shell.run(fs.getName(shell.getRunningProgram()),"nothing") |
126 | + | file.writeLine("labelMode = true -" .. "-boolean, true if waypoint labels are their names, false if their distances. Default: true") |
127 | - | if mapVersion then |
127 | + | file.writeLine("youChar = 'O' -" .. "-string, the character which defaultly represents you in the map. is overwritten by arrows, so this is useless come to think of it. Default: 'O'") |
128 | - | print(" to "..mapVersion) |
128 | + | file.writeLine("waypointChar = '*' -" .. "-string, the character that waypoints on the map are represented by. Default: '*'") |
129 | file.writeLine("blankChar = ' ' -" .. "-string, the blank character that the inside of the map is made of. Default: ' '") | |
130 | - | print("...whatever.") |
130 | + | file.writeLine("refreshSleep = 0.4 -" .. "-number, the delay between each GPS request. Default: 0.4") |
131 | file.writeLine("autoUpdate = false -" .. "-boolean, whether or not Map automatically updates to the latest version. this is reccommended FALSE because new updates could break the program into a state where it can't update again.") | |
132 | file.close() | |
133 | - | elseif tArg[1] == "help" then |
133 | + | |
134 | - | local helpText = [[ |
134 | + | shell.run(mapConfigFile) |
135 | - | 'map update' Updates program. |
135 | + | return contents |
136 | - | 'map fast' Runs term.redirect(term.native()). |
136 | + | |
137 | - | 'map cw' Deletes waypoints. |
137 | + | |
138 | - | 'map cc' Deletes config. |
138 | + | function setConfig(pointname, mode, x, y, z) |
139 | - | 'map oc' Opens config. |
139 | + | config = getConfig() |
140 | - | 'map nothing' gets config, but doesn't run |
140 | + | file = fs.open(waypointFile, "w") |
141 | - | Config path: ']]..mapConfigFile..[[' |
141 | + | |
142 | - | Waypoint directory: ']]..waypointDir..[[']] |
142 | + | |
143 | - | print(helpText) |
143 | + | |
144 | if point[1] == pointname then | |
145 | - | elseif tArg[1] == "fast" then |
145 | + | |
146 | file.writeLine(textutils.serialize(config)) | |
147 | file.close() | |
148 | getConfig() | |
149 | - | local sides = {"up","down","left","right","front","back"} |
149 | + | |
150 | - | for a = 1, #sides do |
150 | + | |
151 | - | if peripheral.getType(sides[a]) == "modem" then |
151 | + | |
152 | - | rednet.open(sides[a]) |
152 | + | |
153 | - | break |
153 | + | |
154 | elseif mode == "add" then | |
155 | if x == nil or y == nil or z == nil then | |
156 | - | local function runMapProgramAlready() --This is to allow me to run pcall on the program. |
156 | + | |
157 | - | function numberToColor(input) |
157 | + | |
158 | - | if type(input) == "number" then |
158 | + | |
159 | - | for k,v in pairs(colors) do |
159 | + | table.insert(config, {pointname, x, y, z}) |
160 | - | if input == v then |
160 | + | |
161 | - | return "colors."..k |
161 | + | |
162 | elseif mode == "rename" then | |
163 | for a = 1, #config do | |
164 | - | elseif type(input) == "table" then |
164 | + | |
165 | - | local output = {} |
165 | + | |
166 | - | for a = 1, #input do |
166 | + | |
167 | - | for k,v in pairs(colors) do |
167 | + | |
168 | - | if input[a] == v then |
168 | + | |
169 | - | table.insert(output,"colors."..k) |
169 | + | |
170 | getConfig() | |
171 | return true | |
172 | end | |
173 | - | return output |
173 | + | |
174 | file.close() | |
175 | return false | |
176 | end | |
177 | - | function yield() |
177 | + | |
178 | - | os.queueEvent("yield") |
178 | + | |
179 | - | os.pullEvent("yield") |
179 | + | |
180 | ||
181 | - | function seperateMethods(input) |
181 | + | |
182 | - | local output={} |
182 | + | file = fs.open(mapConfigFile, "r") |
183 | - | for key,value in pairs(input) do |
183 | + | configFile = file.readAll() |
184 | - | table.insert(output, {key,value}) |
184 | + | configFile = textutils.unserialize(configFile) |
185 | file.close() | |
186 | - | return output |
186 | + | |
187 | file = fs.open(mapConfigFile, "w") | |
188 | - | function defineMapBorders() |
188 | + | settings = { |
189 | - | scr_x, scr_y = term.getSize() |
189 | + | "spoofMode = " .. tostring(spoofMode), |
190 | - | local mapCorners |
190 | + | "scaleFactor = " .. tostring(scaleFactor), |
191 | - | if not monitorMode then |
191 | + | "labelMode = " .. tostring(labelMode), |
192 | - | mapCorners = { --Top left corner, bottom right corner |
192 | + | "youChar = '" .. tostring(youChar) .. "'", |
193 | "waypointChar = '" .. tostring(waypointChar) .. "'", | |
194 | "blankChar = '" .. tostring(blankChar) .. "'", | |
195 | "refreshSleep = " .. tostring(refreshSleep), | |
196 | "autoUpdate = " .. tostring(autoUpdate), | |
197 | } | |
198 | - | scr_x - 1, |
198 | + | for a = 1, #settings do |
199 | - | scr_y - 6, |
199 | + | file.writeLine(settings[a]) |
200 | end | |
201 | file.close() | |
202 | getConfig() | |
203 | - | mapCorners = { |
203 | + | |
204 | ||
205 | - | 1, |
205 | + | function setDefaultConfig() |
206 | - | 1, |
206 | + | if not fs.exists(waypointFile) then |
207 | waypoints = { | |
208 | { | |
209 | - | scr_x, |
209 | + | "Test 1", |
210 | - | scr_y - 3, |
210 | + | |
211 | 62, | |
212 | 6 | |
213 | }, | |
214 | - | corner1 = mapCorners[1] |
214 | + | |
215 | - | corner2 = mapCorners[2] |
215 | + | "Test 2", |
216 | - | midPoint = { |
216 | + | 5, |
217 | - | math.floor((corner1[1] + corner2[1]) / 2), |
217 | + | 70, |
218 | - | math.floor((corner1[2] + corner2[2]) / 2) |
218 | + | 3 |
219 | } | |
220 | - | mapDimensions = { |
220 | + | |
221 | - | corner2[1] - corner1[1], |
221 | + | file = fs.open(waypointFile, "w") |
222 | - | corner2[2] - corner1[2] |
222 | + | file.writeLine(textutils.serialize(waypoints)) |
223 | file.close() | |
224 | end | |
225 | - | --[[ In case adding this to the config messes something up, I want to easily fix it. |
225 | + | |
226 | - | mapColors = { --This controls most of the colors in the program, except for some hardcoded colors. If you are using a normal computer, grayscale or not, colors will not be pulled from this list. |
226 | + | |
227 | - | colors.gray, --Background color (default: colors.gray) |
227 | + | |
228 | - | colors.white, --Border color (default: colors.white) |
228 | + | |
229 | - | colors.yellow, --Waypoint color (default: colors.yellow) |
229 | + | |
230 | - | colors.red, --Offscreen waypoint arrow color (default: colors.red) |
230 | + | |
231 | - | colors.lightBlue, --Direction indicator color (default: colors.lightBlue) |
231 | + | |
232 | - | colors.black, --Command list text color (default: colors.black) |
232 | + | |
233 | - | colors.lightGray, --Command list background color (default: colors.lightGray) |
233 | + | |
234 | - | colors.red, --Background color if not connected to GPS server (default: colors.red) |
234 | + | |
235 | - | colors.black, --Map background color (default: colors.black) |
235 | + | |
236 | else | |
237 | term.setBackgroundColor(colors.black) | |
238 | - | directionSensitivity = 0.15 --This is used to prevent the arrow on the middle of the screen from going crazy. |
238 | + | |
239 | - | --]] |
239 | + | |
240 | if colormode then | |
241 | - | currentlyConnected = false --We don't know, so assume false because of glitch with numpad |
241 | + | |
242 | - | isConnected = true --We still don't know, and it's just safer to assume false because of visual bugs |
242 | + | |
243 | term.setBackgroundColor(colors.white) | |
244 | end | |
245 | end | |
246 | end | |
247 | ||
248 | function setDefaultTextColor() | |
249 | - | youChar = "O" --This used to be a config item, too bad it was useless. Luckily, it was replaced with many, much more useful options for you to screw up. |
249 | + | |
250 | term.setTextColor(mapColors[2]) | |
251 | - | function displayTitleScreen() |
251 | + | |
252 | if isConnected then | |
253 | - | term.setCursorPos(1,1) |
253 | + | |
254 | else | |
255 | - | paintutils.drawImage(mapTitleScreen_adv, 1, 1) |
255 | + | |
256 | end | |
257 | - | if grayAllowed then |
257 | + | |
258 | - | paintutils.drawImage(mapTitleScreen_gray, 1, 1) |
258 | + | |
259 | ||
260 | - | paintutils.drawImage(mapTitleScreen_norm, 1, 1) |
260 | + | |
261 | setDefaultTextColor() | |
262 | setDefaultBackgroundColor() | |
263 | - | term.setTextColor(colors.white) |
263 | + | |
264 | ||
265 | - | term.setBackgroundColor(colors.lightBlue) |
265 | + | |
266 | if spoofMode then | |
267 | - | if grayAllowed then |
267 | + | |
268 | return {fakeX, fakeY, fakeZ} | |
269 | else | |
270 | - | term.setBackgroundColor(colors.gray) |
270 | + | local coord_x, coord_y, coord_z = gps.locate(1) |
271 | if coord_x == nil then | |
272 | if displayStuffs then | |
273 | - | term.setCursorPos(5,4) |
273 | + | |
274 | - | print("Version " .. mapVersion) |
274 | + | |
275 | - | term.setCursorPos(5,3) |
275 | + | |
276 | - | print("Made by EldidiStroyrr") |
276 | + | |
277 | term.setTextColor(colors.white) | |
278 | end | |
279 | - | event, param1 = os.pullEvent() |
279 | + | |
280 | - | until event == "key" or event == "mouse_click" or event == "monitor_touch" |
280 | + | |
281 | if displayStuffs then | |
282 | - | function getConfig(mode) |
282 | + | |
283 | - | if not fs.exists(fs.combine(waypointDir, defaultWaypointFile)) or (not fs.isDir(waypointDir)) then |
283 | + | |
284 | - | if fs.exists("/.waypoints") and (not fs.isDir("/.waypoints")) then |
284 | + | local coord_x, coord_y, coord_z = gps.locate(3) |
285 | - | fs.move("/.waypoints", "/waypoints") |
285 | + | |
286 | - | fs.makeDir(waypointDir) |
286 | + | |
287 | - | fs.move("/waypoints", fs.combine(waypointDir, defaultWaypointFile)) |
287 | + | |
288 | end | |
289 | - | fs.makeDir(waypointDir) |
289 | + | |
290 | - | file = fs.open(fs.combine(waypointDir, defaultWaypointFile), "w") |
290 | + | |
291 | - | file.write({}) |
291 | + | |
292 | if coord_x == nil then | |
293 | isConnected = false | |
294 | return {0, 0, 0} | |
295 | - | local wayFiles = fs.list(waypointDir) |
295 | + | |
296 | term.setCursorPos(1,1) | |
297 | - | fileWaypoints = {} |
297 | + | |
298 | - | for a = 1, #wayFiles do |
298 | + | |
299 | - | if not fs.isDir(fs.combine(waypointDir, wayFiles[a])) then |
299 | + | |
300 | - | file = fs.open(fs.combine(waypointDir, wayFiles[a]), "r") |
300 | + | |
301 | - | contents = file.readAll() |
301 | + | |
302 | - | contents = textutils.unserialize(contents) |
302 | + | |
303 | ||
304 | - | for b = 1, #contents do |
304 | + | |
305 | - | table.insert(waypoints, contents[b]) |
305 | + | |
306 | - | if wayFiles[a] == defaultWaypointFile then |
306 | + | |
307 | - | table.insert(fileWaypoints, contents[b]) |
307 | + | local buffX = corner1[1] + 1 |
308 | local mapLengthInner = (corner2[1]) - (corner1[1]) - 1 | |
309 | local longBlankChar1 = string.rep(blankChar, mapLengthInner) | |
310 | for y = corner1[2] + 1, corner2[2] - 1 do | |
311 | term.setCursorPos(buffX,y) | |
312 | write(longBlankChar1) | |
313 | - | --This part has been modified to automatically fix missing config options, at the cost of the inability to add custom ones. Sorry, but this is more useful. |
313 | + | |
314 | - | local modem = peripheral.find("modem") |
314 | + | local buffX = corner1[1] - 1 |
315 | - | if modem and mapProtocol then |
315 | + | for y = corner1[2], corner2[2] do |
316 | - | for a = 1, #mapProtocol do |
316 | + | term.setCursorPos(buffX,y) |
317 | - | modem.close(mapProtocol[a]) |
317 | + | write(" ") --I do " " because 'blankChar' is for the inside of the map. |
318 | end | |
319 | local buffX = corner2[1] + 1 | |
320 | - | spoofMode = false |
320 | + | for y = corner1[2], corner2[2] do |
321 | - | broadcastData = true |
321 | + | term.setCursorPos(buffX,y) |
322 | - | scaleFactor = 0.25 |
322 | + | write(" ") --Same here. |
323 | - | networkName = "mapuser"..math.random(1,9999) |
323 | + | |
324 | - | mapProtocol = {10666} |
324 | + | |
325 | - | displayTitle = false |
325 | + | buffY = corner1[2] - 1 |
326 | - | labelMode = true |
326 | + | term.setCursorPos(1,buffY) |
327 | - | waypointChar = '*' |
327 | + | |
328 | - | blankChar = ' ' |
328 | + | |
329 | - | refreshSleep = 0.4 |
329 | + | |
330 | - | autoUpdate = false |
330 | + | |
331 | - | if turtle then |
331 | + | |
332 | - | turtleMode = true |
332 | + | |
333 | function drawBorder() | |
334 | - | turtleMode = false |
334 | + | --Drawing border. Always is drawn first. |
335 | if displayStuffs and isConnected then | |
336 | - | keyAgoesRight = false --Useless and probably cauyses problems..but whatever |
336 | + | |
337 | - | spoofStep = 1 |
337 | + | term.setTextColor(mapColors[2]) |
338 | - | mapColors = { --This controls most of the colors in the program, except for some hardcoded colors. If you are using a normal computer, grayscale or not, colors will not be pulled from this list. |
338 | + | |
339 | - | colors.gray, --Background color outside map square |
339 | + | |
340 | - | colors.white, --Border color |
340 | + | |
341 | - | colors.yellow, --Default waypoint color |
341 | + | |
342 | - | colors.red, --Off-screen waypoint text color |
342 | + | |
343 | - | colors.lightBlue, --Player color |
343 | + | |
344 | - | colors.black, --Command screen text color |
344 | + | |
345 | - | colors.lightGray, --Command screen background color |
345 | + | |
346 | - | colors.red, --Background color if not connected to a GPS server |
346 | + | |
347 | - | colors.black, --Background color inside map square |
347 | + | |
348 | local mapLength = corner2[1] - corner1[1] | |
349 | - | directionSensitivity = 0.15 --This is used to prevent the arrow on the middle of the screen from going crazy. |
349 | + | local longMapChar = string.rep("#", mapLength) |
350 | - | monitorTextScale = 0.5 --This determines what scale factor the text has if Map is being ran on a monitor. |
350 | + | |
351 | - | fakeX = 0 |
351 | + | |
352 | - | fakeY = 66 |
352 | + | |
353 | - | fakeZ = 0 |
353 | + | |
354 | - | fakeDir = 0 |
354 | + | |
355 | - | doFlash = fals |
355 | + | |
356 | - | colorLimit = 2 |
356 | + | write("#") |
357 | end | |
358 | - | shell.run(mapConfigFile) --Get the existing config options. |
358 | + | |
359 | - | setColormode() |
359 | + | |
360 | term.setCursorPos(corner2[1],b) | |
361 | - | if not type(networkName) == "string" then networkName = "mapuser"..math.random(1,9999) end |
361 | + | write("#") |
362 | - | if not type(mapProtocol) == "table" then mapProtocol = {10666} end |
362 | + | |
363 | end | |
364 | - | refreshOtherConfig() --Set the config file to what the variables are. |
364 | + | |
365 | term.setTextColor(mapColors[7]) | |
366 | - | scr_x, scr_y = term.getSize() |
366 | + | |
367 | - | if scr_x > 16 or scr_y > 10 then --Determines if Map is being ran on a single monitor block. |
367 | + | |
368 | - | monitorMode = false |
368 | + | |
369 | term.setTextColor(colors.black) | |
370 | - | monitorMode = true |
370 | + | |
371 | else | |
372 | - | if not monitorTextScale then --This whole bit is for monitors, should you be arsed to use them with this. |
372 | + | |
373 | - | monitorTextScale = 0.5 |
373 | + | |
374 | end | |
375 | - | if monitorTextScale < 0.5 then |
375 | + | |
376 | - | monitorTextScale = 0.5 |
376 | + | |
377 | - | elseif monitorTextScale > 5 then |
377 | + | |
378 | - | monitorTextScale = 5 |
378 | + | term.setCursorPos(corner2[1],midPoint[2]) |
379 | write("X") | |
380 | - | if type(monitorTextScale) ~= "number" then |
380 | + | |
381 | - | monitorTextScale = 0.5 |
381 | + | |
382 | return | |
383 | end | |
384 | - | local mon = peripheral.find("monitor") |
384 | + | |
385 | - | if mon then |
385 | + | |
386 | - | if not monitorMode then |
386 | + | |
387 | - | mon.setTextScale(monitorTextScale) |
387 | + | itemX = corner1[1] + 1 |
388 | itemY = corner2[2] + 1 | |
389 | - | mon.setTextScale(0.5) |
389 | + | term.setCursorPos(itemX,itemY) |
390 | setDefaultColors() | |
391 | term.clearLine() | |
392 | - | if mode == "waypoint" then |
392 | + | |
393 | - | return fileWaypoints |
393 | + | |
394 | end | |
395 | - | return contents |
395 | + | |
396 | if colormode then | |
397 | term.setTextColor(colors.orange) | |
398 | - | function set(list) --Used to check if a phrase is in a table. Straight from StackOverflow, by Jon Ericson. |
398 | + | |
399 | - | local set = {} |
399 | + | write(scaleFactor .. "x") |
400 | - | for _, l in ipairs(list) do |
400 | + | |
401 | - | set[l] = true |
401 | + | |
402 | ||
403 | - | return set |
403 | + | |
404 | isConnected = true | |
405 | - | function stringToColor(color) |
405 | + | |
406 | - | local stringColors = {"white","orange","magneta","lightBlue","yellow","lime","pink","gray","lightGray","cyan","purple","blue","brown","green","red","black"} |
406 | + | |
407 | - | local numberColors = {colors.white,colors.orange,colors.magneta,colors.lightBlue,colors.yellow,colors.lime,colors.pink,colors.gray,colors.lightGray,colors.cyan,colors.purple,colors.blue,colors.brown,colors.green,colors.red,colors.black} |
407 | + | |
408 | - | if string.sub(color, 1, 7) == "colors." then |
408 | + | |
409 | - | color = string.sub(color, 8) |
409 | + | |
410 | while true do | |
411 | - | for a = 1, #stringColors do |
411 | + | |
412 | - | if string.lower(color) == string.lower(stringColors[a]) then |
412 | + | |
413 | - | return numberColors[a] |
413 | + | |
414 | poses = getCoordinates() | |
415 | if not isConnected then | |
416 | wasConnected = false | |
417 | if displayStuffs then | |
418 | - | function setConfig(pointname, mode, x, y, z, derf) |
418 | + | |
419 | - | config = getConfig("waypoint") |
419 | + | term.setBackgroundColor(colors.red) |
420 | - | file = fs.open(fs.combine(waypointDir, defaultWaypointFile), "w") |
420 | + | |
421 | term.setBackgroundColor(colors.white) | |
422 | end | |
423 | term.clear() | |
424 | renderCommands() | |
425 | repeat | |
426 | poses = getCoordinates() | |
427 | sleep(0) | |
428 | until isConnected == true | |
429 | end | |
430 | end | |
431 | until isConnected == true | |
432 | if isConnected then | |
433 | setDefaultColors() | |
434 | if not wasConnected then | |
435 | wasConnected = true | |
436 | term.clear() | |
437 | renderCommands() | |
438 | drawBorder() | |
439 | - | table.insert(config, {pointname, x, y, z, derf}) |
439 | + | |
440 | end | |
441 | end | |
442 | oldCoord_x = posX | |
443 | oldCoord_y = posY | |
444 | oldCoord_z = posZ | |
445 | posX = poses[1] | |
446 | posY = poses[2] | |
447 | posZ = poses[3] | |
448 | if oldCoord_x ~= nil then | |
449 | if math.abs(oldCoord_x - posX) > directionSensitivity or math.abs(oldCoord_z - posZ) > directionSensitivity then | |
450 | if math.abs(oldCoord_x - posX) > math.abs(oldCoord_z - posZ) and oldCoord_x - posX > 0 then | |
451 | direction_long = "west" | |
452 | direction = "west" | |
453 | elseif math.abs(oldCoord_x - posX) > math.abs(oldCoord_z - posZ) and oldCoord_x - posX < 0 then | |
454 | direction_long = "east" | |
455 | direction = "east" | |
456 | elseif math.abs(oldCoord_z - posZ) > math.abs(oldCoord_x - posX) and oldCoord_z - posZ > 0 then | |
457 | direction_lat = "south" | |
458 | direction = "south" | |
459 | elseif math.abs(oldCoord_z - posZ) > math.abs(oldCoord_x - posX) and oldCoord_z - posZ < 0 then | |
460 | direction_lat = "north" | |
461 | direction = "north" | |
462 | - | local file = fs.open(mapConfigFile, "w") |
462 | + | |
463 | - | local mapSettings = { |
463 | + | |
464 | - | { |
464 | + | |
465 | - | "spoofMode = " .. tostring(spoofMode), |
465 | + | |
466 | - | "boolean, set true if testing program in emulator. Replaces gps movement detection with arrow keys. Default: false", |
466 | + | |
467 | - | }, |
467 | + | if (oldCoord_x ~= posX or oldCoord_z ~= posZ) then |
468 | - | { |
468 | + | |
469 | - | "broadcastData = " .. tostring(broadcastData), |
469 | + | |
470 | - | "boolean, set true if you want other people to see your location. Default: true", |
470 | + | |
471 | - | }, |
471 | + | if hadCleared then |
472 | - | { |
472 | + | |
473 | - | "networkName = '" .. tostring(networkName) .. "'", |
473 | + | |
474 | - | "string, what your name appears as for other Map clients. Default: 'mapuser'..math.random(1,9999)", |
474 | + | |
475 | - | }, |
475 | + | hadCleared = false |
476 | - | { |
476 | + | |
477 | - | "mapProtocol = " .. textutils.serialize(mapProtocol), |
477 | + | |
478 | - | "table, list of modem protocols of the data broadcasted to other clients. Default: {10666}", |
478 | + | |
479 | - | }, |
479 | + | |
480 | - | { |
480 | + | |
481 | - | "scaleFactor = " .. tostring(scaleFactor), |
481 | + | |
482 | - | "number, the zoom factor for the minimap. Lower means wider range. Does not affect GPS range. Default: 0.25", |
482 | + | |
483 | - | }, |
483 | + | |
484 | - | { |
484 | + | |
485 | - | "displayTitle = " .. tostring(displayTitle), |
485 | + | itemX = math.ceil((midPoint[1] + (wayX - posX) * scaleFactor)) |
486 | - | "boolean, whether or not to display the title screen. I find it kind of garish, but I already did the work. Default: false", |
486 | + | itemZ = math.floor((midPoint[2] + (posZ - wayZ) * scaleFactor)) |
487 | - | }, |
487 | + | |
488 | - | { |
488 | + | |
489 | - | "labelMode = " .. tostring(labelMode), |
489 | + | if itemX > corner1[1] and itemX < corner2[1] and itemZ < corner2[2] and itemZ > corner1[2] then |
490 | - | "boolean, true if waypoint labels are their names, false if their distances. Default: true", |
490 | + | if not (itemX == midPoint[1] and itemZ == midPoint[2]) then |
491 | - | }, |
491 | + | |
492 | - | { |
492 | + | |
493 | - | "waypointChar = '" .. tostring(waypointChar) .. "'", |
493 | + | term.setTextColor(mapColors[3]) |
494 | - | "string, the character that waypoints on the map are represented by. Default: '*'", |
494 | + | |
495 | - | }, |
495 | + | |
496 | - | { |
496 | + | term.setBackgroundColor(colors.black) |
497 | - | "blankChar = '" .. tostring(blankChar) .. "'", |
497 | + | |
498 | - | "string, the blank character that the inside of the map is made of. Default: ' '", |
498 | + | write(waypointChar) |
499 | - | }, |
499 | + | |
500 | - | { |
500 | + | |
501 | - | "refreshSleep = " .. tostring(refreshSleep), |
501 | + | |
502 | - | "number, the delay between each GPS request. Default: 0.4", |
502 | + | |
503 | - | }, |
503 | + | |
504 | - | { |
504 | + | |
505 | - | "autoUpdate = " .. tostring(autoUpdate), |
505 | + | |
506 | - | "boolean, whether or not Map automatically updates to the latest version. this is reccommended FALSE because new updates could break the program into a state where it can't update again. Default: false", |
506 | + | |
507 | - | }, |
507 | + | |
508 | - | { |
508 | + | |
509 | - | "turtleMode = " .. tostring(turtleMode), |
509 | + | term.setTextColor(mapColors[4]) |
510 | - | "boolean, whether Map should be tuned to turtle controlling. Especially useful if used in conjunction with Lyqyd's NSH. Default: false", |
510 | + | |
511 | - | }, |
511 | + | |
512 | - | { |
512 | + | |
513 | - | "keyAgoesRight = " .. tostring(keyAgoesRight), |
513 | + | |
514 | - | "boolean, determines whether to invert the left/right turtle turning controls. Requires turtleMode=true. This option exists because the 'A' button turns the turtle left on the map, but not in minecraft world. Default: false", |
514 | + | |
515 | - | }, |
515 | + | |
516 | - | { |
516 | + | |
517 | - | "spoofStep = " .. tostring(spoofStep), |
517 | + | |
518 | - | "number, amount you move in one keypress in spoof mode. Used to move faster. Default: 1", |
518 | + | |
519 | - | }, |
519 | + | |
520 | - | { |
520 | + | if itemX * -1 >= itemZ * -1 then |
521 | - | "mapColors = " .. string.gsub( textutils.serialize(numberToColor(mapColors)), "\"", "" ), |
521 | + | |
522 | - | "table, there are 9 items in this array, and this controls most of the colors in the program, except for some hardcoded colors and for normal computers. The colors are, in sequence: background color outside, border color, waypoint color, offscreen waypoint arrow color, direction indicator color, command screen text color, command screen background color, background color if not connected to GPS, background color inside. Do not input any values into this config option that isn't a color, or the program will crash. Default: {colors.gray, colors.white, colors.yellow, colors.red, colors.lightBlue, colors.black, colors.lightGray, colors.red, colors.black}", |
522 | + | |
523 | - | }, |
523 | + | |
524 | - | { |
524 | + | |
525 | - | "directionSensitivity = " .. tostring(directionSensitivity), |
525 | + | |
526 | - | "number, this is used to prevent the arrow on the middle of the screen from going crazy. it will only change the middle indicator if you move that amount of meters. Default: 0.15", |
526 | + | |
527 | - | }, |
527 | + | if itemX * -1 >= itemZ then |
528 | - | { |
528 | + | |
529 | - | "monitorTextScale = " .. tostring(monitorTextScale), |
529 | + | |
530 | - | "number, this determines what scale factor the text has if Map is being ran on a monitor. Default: 0.5", |
530 | + | |
531 | - | }, |
531 | + | |
532 | - | { |
532 | + | |
533 | - | "fakeX = " .. tostring(fakeX), |
533 | + | |
534 | - | "number, this is the last recorded X position of the turtle/PDA. Is used in spoofMode, and updates when using turtleMode. Default: 0", |
534 | + | |
535 | - | }, |
535 | + | |
536 | - | { |
536 | + | |
537 | - | "fakeY = " .. tostring(fakeY), |
537 | + | if itemX >= itemZ * -1 then |
538 | - | "number, same as fakeX but for Y. Default: 66", |
538 | + | |
539 | - | }, |
539 | + | |
540 | - | { |
540 | + | |
541 | - | "fakeZ = " .. tostring(fakeZ), |
541 | + | |
542 | - | "number, same as fakeX but for Z. Default: 0", |
542 | + | |
543 | - | }, |
543 | + | |
544 | - | { |
544 | + | if itemX >= itemZ then |
545 | - | "fakeDir = " .. tostring(fakeDir), |
545 | + | |
546 | - | "number, equal to 'f' in Debug mode in Minecraft (F3), range=0-3. Default: nil", |
546 | + | |
547 | - | }, |
547 | + | |
548 | - | { |
548 | + | |
549 | - | "doFlash = " .. tostring(doFlash), |
549 | + | |
550 | - | "boolean, whether or not to do the flash animation when starting map up or exiting a menu. Default: false", |
550 | + | |
551 | - | }, |
551 | + | |
552 | - | { |
552 | + | |
553 | - | "colorLimit = " .. tostring(colorLimit), |
553 | + | |
554 | - | "number, artificially limits the color palate. (0=monochrome,1=grayscale,2=colors). Default: 2", |
554 | + | |
555 | - | }, |
555 | + | |
556 | setDefaultColors() | |
557 | - | file.writeLine("-" .. "- Do not break the format of this config.") |
557 | + | |
558 | - | file.writeLine("-" .. "- This is for EldidiStroyrr/LDDestroier's 'Map' (GPS Minimap). Do 'map cc' to fix broken config.") |
558 | + | |
559 | - | file.writeLine("-" .. "- This config has been last used on version " .. mapVersion .. ", for reference.") |
559 | + | term.setTextColor(mapColors[3]) |
560 | - | for a = 1, #mapSettings do |
560 | + | |
561 | - | file.writeLine(mapSettings[a][1] .. " -" .. "-" .. mapSettings[a][2]) |
561 | + | |
562 | term.setBackgroundColor(colors.black) | |
563 | - | file.writeLine("") |
563 | + | |
564 | if itemZ < corner2[2] + 2 then | |
565 | if labelMode == true then | |
566 | pointName = point[1] | |
567 | pointMidX = math.ceil(itemX - (string.len(pointName) / 2)) | |
568 | pointMidZ = itemZ - 1 | |
569 | term.setCursorPos(pointMidX,pointMidZ) | |
570 | elseif labelMode == false then | |
571 | pointName = tostring(round(math.sqrt((point[2]-posX)^2 + (point[3]-posY)^2 + (point[4]-posZ)^2), 2)) | |
572 | pointMidX = itemX - math.floor(string.len(pointName) / 2) | |
573 | pointMidZ = itemZ - 1 | |
574 | term.setCursorPos(pointMidX,pointMidZ) | |
575 | - | if grayAllowed then |
575 | + | |
576 | - | term.setBackgroundColor(colors.gray) |
576 | + | if pointMidX + string.len(pointName) >= scr_x then |
577 | subLength = (scr_x - pointMidX) + 1 | |
578 | subName = string.sub(pointName, 1, subLength) | |
579 | if pointMidX <= scr_x + 1 then | |
580 | pointName = subName | |
581 | end | |
582 | end | |
583 | if pointMidX <= scr_x then | |
584 | for i = 1, #pointName do | |
585 | labelPosX, labelPosY = term.getCursorPos() | |
586 | if ((labelPosY == corner1[2] or labelPosY == corner2[2]) or (labelPosX == corner1[1] or labelPosX == corner2[1])) and ((labelPosX >= corner1[1] and labelPosX <= corner2[1]) and (labelPosY >= corner1[2] and labelPosY <= corner2[2])) then | |
587 | if colormode then | |
588 | term.setTextColor(mapColors[1]) | |
589 | term.setBackgroundColor(mapColors[2]) | |
590 | else | |
591 | term.setTextColor(colors.white) | |
592 | term.setBackgroundColor(colors.black) | |
593 | end | |
594 | else | |
595 | if colormode then | |
596 | term.setTextColor(mapColors[3]) | |
597 | term.setBackgroundColor(mapColors[1]) | |
598 | else | |
599 | term.setTextColor(colors.white) | |
600 | term.setBackgroundColor(colors.black) | |
601 | end | |
602 | end | |
603 | write(string.sub(pointName, i, i)) | |
604 | - | recordBuffer = {} |
604 | + | |
605 | - | if not oldCoord_x then |
605 | + | |
606 | - | oldCoord_x, oldCoord_y, oldCoord_z = 0,0,0 |
606 | + | |
607 | - | posX, posY, posZ = 0,0,0 |
607 | + | |
608 | end | |
609 | - | local function savePath(path) |
609 | + | term.setCursorPos(midPoint[1],midPoint[2]) |
610 | - | if not path then return false, "you need a table." end |
610 | + | |
611 | - | local pathpath |
611 | + | term.setTextColor(mapColors[5]) |
612 | else | |
613 | if isConnected then | |
614 | term.setTextColor(colors.white) | |
615 | - | print("Save path as: (blank for cancel)") |
615 | + | |
616 | else | |
617 | term.setTextColor(colors.white) | |
618 | - | pathpath = read() |
618 | + | |
619 | - | if pathpath == "" then |
619 | + | |
620 | end | |
621 | if direction == "east" then | |
622 | playerChar = ">" | |
623 | elseif direction == "west" then | |
624 | - | if fs.exists(fs.combine(pathDir,pathpath)) then |
624 | + | playerChar = "<" |
625 | - | pathpath = "" |
625 | + | elseif direction == "south" then |
626 | - | print("That already exists.") |
626 | + | playerChar = "v" |
627 | elseif direction == "north" then | |
628 | - | until pathpath ~= "" |
628 | + | playerChar = "^" |
629 | - | pathpath = fs.combine(pathDir,pathpath) |
629 | + | |
630 | - | local file = fs.open(pathpath,"w") |
630 | + | playerChar = "O" |
631 | - | file.writeLine(textutils.serialize(path)) |
631 | + | |
632 | write(playerChar) | |
633 | - | print("Okay!") |
633 | + | |
634 | if not spoofMode then | |
635 | sleep(refreshSleep) | |
636 | else | |
637 | sleep(0) | |
638 | end | |
639 | end | |
640 | - | currentlyConnected = true |
640 | + | |
641 | - | os.queueEvent("gpsRequest", true) |
641 | + | |
642 | function renderCommands() | |
643 | commands = { | |
644 | - | oldCoord_x, oldCoord_y, oldCoord_z = coord_x, coord_y, coord_z |
644 | + | "(L)abel/distance", |
645 | - | coord_x, coord_y, coord_z = gps.locate(0.75) |
645 | + | "(M)ore Options", |
646 | - | if (coord_x == nil) and isConnected then |
646 | + | "(H)elp", |
647 | - | currentlyConnected = false |
647 | + | |
648 | - | os.queueEvent("gpsRequest", false) |
648 | + | |
649 | if not isConnected then | |
650 | term.setCursorPos(2,1) | |
651 | if colormode then | |
652 | term.setTextColor(colors.gray) | |
653 | else | |
654 | term.setTextColor(colors.black) | |
655 | end | |
656 | gpsNotFoundString = "GPS not found." | |
657 | print(gpsNotFoundString .. string.rep(" ", scr_x-string.len(gpsNotFoundString)-2)) | |
658 | end | |
659 | - | term.clearLine() |
659 | + | |
660 | startY = corner2[2] + 1 | |
661 | commandX = startX | |
662 | - | for a = 1, 5 do |
662 | + | |
663 | - | coord_x, coord_y, coord_z = gps.locate(1) |
663 | + | |
664 | - | if coord_x == nil then os.queueEvent("gpsRequest", false) end |
664 | + | term.setCursorPos(startX,startY) |
665 | term.clearLine() | |
666 | term.setCursorPos(commandX,commandY) | |
667 | if colormode then | |
668 | term.setTextColor(mapColors[6]) | |
669 | term.setBackgroundColor(mapColors[7]) | |
670 | else | |
671 | term.setTextColor(colors.white) | |
672 | term.setBackgroundColor(colors.black) | |
673 | end | |
674 | term.clearLine() | |
675 | - | os.queueEvent("gpsRequest", false) |
675 | + | |
676 | - | return nil |
676 | + | |
677 | scr_x, scr_y = term.getSize() | |
678 | if scr_x - comPosX <= string.len(commands[f]) + 1 then | |
679 | - | currentlyConnected = true |
679 | + | |
680 | - | os.queueEvent("gpsRequest", true) |
680 | + | |
681 | - | fakeX, fakeY, fakeZ = coord_x, coord_y, coord_z |
681 | + | |
682 | - | if recording then |
682 | + | |
683 | - | if (math.floor(coord_x) ~= math.floor(oldCoord_x)) or (math.floor(coord_y) ~= math.floor(oldCoord_y)) or (math.floor(coord_z) ~= math.floor(oldCoord_z)) then |
683 | + | if f ~= #commands then |
684 | - | table.insert(recordBuffer,{math.floor(coord_x),math.floor(coord_y),math.floor(coord_z)}) |
684 | + | write(", ") |
685 | end | |
686 | end | |
687 | - | if #recordBuffer > 0 then |
687 | + | |
688 | - | currentLocation = "savePath" |
688 | + | |
689 | - | displayStuffs = false |
689 | + | |
690 | - | savePath(recordBuffer) |
690 | + | |
691 | - | displayStuffs = true |
691 | + | |
692 | - | currentLocation = "renderMap" |
692 | + | |
693 | term.setCursorPos(1,2) | |
694 | - | recordBuffer = {} |
694 | + | |
695 | term.setTextColor(colors.orange) | |
696 | end | |
697 | print(" 'Map v1.3' is a GPS minimap program made by EldidiStroyrr (LDDestroier).") | |
698 | setDefaultColors() | |
699 | print(" * 'map cc' clears config.") | |
700 | print(" * 'map cw' clears waypoints.") | |
701 | - | function rollOver(input, max) |
701 | + | print(" * A red screen means no access to a GPS server.") |
702 | - | return math.floor(input % max) |
702 | + | print(" * Pressing numpad '+' or '-' will zoom in and out without a prompt.") |
703 | print(" * Do 'map update' to update Map.") | |
704 | sleep(0.1) | |
705 | - | function drawMovingLine(ypos, size, speed, spacesize) |
705 | + | |
706 | - | for a = 1, size do |
706 | + | |
707 | - | if currentLocation == "waypointSettings" then |
707 | + | |
708 | - | term.setCursorPos(1,ypos) |
708 | + | |
709 | print("Press a key to continue.") | |
710 | - | term.setTextColor(colors.orange) |
710 | + | |
711 | local event, key = os.pullEvent("key") | |
712 | - | if grayAllowed then |
712 | + | |
713 | end | |
714 | function setWaypoint() | |
715 | - | if isConnected then |
715 | + | |
716 | defaultNewPointName = "way" --Not used, in favor of a way to cancel. | |
717 | print("Set waypoint.") | |
718 | - | term.setTextColor(colors.black) |
718 | + | |
719 | write(">") | |
720 | newName = tostring(read()) | |
721 | if newName == "" then | |
722 | - | for x = 1, scr_x do |
722 | + | |
723 | - | if rollOver(x - a, size) < spacesize then |
723 | + | |
724 | - | write(" ") |
724 | + | |
725 | end | |
726 | - | write("-") |
726 | + | print("What X? (default: here)") |
727 | write(">") | |
728 | newX = tonumber(read()) | |
729 | - | sleep(speed) |
729 | + | |
730 | newX = math.floor(posX) | |
731 | end | |
732 | print("What Y? (default: here)") | |
733 | write(">") | |
734 | - | function flashScreen(times) |
734 | + | newY = tonumber(read()) |
735 | - | if (not times) or (type(times) ~= "number") then |
735 | + | if newY == nil then |
736 | - | times = 1 |
736 | + | newY = math.floor(posY) |
737 | end | |
738 | - | if colormode or grayAllowed then |
738 | + | print("What Z? (default: here)") |
739 | - | flashes = { |
739 | + | |
740 | - | colors.black, |
740 | + | newZ = tonumber(read()) |
741 | - | colors.gray, |
741 | + | if newZ == nil then |
742 | - | colors.lightGray, |
742 | + | newZ = math.floor(posZ) |
743 | - | colors.white, |
743 | + | |
744 | - | colors.lightGray, |
744 | + | setConfig(newName, "add", newX, newY, newZ) |
745 | - | colors.black, |
745 | + | |
746 | print("Waypoint '" .. newName .. "' set!") | |
747 | getConfig() | |
748 | - | flashes = { |
748 | + | |
749 | - | colors.black, |
749 | + | |
750 | - | colors.white, |
750 | + | |
751 | function setScale() | |
752 | term.setCursorPos(1,2) | |
753 | - | if doFlash then |
753 | + | |
754 | - | for a = 1, times do |
754 | + | |
755 | - | for b = 1, #flashes do |
755 | + | |
756 | - | term.setBackgroundColor(flashes[b]) |
756 | + | |
757 | - | term.clear() |
757 | + | |
758 | - | sleep(0) |
758 | + | |
759 | print("Cancelling.") | |
760 | sleep(0.2) | |
761 | return | |
762 | - | flashes = nil |
762 | + | |
763 | newScale = tonumber(newScaleRaw) | |
764 | if newScale == nil then | |
765 | print("That's not a number!") | |
766 | - | --The badly whitespaced function were made by PhyscoKillerMonkey. Beta. |
766 | + | |
767 | - | local function forward() |
767 | + | |
768 | - | while not mapturt.forward() do |
768 | + | |
769 | - | --print("Can't move, checking fuel") |
769 | + | |
770 | - | if turtle.getFuelLevel() == 0 then |
770 | + | |
771 | - | turtle.select(1) |
771 | + | |
772 | - | turtle.refuel(1) |
772 | + | |
773 | - | end |
773 | + | |
774 | - | if digBlocks then |
774 | + | |
775 | - | turtle.dig() |
775 | + | |
776 | - | else |
776 | + | |
777 | - | mapturt.up() |
777 | + | |
778 | - | goneUp = goneUp + 1 |
778 | + | |
779 | - | cy = cy + 1 |
779 | + | |
780 | - | end |
780 | + | |
781 | - | end |
781 | + | |
782 | - | if dir == 0 then cz = cz + 1 |
782 | + | |
783 | - | elseif dir == 1 then cx = cx - 1 |
783 | + | |
784 | - | elseif dir == 2 then cz = cz - 1 |
784 | + | |
785 | - | elseif dir == 3 then cx = cx + 1 end |
785 | + | |
786 | - | while goneUp > 0 and not turtle.detectDown() do |
786 | + | |
787 | - | mapturt.down() |
787 | + | |
788 | - | goneUp = goneUp - 1 |
788 | + | |
789 | - | cy = cy - 1 |
789 | + | |
790 | - | end |
790 | + | |
791 | for a = 1, #waypoints do | |
792 | - | local function up() |
792 | + | |
793 | - | while not mapturt.up() do |
793 | + | |
794 | - | --print("Can't move, checking fuel") |
794 | + | |
795 | - | if turtle.getFuelLevel() == 0 then |
795 | + | |
796 | - | turtle.select(1) |
796 | + | |
797 | - | turtle.refuel(1) |
797 | + | |
798 | - | end |
798 | + | |
799 | - | if digBlocks then |
799 | + | |
800 | - | turtle.digUp() |
800 | + | |
801 | - | end |
801 | + | |
802 | - | end |
802 | + | |
803 | - | cy = cy + 1 |
803 | + | |
804 | return false | |
805 | - | local function down() |
805 | + | |
806 | - | while not mapturt.down() do |
806 | + | |
807 | - | --print("Can't move, checking fuel") |
807 | + | |
808 | - | if turtle.getFuelLevel() == 0 then |
808 | + | |
809 | - | turtle.select(1) |
809 | + | |
810 | - | turtle.refuel(1) |
810 | + | |
811 | - | end |
811 | + | |
812 | - | if digBlocks then |
812 | + | |
813 | - | turtle.digDown() |
813 | + | |
814 | - | end |
814 | + | |
815 | - | end |
815 | + | |
816 | - | cy = cy - 1 |
816 | + | |
817 | if colormode then | |
818 | - | local function getPos() |
818 | + | |
819 | - | --print("Getting position") |
819 | + | |
820 | - | cx, cy, cz = gps.locate(5) |
820 | + | |
821 | - | --print(cx, cy, cz) |
821 | + | renName = tostring(read()) |
822 | print("Rename to what?") | |
823 | - | local function getDir() |
823 | + | |
824 | - | --print("Getting direction") |
824 | + | |
825 | - | getPos() |
825 | + | |
826 | - | ox, oy, oz = cx, cy, cz |
826 | + | |
827 | - | forward() |
827 | + | |
828 | - | getPos() |
828 | + | |
829 | - | if oz > cz then dir = 0 |
829 | + | |
830 | - | elseif oz < cz then dir = 2 |
830 | + | |
831 | - | elseif ox < cx then dir = 1 |
831 | + | |
832 | - | elseif ox > cx then dir = 3 end |
832 | + | |
833 | - | --print(dir) |
833 | + | |
834 | - | mapturt.back() |
834 | + | |
835 | - | getPos() |
835 | + | |
836 | print("Invalid waypoint '" .. renName .. "'!") | |
837 | - | local function turn(d) |
837 | + | |
838 | - | --getDir() |
838 | + | |
839 | - | --print("Aligning") |
839 | + | |
840 | - | --print(dir, d) |
840 | + | |
841 | - | while dir ~= d do |
841 | + | |
842 | - | mapturt.turnRight() |
842 | + | -- setDefaultColors() |
843 | - | dir = dir + 1 |
843 | + | -- term.clear() |
844 | - | if dir == 4 then dir = 0 end |
844 | + | |
845 | - | end |
845 | + | -- clearMap() |
846 | -- renderCommands() | |
847 | - | local function moveX() |
847 | + | |
848 | - | --print("Moving X") |
848 | + | |
849 | - | --getPos() |
849 | + | |
850 | - | if gox > cx then |
850 | + | |
851 | - | turn(1) |
851 | + | |
852 | - | for x = 1, gox - cx do |
852 | + | |
853 | - | forward() |
853 | + | |
854 | - | cx = cx + 1 |
854 | + | print(" Map Options:") |
855 | - | end |
855 | + | term.setCursorPos(1,3) |
856 | - | elseif gox < cx then |
856 | + | for a = 1, scr_x do |
857 | - | turn(3) |
857 | + | write("-") |
858 | - | for x = 1, cx - gox do |
858 | + | |
859 | - | forward() |
859 | + | term.setCursorPos(1,5) |
860 | - | cx = cx - 1 |
860 | + | |
861 | - | end |
861 | + | |
862 | - | end |
862 | + | |
863 | print(" * (C)reate Waypoint") | |
864 | - | local function moveZ() |
864 | + | print(" * (D)elete Waypoint") |
865 | - | --print("Moving Z") |
865 | + | print(" * (R)ename Waypoint") |
866 | - | --getPos() |
866 | + | print(" * Edit C(o)nfig") |
867 | - | if goz > cz then |
867 | + | print(" * (S)et Scale") |
868 | - | turn(2) |
868 | + | print(" * E(x)it") |
869 | - | for z = 1, goz - cz do |
869 | + | |
870 | - | forward() |
870 | + | key = keys.getName(key) |
871 | - | cz = cz + 1 |
871 | + | until string.find("cdrosx", key) |
872 | - | end |
872 | + | |
873 | - | elseif goz < cz then |
873 | + | displayStuffs = false |
874 | - | turn(0) |
874 | + | |
875 | - | for z = 1, cz - goz do |
875 | + | |
876 | - | forward() |
876 | + | |
877 | - | cz = cz - 1 |
877 | + | |
878 | - | end |
878 | + | |
879 | - | end |
879 | + | |
880 | displayStuffs = true | |
881 | - | local function moveY() |
881 | + | |
882 | - | --print("Moving Y") |
882 | + | |
883 | - | --getPos() |
883 | + | |
884 | - | if goy > cy then |
884 | + | |
885 | - | for z = 1, goy - cy do |
885 | + | displayStuffs = false |
886 | - | up() |
886 | + | |
887 | - | cy = cy + 1 |
887 | + | |
888 | - | end |
888 | + | |
889 | - | elseif goy < cy then |
889 | + | |
890 | - | for z = 1, cy - goy do |
890 | + | |
891 | - | down() |
891 | + | |
892 | - | cy = cy - 1 |
892 | + | |
893 | - | end |
893 | + | |
894 | - | end |
894 | + | |
895 | end | |
896 | if key == "s" then | |
897 | displayStuffs = false | |
898 | setDefaultColors() | |
899 | - | if not doGrid then |
899 | + | |
900 | - | setDefaultTextColor() |
900 | + | |
901 | setScale() | |
902 | - | term.setBackgroundColor(mapColors[9]) |
902 | + | |
903 | sleep(0) | |
904 | displayStuffs = true | |
905 | redrawSceen() | |
906 | - | local mapLengthInner = (corner2[1]) - (corner1[1]) - 1 |
906 | + | |
907 | - | local longBlankChar1 = string.rep(blankChar, mapLengthInner) |
907 | + | |
908 | - | for y = corner1[2] + 1, corner2[2] - 1 do |
908 | + | |
909 | - | term.setCursorPos(corner1[1]+1,y) |
909 | + | |
910 | - | if y == math.floor(midPoint[2]) then |
910 | + | displayStuffs = false |
911 | - | write(string.rep(blankChar, math.ceil(mapLengthInner/2)-1)) |
911 | + | |
912 | - | term.setCursorPos(midPoint[1]+1,y) |
912 | + | |
913 | - | write(string.rep(blankChar, math.floor(mapLengthInner/2))) |
913 | + | |
914 | shell.run("edit " .. mapConfigFile) | |
915 | - | write(longBlankChar1) |
915 | + | |
916 | displayStuffs = true | |
917 | getConfig() | |
918 | setDefaultColors() | |
919 | - | for y = corner1[2], corner2[2] do |
919 | + | |
920 | - | term.setCursorPos(corner1[1]-1,y) |
920 | + | |
921 | - | write(" ") --I do " " because 'blankChar' is for the inside of the map. |
921 | + | |
922 | end | |
923 | - | for y = corner1[2], corner2[2] do |
923 | + | |
924 | - | term.setCursorPos(corner2[1]+1,y) |
924 | + | displayStuffs = false |
925 | - | write(" ") --Same here. |
925 | + | |
926 | term.clear() | |
927 | sleep(0) | |
928 | - | term.setCursorPos(1,corner1[2]-1) |
928 | + | |
929 | term.clear() | |
930 | sleep(0) | |
931 | displayStuffs = true | |
932 | redrawSceen() | |
933 | end | |
934 | if key == "x" then | |
935 | sleep(0) | |
936 | return | |
937 | - | defineMapBorders() |
937 | + | |
938 | print("Cancelling.") | |
939 | sleep(0.1) | |
940 | - | term.setTextColor(colors.lightGray) |
940 | + | |
941 | end | |
942 | ||
943 | function keyPress() | |
944 | displayStuffs = true | |
945 | while true do | |
946 | local event, key = os.pullEvent("key") | |
947 | - | if grayAllowed then |
947 | + | key = tostring(keys.getName(key)) |
948 | if key == "l" then | |
949 | - | term.setBackgroundColor(colors.gray) |
949 | + | if labelMode == true then |
950 | labelMode = false | |
951 | elseif labelMode == false then | |
952 | labelMode = true | |
953 | end | |
954 | refreshOtherConfig() | |
955 | drawBorder() | |
956 | clearMap() | |
957 | - | local mapHeight = corner2[2] - corner1[2] |
957 | + | |
958 | - | local longMapChar = string.rep(" ", mapLength) |
958 | + | if spoofMode then |
959 | - | local longMapCharHalf = string.rep(" ", math.floor(mapLength/2)) |
959 | + | |
960 | fakeX = fakeX - 1 | |
961 | - | write(longMapCharHalf) |
961 | + | sleep(0.07) |
962 | - | term.setCursorPos(midPoint[1]+1,corner1[2]) |
962 | + | |
963 | - | write(longMapCharHalf) |
963 | + | |
964 | fakeX = fakeX + 1 | |
965 | sleep(0.07) | |
966 | end | |
967 | if key == "down" then | |
968 | fakeZ = fakeZ - 1 | |
969 | - | write(" ") |
969 | + | sleep(0.07) |
970 | end | |
971 | - | write("X") |
971 | + | |
972 | fakeZ = fakeZ + 1 | |
973 | sleep(0.07) | |
974 | end | |
975 | - | term.setCursorPos(corner2[1],b) |
975 | + | |
976 | - | write(" ") |
976 | + | if key == "h" then |
977 | displayStuffs = false | |
978 | - | |
978 | + | |
979 | term.clear() | |
980 | sleep(0) | |
981 | - | -- term.setCursorPos(corner1[1],midPoint[2]) |
981 | + | displayHelp() |
982 | - | -- write("X") |
982 | + | |
983 | sleep(0) | |
984 | displayStuffs = true | |
985 | clearMap() | |
986 | drawBorder() | |
987 | renderCommands() | |
988 | end | |
989 | if key == "m" then | |
990 | - | scaleX = corner1[1] + 1 |
990 | + | displayStuffs = false |
991 | - | if not monitorMode then |
991 | + | |
992 | - | scaleY = corner2[2] + 1 |
992 | + | |
993 | sleep(0) | |
994 | - | scaleY = scr_y - 2 |
994 | + | waypointSettings() |
995 | term.clear() | |
996 | - | term.setCursorPos(scaleX,scaleY) |
996 | + | |
997 | displayStuffs = true | |
998 | clearMap() | |
999 | drawBorder() | |
1000 | renderCommands() | |
1001 | end | |
1002 | if key == "numPadAdd" or key == "add" then | |
1003 | scaleFactor = scaleFactor * 1.1 | |
1004 | displayStuffs = true | |
1005 | - | if grayAllowed then |
1005 | + | |
1006 | - | term.setTextColor(colors.gray) |
1006 | + | |
1007 | drawBorder() | |
1008 | - | term.setTextColor(colors.black) |
1008 | + | drawScaleIndicator() |
1009 | elseif key == "minus" or key == "numPadSubtract" then | |
1010 | scaleFactor = scaleFactor / 1.1 | |
1011 | displayStuffs = true | |
1012 | refreshOtherConfig() | |
1013 | clearMap() | |
1014 | drawBorder() | |
1015 | drawScaleIndicator() | |
1016 | - | if grayAllowed then |
1016 | + | |
1017 | - | term.setTextColor(colors.lightGray) |
1017 | + | |
1018 | sleep(0) | |
1019 | return | |
1020 | end | |
1021 | end | |
1022 | - | term.setTextColor(colors.black) |
1022 | + | |
1023 | ||
1024 | getConfig() | |
1025 | ||
1026 | - | if not monitorMode then |
1026 | + | fakeX = 3 --Used if spoofMode == true, if not then these are set in the event that it is later set true. |
1027 | - | write(string.sub(scaleFactor, 1, 12).. "x") |
1027 | + | fakeY = 62 |
1028 | fakeZ = 5 | |
1029 | - | write(string.sub(scaleFactor, 1, 6) .. "x") |
1029 | + | |
1030 | if autoUpdate then | |
1031 | write("Automatically updating Map...") | |
1032 | updateMapProgram() | |
1033 | print("up to date!") | |
1034 | - | local function printOutput(commie) |
1034 | + | |
1035 | - | local oldCurX, oldCurY = term.getCursorPos() |
1035 | + | |
1036 | - | if type(commie) == "table" then |
1036 | + | parallel.waitForAny(renderMap, keyPress) |
1037 | - | for a = 1, #commie do |
1037 | + | |
1038 | - | term.setCursorPos(2,scr_y-(#commie-a)) |
1038 | + | |
1039 | term.setBackgroundColor(colors.black) | |
1040 | - | term.setTextColor(colors.gray) |
1040 | + | |
1041 | - | term.setBackgroundColor(colors.lightGray) |
1041 | + | |
1042 | print("Thanks for using Map v" .. mapVersion .. "!") | |
1043 | print("(code: 4RfTdBFk)") | |
1044 | sleep(0) |