From 1e44f1db110ae94b3abd309f059b0a068236ce21 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Sat, 18 Sep 2021 18:33:44 -0600 Subject: [PATCH] fix C++ type error for playground --- projects/nat-archive-tool/src/nat/Archive.kiss | 6 ++++-- projects/nat-archive-tool/src/nat/System.kiss | 6 +++++- .../source/EntrySpriteSystem.kiss | 15 +++++++++++++-- .../nat-flixel-playground/source/PlayState.kiss | 17 ++++++++++------- 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/projects/nat-archive-tool/src/nat/Archive.kiss b/projects/nat-archive-tool/src/nat/Archive.kiss index 766f8337..8326b504 100644 --- a/projects/nat-archive-tool/src/nat/Archive.kiss +++ b/projects/nat-archive-tool/src/nat/Archive.kiss @@ -29,8 +29,10 @@ (refreshEntry e) e)) -// After modifying an entry, this must be called. If you are writing in a createEntry initializer or a system's processEntry function, this will happen automatically. -// Otherwise, you can guarantee it happens automatically by using the (withWritableEntry) macro in Lib.kiss +// After modifying an entry, this must be called. If you are writing in a createEntry +// initializer or a system's processEntry function, this will happen automatically. +// Otherwise, you can guarantee it happens automatically by using the (withWritableEntry) +// and (withWritableComponents) macros in Lib.kiss (method refreshEntry [:Entry e] (_saveEntry e) (doFor system systems diff --git a/projects/nat-archive-tool/src/nat/System.kiss b/projects/nat-archive-tool/src/nat/System.kiss index 7f2bd3a9..3577251e 100644 --- a/projects/nat-archive-tool/src/nat/System.kiss +++ b/projects/nat-archive-tool/src/nat/System.kiss @@ -9,9 +9,13 @@ &prop :EntryProcessor processEntry] []) +(prop &mut :Null onRemoveEntry) + (method :Void checkEntryInOrOut [:Archive archive :Entry e] (if (canProcessEntry archive e) (dictSet entries e.id e) - (entries.remove e.id))) + (when (entries.exists e.id) + (entries.remove e.id) + (when onRemoveEntry (onRemoveEntry archive e))))) // TODO systems may need access to a UI diff --git a/projects/nat-flixel-playground/source/EntrySpriteSystem.kiss b/projects/nat-flixel-playground/source/EntrySpriteSystem.kiss index f3b6a73d..fd85de79 100644 --- a/projects/nat-flixel-playground/source/EntrySpriteSystem.kiss +++ b/projects/nat-flixel-playground/source/EntrySpriteSystem.kiss @@ -1,9 +1,11 @@ (loadFrom "nat-archive-tool" "src/nat/Lib.kiss") +(prop :Map sprites (new Map)) + (defNew [:String tagFilterString :String positionKey :PlayState playState] (super ->[archive e] - (and (tagsMatch archive e tagFilterString) (hasComponent e Images)) + ?(and (tagsMatch archive e tagFilterString) (hasComponent e Images)) ->[archive e] { (when !(hasComponent e Positions) @@ -12,5 +14,14 @@ (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)) + (let [sprite (new EntrySprite positionKey archive e)] + (playState.entryGroup.add sprite) + (dictSet sprites e.id sprite)) + }) + + (set onRemoveEntry + ->[archive e] + { + (.kill (dictGet sprites e.id)) + (sprites.remove e.id) })) \ No newline at end of file diff --git a/projects/nat-flixel-playground/source/PlayState.kiss b/projects/nat-flixel-playground/source/PlayState.kiss index 28742647..5dca9193 100644 --- a/projects/nat-flixel-playground/source/PlayState.kiss +++ b/projects/nat-flixel-playground/source/PlayState.kiss @@ -38,11 +38,10 @@ // 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)) - - ) + (prop &mut :EntrySpriteSystem spriteSystem) + (set spriteSystem (new EntrySpriteSystem "!done" "Playground-MAIN" this)) + (archive.addSystem spriteSystem) + (spriteSystem.process archive)) (method &override :Void update [:Float elapsed] (super.update elapsed) @@ -153,9 +152,13 @@ (method handleChanges [:Archive archive :ChangeSet changeSet] - // TODO refresh the sprites/other UI elements for entries that changed data (doFor e changeSet - (print (archive.fullString e)))) + // refresh the sprites for entries that changed data. + // Entries whose data changed to remove them from the sprite pool will already have been removed + // by refreshEntry() + (when (spriteSystem.entries.exists e.id) + (spriteSystem.onRemoveEntry e) + (spriteSystem.processEntry e)))) (prop &mut :Int uiY 0)