Image attachment tracking system, adjustable pins

This commit is contained in:
2021-09-17 23:13:28 -06:00
parent 61885f4bba
commit 25d1031c88
4 changed files with 41 additions and 1 deletions

View File

@@ -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<Entry> 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)) []))

View File

@@ -0,0 +1,6 @@
package nat.components;
typedef Images = {
imageFiles:Array<FileRef>,
pinnedImageIndex:Int
};

View File

@@ -0,0 +1,7 @@
package nat.systems;
import kiss.Prelude;
import kiss.List;
@:build(kiss.Kiss.build())
class ImageAttachmentSystem extends AttachmentSystem {}

View File

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