add menu to newdesign
This commit is contained in:
53
src/main.lua
53
src/main.lua
@@ -90,15 +90,58 @@ local function newdesign()
|
||||
end
|
||||
end
|
||||
end
|
||||
term.setcol(colors.yellow, colors.black)
|
||||
local _,y = term.getSize()
|
||||
term.setCursorPos(1,y)
|
||||
term.write("Press Ctrl for menu.")
|
||||
|
||||
-- user input
|
||||
local event = table.pack(os.pullEvent())
|
||||
if (event[1] == "mouse_click" or event[1] == "mouse_drag") and event[3] > 0 and event[3] <= dimensions["x"] and event[4] > 0 and event[4] <= dimensions["z"] then
|
||||
if event[2] == 1 then -- left button, set
|
||||
buf[posasstring(event[3], currentfloor, event[4])] = true
|
||||
if event[1] == "mouse_click" or event[1] == "mouse_drag" then
|
||||
if event[3] <= dimensions["x"] and event[4] <= dimensions["z"] then
|
||||
if event[2] == 1 then -- left button, set
|
||||
buf[posasstring(event[3], currentfloor, event[4])] = true
|
||||
end
|
||||
if event[2] == 2 then -- right button, erase
|
||||
buf[posasstring(event[3], currentfloor, event[4])] = false
|
||||
end
|
||||
end
|
||||
if event[2] == 2 then -- right button, erase
|
||||
buf[posasstring(event[3], currentfloor, event[4])] = false
|
||||
end
|
||||
if event[1] == "key" and keys.getName(event[2]) == "leftCtrl" then -- menu
|
||||
local action = selopt({
|
||||
"Save",
|
||||
"Load",
|
||||
"Exit",
|
||||
"Change X size",
|
||||
"Change floor amount",
|
||||
"Change Z size"
|
||||
}, "menu")
|
||||
if action == 3 then return end -- exit
|
||||
if action == 1 then -- save
|
||||
reset()
|
||||
write("Enter name: ")
|
||||
local name = read()
|
||||
local file = fs.open("designs/"..name, "w")
|
||||
file.write(textutils.serialiseJSON({
|
||||
["dimensions"] = dimensions,
|
||||
["buf"] = buf
|
||||
}))
|
||||
file.close()
|
||||
end
|
||||
if action == 2 then -- load
|
||||
reset()
|
||||
write("Enter name: ")
|
||||
local name = read()
|
||||
if not fs.exists("designs/"..name) then
|
||||
printError("Design not found!")
|
||||
else
|
||||
local file = fs.open("designs/"..name, "r")
|
||||
local content = file.readAll()
|
||||
file.close()
|
||||
content = textutils.unserialiseJSON(content)
|
||||
dimensions = content["dimensions"]
|
||||
buf = content["buf"]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user