diff --git a/Tupfile.lua b/Tupfile.lua index 4bc29ef8..faca33a4 100644 --- a/Tupfile.lua +++ b/Tupfile.lua @@ -64,3 +64,34 @@ local files = fbsprite(files, "build/smogon/fbsprites/xy/%B.png") twittersprite(files, "build/smogon/twittersprites/xy/%B.png") +-- Trainers + +function padtrainer(input, output) + return "convert " .. input .. " -background transparent -gravity center -extent 80x80 " .. output +end + +-- TODO: move some of these to util, when we figure out the precise abstractions desired + +function compresspng(filename, opts) + local cmds = {} + if opts.optipng then + cmds += "optipng -q " .. opts.optipng .. " " .. filename + end + if opts.advpng then + cmds += "advpng -q " .. opts.advpng .. " " .. filename + end + return cmds +end + +function makecmd(cmds) + return table.concat(flatten(cmds), " && ") +end + +tup.foreach_rule( + {"src/canonical/trainers/*"}, + "^ pad trainer %f^ " .. makecmd{padtrainer("%f", "%o"), compresspng("%f", {})}, + {"build/padded-trainers/canonical/%b"} +) + + + diff --git a/util/lua-ext.lua b/util/lua-ext.lua index 8668a4ca..f6d25a43 100644 --- a/util/lua-ext.lua +++ b/util/lua-ext.lua @@ -19,3 +19,21 @@ function astable(table) return {} end end + +-- Adapted from premake +function flatten(arr) + local result = { } + + local function flatten(arr) + for v in iter(arr) do + if type(v) == "table" then + flatten(v) + else + table.insert(result, v) + end + end + end + + flatten(arr) + return result +end