move saving flxsprite to png to SpriteTools

This commit is contained in:
2022-07-02 23:19:56 +00:00
parent df462597d3
commit 96036dd31b
4 changed files with 14 additions and 39 deletions

View File

@@ -6,6 +6,11 @@ import flixel.FlxSprite;
import flixel.util.FlxColor; import flixel.util.FlxColor;
import flixel.text.FlxText; import flixel.text.FlxText;
import flixel.math.FlxPoint; import flixel.math.FlxPoint;
import flash.display.PNGEncoderOptions;
import flash.utils.ByteArray;
#if sys
import sys.io.File;
#end
enum RelativeCoordinate { enum RelativeCoordinate {
// Negative means to count back from the far edge // Negative means to count back from the far edge

View File

@@ -50,4 +50,12 @@
(let [text (new FlxText 0 0 0 text size)] (let [text (new FlxText 0 0 0 text size)]
(when color (when color
(set text.color color)) (set text.color color))
(drawOnSprite text canvas pos))))) (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))))

View File

@@ -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 {}

View File

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