Skip to content

Commit

Permalink
Show Ruler block length
Browse files Browse the repository at this point in the history
  • Loading branch information
Silverfeelin committed Feb 6, 2017
1 parent 7459a13 commit 28d04c8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .metadata
Expand Up @@ -2,7 +2,7 @@
"name" : "WEdit",
"friendlyName" : "WEdit - World Edit Tech",
"priority" : 999,
"version" : "1.2.2.1",
"version" : "1.2.2.2",
"author" : "Silverfeelin",
"description" : "Allows you to edit the world around you on a larger scale.

Expand Down
27 changes: 16 additions & 11 deletions scripts/weditActions.lua
Expand Up @@ -641,6 +641,8 @@ function wedit.actions.WE_Ruler()
wedit.info("^shadow;^yellow;Current Block: ^red;" .. wedit.controller.selectedBlockToString() .. "^yellow;.", {0,-3})
wedit.info("^shadow;^yellow;Current Layer: ^red;" .. wedit.controller.layer .. "^yellow;.", {0,-4})

local line = wedit.controller.line

-- Make selection (similar to WE_Select, but doesn't convert the two points to the bottom left and top right corner).
if wedit.controller.lineStage == 0 then
-- Select stage 0: Not selecting.
Expand All @@ -649,23 +651,23 @@ function wedit.actions.WE_Ruler()
if wedit.controller.primaryFire then
-- Start selection; set first point.
wedit.controller.lineStage = 1
wedit.controller.line[2] = {}
wedit.controller.line[1] = tech.aimPosition()
line[2] = {}
line[1] = tech.aimPosition()
end

elseif wedit.controller.lineStage == 1 then
wedit.info("^shadow;^yellow;Drag mouse and let go to finish the selection.", {0,-1})
-- Select stage 1: Selection started.
if wedit.controller.primaryFire then
-- Dragging selection; update second point.
wedit.controller.line[2] = tech.aimPosition()
line[2] = tech.aimPosition()

-- Round each value down.
wedit.controller.line[1][1] = math.floor(wedit.controller.line[1][1])
wedit.controller.line[2][1] = math.floor(wedit.controller.line[2][1])
line[1][1] = math.floor(line[1][1])
line[2][1] = math.floor(line[2][1])

wedit.controller.line[1][2] = math.floor(wedit.controller.line[1][2])
wedit.controller.line[2][2] = math.floor(wedit.controller.line[2][2])
line[1][2] = math.floor(line[1][2])
line[2][2] = math.floor(line[2][2])
else
-- Selection ended; reset stage to allow next selection.
wedit.controller.lineStage = 0
Expand All @@ -676,22 +678,25 @@ function wedit.actions.WE_Ruler()
end

-- Drawing and allowing RMB only works with a valid selection
if wedit.controller.line[1] and wedit.controller.line[1][1] and wedit.controller.line[2] and wedit.controller.line[2][1] then
if line[1] and line[1][1] and line[2] and line[2][1] then
-- Draw boxes around every block in the current selection.
wedit.bresenham(wedit.controller.line[1], wedit.controller.line[2],
wedit.bresenham(line[1], line[2],
function(x, y)
world.debugLine({x, y}, {x + 1, y}, "green")
world.debugLine({x, y + 1}, {x + 1, y + 1}, "green")
world.debugLine({x, y}, {x, y + 1}, "green")
world.debugLine({x + 1, y}, {x + 1, y + 1}, "green")
end)

wedit.info("^shadow;^yellow;Current line is indicated with green blocks.", {0,-5})
-- Calculate line length for display
local w, h = math.abs(line[1][1] - line[2][1]) + 1, math.abs(line[1][2] - line[2][2]) + 1
local length = w > h and w or h
wedit.info("^shadow;^yellow;Current Length: ^red;" .. length .. " ^yellow;blocks ^red;(" .. w .. "x" .. h .. ")^yellow;.", {0,-5})

-- RMB : Fill selection.
if not wedit.controller.fireLocked and wedit.controller.altFire then
wedit.controller.fireLock()
wedit.line(wedit.controller.line[1], wedit.controller.line[2], wedit.controller.layer, wedit.controller.selectedBlockToString())
wedit.line(line[1], line[2], wedit.controller.layer, wedit.controller.selectedBlockToString())
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion scripts/weditController.lua
Expand Up @@ -119,7 +119,7 @@ function controller.showSelection()
-- Draw selections if they have been made.
if controller.validSelection() then
wedit.debugRectangle(controller.selection[1], controller.selection[2])
wedit.debugText(string.format("^shadow;WEdit Selection (%s,%s)", controller.selection[2][1] - controller.selection[1][1], controller.selection[2][2] - controller.selection[1][2]), {controller.selection[1][1], controller.selection[2][2]}, "green")
wedit.debugText(string.format("^shadow;WEdit Selection (%sx%s)", controller.selection[2][1] - controller.selection[1][1], controller.selection[2][2] - controller.selection[1][2]), {controller.selection[1][1], controller.selection[2][2]}, "green")

if storage.weditCopy and storage.weditCopy.size then
local copy = storage.weditCopy
Expand Down

0 comments on commit 28d04c8

Please sign in to comment.