Make sprites for NAT entries with images

This commit is contained in:
2021-09-18 16:42:28 -06:00
parent 547dad9e66
commit b8372420f0
6 changed files with 83 additions and 4 deletions

View File

@@ -0,0 +1,6 @@
package nat.components;
/**
* Entries can have multiple positions in different UIs/folders/whatever.
*/
typedef Positions = Map<String, {x:Float, y:Float, z:Float}>;

View File

@@ -0,0 +1,14 @@
package;
import kiss.Prelude;
import kiss.List;
import flash.display.BitmapData;
import flixel.FlxSprite;
import nat.Entry;
import nat.Archive;
import nat.BoolExpInterp;
import nat.components.Images;
import nat.components.Positions;
@:build(kiss.Kiss.build())
class EntrySprite extends FlxSprite {}

View File

@@ -0,0 +1,11 @@
(loadFrom "nat-archive-tool" "src/nat/Lib.kiss")
(defNew [:String positionKey
&prop :Archive archive
&prop :Entry e]
(let [images (readComponent archive e Images)]
(case (dictGet (readComponent archive e Positions) positionKey)
((object x x y y z z)
(super x y)))
(.onComplete (BitmapData.loadFromFile (joinPath archive.archiveDir "files" (nth images.imageFiles images.pinnedImageIndex)))
->bitmapData (loadGraphic bitmapData))))

View File

@@ -0,0 +1,10 @@
package;
import kiss.Prelude;
import kiss.List;
import nat.System;
import nat.BoolExpInterp;
import nat.components.Positions;
@:build(kiss.Kiss.build())
class EntrySpriteSystem extends System {}

View File

@@ -0,0 +1,16 @@
(loadFrom "nat-archive-tool" "src/nat/Lib.kiss")
(defNew [:String tagFilterString :String positionKey :PlayState playState]
(super
->[archive e]
(and (tagsMatch archive e tagFilterString) (hasComponent e Images))
->[archive e]
{
(when !(hasComponent e Positions)
(withWritableEntry archive e
(addComponent archive e Positions (new Map))))
(withWritableComponents archive e [positions Positions]
(when !(positions.exists positionKey)
(dictSet positions positionKey (object x 0.0 y 0.0 z 0.0))))
(playState.entryGroup.add (new EntrySprite positionKey archive e))
}))

View File

@@ -1,16 +1,28 @@
(loadFrom "nat-archive-tool" "src/nat/Lib.kiss")
// TODO store a map of Entry IDs -> EntrySprites.
// TODO handleChanges() will need to kill every changed Entry's sprite and make a new one
// TODO make the EntrySprite constructor assign the entry a serialized position component
// maybe by writing a Map<String, Point> positions component so there can be multiple?
(method &override :Void create []
(super.create)
// TODO find a better way to pass the archiveDir to a HaxeFlixel game
(let [archiveDir (or (Sys.getEnv "NAT_DIR") (throw "NAT_DIR environment variable must be set"))]
(let [archiveDir
(or (Sys.getEnv "NAT_DIR") (throw "NAT_DIR environment variable must be set"))
archive
(new Archive archiveDir)]
(set this.archive archive)
(new ArchiveController
(new Archive archiveDir)
archive
this))
(prop &mut :FlxGroup uiGroup (new FlxGroup))
(add uiGroup)
(prop :FlxGroup entryGroup (new FlxGroup))
(add entryGroup)
(prop uiCamera (new FlxCamera 0 0 FlxG.width FlxG.height))
(set uiCamera.bgColor FlxColor.TRANSPARENT)
(FlxG.cameras.add uiCamera false)
@@ -18,7 +30,15 @@
(set uiGroup.cameras [uiCamera])
// TODO make a button that can be clicked to run typeCommand()
// TODO make sprites for entries that have images
// make interactible sprites for entries that have images
// TODO allow configuring the tags at runtime and erasing/re-creating sprites later
// TODO allow using other position keys and erasing/re-creating sprites later
(let [entrySpriteSystem (new EntrySpriteSystem "!done" "Playground-MAIN" this)]
(archive.addSystem entrySpriteSystem)
(entrySpriteSystem.process archive))
)
(method &override :Void update [:Float elapsed]
@@ -75,8 +95,10 @@
Math.POSITIVE_INFINITY))
(prop &mut :ArchiveController controller)
(prop &mut :Archive archive)
(method :Void setController [controller] (set this.controller controller))
(method :Void setController [controller]
(set this.controller controller))
(prop &mut :FlxText textInputLabel null)
(prop &mut :FlxInputText textInput null)