From 420d8da4142ab449cbc8e5a1043535dc31b4c25d Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Thu, 30 Sep 2021 17:05:21 -0600 Subject: [PATCH] Allow Playground to download images and create text sprites at runtime --- projects/nat-archive-tool/src/nat/Lib.kiss | 5 +++++ .../src/nat/systems/WikipediaImageSystem.kiss | 3 +++ projects/nat-flixel-desktop-playground/source/PlayState.kiss | 2 ++ 3 files changed, 10 insertions(+) diff --git a/projects/nat-archive-tool/src/nat/Lib.kiss b/projects/nat-archive-tool/src/nat/Lib.kiss index 2bcd3a84..fe76a2e4 100644 --- a/projects/nat-archive-tool/src/nat/Lib.kiss +++ b/projects/nat-archive-tool/src/nat/Lib.kiss @@ -20,6 +20,11 @@ (print (+ "adding " (the nat.components ,componentType ,c) " as " ,(symbolName componentType) " for " .id ,e)) (dictSet .components ,e ,(symbolName componentType) (tink.Json.stringify (the nat.components ,componentType ,c))))) +(defMacro removeComponent [archive e componentType] + `(withWritableEntry ,archive ,e + (print (+ "removing " ,(symbolName componentType) " component from " .id ,e)) + (.remove .components ,e ,(symbolName componentType)))) + // Retrieve multiple components from an Entity with mutable access. // All components will be serialized after the block is done. (defMacro withWritableComponents [archive e bindings &body body] diff --git a/projects/nat-archive-tool/src/nat/systems/WikipediaImageSystem.kiss b/projects/nat-archive-tool/src/nat/systems/WikipediaImageSystem.kiss index e4f3708e..19f7dac4 100644 --- a/projects/nat-archive-tool/src/nat/systems/WikipediaImageSystem.kiss +++ b/projects/nat-archive-tool/src/nat/systems/WikipediaImageSystem.kiss @@ -21,7 +21,10 @@ (.urlDecode (url.withoutDirectory)) // Some symbols shouldn't be decoded because they're invalid in file systems! "\"" "%22"))] + // TODO do this with ui.displayMessage (print url "downloading") (assertProcess "curl" ["--output" filePath url]) filePath))) + // Trigger the creation of a new Images component including the wikipedia images + (removeComponent archive e Images) (addTags archive e ["wikipediaProcessed"]))) diff --git a/projects/nat-flixel-desktop-playground/source/PlayState.kiss b/projects/nat-flixel-desktop-playground/source/PlayState.kiss index 32042fc7..b7291ec3 100644 --- a/projects/nat-flixel-desktop-playground/source/PlayState.kiss +++ b/projects/nat-flixel-desktop-playground/source/PlayState.kiss @@ -171,6 +171,8 @@ (doFor e changeSet // process the WikipediaImageSystem and run spriteSystem process on newly created entries that get one (archive.processSystems) + // Do a second loop through the systems, so Playground systems that trigger Core systems have their effects processed + (archive.processSystems) // Entries whose data changed to remove them from the sprite pool will already have been removed // by refreshEntry()