Permalink
Browse files

Calibrate tool

Still needs an item with icon & compact interface option.
  • Loading branch information...
Silverfeelin committed Jun 24, 2018
1 parent 764ad3b commit e0bf1ba90064282e625398eacd6f3cf9c9852f0b
Showing with 94 additions and 3 deletions.
  1. +2 −2 .metadata
  2. +16 −1 scripts/wedit/actions.lua
  3. +76 −0 scripts/wedit/wedit.lua
@@ -9,5 +9,5 @@
"requires" : [],
"steamContentId" : "734859295",
"tags" : "Crafting and Building|Cheats and God Items|User Interface|In-Game Tools",
"version" : "1.3.3"
}
"version" : "1.3.3.1"
}
@@ -329,7 +329,6 @@ function wedit.actions.WE_Stamp()
controller.info("^shadow;^orange;WEdit: Stamp Tool")
controller.info("^shadow;^yellow;Primary Fire: Copy selection.", {0,-1})
controller.info("^shadow;^yellow;Alt Fire: Paste selection.", {0,-2})
controller.info("^shadow;^yellow;The paste area is defined by the bottom left point of your selection.", {0,-3})
controller.info("^shadow;^yellow;Shift + Primary Fire: Forget copy.", {0,-3})
controller.info("^shadow;^yellow;The paste area is defined by the bottom left point of your selection.", {0,-4})
@@ -767,3 +766,19 @@ function wedit.actions.WE_Dye()
end
end
end
function wedit.actions.WE_Calibrate()
controller.info("^shadow;^orange;WEdit: Calibrator")
controller.info("^shadow;^yellow;Primary Fire: Calibrate delay.", {0,-1})
controller.info("^shadow;^yellow;Make sure the highlighted block is", {0,-2})
controller.info("^shadow;^yellow;empty and has a background block.", {0,-3})
local aimPos = tech.aimPosition()
wedit.debugRenderer:drawBlock(aimPos, "green")
if not controller.fireLocked and controller.primaryFire then
controller.fireLock()
wedit.calibrate(aimPos)
end
end
@@ -1055,6 +1055,82 @@ function wedit.hydrate(bottomLeft, topRight, liquidId)
end)
end
--- Calculates an optimal 'delay'.
-- A block is placed, modified and broken a total of 5 times.
-- The time each step takes is used to determine the minimum delay WEdit can get away with.
-- @param pos Position to calibrate on. Should have a background but no foreground.
-- @param [maxTicks=60] Maximum delay. If calibration times out, this value is used.
function wedit.calibrate(pos, maxTicks)
if world.tileIsOccupied(pos, true) or not world.material(pos, "background") then return end
local attempts = maxTicks or 60 -- 1 sec.
local times = {}
local placeBlock = function(task)
if task.stageProgress == 0 then
world.placeMaterial(pos, "foreground", "hazard")
end
task.stageProgress = task.stageProgress + 1
if world.material(pos, "foreground") or task.stageProgress > attempts then
table.insert(times, task.stageProgress)
task:nextStage()
end
end
local placeMod = function(task)
if task.stageProgress == 0 then
world.placeMod(pos, "foreground", "coal")
end
task.stageProgress = task.stageProgress + 1
if world.mod(pos, "foreground") or task.stageProgress > attempts then
table.insert(times, task.stageProgress)
task:nextStage()
end
end
local breakMod = function(task)
if task.stageProgress == 0 then
world.damageTiles({pos}, "foreground", pos, "blockish", 9999, 0)
end
task.stageProgress = task.stageProgress + 1
if not world.mod(pos, "foreground") or task.stageProgress > attempts then
table.insert(times, task.stageProgress)
task:nextStage()
end
end
local breakBlock = function(task)
if task.stageProgress == 0 then
world.damageTiles({pos}, "foreground", pos, "blockish", 9999, 0)
end
task.stageProgress = task.stageProgress + 1
if not world.material(pos, "foreground") or task.stageProgress > attempts then
table.insert(times, task.stageProgress)
task:nextStage()
end
end
local finalize = function(task)
local delay = 1
for _,v in ipairs(times) do
if v > delay then delay = v end
end
wedit.controller.setUserConfig("delay", delay + 1)
task:complete()
end
local stages = {
placeBlock, placeMod, breakMod, breakBlock,
placeBlock, placeMod, breakMod, breakBlock,
placeBlock, placeMod, breakMod, breakBlock,
placeBlock, placeMod, breakMod, breakBlock,
placeBlock, placeMod, breakMod, breakBlock,
finalize
}
wedit.taskManager:start(Task.new(stages, 1))
end
--- For each block in a line between two points, calls the callback function.
-- This uses the bresenham algorithm implementation by kikito.
-- Licensed under the MIT license: https://github.com/kikito/bresenham.lua/blob/master/MIT-LICENSE.txt.

0 comments on commit e0bf1ba

Please sign in to comment.