~tuxpup/asesprite-script-center-selection

d4251cdcda265771df965b53f05652d2652ddc31 — Geoff Beier 2 years ago master
first version of quick and dirty selection centering script
4 files changed, 89 insertions(+), 0 deletions(-)

A .gitignore
A CenterSelectionOnCanvas.lua
A LICENSE.txt
A README.md
A  => .gitignore +2 -0
@@ 1,2 @@
install.sh


A  => CenterSelectionOnCanvas.lua +57 -0
@@ 1,57 @@
----------------------------------------------------------------------
-- Center the current selection on the sprite
-- Copyright 2020 Geoff Beier <geoff@tuxpup.com>
-- Licensed under the MIT license. See LICENSE.txt for details.
----------------------------------------------------------------------

-- bail if there's no active sprite
local spr = app.activeSprite
if not spr then return end

-- bail if nothing's selected
local sel = spr.selection
if sel.isEmpty then return end

--print("sel:"..sel.bounds.x..","..sel.bounds.y)

-- The MoveMask command requires us to specify X <units> up, Y <units> down
-- rather than just specifying new coordinates.
new_x = spr.bounds.width/2 - sel.bounds.width/2
x_dir = "right"
x_distance = 0
if new_x < sel.bounds.x then
	x_dir = "left"
	x_distance = sel.bounds.x - new_x
elseif new_x > sel.bounds.x then
	x_dir = "right"
	x_distance = new_x - sel.bounds.x
end

new_y = spr.bounds.height/2 - sel.bounds.height/2
y_dir = "down"
y_distance = 0
if new_y < sel.bounds.y then
	y_dir = "up"
	y_distance = sel.bounds.y - new_y
elseif new_y > sel.bounds.y then
	y_dir = "down"
	y_distance = new_y - sel.bounds.y
end

--print('need to move ' .. x_dir .. ' ' .. tostring(x_distance) .. ' and ' .. y_dir .. ' ' .. tostring(y_distance))

if x_distance ~= 0 then
	app.command.MoveMask{
		direction=x_dir,
		units="pixel",
		quantity=x_distance
	}
end

if y_distance ~= 0 then
	app.command.MoveMask{
		direction=y_dir,
		units="pixel",
		quantity=y_distance
	}
end

A  => LICENSE.txt +21 -0
@@ 1,21 @@

Copyright (c) 2020 Geoff Beier

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

A  => README.md +9 -0
@@ 1,9 @@
# Center Selection On Canvas

This is a quick and dirty script that attempts to take the current selection and center it on the current canvas in aseprite.

It is immensely helpful to me, but it hasn't been tested extensively. There are no guarantees. If it doesn't work for you, let me know and I will either try to fix it or offer you any ideas I have on how to fix it.

I'm just getting started with aseprite and this may not be the best way to do it at all... it really speeds up my workflow, though.

License is MIT. Do what you want with it.