made VPrint a mode and experimental
This commit is contained in:
127
src/main.lua
127
src/main.lua
@@ -297,7 +297,7 @@ local function newdesign()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local function move(direction)
|
local function move(direction, continousattempt)
|
||||||
if direction == "left" then
|
if direction == "left" then
|
||||||
turtle.turnLeft()
|
turtle.turnLeft()
|
||||||
return
|
return
|
||||||
@@ -321,11 +321,11 @@ local function move(direction)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
local suc,reason = turtle[direction]()
|
local suc,reason = turtle[direction]()
|
||||||
if not suc then
|
if not suc and not continousattempt then
|
||||||
printError(reason)
|
printError(reason)
|
||||||
print("Resolve the error and press enter to continue.")
|
print("Resolve the error and press enter to continue.")
|
||||||
read("")
|
read("")
|
||||||
else
|
elseif suc then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -549,6 +549,61 @@ local function printdes(buf, dimensions)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- vertical stack printing
|
-- 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)
|
local function VP_optimizestack(target)
|
||||||
-- go from top to bottom and erase false entries until we encounter a true one.
|
-- go from top to bottom and erase false entries until we encounter a true one.
|
||||||
local index = #target
|
local index = #target
|
||||||
@@ -645,15 +700,43 @@ end
|
|||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
integritycheck()
|
integritycheck()
|
||||||
local action = selopt({
|
local action = selopt({
|
||||||
"New Design",
|
"New Design",
|
||||||
"Print Design"
|
"Print Design",
|
||||||
|
"VPrint Design",
|
||||||
}, "Select Action")
|
}, "Select Action")
|
||||||
|
|
||||||
if action == 1 then
|
if action == 1 then
|
||||||
@@ -688,5 +771,39 @@ while true do
|
|||||||
end
|
end
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user