User-configurable compression settings

This commit is contained in:
Christopher Monsanto 2020-05-01 02:59:41 -04:00
parent eb5bde52dd
commit f8bc65549d
3 changed files with 22 additions and 9 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@ build/
.tup
node_modules
pnpm-debug.log
tup.config

View File

@ -57,7 +57,8 @@ twittersprite(files, "build/smogon/twittersprites/xy/%B.png")
tup.foreach_rule(
{"src/canonical/trainers/*"},
"^ pad trainer %f^ " .. makecmd{pad(80, 80, "%f", "%o"), compresspng("%f", {})},
"^ pad trainer %f^ " .. makecmd{pad(80, 80, "%f", "%o"),
compresspng{config="TRAINERS"}},
{"build/padded-trainers/canonical/%b"}
)
@ -66,7 +67,8 @@ tup.foreach_rule(
for dir in iter{"front", "front-cosmetic", "front-shiny", "front-shiny-cosmetic"} do
tup.foreach_rule(
rep{"src/canonical/dex/{dir}/*", dir=dir},
"^ pad dex %f^ " .. makecmd{pad(120, 120, "%f", "%o"), compresspng("%f", {})},
"^ pad dex %f^ " .. makecmd{pad(120, 120, "%f", "%o"),
compresspng{config="DEX"}},
rep{"build/padded-dex/canonical/{dir}/%b", dir=dir}
)
end

View File

@ -13,15 +13,25 @@ function pad(w, h, input, output)
}
end
function compresspng(filename, opts)
local DEFAULT_OPTIPNG = getconfig("DEFAULT_OPTIPNG")
local DEFAULT_ADVPNG = getconfig("DEFAULT_ADVPNG")
function compresspng(opts)
local cmds = {}
if opts.optipng then
cmds += rep{"optipng -q {opts} {filename}", opts=opts.optipng, filename=filename}
local output = opts.output or "%o"
local optipng = DEFAULT_OPTIPNG
if opts.config then
optipng = getconfig(opts.config .. "_OPTIPNG") or optipng;
end
if opts.advpng then
cmds += rep{"advpng -q {opts} {filename}", opts=opts.advpng, filename=filename}
local advpng = DEFAULT_ADVPNG
if opts.config then
advpng = getconfig(opts.config .. "_ADVPNG") or advpng;
end
if optipng then
cmds += rep{"optipng -q {opts} {output}", opts=optipng, output=output}
end
if advpng then
cmds += rep{"advpng -q {opts} {output}", opts=advpng, output=output}
end
return cmds
end