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

@@ -22,6 +22,7 @@
archive
this)))
(prop &mut :FlxGroup uiGroup (new FlxGroup))
(add uiGroup)
@@ -34,7 +35,8 @@
(set uiGroup.cameras [uiCamera])
// TODO make a button that can be clicked to run typeCommand()
// make text-only sprites for entries that have no images:
(archive.addSystem (new TextSpriteSystem))
// make interactible sprites for entries that have images
@@ -43,7 +45,7 @@
(prop &mut :EntrySpriteSystem spriteSystem)
(set spriteSystem (new EntrySpriteSystem "!done" "Playground-MAIN" this controller))
(archive.addSystem spriteSystem)
(spriteSystem.process archive))
(archive.processSystems))
(method &override :Void update [:Float elapsed]
(super.update elapsed)
@@ -167,6 +169,8 @@
(method handleChanges [:Archive archive :ChangeSet changeSet]
(doFor e changeSet
// TODO process the WikipediaImageSystem and run spriteSystem process on newly created entries that get one
// Entries whose data changed to remove them from the sprite pool will already have been removed
// by refreshEntry()
(when (spriteSystem.entries.exists e.id)

View File

@@ -0,0 +1,17 @@
package;
import kiss.Prelude;
import kiss.List;
import nat.System;
import nat.BoolExpInterp;
import nat.ArchiveController;
import nat.components.Positions;
import flash.display.PNGEncoderOptions;
import flash.utils.ByteArray;
import flixel.text.FlxText;
import sys.io.File;
using nat.Lib;
@:build(kiss.Kiss.build())
class TextSpriteSystem extends System {}

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])))
}))