add scale to each image in Images components
This commit is contained in:
@@ -285,10 +285,10 @@
|
|||||||
|
|
||||||
(method adjustImagePins [:Array<Entry> entries increment]
|
(method adjustImagePins [:Array<Entry> entries increment]
|
||||||
(doFor e entries
|
(doFor e entries
|
||||||
(if (hasComponent e Images)
|
(if (hasComponent e Images2)
|
||||||
(withWritableComponents archive e [images Images]
|
(withWritableComponents archive e [images Images2]
|
||||||
(set images.pinnedImageIndex (max 0 (min (- images.imageFiles.length 1) (+ increment images.pinnedImageIndex)))))
|
(set images.pinnedImageIndex (max 0 (min (- images.imageFiles.length 1) (+ increment images.pinnedImageIndex)))))
|
||||||
(ui.reportError "Entry $e has no Images component")))
|
(ui.reportError "Entry $e has no Images2 component")))
|
||||||
entries)
|
entries)
|
||||||
|
|
||||||
(defCommand PinNextImage [entries (SelectedEntries 1 null)]
|
(defCommand PinNextImage [entries (SelectedEntries 1 null)]
|
||||||
@@ -299,10 +299,14 @@
|
|||||||
|
|
||||||
(defCommand SetScale [entries (SelectedEntries 1 null) scale (Number 0 null null)]
|
(defCommand SetScale [entries (SelectedEntries 1 null) scale (Number 0 null null)]
|
||||||
(doFor e entries
|
(doFor e entries
|
||||||
(if (hasComponent e Scale)
|
(cond
|
||||||
(withWritableComponents archive e [scaleComponent Scale]
|
((hasComponent e Images2)
|
||||||
(set scaleComponent scale))
|
(withWritableComponents archive e [i2 Images2]
|
||||||
(addComponent archive e Scale scale)))
|
(setNth i2.imageScales i2.pinnedImageIndex scale)))
|
||||||
|
((hasComponent e Scale)
|
||||||
|
(withWritableComponents archive e [scaleComponent Scale]
|
||||||
|
(set scaleComponent scale)))
|
||||||
|
(true (addComponent archive e Scale scale))))
|
||||||
entries)
|
entries)
|
||||||
|
|
||||||
(defCommand CreatePlayground [name (Text null) catsMatchExp (Text null)]
|
(defCommand CreatePlayground [name (Text null) catsMatchExp (Text null)]
|
||||||
|
@@ -109,3 +109,10 @@
|
|||||||
(withWritableComponents archive e [tags Tags]
|
(withWritableComponents archive e [tags Tags]
|
||||||
(doFor tag tagsToRemove (tags.remove tag)))))
|
(doFor tag tagsToRemove (tags.remove tag)))))
|
||||||
|
|
||||||
|
(function :Float getScale [:nat.Entry e]
|
||||||
|
(if (hasComponent e Images2)
|
||||||
|
(let [i2 (readComponent e Images2)]
|
||||||
|
(nth i2.imageScales i2.pinnedImageIndex))
|
||||||
|
(if (hasComponent e Scale)
|
||||||
|
(readComponent e Scale)
|
||||||
|
1.0)))
|
7
projects/nat-archive-tool/src/nat/components/Images2.hx
Normal file
7
projects/nat-archive-tool/src/nat/components/Images2.hx
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package nat.components;
|
||||||
|
|
||||||
|
typedef Images2 = {
|
||||||
|
imageFiles:Array<FileRef>,
|
||||||
|
imageScales:Array<Float>,
|
||||||
|
pinnedImageIndex:Int
|
||||||
|
};
|
@@ -2,6 +2,7 @@ package nat.systems;
|
|||||||
|
|
||||||
import kiss.Prelude;
|
import kiss.Prelude;
|
||||||
import kiss.List;
|
import kiss.List;
|
||||||
|
using StringTools;
|
||||||
|
|
||||||
@:build(kiss.Kiss.build())
|
@:build(kiss.Kiss.build())
|
||||||
class ImageAttachmentSystem extends AttachmentSystem {}
|
class ImageAttachmentSystem extends AttachmentSystem {}
|
||||||
|
@@ -4,8 +4,39 @@
|
|||||||
(super
|
(super
|
||||||
["jpg" "jpeg" "png"]
|
["jpg" "jpeg" "png"]
|
||||||
->[archive e imageFiles &opt ui]
|
->[archive e imageFiles &opt ui]
|
||||||
(unless (hasComponent e Images)
|
(unless (upgradeToVersion2 archive e)
|
||||||
(addComponent archive e Images
|
// TODO an edge case exists when more image files are added to an Entry
|
||||||
(object
|
// after it is assigned an Images component. The new files won't be added
|
||||||
imageFiles imageFiles
|
(unless (hasComponent e Images2)
|
||||||
pinnedImageIndex 0)))))
|
(addComponent archive e Images2
|
||||||
|
(object
|
||||||
|
imageFiles imageFiles
|
||||||
|
imageScales (for _ (range imageFiles.length) 1.0)
|
||||||
|
pinnedImageIndex 0))))))
|
||||||
|
|
||||||
|
// Retrofit Images components into Images2 components,
|
||||||
|
// which can track a separate scale value for each image.
|
||||||
|
// Also, remove text image files -- now that text sprites
|
||||||
|
// are generated on the fly.
|
||||||
|
(function :Bool upgradeToVersion2 [:nat.Archive archive :nat.Entry e]
|
||||||
|
(when (hasComponent e Images)
|
||||||
|
(let [images1 (readComponent e Images)
|
||||||
|
scale (readComponentOr e Scale 1.0)
|
||||||
|
pIdx images1.pinnedImageIndex
|
||||||
|
textImageFiles (filter images1.imageFiles ->[:String f] (f.startsWith "textImage"))]
|
||||||
|
(removeComponent archive e Images)
|
||||||
|
(removeFiles archive e textImageFiles)
|
||||||
|
(doFor f textImageFiles (images1.imageFiles.remove f))
|
||||||
|
// If all images were removed (the entry only had a text image), don't add Images2
|
||||||
|
(unless images1.imageFiles (return true))
|
||||||
|
|
||||||
|
(addComponent archive e Images2
|
||||||
|
(object
|
||||||
|
imageFiles images1.imageFiles
|
||||||
|
imageScales (cast (concat
|
||||||
|
(for _ (range pIdx) 1.0)
|
||||||
|
[scale]
|
||||||
|
(for _ (range (- images1.imageFiles.length 1 pIdx)) 1.0)))
|
||||||
|
pinnedImageIndex pIdx))
|
||||||
|
(removeComponent archive e Scale)
|
||||||
|
true)))
|
@@ -8,18 +8,17 @@
|
|||||||
&prop :ArchiveController controller]
|
&prop :ArchiveController controller]
|
||||||
[&mut :Bool selected false]
|
[&mut :Bool selected false]
|
||||||
(super position.x position.y)
|
(super position.x position.y)
|
||||||
(if (hasComponent e Images)
|
(if (hasComponent e Images2)
|
||||||
(let [images (readComponent e Images)]
|
(let [images (readComponent e Images2)]
|
||||||
(.onComplete (BitmapData.loadFromFile (joinPath archive.archiveDir "files" (nth images.imageFiles images.pinnedImageIndex)))
|
(.onComplete (BitmapData.loadFromFile (joinPath archive.archiveDir "files" (nth images.imageFiles images.pinnedImageIndex)))
|
||||||
->bitmapData {
|
->bitmapData {
|
||||||
(loadGraphic bitmapData)
|
(loadGraphic bitmapData)
|
||||||
}))
|
}))
|
||||||
(set pixels .pixels (new FlxText 0 0 0 (readComponent e Name) PlayState.TEXT_SIZE)))
|
(set pixels .pixels (new FlxText 0 0 0 (readComponent e Name) PlayState.TEXT_SIZE)))
|
||||||
(updateColor)
|
(updateColor)
|
||||||
(when (hasComponent e Scale)
|
(let [:Float scale (getScale e)]
|
||||||
(let [:Float scale (readComponent e Scale)]
|
(this.scale.set scale scale)
|
||||||
(this.scale.set scale scale)
|
(updateHitbox))
|
||||||
(updateHitbox)))
|
|
||||||
(enableMouseClicks false)
|
(enableMouseClicks false)
|
||||||
(enableMouseDrag)
|
(enableMouseDrag)
|
||||||
(set mouseStartDragCallback
|
(set mouseStartDragCallback
|
||||||
|
Reference in New Issue
Block a user