generalize EntrySpriteSystem into PlaygroundSystem which all ui will provide

This commit is contained in:
2022-07-02 19:51:30 +00:00
parent 54799d8450
commit bfbf052ab8
6 changed files with 67 additions and 1 deletions

View File

@@ -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))

View File

@@ -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
*/

View File

@@ -0,0 +1,3 @@
package nat.components;
typedef Position = {x:Float, y:Float, z:Float};

View File

@@ -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>;

View File

@@ -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 {}

View File

@@ -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))