Skip to content

Commit

Permalink
ready for release
Browse files Browse the repository at this point in the history
  • Loading branch information
David Fletcher committed Oct 20, 2021
1 parent 9ba4665 commit c93b64c
Show file tree
Hide file tree
Showing 7 changed files with 370 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Other ignores
**.vscode

# Compiled Lua sources
luac.out

Expand Down
29 changes: 28 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,29 @@
# new-with-ratios
# New With Ratios
![hero image](./assets/hero.png)

An Aseprite extension to create a new file that has ratio presets to make file creation easier.

## How to Use New With Ratios

1. Download this extension by visiting the releases page! (Double click the extension once downloaded to install)
2. In Aseprite, select `File > New With Ratio...`
3. The dialog will allow you to first specify your pixel art dimensions constrained to a ratio before moving onto the standard file creation flow!

![demonstration gif](https://media.giphy.com/media/9XoYy2cl7aN9rDMVzG/giphy.gif)

Currently, the ratios supported are:

* 1:1
* 4:7
* 7:8
* 16:9

I'm open to adding more ratios to the script, so please let me know if you'd like to see another ratio in this dialog as well! It's minimal effort to add new ones, so don't be shy!

## Credits

This extension was commissioned by [@timesnewredux](https://twitter.com/timesnewredux) on Twitter.

As an advocate of open-source software, feel free to suggest edits, or just fork this repository and make your own! The license on this software is open for commercial and private use. This extension will remain free forever; however, if you'd like to buy me a coffee, you can do so here:

[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/L3L766S5F)
Binary file added assets/hero.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
267 changes: 267 additions & 0 deletions extension/new-with-ratios.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
-- MIT License

-- Copyright (c) 2021 David Fletcher

-- 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.

local function mainWindow()
local dialog = Dialog("New File...")
local ratio_width = 1
local ratio_height = 1

local function adjust_for_ratio(num, divisor, dividend)
return math.floor(num * (dividend / divisor))
end

-----------------------------------
-- RATIOS
-----------------------------------
dialog:separator {
id="ratios",
text="Ratios"
}

dialog:label {
id="help1",
label="NOTE:",
text="In the following ratios, the first value is the"
}

dialog:newrow()

dialog:label {
id="help2",
text="width, and the second is the height ( W : H )"
}

dialog:button {
id="onetoone",
text="1 : 1",
enabled=false,
onclick=function()
ratio_width = 1
ratio_height = 1
local new_height = adjust_for_ratio(dialog.data.width, ratio_width, ratio_height)
dialog:modify {
id="height",
text=new_height
}

dialog:modify {
id="onetoone",
enabled=false
}

dialog:modify {
id="fourtoseven",
enabled=true
}

dialog:modify {
id="seventoeight",
enabled=true
}

dialog:modify {
id="sixteentonine",
enabled=true
}
end
}

dialog:button {
id="fourtoseven",
text="4 : 7",
onclick=function()
ratio_width = 4
ratio_height = 7
local new_height = adjust_for_ratio(dialog.data.width, ratio_width, ratio_height)
dialog:modify {
id="height",
text=new_height
}

dialog:modify {
id="onetoone",
enabled=true
}

dialog:modify {
id="fourtoseven",
enabled=false
}

dialog:modify {
id="seventoeight",
enabled=true
}

dialog:modify {
id="sixteentonine",
enabled=true
}
end
}

dialog:newrow()

dialog:button {
id="seventoeight",
text="7 : 8",
onclick=function()
ratio_width = 7
ratio_height = 8
local new_height = adjust_for_ratio(dialog.data.width, ratio_width, ratio_height)
dialog:modify {
id="height",
text=new_height
}

dialog:modify {
id="onetoone",
enabled=true
}

dialog:modify {
id="fourtoseven",
enabled=true
}

dialog:modify {
id="seventoeight",
enabled=false
}

dialog:modify {
id="sixteentonine",
enabled=true
}
end
}

dialog:button {
id="sixteentonine",
text="16 : 9",
onclick=function()
ratio_width = 16
ratio_height = 9
local new_height = adjust_for_ratio(dialog.data.width, ratio_width, ratio_height)
dialog:modify {
id="height",
text=new_height
}

dialog:modify {
id="onetoone",
enabled=true
}

dialog:modify {
id="fourtoseven",
enabled=true
}

dialog:modify {
id="seventoeight",
enabled=true
}

dialog:modify {
id="sixteentonine",
enabled=false
}
end
}

-----------------------------------
-- PIXELS
-----------------------------------
dialog:separator {
id="pixels",
text="Size"
}

dialog:number {
id="width",
label="Width:",
decimals=0,
onchange=function()
local new_height = adjust_for_ratio(dialog.data.width, ratio_width, ratio_height)
dialog:modify {
id="height",
text=new_height
}
end
}

dialog:number {
id="height",
label="Height:",
decimals=0,
onchange=function()
local new_width = adjust_for_ratio(dialog.data.height, ratio_height, ratio_width)
dialog:modify {
id="width",
text=new_width
}
end
}

-----------------------------------
-- FINALIZE
-----------------------------------

dialog:separator {
id="footer",
text="Finalize"
}

dialog:button {
id="create",
text="Create New",
onclick=function()
dialog:close()
app.command.NewFile {
ui=true,
width=dialog.data.width,
height=dialog.data.height,
colorMode=ColorMode.RGB,
fromClipboard=false
}
end
}

-----------------------------------
-- ENSURE DEFAULT CANVAS SIZE
-----------------------------------

dialog:modify {
id="width",
text=64
}

dialog:modify {
id="height",
text=64
}

return dialog
end

mainWindow():show{ wait=true }
18 changes: 18 additions & 0 deletions extension/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "new-with-ratios",
"displayName": "New With Ratios",
"description": "Create new sprites with pre-defined ratios",
"version": "1.0",
"author": { "name": "David Fletcher",
"email": "david.login@aol.com",
"url": "https://github.com/david-fletcher" },
"contributors": [ ],
"publisher": "David Fletcher",
"license": "MIT",
"categories": [ "Scripts" ],
"contributes": {
"scripts": [
{ "path": "./plugin.lua" }
]
}
}
54 changes: 54 additions & 0 deletions extension/plugin.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
-- MIT License

-- Copyright (c) 2021 David Fletcher

-- 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.

function init(plugin)
print("Aseprite is initializing New With Ratios")

-----------------------------------
-- PLUGIN COMMANDS
-----------------------------------
-- A plugin command is simply a menu element that, when clicked, runs the function passed to onclick.
-- In this file, we specify menu element definitions, but abstract away their implementations to different Lua scripts.
-- This is done for organizational purposes, and to ease the iterative development of scripts. With this structure,
-- we can develop the script file independently of the plugin definition, using Aseprite's scripting engine
-- to run scripts as we build out our functionality, then wrap the finalized scripts in a plugin.
-----------------------------------
-- We use the parameter to init, plugin, to access the preferences table. This table will be saved on exit and restored
-- upon re-entry, so that you can easily save any user-defined preferences you need to. You will notice that we use
-- loadfile() to create a Lua chunk based on our script, and then pass the preferences table to the script as an argument.
-- The script can modify that table, which will then be saved automagically by Aseprite's API.
-----------------------------------
plugin:newCommand {
id="new-with-ratios",
title="New with Ratio...",
group="file_new",
onclick=function()
local executable = app.fs.joinPath(app.fs.userConfigPath, "extensions", "new-with-ratios", "new-with-ratios.lua")
-- load the lua script into a Lua chunk, then execute it with the parameter plugin.preferences
loadfile(executable)(plugin.preferences)
end
}
end

function exit(plugin)
print("Aseprite is closing YOUR PLUGIN")
end
Binary file added new-with-ratios.aseprite-extension
Binary file not shown.

0 comments on commit c93b64c

Please sign in to comment.