SLADE icon indicating copy to clipboard operation
SLADE copied to clipboard

Enable Lua scripts to change the coordinates of map vertices

Open flarn2006 opened this issue 4 years ago • 1 comments

SLADE Version: 3.1.11 Operating System: Linux

Issue Details: I've written the following script to rescale a map on the X and Y dimensions:

-- A map script will run the execute function (below) on the current map
-- Map scripts can be selected and run from the "Tools->Run Script" menu in the map editor

function execute(map)
	local scale = App.promptNumber('Rescale Map', 'What scale factor?', 1, 0, 1024)

	if scale then
		for i,v in ipairs(map.vertices) do
			v:setFloatProperty('x', scale * v:x())
			v:setFloatProperty('y', scale * v:y())
		end
		
		for i,t in ipairs(map.things) do
			t:setFloatProperty('x', scale * t.x)
			t:setFloatProperty('y', scale * t.y)
		end
	end
end

It works fine for the Things on the map, but the vertices don't move.

flarn2006 avatar Apr 29 '20 16:04 flarn2006

I just looked at the Console window and now I see a message saying that the X and Y properties of vertices can't be changed via scripting. If there's no way to make this work, one suggestion I have is to at least open the output window to display that message.

I'll leave this open as an enhancement request for adding the functionality to change these properties; if this isn't something you think would be worth adding, feel free to close it of course.

flarn2006 avatar Apr 29 '20 16:04 flarn2006