diff --git a/Tupfile.lua b/Tupfile.lua index ae0b23d4..97efee28 100644 --- a/Tupfile.lua +++ b/Tupfile.lua @@ -63,15 +63,7 @@ rule( -- Smogdex social images -local input = {} -for file in iter(glob{"newsrc/models/*"}) do - local sd = spritedata(tup.base(file)) - if sd.data.b or sd.data.s then - goto continue - end - input += file - ::continue:: -end +local input = spriteglob("newsrc/models/*", {b = false, s = false}) foreach_rule( input, @@ -128,10 +120,11 @@ for file in iter(dexOutput) do end local dexMissing = {} -for file in iter(glob{"newsrc/sprites/gen5/*.gif", "newsrc/models/*.gif"}) do +for file in iter(spriteglob( + {"newsrc/sprites/gen5/*.gif", "newsrc/models/*.gif"}, + {b = false, s = false})) do local base = tup.base(file) - local sd = spritedata(base) - if sd.data.b or sd.data.s or dexSet[base] then + if dexSet[base] then goto continue end dexMissing += file diff --git a/util/lua-ext.lua b/util/lua-ext.lua index dead628b..808a06ac 100644 --- a/util/lua-ext.lua +++ b/util/lua-ext.lua @@ -64,3 +64,23 @@ function flatten(arr) flatten(arr) return result end + +-- Adapted from https://stackoverflow.com/a/53038524 +function filter(t, fn) + local j, n = 1, #t + + for i=1,n do + if fn(t[i]) then + -- Move i's kept value to j's position, if it's not already there. + if (i ~= j) then + t[j] = t[i] + t[i] = nil + end + j = j + 1 -- Increment position of where we'll place the next kept value. + else + t[i] = nil + end + end + + return t +end diff --git a/util/sprites.lua b/util/sprites.lua index d18b6d45..6a036a11 100644 --- a/util/sprites.lua +++ b/util/sprites.lua @@ -13,3 +13,19 @@ function spritedata(basename) end return result end + +function spriteglob(pat, flagspec) + local results = glob(pat) + local function fn(filename) + local sd = spritedata(tup.base(filename)) + for k, v in pairs(flagspec) do + -- Make sure both are booleans + if not not v ~= not not sd.data[k] then + return false + end + end + return true + end + filter(results, fn) + return results +end