add menu to newdesign

This commit is contained in:
Justus Wolff
2026-02-15 11:16:07 +01:00
parent 3396396379
commit a6aec5167a

View File

@@ -90,10 +90,15 @@ 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[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
@@ -102,6 +107,44 @@ local function newdesign()
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
while true do