From 25d1031c88b998ff43bd7b84dabf4891e71253b0 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Fri, 17 Sep 2021 23:13:28 -0600 Subject: [PATCH] Image attachment tracking system, adjustable pins --- .../src/nat/ArchiveController.kiss | 17 ++++++++++++++++- .../src/nat/components/Images.hx | 6 ++++++ .../src/nat/systems/ImageAttachmentSystem.hx | 7 +++++++ .../src/nat/systems/ImageAttachmentSystem.kiss | 12 ++++++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 projects/nat-archive-tool/src/nat/components/Images.hx create mode 100644 projects/nat-archive-tool/src/nat/systems/ImageAttachmentSystem.hx create mode 100644 projects/nat-archive-tool/src/nat/systems/ImageAttachmentSystem.kiss diff --git a/projects/nat-archive-tool/src/nat/ArchiveController.kiss b/projects/nat-archive-tool/src/nat/ArchiveController.kiss index 9bd3a92c..6cecdbb9 100644 --- a/projects/nat-archive-tool/src/nat/ArchiveController.kiss +++ b/projects/nat-archive-tool/src/nat/ArchiveController.kiss @@ -152,6 +152,7 @@ // Add systems! (archive.addSystem nameSystem) (archive.addSystem (new WikipediaImageSystem)) + (archive.addSystem (new ImageAttachmentSystem)) // Just for testing: // (archive.addSystem (new AttachmentSystem ["jpg" "jpeg" "png"] ->[archive e files] ~files)) @@ -215,6 +216,20 @@ (doFor e entries (addFiles archive e files)) entries) - + + (method adjustImagePins [:Array entries increment] + (doFor e entries + (if (hasComponent e Images) + (withWritableComponents archive e [images Images] + (set images.pinnedImageIndex (max 0 (min images.imageFiles.length (+ increment images.pinnedImageIndex))))) + (ui.reportError "Entry $e has no Images component"))) + entries) + + (defCommand PinNextImage [entries (SelectedEntries 1 null)] + (adjustImagePins entries 1)) + + (defCommand PinPreviousImage [entries (SelectedEntries 1 null)] + (adjustImagePins entries -1)) + (defCommand SelectByName [name (Text null)] (SelectEntries (nameSystem.getEntries name)) [])) diff --git a/projects/nat-archive-tool/src/nat/components/Images.hx b/projects/nat-archive-tool/src/nat/components/Images.hx new file mode 100644 index 00000000..58ee3621 --- /dev/null +++ b/projects/nat-archive-tool/src/nat/components/Images.hx @@ -0,0 +1,6 @@ +package nat.components; + +typedef Images = { + imageFiles:Array, + pinnedImageIndex:Int +}; diff --git a/projects/nat-archive-tool/src/nat/systems/ImageAttachmentSystem.hx b/projects/nat-archive-tool/src/nat/systems/ImageAttachmentSystem.hx new file mode 100644 index 00000000..31f29602 --- /dev/null +++ b/projects/nat-archive-tool/src/nat/systems/ImageAttachmentSystem.hx @@ -0,0 +1,7 @@ +package nat.systems; + +import kiss.Prelude; +import kiss.List; + +@:build(kiss.Kiss.build()) +class ImageAttachmentSystem extends AttachmentSystem {} diff --git a/projects/nat-archive-tool/src/nat/systems/ImageAttachmentSystem.kiss b/projects/nat-archive-tool/src/nat/systems/ImageAttachmentSystem.kiss new file mode 100644 index 00000000..6a3ad21c --- /dev/null +++ b/projects/nat-archive-tool/src/nat/systems/ImageAttachmentSystem.kiss @@ -0,0 +1,12 @@ +(load "../Lib.kiss") + +(defNew [] + (super + ["jpg" "jpeg" "png"] + ->[archive e imageFiles] + (unless (hasComponent e Images) + (withWritableEntry archive e + (addComponent archive e Images + (object + imageFiles imageFiles + pinnedImageIndex 0)))))) \ No newline at end of file