diff --git a/projects/kiss-flixel/src/kiss_flixel/SpriteTools.hx b/projects/kiss-flixel/src/kiss_flixel/SpriteTools.hx index f026fc7b..90976038 100644 --- a/projects/kiss-flixel/src/kiss_flixel/SpriteTools.hx +++ b/projects/kiss-flixel/src/kiss_flixel/SpriteTools.hx @@ -6,6 +6,11 @@ import flixel.FlxSprite; import flixel.util.FlxColor; import flixel.text.FlxText; import flixel.math.FlxPoint; +import flash.display.PNGEncoderOptions; +import flash.utils.ByteArray; +#if sys +import sys.io.File; +#end enum RelativeCoordinate { // Negative means to count back from the far edge diff --git a/projects/kiss-flixel/src/kiss_flixel/SpriteTools.kiss b/projects/kiss-flixel/src/kiss_flixel/SpriteTools.kiss index 9f4e3bc5..ff6f9eb4 100644 --- a/projects/kiss-flixel/src/kiss_flixel/SpriteTools.kiss +++ b/projects/kiss-flixel/src/kiss_flixel/SpriteTools.kiss @@ -50,4 +50,12 @@ (let [text (new FlxText 0 0 0 text size)] (when color (set text.color color)) - (drawOnSprite text canvas pos))))) \ No newline at end of file + (drawOnSprite text canvas pos))))) + +// Source: https://gist.github.com/miltoncandelero/0c452f832fa924bfdd60fe9d507bc581 +(#when sys + (function :Void saveToPNG [:FlxSprite sprite :String file] + (let [bitmapData sprite.pixels + &mut bytes (new ByteArray)] + (set bytes (bitmapData.encode bitmapData.rect (new PNGEncoderOptions true) bytes)) + (File.saveBytes file bytes)))) \ No newline at end of file diff --git a/projects/nat-flixel-desktop-playground/source/TextSpriteSystem.hx b/projects/nat-flixel-desktop-playground/source/TextSpriteSystem.hx deleted file mode 100644 index b090952a..00000000 --- a/projects/nat-flixel-desktop-playground/source/TextSpriteSystem.hx +++ /dev/null @@ -1,17 +0,0 @@ -package; - -import kiss.Prelude; -import kiss.List; -import nat.System; -import nat.BoolExpInterp; -import nat.ArchiveController; -import nat.components.Positions; -import flash.display.PNGEncoderOptions; -import flash.utils.ByteArray; -import flixel.text.FlxText; -import sys.io.File; - -using nat.Lib; - -@:build(kiss.Kiss.build()) -class TextSpriteSystem extends System {} diff --git a/projects/nat-flixel-desktop-playground/source/TextSpriteSystem.kiss b/projects/nat-flixel-desktop-playground/source/TextSpriteSystem.kiss deleted file mode 100644 index 347b540e..00000000 --- a/projects/nat-flixel-desktop-playground/source/TextSpriteSystem.kiss +++ /dev/null @@ -1,21 +0,0 @@ -(loadFrom "nat-archive-tool" "src/nat/Lib.kiss") - -// Named entries without Images should be given an image generated with the name's text - -(defNew [] - (super - ->[archive e] - ?(and !(hasComponent e Images) (hasComponent e Name)) - ->[archive e &opt ui] - { - // TODO refactor this to kiss-flixel SpriteTools as #if sys savePNG - (let [name (readComponent e Name) - sprite (new FlxText 0 0 0 name 16) - bitmapData sprite.pixels - // Source: https://gist.github.com/miltoncandelero/0c452f832fa924bfdd60fe9d507bc581 - &mut bytes (new ByteArray)] - (set bytes (bitmapData.encode bitmapData.rect (new PNGEncoderOptions true) bytes)) - (let [path (joinPath archive.archiveDir "files" "textImage${name}.png")] - (File.saveBytes path bytes) - (archive.addFiles e [path]))) - })) \ No newline at end of file