SVG support in NATFlixel. Close #165

This commit is contained in:
2022-12-05 00:06:54 +00:00
parent 8579b6b8f0
commit 4811395d43
6 changed files with 19 additions and 7 deletions

View File

@@ -73,5 +73,5 @@
(method fullString [:Entry e]
(haxe.Json.stringify e null "\t"))
(method filePath [file]
(method :String filePath [file]
(joinPath archiveDir "files" file))

View File

@@ -2,7 +2,7 @@
(defNew []
(super
["jpg" "jpeg" "png"]
["jpg" "jpeg" "png" "svg"]
->[archive e imageFiles &opt ui]
(unless (upgradeToVersion2 archive e)
// TODO an edge case exists when more image files are added to an Entry

View File

@@ -36,6 +36,7 @@
<!-- _______________________________ Libraries ______________________________ -->
<haxelib name="flixel" />
<haxelib name="svg" />
<haxelib name="kiss" />
<haxelib name="kiss-tools" />

View File

@@ -3,6 +3,8 @@ package;
import kiss.Prelude;
import kiss.List;
import flash.display.BitmapData;
import openfl.display.Sprite;
import format.SVG;
import kiss_flixel.KissExtendedSprite;
import flixel.text.FlxText;
import flixel.util.FlxSpriteUtil;
@@ -13,7 +15,9 @@ import nat.BoolExpInterp;
import nat.components.Images;
import nat.components.Position;
import nat.components.Scale;
import sys.io.File;
using kiss_flixel.CameraTools;
using haxe.io.Path;
@:build(kiss.Kiss.build())
class EntrySprite extends KissExtendedSprite {}

View File

@@ -16,11 +16,17 @@
(cond
((hasComponent e Images2)
(let [images (readComponent e Images2)]
(.onComplete (BitmapData.loadFromFile (archive.filePath (nth images.imageFiles images.pinnedImageIndex)))
->bitmapData {
(loadGraphic bitmapData)
})))
(let [images (readComponent e Images2)
pinnedImage (archive.filePath (nth images.imageFiles images.pinnedImageIndex))]
(case (pinnedImage.extension)
("svg" (let [sprite (new Sprite)]
(.render (new SVG (File.getContent pinnedImage)) sprite.graphics)
(let [bitmapData (new BitmapData (Std.int sprite.width) (Std.int sprite.height))]
(bitmapData.draw sprite)
(loadGraphic bitmapData))))
(otherwise
(.onComplete (BitmapData.loadFromFile pinnedImage)
->bitmapData (loadGraphic bitmapData))))))
((hasComponent e Circle)
(set isCircle true)
(let [c (readComponent e Circle)

View File

@@ -18,6 +18,7 @@ then
haxelib install flixel-addons --quiet
haxelib install flixel-ui --quiet
haxelib install hxcpp --quiet
haxelib install svg --quiet
fi
# if "desktop-" is in the project name, only test for C++