Exactly as @Olga_Galvanova mentioned, packaging your script into a plugin and using plugin.preferences
is your best choice in this case.
I’d advise against implementing your own system for saving settings to a file, as I can tell you from experience that it’s very likely not worth the hassle. On top of that, in my opinion, asking a user to give file access to a script is a lot, especially when you don’t really need to do that.
plugin.preferences
is very handy to use as long as you stick to basic types - numbers, strings, tables. Any Aseprite-specific types like Point
, Rectangle
or Color
will not be correctly serialized and deserialized and you’ll just lose this data.
plugin.preferences
is persisted between sessions which means it will be kept after you reopen Aseprite, if you’d like to just keep these values in memory for a single session instead you can save data in a Lua table instead.
function init(plugin)
local data = {
tileWidth = 32,
tileHeight = 32,
marginWidth = 8,
marginHeight = 8
}
plugin:newCommand{
id = "TrimSheetBuilder",
title = "Trim Sheet Builder",
group = "cel_popup_properties",
onclick = function()
local dlg = Dialog("Trim Sheet Builder")
dlg:number{
id = "tileWidth",
label = "Tile Width",
text = tostring(data.tileWidth),
onchange = function()
data.tileWidth = dlg.data.tileWidth
end
}
dlg:number{
id = "tileHeight",
label = "Tile Height",
text = tostring(data.tileHeight),
onchange = function()
data.tileHeight = dlg.data.tileHeight
end
}
dlg:number{
id = "marginWidth",
label = "Margin Width",
text = tostring(data.marginWidth),
onchange = function()
data.marginWidth = dlg.data.marginWidth
end
}
dlg:number{
id = "marginHeight",
label = "Margin Height",
text = tostring(data.marginHeight),
onchange = function()
data.marginHeight = dlg.data.marginHeight
end
}
dlg:button{id = "ok", text = "Ok"}
dlg:button{id = "cancel", text = "Cancel"}
dlg:show()
end
}
end
function exit(plugin)
-- You don't really need to do anything specific here
end