move saving flxsprite to png to SpriteTools
This commit is contained in:
@@ -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
|
||||
|
@@ -51,3 +51,11 @@
|
||||
(when color
|
||||
(set text.color color))
|
||||
(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))))
|
@@ -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 {}
|
@@ -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])))
|
||||
}))
|
Reference in New Issue
Block a user