Skip to content

Commit 39a838f

Browse files
committed
Deprecate FlxGraphicSource in favor of FlxGraphicAsset
1 parent c27d279 commit 39a838f

File tree

7 files changed

+27
-17
lines changed

7 files changed

+27
-17
lines changed

flixel/graphics/atlas/FlxAtlas.hx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class FlxAtlas implements IFlxDestroyable
173173
* You can omit it if you pass `String` or `Class<Dynamic>` as a `Graphic` source.
174174
* @return Newly created and added node, or `null` if there is no space for it.
175175
*/
176-
public function addNode(Graphic:FlxGraphicSource, ?Key:String):FlxNode
176+
public function addNode(Graphic:FlxGraphicAsset, ?Key:String):FlxNode
177177
{
178178
var key:String = FlxAssets.resolveKey(Graphic, Key);
179179

@@ -602,7 +602,7 @@ class FlxAtlas implements IFlxDestroyable
602602
* @param region Region of source image to use as a source graphic
603603
* @return Generated `FlxTileFrames` for the added node
604604
*/
605-
public function addNodeWithSpacesAndBorders(Graphic:FlxGraphicSource, ?Key:String, tileSize:FlxPoint, tileSpacing:FlxPoint, ?tileBorder:FlxPoint,
605+
public function addNodeWithSpacesAndBorders(Graphic:FlxGraphicAsset, ?Key:String, tileSize:FlxPoint, tileSpacing:FlxPoint, ?tileBorder:FlxPoint,
606606
?region:FlxRect):FlxTileFrames
607607
{
608608
var key:String = FlxAssets.resolveKey(Graphic, Key);

flixel/system/FlxAssets.hx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,20 @@ class VirtualInputData extends #if nme ByteArray #else ByteArrayData #end {}
3636
typedef FlxTexturePackerJsonAsset = FlxJsonAsset<TexturePackerAtlas>;
3737
typedef FlxAsepriteJsonAsset = FlxJsonAsset<AseAtlas>;
3838
typedef FlxSoundAsset = OneOfThree<String, Sound, Class<Sound>>;
39-
typedef FlxGraphicAsset = OneOfThree<FlxGraphic, BitmapData, String>;
4039
typedef FlxTilemapGraphicAsset = OneOfFour<FlxFramesCollection, FlxGraphic, BitmapData, String>;
4140
typedef FlxBitmapFontGraphicAsset = OneOfFour<FlxFrame, FlxGraphic, BitmapData, String>;
42-
abstract FlxGraphicSource(OneOfThree<BitmapData, Class<Dynamic>, String>) from BitmapData from Class<Dynamic> from String
41+
42+
abstract FlxGraphicAsset(OneOfFour<FlxGraphic, BitmapData, String, Class<Dynamic>>) from FlxGraphic to FlxGraphic from BitmapData to BitmapData from String to String from Class<Dynamic> to Class<Dynamic>
4343
{
44-
public function resolveBitmapData()
44+
public inline function resolveBitmapData():BitmapData
4545
{
4646
return FlxAssets.resolveBitmapData(cast this);
4747
}
4848
}
4949

50+
@:deprecated("`FlxGraphicSource` is deprecated, use `FlxGraphicAsset` instead")
51+
typedef FlxGraphicSource = FlxGraphicAsset;
52+
5053
abstract FlxAngelCodeAsset(OneOfThree<Xml, String, Bytes>) from Xml from String from Bytes
5154
{
5255
public inline function parse()
@@ -55,7 +58,6 @@ abstract FlxAngelCodeAsset(OneOfThree<Xml, String, Bytes>) from Xml from String
5558
}
5659
}
5760

58-
5961
@:deprecated("`FlxAngelCodeXmlAsset` is deprecated, use `FlxAngelCodeAsset` instead")// 5.6.0
6062
typedef FlxAngelCodeXmlAsset = FlxAngelCodeAsset;
6163

@@ -304,8 +306,12 @@ class FlxAssets
304306
* @param graphic input data to get BitmapData object for.
305307
* @return BitmapData for specified Dynamic object.
306308
*/
307-
public static function resolveBitmapData(graphic:FlxGraphicSource):BitmapData
309+
public static function resolveBitmapData(graphic:FlxGraphicAsset):BitmapData
308310
{
311+
if ((graphic is FlxGraphic))
312+
{
313+
return cast(graphic, FlxGraphic).bitmap;
314+
}
309315
if ((graphic is BitmapData))
310316
{
311317
return cast graphic;
@@ -333,12 +339,16 @@ class FlxAssets
333339
* @param key optional key string.
334340
* @return Key String for specified Graphic object.
335341
*/
336-
public static function resolveKey(graphic:FlxGraphicSource, ?key:String):String
342+
public static function resolveKey(graphic:FlxGraphicAsset, ?key:String):String
337343
{
338344
if (key != null)
339345
return key;
340346

341-
if ((graphic is BitmapData))
347+
if ((graphic is FlxGraphic))
348+
{
349+
return cast(graphic, FlxGraphic).key;
350+
}
351+
else if ((graphic is BitmapData))
342352
{
343353
return key;
344354
}

flixel/system/debug/FlxDebugger.hx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,9 +415,9 @@ class FlxDebugger extends openfl.display.Sprite
415415
resetButtonLayout();
416416
}
417417

418-
public function addWindowToggleButton(window:Window, icon:FlxGraphicSource):Void
418+
public function addWindowToggleButton(window:Window, icon:FlxGraphicAsset):Void
419419
{
420-
var button = addButton(RIGHT, icon.resolveBitmapData(), window.toggleVisible, true, true);
420+
var button = addButton(RIGHT, FlxAssets.resolveBitmapData(icon), window.toggleVisible, true, true);
421421
window.toggleButton = button;
422422
button.toggled = !window.visible;
423423
}

flixel/system/debug/interaction/tools/Tool.hx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ class Tool extends Sprite implements IFlxDestroyable
4343
return _brain.activeTool == this && _brain.visible;
4444
}
4545

46-
function setButton(icon:FlxGraphicSource):Void
46+
function setButton(icon:FlxGraphicAsset):Void
4747
{
48-
button = new FlxSystemButton(icon.resolveBitmapData(), onButtonClicked, true);
48+
button = new FlxSystemButton(FlxAssets.resolveBitmapData(icon), onButtonClicked, true);
4949
button.toggled = true;
5050

5151
var tooltipName = _name;

flixel/tile/FlxBaseTilemap.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ class FlxBaseTilemap<Tile:FlxObject> extends FlxObject
527527
* @return A reference to this instance of FlxTilemap, for chaining as usual :)
528528
* @since 4.1.0
529529
*/
530-
public function loadMapFromGraphic(mapGraphic:FlxGraphicSource, invert = false, scale = 1, ?colorMap:Array<FlxColor>,
530+
public function loadMapFromGraphic(mapGraphic:FlxGraphicAsset, invert = false, scale = 1, ?colorMap:Array<FlxColor>,
531531
tileGraphic:FlxTilemapGraphicAsset, tileWidth = 0, tileHeight = 0, ?autoTile:FlxTilemapAutoTiling,
532532
startingIndex = 0, drawIndex = 1, collideIndex = 1)
533533
{

flixel/util/FlxSpriteUtil.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class FlxSpriteUtil
5454
* @param mask The mask to apply. Remember the non-alpha zero areas are the parts that will display.
5555
* @return The FlxSprite for chaining
5656
*/
57-
public static function alphaMask(output:FlxSprite, source:FlxGraphicSource, mask:FlxGraphicSource):FlxSprite
57+
public static function alphaMask(output:FlxSprite, source:FlxGraphicAsset, mask:FlxGraphicAsset):FlxSprite
5858
{
5959
var data:BitmapData = FlxAssets.resolveBitmapData(source);
6060
var maskData:BitmapData = FlxAssets.resolveBitmapData(mask);

flixel/util/FlxStringUtil.hx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,9 +562,9 @@ class FlxStringUtil
562562
* @param colorMap An array of color values (alpha values are ignored) in the order they're intended to be assigned as indices
563563
* @return A comma-separated string containing the level data in a FlxTilemap-friendly format.
564564
*/
565-
public static function imageToCSV(graphic:FlxGraphicSource, invert = false, scale = 1, ?colorMap:Array<FlxColor>):String
565+
public static function imageToCSV(graphic:FlxGraphicAsset, invert = false, scale = 1, ?colorMap:Array<FlxColor>):String
566566
{
567-
return bitmapToCSV(graphic.resolveBitmapData(), invert, scale, colorMap);
567+
return bitmapToCSV(FlxAssets.resolveBitmapData(graphic), invert, scale, colorMap);
568568
}
569569

570570
/**

0 commit comments

Comments
 (0)