made VPrint a mode and experimental

This commit is contained in:
justuswolff
2026-02-18 20:02:40 +01:00
parent 529b10e8dd
commit cd8a403d6e

View File

@@ -297,7 +297,7 @@ local function newdesign()
end
end
end
local function move(direction)
local function move(direction, continousattempt)
if direction == "left" then
turtle.turnLeft()
return
@@ -321,11 +321,11 @@ local function move(direction)
end
end
local suc,reason = turtle[direction]()
if not suc then
if not suc and not continousattempt then
printError(reason)
print("Resolve the error and press enter to continue.")
read("")
else
elseif suc then
break
end
end
@@ -549,6 +549,61 @@ local function printdes(buf, dimensions)
end
-- vertical stack printing
local function VP_movetoy(y, target)
while y > target do
move("down", true)
y = y - 1
end
while y < target do
move("up", true)
y = y + 1
end
return target
end
local function VP_moveto(x,z, cx,cz,direction)
local y = 0
--[[
y lanes for directions:
1: +x
2: -x
3: +z
4: -z
]]--
while x ~= cx do
if cx < x then -- x
center(direction)
direction = 0
y = VP_movetoy(y, 1)
cx = cx + 1
move("forward", true)
end
if cx > x then
center(direction)
direction = 0
y = VP_movetoy(y, 2)
cx = cx - 1
move("back", true)
end
end
while y ~= cz do
if y > cz then -- z
if center(direction, 1) then move("right") end
y = VP_movetoy(y, 3)
cz = cz + 1
move("forward", true)
direction = 1
end
if y < cz then
if center(direction, -1) then move("left") end
y = VP_movetoy(y, 4)
cz = cz - 1
move("forward", true)
direction = -1
end
end
VP_movetoy(y, 0)
return cx,cz,direction
end
local function VP_optimizestack(target)
-- go from top to bottom and erase false entries until we encounter a true one.
local index = #target
@@ -645,15 +700,43 @@ end
end
end
end]]
local function VP_printstack(buf, dimensions)
local function VP_printstack(buf, dimensions, cx,cz,direction)
reset()
move("up")
for _=1,buf["height"],1 do
move("up")
end
for x=1,dimensions["x"],1 do
for z=1,dimensions["z"],1 do
local tempbuf = buf["stacks"][posasstring(x,z)]
if tempbuf then
cx,cz,direction = VP_moveto(x,z, cx,cz,direction)
for _=1,buf["height"],1 do
move("down")
end
for _,v in pairs(tempbuf) do
if v then
place("down")
end
move("up")
end
end
end
end
for _=1,buf["height"],1 do
move("down")
end
return cx,cz,direction
end
while true do
integritycheck()
local action = selopt({
"New Design",
"Print Design"
"Print Design",
"VPrint Design",
}, "Select Action")
if action == 1 then
@@ -688,5 +771,39 @@ while true do
end
end
end
if action == 3 then
reset()
term.write("This mode is experimental! Be cautious!")
incline()
term.write("Enter to continue.")
read("")
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)
local stacks = VP_createstack(buf, dimensions)
if turtle.getFuelLevel() < cost then
write("WARNING: Not enough fuel! Continue anyway? y/n: ")
while true do
local ans = read("")
if ans == "y" then
VP_printstack(stacks, dimensions)
break
elseif ans == "n" then break end
end
else
VP_printstack(stacks, dimensions)
end
end
end
end