started work on printdes
This commit is contained in:
132
src/main.lua
132
src/main.lua
@@ -10,6 +10,7 @@ print("House building system")
|
|||||||
print("JUFS Technologies (c) 2026 (Justus Wolff)")
|
print("JUFS Technologies (c) 2026 (Justus Wolff)")
|
||||||
|
|
||||||
print("fuel: "..tostring(turtle.getFuelLevel()).."/"..tostring(turtle.getFuelLimit()))
|
print("fuel: "..tostring(turtle.getFuelLevel()).."/"..tostring(turtle.getFuelLimit()))
|
||||||
|
os.sleep(0.1)
|
||||||
|
|
||||||
function term.setcol(fc, bc)
|
function term.setcol(fc, bc)
|
||||||
term.setTextColor(fc)
|
term.setTextColor(fc)
|
||||||
@@ -66,6 +67,13 @@ local function posasstring(...)
|
|||||||
end
|
end
|
||||||
return out
|
return out
|
||||||
end
|
end
|
||||||
|
local function load(name)
|
||||||
|
local file = fs.open("designs/"..name, "r")
|
||||||
|
local content = file.readAll()
|
||||||
|
file.close()
|
||||||
|
content = textutils.unserialiseJSON(content)
|
||||||
|
return content["buf"],content["dimensions"]
|
||||||
|
end
|
||||||
local function newdesign()
|
local function newdesign()
|
||||||
local buf = {}
|
local buf = {}
|
||||||
local dimensions = {
|
local dimensions = {
|
||||||
@@ -151,12 +159,7 @@ local function newdesign()
|
|||||||
if not fs.exists("designs/"..name) or name == "" then
|
if not fs.exists("designs/"..name) or name == "" then
|
||||||
printError("Design not found!")
|
printError("Design not found!")
|
||||||
else
|
else
|
||||||
local file = fs.open("designs/"..name, "r")
|
buf,dimensions = load(name)
|
||||||
local content = file.readAll()
|
|
||||||
file.close()
|
|
||||||
content = textutils.unserialiseJSON(content)
|
|
||||||
dimensions = content["dimensions"]
|
|
||||||
buf = content["buf"]
|
|
||||||
camx,camy,currentfloor = 0,0,1
|
camx,camy,currentfloor = 0,0,1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -200,6 +203,94 @@ local function newdesign()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
local function move(direction)
|
||||||
|
if direction == "left" then
|
||||||
|
turtle.turnLeft()
|
||||||
|
end
|
||||||
|
if direction == "right" then
|
||||||
|
turtle.turnRight()
|
||||||
|
end
|
||||||
|
while true do
|
||||||
|
if turtle.getFuelLevel() == 0 then
|
||||||
|
reset()
|
||||||
|
print("Out of fuel! Please insert fuel into current slot.")
|
||||||
|
while true do
|
||||||
|
local suc = turtle.refuel(64)
|
||||||
|
if suc then
|
||||||
|
print("Refuelled. Press enter to continue.")
|
||||||
|
read("")
|
||||||
|
break
|
||||||
|
end
|
||||||
|
os.sleep(1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local suc,reason = turtle[direction]()
|
||||||
|
if not suc then
|
||||||
|
printError(reason)
|
||||||
|
print("Resolve the error and press enter to continue.")
|
||||||
|
read("")
|
||||||
|
else
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local function place(direction)
|
||||||
|
local func = turtle.place
|
||||||
|
if direction == "down" then
|
||||||
|
func = turtle.placeDown
|
||||||
|
end
|
||||||
|
if direction == "up" then
|
||||||
|
func = turtle.placeUp
|
||||||
|
end
|
||||||
|
|
||||||
|
while true do
|
||||||
|
local suc = func()
|
||||||
|
if not suc then -- next slot
|
||||||
|
local current = turtle.getSelectedSlot()
|
||||||
|
if current == 16 then
|
||||||
|
turtle.select(1)
|
||||||
|
else
|
||||||
|
turtle.select(current+1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
os.sleep(0) -- yield
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local function placebuf(buf, x, y, z)
|
||||||
|
if buf[posasstring(x,y,z)] then
|
||||||
|
place("down")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local function printdes(buf, dimensions)
|
||||||
|
move("up")
|
||||||
|
move("forward")
|
||||||
|
|
||||||
|
for cy=1,dimensions["y"],1 do
|
||||||
|
for cz=1,dimensions["z"],1 do
|
||||||
|
for cx=1,dimensions["x"],1 do
|
||||||
|
placebuf(buf, cx, cy, cz)
|
||||||
|
move("forward")
|
||||||
|
end
|
||||||
|
-- return to standard pos but +1 to z
|
||||||
|
move("back")
|
||||||
|
move("right")
|
||||||
|
move("forward")
|
||||||
|
move("right")
|
||||||
|
for _=1,dimensions["x"],1 do
|
||||||
|
move("forward")
|
||||||
|
end
|
||||||
|
move("right")
|
||||||
|
move("right")
|
||||||
|
end
|
||||||
|
-- return to standard pos but +1 to y
|
||||||
|
move("left")
|
||||||
|
for _=1,dimensions["z"],1 do
|
||||||
|
move("forward")
|
||||||
|
end
|
||||||
|
move("right")
|
||||||
|
move("up")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
integritycheck()
|
integritycheck()
|
||||||
@@ -211,5 +302,34 @@ while true do
|
|||||||
if action == 1 then
|
if action == 1 then
|
||||||
newdesign()
|
newdesign()
|
||||||
end
|
end
|
||||||
|
if action == 2 then
|
||||||
|
reset()
|
||||||
|
for _,v in pairs(fs.list("designs")) do
|
||||||
|
term.write(v)
|
||||||
|
incline()
|
||||||
|
end
|
||||||
|
write("Enter name: ")
|
||||||
|
local name = read()
|
||||||
|
if not fs.exists("designs/"..name) or name == "" then
|
||||||
|
printError("Design not found!")
|
||||||
|
else
|
||||||
|
local buf,dimensions = load(name)
|
||||||
|
write("Calculating fuel cost...")
|
||||||
|
local cost = dimensions["x"]*dimensions["z"]*(dimensions["y"]*4-1)
|
||||||
|
print(tostring(turtle.getFuelLevel()).."/"..tostring(cost))
|
||||||
|
if turtle.getFuelLevel() < cost then
|
||||||
|
write("WARNING: Not enough fuel! Continue anyway? y/n: ")
|
||||||
|
while true do
|
||||||
|
local ans = read("")
|
||||||
|
if ans == "y" then
|
||||||
|
printdes(buf, dimensions)
|
||||||
|
break
|
||||||
|
elseif ans == "n" then break end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
printdes(buf, dimensions)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user