(loadFrom "nat-archive-tool" "src/nat/Lib.kiss") (defNew [&prop :EntrySpriteSystem system &prop :String positionKey &prop :Position position &prop :Archive archive &prop :Entry e &prop :ArchiveController controller] [&mut :Bool selected false &mut :Bool isCircle false] (super position.x position.y) (cond ((hasComponent e Images2) (let [images (readComponent e Images2)] (.onComplete (BitmapData.loadFromFile (joinPath archive.archiveDir "files" (nth images.imageFiles images.pinnedImageIndex))) ->bitmapData { (loadGraphic bitmapData) }))) ((hasComponent e Circle) (set isCircle true) (let [c (readComponent e Circle) diam (Std.int (* 2 c.radius))] (makeGraphic diam diam FlxColor.TRANSPARENT true) (FlxSpriteUtil.drawCircle this -1 -1 c.radius FlxColor.TRANSPARENT (object thickness 5 color CIRCLE_COLOR)))) (true (set pixels .pixels (new FlxText 0 0 0 (readComponent e Name) PlayState.TEXT_SIZE)))) (updateColor) (let [:Float scale (getScale e)] (this.scale.set scale scale) (updateHitbox)) (enableMouseClicks false (hasComponent e Circle)) // pixel-perfect if the sprite is a circle (enableMouseDrag false (hasComponent e Circle)) (set mouseStartDragCallback ->[self _dx _dy] (doFor sprite (system.getSelectedSprites) (unless (= sprite.e.id this.e.id) (sprite.fixToSprite this)))) (set mouseStopDragCallback ->[self _dx _dy] { (savePos) (doFor sprite (system.getSelectedSprites) (unless (= sprite.e.id this.e.id) (sprite.endFixToSprite))) })) (prop &mut :EntrySprite fixedToSprite) (prop &mut :FlxPoint fixedOffset) (method savePos [] (FlxG.camera.extendScrollBounds this PlayState.SCROLL_BOUND_MARGIN) (withWritableComponents archive e [positions Positions] (let [pos (dictGet positions positionKey)] (dictSet positions positionKey (object x (cast this.x Float) y (cast this.y Float) z pos.z))))) (method &override :Void update [:Float elapsed] (super.update elapsed) (when fixedToSprite (set x (+ fixedToSprite.x fixedOffset.x)) (set y (+ fixedToSprite.y fixedOffset.y)))) (method fixToSprite [:EntrySprite sprite] (set fixedToSprite sprite) (set fixedOffset (new FlxPoint (- x sprite.x) (- y sprite.y)))) (method endFixToSprite [] (savePos) (set fixedToSprite null)) (method updateColor [] (if (controller.isSelected e) { (set color (if isCircle CIRCLE_SELECTED_COLOR SELECTED_COLOR)) } { (set color FlxColor.WHITE) })) (var SELECTED_COLOR FlxColor.BLUE) (var CIRCLE_COLOR FlxColor.LIME) (var CIRCLE_SELECTED_COLOR FlxColor.GRAY) (var DEFAULT_COLOR FlxColor.WHITE)