Make sprites for NAT entries with images
This commit is contained in:
@@ -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}>;
|
14
projects/nat-flixel-playground/source/EntrySprite.hx
Normal file
14
projects/nat-flixel-playground/source/EntrySprite.hx
Normal 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 {}
|
11
projects/nat-flixel-playground/source/EntrySprite.kiss
Normal file
11
projects/nat-flixel-playground/source/EntrySprite.kiss
Normal 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))))
|
10
projects/nat-flixel-playground/source/EntrySpriteSystem.hx
Normal file
10
projects/nat-flixel-playground/source/EntrySpriteSystem.hx
Normal 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 {}
|
16
projects/nat-flixel-playground/source/EntrySpriteSystem.kiss
Normal file
16
projects/nat-flixel-playground/source/EntrySpriteSystem.kiss
Normal 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))
|
||||
}))
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user