2026-02-14 22:07:35 +01:00
|
|
|
-- https://git.l--n.de/justuswolff/cc_housebuild/raw/branch/main/src/main.lua
|
|
|
|
|
|
|
|
|
|
if not _G["turtle"] then
|
|
|
|
|
error("This program only runs on turtles!")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local turtle = _G["turtle"]
|
|
|
|
|
|
2026-02-14 22:24:37 +01:00
|
|
|
print("House building system")
|
|
|
|
|
print("JUFS Technologies (c) 2026 (Justus Wolff)")
|
|
|
|
|
|
2026-02-14 22:07:35 +01:00
|
|
|
print("fuel: "..tostring(turtle.getFuelLevel()).."/"..tostring(turtle.getFuelLimit()))
|
|
|
|
|
|
2026-02-14 22:27:16 +01:00
|
|
|
function term.setcol(fc, bc)
|
|
|
|
|
term.setTextColor(fc)
|
|
|
|
|
term.setBackgroundColor(bc)
|
|
|
|
|
end
|
2026-02-14 22:24:37 +01:00
|
|
|
local function reset()
|
2026-02-14 22:28:25 +01:00
|
|
|
term.setcol(colors.white, colors.black)
|
2026-02-14 22:24:37 +01:00
|
|
|
term.clear()
|
|
|
|
|
term.setCursorPos(1,1)
|
|
|
|
|
end
|
|
|
|
|
local function incline()
|
2026-02-14 22:25:53 +01:00
|
|
|
local _,y = term.getCursorPos()
|
|
|
|
|
term.setCursorPos(1,y+1)
|
2026-02-14 22:24:37 +01:00
|
|
|
end
|
|
|
|
|
local function selopt(options, title)
|
|
|
|
|
local selected = 1
|
|
|
|
|
|
|
|
|
|
while true do
|
2026-02-14 22:26:20 +01:00
|
|
|
reset()
|
|
|
|
|
term.setcol(colors.black, colors.white)
|
|
|
|
|
term.write(title)
|
2026-02-14 22:24:37 +01:00
|
|
|
for i,v in pairs(options) do
|
|
|
|
|
incline()
|
|
|
|
|
if i == selected then
|
|
|
|
|
term.setcol(colors.black, colors.blue)
|
|
|
|
|
else
|
|
|
|
|
term.setcol(colors.white, colors.black)
|
|
|
|
|
end
|
|
|
|
|
term.write(v)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local event,key = os.pullEvent("key")
|
|
|
|
|
if keys.getName(key) == "w" and selected ~= 1 then
|
|
|
|
|
selected = selected - 1
|
|
|
|
|
end
|
|
|
|
|
if keys.getName(key) == "s" and selected ~= #options then
|
|
|
|
|
selected = selected + 1
|
|
|
|
|
end
|
|
|
|
|
if keys.getName(key) == "enter" then
|
|
|
|
|
return selected
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2026-02-15 10:58:55 +01:00
|
|
|
local function integritycheck()
|
|
|
|
|
if not fs.exists("designs") then
|
|
|
|
|
fs.makeDir("designs")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
local function posasstring(...)
|
|
|
|
|
local positions = {...}
|
|
|
|
|
local out = ""
|
|
|
|
|
for _,v in pairs(positions) do
|
|
|
|
|
out = out .. tostring(v) .. ":"
|
|
|
|
|
end
|
|
|
|
|
return out
|
|
|
|
|
end
|
|
|
|
|
local function newdesign()
|
|
|
|
|
local buf = {}
|
|
|
|
|
local dimensions = {
|
|
|
|
|
x = 8,
|
|
|
|
|
z = 8,
|
|
|
|
|
y = 1
|
|
|
|
|
}
|
|
|
|
|
local currentfloor = 1
|
|
|
|
|
|
|
|
|
|
while true do
|
|
|
|
|
-- render buf
|
|
|
|
|
reset()
|
|
|
|
|
for x=1,dimensions["x"],1 do
|
|
|
|
|
for z=1,dimensions["z"],1 do
|
|
|
|
|
local currentbuf = buf[posasstring(x, currentfloor, z)]
|
|
|
|
|
if currentbuf then
|
|
|
|
|
term.setCursorPos(x, z)
|
|
|
|
|
term.blit(" ", colors.toBlit(colors.white), colors.toBlit(colors.white))
|
2026-02-15 11:03:26 +01:00
|
|
|
else
|
|
|
|
|
term.setCursorPos(x, z)
|
2026-02-15 11:04:20 +01:00
|
|
|
term.blit("\127", colors.toBlit(colors.gray), colors.toBlit(colors.black))
|
2026-02-15 10:58:55 +01:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2026-02-15 11:16:07 +01:00
|
|
|
term.setcol(colors.yellow, colors.black)
|
|
|
|
|
local _,y = term.getSize()
|
|
|
|
|
term.setCursorPos(1,y)
|
|
|
|
|
term.write("Press Ctrl for menu.")
|
2026-02-14 22:24:37 +01:00
|
|
|
|
2026-02-15 10:58:55 +01:00
|
|
|
-- user input
|
|
|
|
|
local event = table.pack(os.pullEvent())
|
2026-02-15 11:16:07 +01:00
|
|
|
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
|
|
|
|
|
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()
|
2026-02-15 10:58:55 +01:00
|
|
|
end
|
2026-02-15 11:16:07 +01:00
|
|
|
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
|
2026-02-15 10:58:55 +01:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
while true do
|
|
|
|
|
integritycheck()
|
|
|
|
|
local action = selopt({
|
|
|
|
|
"New Design",
|
|
|
|
|
"Print Design"
|
|
|
|
|
}, "Select Action")
|
|
|
|
|
|
|
|
|
|
if action == 1 then
|
|
|
|
|
newdesign()
|
|
|
|
|
end
|
|
|
|
|
end
|
2026-02-14 22:24:37 +01:00
|
|
|
|