add filter, spriteglob()

This commit is contained in:
Christopher Monsanto
2020-05-26 16:29:15 -04:00
parent dcd76c548c
commit 41e4f99c7e
3 changed files with 41 additions and 12 deletions

View File

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

View File

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

View File

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