generalize EntrySpriteSystem into PlaygroundSystem which all ui will provide

This commit is contained in:
2022-07-02 19:51:30 +00:00
parent f62b42f06b
commit bcd1eca9a0
13 changed files with 97 additions and 29 deletions

View File

@@ -9,7 +9,7 @@ import nat.Archive;
import nat.ArchiveController;
import nat.BoolExpInterp;
import nat.components.Images;
import nat.components.Positions;
import nat.components.Position;
import nat.components.Scale;
using kiss_flixel.CameraTools;

View File

@@ -2,14 +2,14 @@
(defNew [&prop :EntrySpriteSystem system
&prop :String positionKey
&prop :Position position
&prop :Archive archive
&prop :Entry e
&prop :ArchiveController controller]
[&mut :Bool selected false]
(let [images (readComponent e Images)]
(whenLet [(objectWith x y z) (dictGet (readComponent e Positions) positionKey)]
(super x y))
(super position.x position.y)
(.onComplete (BitmapData.loadFromFile (joinPath archive.archiveDir "files" (nth images.imageFiles images.pinnedImageIndex)))
->bitmapData {
(loadGraphic bitmapData)

View File

@@ -1,7 +1,7 @@
(loadFrom "nat-archive-tool" "src/nat/Lib.kiss")
(method z [:Entry e]
.z (dictGet (readComponent e Positions) spriteSystem.positionKey))
.z (dictGet (readComponent e Positions) (spriteSystem.getPlaygroundKey)))
(method :Array<EntrySprite> collectOverlapping [:EntrySprite s &opt :Array<EntrySprite> overlapping]
(unless overlapping (set overlapping []))
@@ -21,7 +21,7 @@
!(= 0 (z e)))
->[archive e &opt ui]
(let [:Array<EntrySprite> inOrder
~(sortBy
(sortBy
(collectOverlapping (dictGet spriteSystem.sprites e.id))
->s (- (z s.e)))]
// Looping twice avoids having to splice() the group

View File

@@ -5,7 +5,9 @@ import kiss.List;
import nat.System;
import nat.BoolExpInterp;
import nat.ArchiveController;
import nat.ArchiveUI;
import nat.components.Positions;
import nat.systems.PlaygroundSystem;
@:build(kiss.Kiss.build())
class EntrySpriteSystem extends System {}
class EntrySpriteSystem extends PlaygroundSystem {}

View File

@@ -2,21 +2,19 @@
(prop :Map<String,EntrySprite> sprites (new Map))
(defNew [:String tagFilterString
&prop :String positionKey
:PlayState playState
// TODO this can also handle text sprites, and instead of saving out the text bitmap,
// just make the FlxText every time at runtime -- so PinNextImage won't be needed
// when the media tag is added
(defNew [:PlayState playState
&prop :ArchiveController controller]
(super
playState
->[archive e]
?(and (tagsMatch e tagFilterString) (hasComponent e Images))
->[archive e &opt ui]
?(hasComponent e Images)
->[archive e pos &opt ui]
(unless (sprites.exists e.id)
(when !(hasComponent e Positions)
(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))))
(let [sprite (new EntrySprite this positionKey archive e controller)]
(let [sprite (new EntrySprite this _playgroundKey pos archive e controller)]
(playState.entryGroup.add sprite)
(dictSet sprites e.id sprite))))
@@ -29,5 +27,7 @@
(controller.DeSelectEntry e)
}))
// TODO override process to z-sort all sprites after making them
(method getSelectedSprites []
(filter (for e (controller.getSelectedEntries) (dictGet sprites e.id))))

View File

@@ -21,6 +21,7 @@ using StringTools;
using kiss_flixel.CameraTools;
import kiss_tools.KeyShortcutHandler;
import kiss_tools.FlxKeyShortcutHandler;
import nat.systems.PlaygroundSystem;
@:build(kiss.Kiss.build())
class PlayState extends FlxState implements ArchiveUI {}

View File

@@ -2,6 +2,13 @@
// TODO handleChanges() will need to kill every changed Entry's sprite and make a new one
// make interactible sprites for entries that have images
(prop &mut :EntrySpriteSystem spriteSystem)
(method :PlaygroundSystem playgroundSystem []
(set spriteSystem (new EntrySpriteSystem this controller)))
(method &override :Void create []
(super.create)
@@ -91,14 +98,6 @@
// make text-only sprites for entries that have no images:
(archive.addSystem (new TextSpriteSystem))
// 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
(prop &mut :EntrySpriteSystem spriteSystem)
(set spriteSystem (new EntrySpriteSystem "!done" "Playground-MAIN" this controller))
(archive.addSystem spriteSystem)
(prop &mut :EntrySpriteDepthSystem spriteDepthSystem)
(set spriteDepthSystem (new EntrySpriteDepthSystem this spriteSystem))
(archive.addSystem spriteDepthSystem)
@@ -148,7 +147,7 @@
(FlxG.camera.updateScrollWheelZoom elapsed 1)
// Don't check keys that can be used in shortcuts outside this block:
(unless sh.currentMap
(unless (or sh.currentMap (and textInput textInput.hasFocus))
(when FlxG.keys.justPressed.SEMICOLON
(sh.start)
(return))
@@ -156,10 +155,10 @@
(doFor e (controller.getSelectedEntries)
(when FlxG.keys.justPressed.MINUS
(withWritableComponents archive e [positions Positions]
(-= .z (dictGet positions spriteSystem.positionKey) 1)))
(-= .z (dictGet positions (spriteSystem.getPlaygroundKey)) 1)))
(when FlxG.keys.justPressed.PLUS
(withWritableComponents archive e [positions Positions]
(+= .z (dictGet positions spriteSystem.positionKey) 1))))
(+= .z (dictGet positions (spriteSystem.getPlaygroundKey)) 1))))
// don't move the ui camera before ui has been placed -- new UI elements could appear offscreen
(when (> uiGroup.length 0)