Skip to content

Instantly share code, notes, and snippets.

@NoelFB
Created April 22, 2020 17:11
Show Gist options
  • Save NoelFB/0313ee2cbd16705153456bd121218aa5 to your computer and use it in GitHub Desktop.
Save NoelFB/0313ee2cbd16705153456bd121218aa5 to your computer and use it in GitHub Desktop.
creating unique GUIDs for Aseprite files
-- This creates proper GUIDs for Aseprite files so the game can load them.
-- To Use:
-- 1) Open Aseprite and go to File -> Scripts -> Open Scripts Folder and place this file there
-- 2) Restart Aseprite
-- 3) Run this script when you save an Aseprite file and it will automatically create
-- GUIDs for the sprite along with every slice
-- More Info: https://www.aseprite.org/docs/scripting/
local numbers = "0123456789ABCDEF"
local output = {}
local updated = 0
function rndl(n)
local result = ""
for i = 1,n,1 do
local index = math.random(1, 16)
result = result .. numbers:sub(index, index)
end
return result
end
function makeguid()
return rndl(8) .. "-" .. rndl(4) .. "-" .. rndl(4) .. "-" .. rndl(4) .. "-" .. rndl(12)
end
function checkguid(obj, type)
if obj.data:len() < 41 or obj.data:sub(0, 4) ~= "GUID" then
local guid = makeguid()
obj.data = "GUID:" .. guid
obj.color = Color{ r=215, g=123, b=186, a=255 }
table.insert(output, "Set " .. type .. " '" .. obj.name .. "' GUID to '" .. guid .. "'")
updated = updated + 1
end
end
local sprite = app.activeSprite
-- Set a GUID on the Sprite's bottom Layer
checkguid(sprite.layers[1], "Layer")
-- Set a GUID to each Slice
for i,slice in ipairs(sprite.slices) do
checkguid(slice, "Slice")
end
-- Tell the User if any GUIDs were updated
if updated > 0 then
app.alert{ title="Updated " .. updated .. " GUIDs", text=output }
end
-- Save the File
app.command.SaveFile()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment