pass a UI to NAT entryProcessors
This commit is contained in:
@@ -24,8 +24,8 @@
|
|||||||
(systems.push system)
|
(systems.push system)
|
||||||
system)
|
system)
|
||||||
|
|
||||||
(method processSystems []
|
(method processSystems [&opt :ArchiveUI ui]
|
||||||
(doFor system systems (system.process this)))
|
(doFor system systems (system.process this ui)))
|
||||||
|
|
||||||
(method :Entry createEntry [:Entry->Dynamic initializer] // initializer returns Dynamic so ->:Void isn't required
|
(method :Entry createEntry [:Entry->Dynamic initializer] // initializer returns Dynamic so ->:Void isn't required
|
||||||
(let [e (_newEntry)]
|
(let [e (_newEntry)]
|
||||||
|
@@ -80,7 +80,7 @@
|
|||||||
|
|
||||||
|
|
||||||
(method handleChanges [:Archive archive :ChangeSet changeSet]
|
(method handleChanges [:Archive archive :ChangeSet changeSet]
|
||||||
(archive.processSystems)
|
(archive.processSystems this)
|
||||||
(doFor e changeSet
|
(doFor e changeSet
|
||||||
(print (archive.fullString e))))
|
(print (archive.fullString e))))
|
||||||
|
|
||||||
|
@@ -3,7 +3,7 @@ package nat;
|
|||||||
import kiss.Prelude;
|
import kiss.Prelude;
|
||||||
|
|
||||||
typedef EntryChecker = (Archive, Entry) -> Bool;
|
typedef EntryChecker = (Archive, Entry) -> Bool;
|
||||||
typedef EntryProcessor = (Archive, Entry) -> Dynamic; // Whatever value is returned will be dropped, but this is easier than requiring ->:Void
|
typedef EntryProcessor = (Archive, Entry, ?ArchiveUI) -> Dynamic; // Whatever value is returned will be dropped, but this is easier than requiring ->:Void
|
||||||
|
|
||||||
@:build(kiss.Kiss.build())
|
@:build(kiss.Kiss.build())
|
||||||
class System {}
|
class System {}
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
(prop :Map<String,Entry> entries (new Map))
|
(prop :Map<String,Entry> entries (new Map))
|
||||||
|
|
||||||
(method :Void process [:Archive archive]
|
(method :Void process [:Archive archive &opt :ArchiveUI ui]
|
||||||
(doFor e (entries.iterator)
|
(doFor e (entries.iterator)
|
||||||
(processEntry archive e)))
|
(processEntry archive e ui)))
|
||||||
|
|
||||||
(defNew [&prop :EntryChecker canProcessEntry
|
(defNew [&prop :EntryChecker canProcessEntry
|
||||||
&prop :EntryProcessor processEntry]
|
&prop :EntryProcessor processEntry]
|
||||||
@@ -17,4 +17,4 @@
|
|||||||
(entries.remove e.id)
|
(entries.remove e.id)
|
||||||
(when onRemoveEntry (onRemoveEntry archive e)))))
|
(when onRemoveEntry (onRemoveEntry archive e)))))
|
||||||
|
|
||||||
// TODO systems may need access to a UI or ArchiveController
|
// TODO systems may need access to an ArchiveController
|
||||||
|
@@ -7,7 +7,7 @@ import haxe.Json;
|
|||||||
|
|
||||||
using haxe.io.Path;
|
using haxe.io.Path;
|
||||||
|
|
||||||
typedef AttachmentProcessor = (Archive, Entry, Array<FileRef>) -> Dynamic;
|
typedef AttachmentProcessor = (Archive, Entry, Array<FileRef>, ?ArchiveUI) -> Dynamic;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base System that processes Entries based on whether they have file attachments
|
* Base System that processes Entries based on whether they have file attachments
|
||||||
|
@@ -12,5 +12,5 @@
|
|||||||
(return true)))
|
(return true)))
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
->[archive e]
|
->[archive e &opt ui]
|
||||||
(processor archive e (filter e.files ->file !(= -1 (extensions.indexOf (file.extension)))))))
|
(processor archive e (filter e.files ->file !(= -1 (extensions.indexOf (file.extension)))) ui)))
|
@@ -3,7 +3,7 @@
|
|||||||
(defNew []
|
(defNew []
|
||||||
(super
|
(super
|
||||||
["jpg" "jpeg" "png"]
|
["jpg" "jpeg" "png"]
|
||||||
->[archive e imageFiles]
|
->[archive e imageFiles &opt ui]
|
||||||
(unless (hasComponent e Images)
|
(unless (hasComponent e Images)
|
||||||
(addComponent archive e Images
|
(addComponent archive e Images
|
||||||
(object
|
(object
|
||||||
|
@@ -6,7 +6,7 @@
|
|||||||
(defNew []
|
(defNew []
|
||||||
(super
|
(super
|
||||||
->[archive e] (hasComponent e Name)
|
->[archive e] (hasComponent e Name)
|
||||||
->[archive e] (let [name (readComponent e Name)]
|
->[archive e &opt ui] (let [name (readComponent e Name)]
|
||||||
(if (entriesByName.exists (name.toLowerCase))
|
(if (entriesByName.exists (name.toLowerCase))
|
||||||
(.push (dictGet entriesByName (name.toLowerCase)) e)
|
(.push (dictGet entriesByName (name.toLowerCase)) e)
|
||||||
(dictSet entriesByName (name.toLowerCase) [e]))
|
(dictSet entriesByName (name.toLowerCase) [e]))
|
||||||
|
@@ -3,7 +3,7 @@
|
|||||||
(defNew []
|
(defNew []
|
||||||
(super
|
(super
|
||||||
->[archive e] false
|
->[archive e] false
|
||||||
->[archive e] null)
|
->[archive e &opt ui] null)
|
||||||
|
|
||||||
~(#extern String js
|
~(#extern String js
|
||||||
(object
|
(object
|
||||||
|
@@ -8,7 +8,7 @@
|
|||||||
1))
|
1))
|
||||||
|
|
||||||
// named method in case a user will want to run it on selectedEntries instead of on media entries
|
// named method in case a user will want to run it on selectedEntries instead of on media entries
|
||||||
(method scrapeForImages [archive e]
|
(method scrapeForImages [archive e &opt ui]
|
||||||
(let [:String title
|
(let [:String title
|
||||||
(readComponent e Name)
|
(readComponent e Name)
|
||||||
:Array<String> wikipediaImageUrls
|
:Array<String> wikipediaImageUrls
|
||||||
@@ -21,7 +21,9 @@
|
|||||||
(.urlDecode (url.withoutDirectory))
|
(.urlDecode (url.withoutDirectory))
|
||||||
// Some symbols shouldn't be decoded because they're invalid in file systems!
|
// Some symbols shouldn't be decoded because they're invalid in file systems!
|
||||||
"\"" "%22"))]
|
"\"" "%22"))]
|
||||||
// TODO do this with ui.displayMessage
|
// TODO write a macro that either does both print and displayMessage if a ui is available
|
||||||
|
(when ui
|
||||||
|
(ui.displayMessage "Downloading $title image: $url"))
|
||||||
(print url "downloading")
|
(print url "downloading")
|
||||||
(assertProcess "curl" ["--output" filePath url])
|
(assertProcess "curl" ["--output" filePath url])
|
||||||
filePath)))
|
filePath)))
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
(super
|
(super
|
||||||
->[archive e]
|
->[archive e]
|
||||||
?(and (tagsMatch archive e tagFilterString) (hasComponent e Images))
|
?(and (tagsMatch archive e tagFilterString) (hasComponent e Images))
|
||||||
->[archive e]
|
->[archive e &opt ui]
|
||||||
(unless (sprites.exists e.id)
|
(unless (sprites.exists e.id)
|
||||||
(when !(hasComponent e Positions)
|
(when !(hasComponent e Positions)
|
||||||
(addComponent archive e Positions (new Map)))
|
(addComponent archive e Positions (new Map)))
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
(dictSet sprites e.id sprite))))
|
(dictSet sprites e.id sprite))))
|
||||||
|
|
||||||
(set onRemoveEntry
|
(set onRemoveEntry
|
||||||
->[archive e]
|
->[archive e &opt ui]
|
||||||
{
|
{
|
||||||
(.kill (dictGet sprites e.id))
|
(.kill (dictGet sprites e.id))
|
||||||
(sprites.remove e.id)
|
(sprites.remove e.id)
|
||||||
|
@@ -94,7 +94,7 @@
|
|||||||
(prop &mut :EntrySpriteSystem spriteSystem)
|
(prop &mut :EntrySpriteSystem spriteSystem)
|
||||||
(set spriteSystem (new EntrySpriteSystem "!done" "Playground-MAIN" this controller))
|
(set spriteSystem (new EntrySpriteSystem "!done" "Playground-MAIN" this controller))
|
||||||
(archive.addSystem spriteSystem)
|
(archive.addSystem spriteSystem)
|
||||||
(archive.processSystems))
|
(archive.processSystems this))
|
||||||
|
|
||||||
(method &override :Void update [:Float elapsed]
|
(method &override :Void update [:Float elapsed]
|
||||||
(super.update elapsed)
|
(super.update elapsed)
|
||||||
|
@@ -6,7 +6,7 @@
|
|||||||
(super
|
(super
|
||||||
->[archive e]
|
->[archive e]
|
||||||
?(and !(hasComponent e Images) (hasComponent e Name))
|
?(and !(hasComponent e Images) (hasComponent e Name))
|
||||||
->[archive e]
|
->[archive e &opt ui]
|
||||||
{
|
{
|
||||||
(let [name (readComponent e Name)
|
(let [name (readComponent e Name)
|
||||||
sprite (new FlxText 0 0 0 name 16)
|
sprite (new FlxText 0 0 0 name 16)
|
||||||
|
Reference in New Issue
Block a user