Make text sprites for entries that don't get WikipediaImage images
This commit is contained in:
@@ -22,6 +22,7 @@
|
|||||||
archive
|
archive
|
||||||
this)))
|
this)))
|
||||||
|
|
||||||
|
|
||||||
(prop &mut :FlxGroup uiGroup (new FlxGroup))
|
(prop &mut :FlxGroup uiGroup (new FlxGroup))
|
||||||
(add uiGroup)
|
(add uiGroup)
|
||||||
|
|
||||||
@@ -34,7 +35,8 @@
|
|||||||
|
|
||||||
(set uiGroup.cameras [uiCamera])
|
(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
|
// make interactible sprites for entries that have images
|
||||||
|
|
||||||
@@ -43,7 +45,7 @@
|
|||||||
(prop &mut :EntrySpriteSystem spriteSystem)
|
(prop &mut :EntrySpriteSystem spriteSystem)
|
||||||
(set spriteSystem (new EntrySpriteSystem "!done" "Playground-MAIN" this controller))
|
(set spriteSystem (new EntrySpriteSystem "!done" "Playground-MAIN" this controller))
|
||||||
(archive.addSystem spriteSystem)
|
(archive.addSystem spriteSystem)
|
||||||
(spriteSystem.process archive))
|
(archive.processSystems))
|
||||||
|
|
||||||
(method &override :Void update [:Float elapsed]
|
(method &override :Void update [:Float elapsed]
|
||||||
(super.update elapsed)
|
(super.update elapsed)
|
||||||
@@ -167,6 +169,8 @@
|
|||||||
|
|
||||||
(method handleChanges [:Archive archive :ChangeSet changeSet]
|
(method handleChanges [:Archive archive :ChangeSet changeSet]
|
||||||
(doFor e 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
|
// Entries whose data changed to remove them from the sprite pool will already have been removed
|
||||||
// by refreshEntry()
|
// by refreshEntry()
|
||||||
(when (spriteSystem.entries.exists e.id)
|
(when (spriteSystem.entries.exists e.id)
|
||||||
|
@@ -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 {}
|
@@ -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])))
|
||||||
|
}))
|
Reference in New Issue
Block a user