Last active
August 25, 2016 18:42
-
-
Save personalnadir/cfe6105837986291ba65 to your computer and use it in GitHub Desktop.
Manages the multiple image sheets and sheet config files generated by TexturePacker's multipack mode. Returns a function that fetches sheet and frameIndex for specified image name.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local M={} | |
multipackmanager=M | |
local require=require | |
local assert=assert | |
local pairs=pairs | |
local graphics=graphics | |
local pcall=pcall | |
setfenv(1,M) | |
function init(infodir,sheetdir,infoPrefix,imgPrefix) | |
local infos={} | |
local images={} | |
local sheets={} | |
if not sheetdir:find("/$") then | |
sheetdir=sheetdir.."/" | |
end | |
local function load() | |
local fileIndex=#infos | |
local m=require (infodir .."."..infoPrefix..fileIndex) | |
assert(m) | |
local id=fileIndex+1 | |
infos[id]=m | |
sheets[id]=graphics.newImageSheet(sheetdir..""..imgPrefix..fileIndex..".png",m:getSheet()) | |
for k,v in pairs(m.frameIndex) do | |
assert(not images[k]) | |
images[k]=id | |
end | |
end | |
while pcall(load) do | |
end | |
return function(img) | |
local id=images[img] | |
assert(id) | |
return sheets[id],infos[id]:getFrameIndex(img) | |
end | |
end | |
return M |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment