generalize EntrySpriteSystem into PlaygroundSystem which all ui will provide
This commit is contained in:
@@ -162,6 +162,10 @@
|
||||
(archive.addSystem (new ImageAttachmentSystem))
|
||||
(archive.addSystem (new KeyShortcutSystem this))
|
||||
(archive.addSystem (new DLSystem))
|
||||
(whenLet [ps (ui.playgroundSystem)]
|
||||
(archive.addSystem ps)
|
||||
// TODO allow saving a different default playground
|
||||
(ps.switchPlaygroundKey "Playground-MAIN"))
|
||||
|
||||
// Just for testing:
|
||||
// (archive.addSystem (new AttachmentSystem ["jpg" "jpeg" "png"] ->[archive e files] ~files))
|
||||
|
@@ -3,6 +3,7 @@ package nat;
|
||||
import nat.Entry;
|
||||
import nat.ArchiveController;
|
||||
import kiss_tools.KeyShortcutHandler;
|
||||
import nat.systems.PlaygroundSystem;
|
||||
|
||||
interface ArchiveUI {
|
||||
/**
|
||||
@@ -15,6 +16,11 @@ interface ArchiveUI {
|
||||
*/
|
||||
var shortcutHandler(default, null):Null<KeyShortcutHandler<Entry>>;
|
||||
|
||||
/**
|
||||
* A PlaygroundSystem that will display interactible entry representations
|
||||
*/
|
||||
function playgroundSystem():Null<PlaygroundSystem>;
|
||||
|
||||
/**
|
||||
* Prompt the user to enter text
|
||||
*/
|
||||
|
3
projects/nat-archive-tool/src/nat/components/Position.hx
Normal file
3
projects/nat-archive-tool/src/nat/components/Position.hx
Normal file
@@ -0,0 +1,3 @@
|
||||
package nat.components;
|
||||
|
||||
typedef Position = {x:Float, y:Float, z:Float};
|
@@ -1,6 +1,7 @@
|
||||
package nat.components;
|
||||
|
||||
|
||||
/**
|
||||
* Entries can have multiple positions in different UIs/folders/whatever.
|
||||
*/
|
||||
typedef Positions = Map<String, {x:Float, y:Float, z:Float}>;
|
||||
typedef Positions = Map<String, Position>;
|
||||
|
@@ -0,0 +1,15 @@
|
||||
package nat.systems;
|
||||
|
||||
import kiss.Prelude;
|
||||
import kiss.List;
|
||||
import nat.System;
|
||||
import nat.components.Position;
|
||||
|
||||
typedef PlaygroundEntryProcessor = (Archive, Entry, Position, ?ArchiveUI) -> Dynamic; // Whatever value is returned will be dropped, but this is easier than requiring ->:Void
|
||||
|
||||
/**
|
||||
* Base class for Systems that process Entries in a playground view and displays them in an interactive form
|
||||
* (EntrySpriteSystem, for example)
|
||||
*/
|
||||
@:build(kiss.Kiss.build())
|
||||
class PlaygroundSystem extends System {}
|
@@ -0,0 +1,37 @@
|
||||
(load "../Lib.kiss")
|
||||
|
||||
(prop &mut :String _playgroundKey "")
|
||||
(method :String getPlaygroundKey [] _playgroundKey)
|
||||
|
||||
(defNew [&prop :ArchiveUI ui
|
||||
:EntryChecker canProcess
|
||||
&prop :PlaygroundEntryProcessor processor]
|
||||
|
||||
(super
|
||||
->[archive e]
|
||||
(and (tagsMatch e "!(or done hidden)") (canProcess archive e))
|
||||
->[archive e &opt ui]
|
||||
{
|
||||
(when !(hasComponent e Positions)
|
||||
(addComponent archive e Positions (new Map)))
|
||||
(withWritableComponents archive e [positions Positions]
|
||||
(when !(positions.exists _playgroundKey)
|
||||
// TODO do a playground check before giving a default position.
|
||||
(dictSet positions _playgroundKey (defaultPosition e))))
|
||||
(let [pos (dictGet (readComponent e Positions) _playgroundKey)]
|
||||
(processor archive e pos ui))
|
||||
}))
|
||||
|
||||
(method switchPlaygroundKey [key]
|
||||
(when _playgroundKey
|
||||
(clear))
|
||||
(set _playgroundKey key)
|
||||
(process ui.controller.archive ui))
|
||||
|
||||
(method clear [])
|
||||
|
||||
(method &override :Void process [:Archive archive &opt :ArchiveUI ui]
|
||||
(when _playgroundKey (super.process archive ui)))
|
||||
|
||||
(method defaultPosition [:Entry e]
|
||||
(object x 0.0 y 0.0 z 0.0))
|
@@ -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;
|
||||
|
||||
|
@@ -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)
|
||||
|
@@ -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
|
||||
|
@@ -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 {}
|
||||
|
@@ -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))))
|
@@ -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 {}
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user