add menu to newdesign
This commit is contained in:
45
src/main.lua
45
src/main.lua
@@ -90,10 +90,15 @@ local function newdesign()
|
|||||||
end
|
end
|
||||||
end
|
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
|
-- user input
|
||||||
local event = table.pack(os.pullEvent())
|
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[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
|
if event[2] == 1 then -- left button, set
|
||||||
buf[posasstring(event[3], currentfloor, event[4])] = true
|
buf[posasstring(event[3], currentfloor, event[4])] = true
|
||||||
end
|
end
|
||||||
@@ -102,6 +107,44 @@ local function newdesign()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
|
|||||||
Reference in New Issue
Block a user