Make text sprites for entries that don't get WikipediaImage images

This commit is contained in:
2021-09-30 15:04:18 -06:00
parent 4804b121d0
commit 7cdec42351
3 changed files with 43 additions and 2 deletions

View File

@@ -0,0 +1,20 @@
(loadFrom "nat-archive-tool" "src/nat/Lib.kiss")
// Named entries without Images should be given an image generated with the name's text
(defNew []
(super
->[archive e]
?(and !(hasComponent e Images) (hasComponent e Name))
->[archive e]
{
(let [name (readComponent e Name)
sprite (new FlxText 0 0 0 name 16)
bitmapData sprite.pixels
// Source: https://gist.github.com/miltoncandelero/0c452f832fa924bfdd60fe9d507bc581
&mut bytes (new ByteArray)]
(set bytes (bitmapData.encode bitmapData.rect (new PNGEncoderOptions true) bytes))
(let [path (joinPath archive.archiveDir "files" "textImage${name}.png")]
(File.saveBytes path bytes)
(archive.addFiles e [path])))
}))