mirror of
https://github.com/smogon/sprites.git
synced 2026-08-17 23:08:35 -05:00
add filter, spriteglob()
This commit is contained in:
17
Tupfile.lua
17
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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user