From 6b0ec36b145dee2cc8d8056ba3048da5c6b83379 Mon Sep 17 00:00:00 2001 From: George Kurelic Date: Wed, 5 Jun 2024 17:23:35 -0500 Subject: [PATCH 01/35] 5.9.0 compat (#431) --- flixel/addons/editors/ogmo/FlxOgmo3Loader.hx | 4 + flixel/addons/tile/FlxRayCastTilemap.hx | 6 +- flixel/addons/tile/FlxTilemapExt.hx | 93 +++++++++++++++++++- flixel/addons/weapon/FlxWeapon.hx | 12 ++- 4 files changed, 102 insertions(+), 13 deletions(-) diff --git a/flixel/addons/editors/ogmo/FlxOgmo3Loader.hx b/flixel/addons/editors/ogmo/FlxOgmo3Loader.hx index 95dd88f5..b5702fa0 100644 --- a/flixel/addons/editors/ogmo/FlxOgmo3Loader.hx +++ b/flixel/addons/editors/ogmo/FlxOgmo3Loader.hx @@ -284,7 +284,11 @@ class FlxOgmo3Loader for (i in 0...tileFlags.length) { var flag = tileFlags[i]; + #if (flixel < "5.9.0") var specialTile = new FlxTileSpecial(tilemap.getTileByIndex(i), false, false, 0); + #else + var specialTile = new FlxTileSpecial(tilemap.getTileIndex(i), false, false, 0); + #end if (flag & 4 > 0) specialTile.flipX = true; diff --git a/flixel/addons/tile/FlxRayCastTilemap.hx b/flixel/addons/tile/FlxRayCastTilemap.hx index 3d5e5b13..b708ba1b 100644 --- a/flixel/addons/tile/FlxRayCastTilemap.hx +++ b/flixel/addons/tile/FlxRayCastTilemap.hx @@ -6,6 +6,7 @@ import flixel.math.FlxPoint; /** * @author greglieberman */ +@:deprecated("FlxRayCastTilemap is deprecated, use FlxTilemap.ray or rayStep, instead")// for flixel 5.9.0 class FlxRayCastTilemap extends FlxTilemap { /** @@ -222,11 +223,6 @@ class FlxRayCastTilemap extends FlxTilemap return Y * widthInTiles + X; } - public function getTileIndex(X:Int, Y:Int):Int - { - return Y * widthInTiles + X; - } - public function coordsToTileX(CoordX:Float):Float { return Std.int((CoordX - x) / scaledTileWidth); diff --git a/flixel/addons/tile/FlxTilemapExt.hx b/flixel/addons/tile/FlxTilemapExt.hx index 7973569b..538241f3 100644 --- a/flixel/addons/tile/FlxTilemapExt.hx +++ b/flixel/addons/tile/FlxTilemapExt.hx @@ -322,6 +322,7 @@ class FlxTilemapExt extends FlxTilemap } } + #if (flixel < "5.9.0") /** * THIS IS A COPY FROM FlxTilemap BUT IT SOLVES SLOPE COLLISION TOO * Checks if the Object overlaps any tiles with any collision flags set, @@ -334,7 +335,7 @@ class FlxTilemapExt extends FlxTilemap * @param position Optional, specify a custom position for the tilemap (useful for overlapsAt()-type functionality). * @return Whether there were overlaps, or if a callback was specified, whatever the return value of the callback was. */ - override public function overlapsWithCallback(object:FlxObject, ?callback:FlxObject->FlxObject->Bool, flipCallbackParams:Bool = false, + override function overlapsWithCallback(object:FlxObject, ?callback:FlxObject->FlxObject->Bool, flipCallbackParams:Bool = false, ?position:FlxPoint):Bool { var results:Bool = false; @@ -375,8 +376,7 @@ class FlxTilemapExt extends FlxTilemap continue; final tile = _tileObjects[dataIndex]; - - if (tile.allowCollisions != NONE) + if (tile.solid) { var overlapFound = false; @@ -400,7 +400,10 @@ class FlxTilemapExt extends FlxTilemap } else { - overlapFound = (object.x + object.width > tile.x) && (object.x < tile.x + tile.width) && (object.y + object.height > tile.y) + overlapFound + = (object.x + object.width > tile.x) + && (object.x < tile.x + tile.width) + && (object.y + object.height > tile.y) && (object.y < tile.y + tile.height); } @@ -425,6 +428,88 @@ class FlxTilemapExt extends FlxTilemap return results; } + #else + /** + * Hacky fix for `FlxTilemapExt`, with all the new changes to 5.9.0 it's better to perfectly + * recreate the old behavior, here and then make a new tilemap with slopes that uses the new + * features to eventually replace it + */ + override function processOverlaps(object:TObj, ?processCallback:(FlxTile, TObj)->Bool, ?position:FlxPoint, isCollision = true):Bool + { + var results:Bool = false; + + var xPos:Float = x; + var yPos:Float = y; + + if (position != null) + { + xPos = position.x; + yPos = position.y; + position.putWeak(); + } + + inline function bindInt(value:Int, min:Int, max:Int) + { + return Std.int(FlxMath.bound(value, min, max)); + } + + // Figure out what tiles we need to check against, and bind them by the map edges + final minTileX:Int = bindInt(Math.floor((object.x - xPos) / scaledTileWidth), 0, widthInTiles); + final minTileY:Int = bindInt(Math.floor((object.y - yPos) / scaledTileHeight), 0, heightInTiles); + final maxTileX:Int = bindInt(Math.ceil((object.x + object.width - xPos) / scaledTileWidth), 0, widthInTiles); + final maxTileY:Int = bindInt(Math.ceil((object.y + object.height - yPos) / scaledTileHeight), 0, heightInTiles); + + // Cache tilemap movement + final deltaX:Float = xPos - last.x; + final deltaY:Float = yPos - last.y; + + // Loop through the range of tiles and call the callback on them, accordingly + for (row in minTileY...maxTileY) + { + for (column in minTileX...maxTileX) + { + final mapIndex:Int = (row * widthInTiles) + column; + final dataIndex:Int = _data[mapIndex]; + if (dataIndex < 0) + continue; + + final tile = _tileObjects[dataIndex]; + tile.orientAt(xPos, yPos, column, row); + + if (tile.solid) + { + var overlapFound = false; + if (processCallback != null) + { + overlapFound = processCallback(tile, object); + } + else + { + overlapFound = tile.overlapsObject(object); + } + + // New generalized slope collisions + if (overlapFound || checkArrays(tile.index)) + { + if ((tile.callbackFunction != null) && ((tile.filter == null) || Std.isOfType(object, tile.filter))) + { + tile.callbackFunction(tile, object); + tile.onCollide.dispatch(tile, object); + } + results = true; + } + } + else if ((tile.callbackFunction != null) && ((tile.filter == null) || Std.isOfType(object, tile.filter))) + { + tile.callbackFunction(tile, object); + tile.onCollide.dispatch(tile, object); + } + } + } + + return results; + } + #end /** * Set glue to force contact with slopes and a slow down factor while climbing diff --git a/flixel/addons/weapon/FlxWeapon.hx b/flixel/addons/weapon/FlxWeapon.hx index 0c43dd37..d8c04de5 100644 --- a/flixel/addons/weapon/FlxWeapon.hx +++ b/flixel/addons/weapon/FlxWeapon.hx @@ -430,16 +430,20 @@ class FlxTypedWeapon } } - function shouldBulletHit(Object:FlxObject, Bullet:FlxObject):Bool + function shouldBulletHit(object:FlxObject, bullet:FlxObject):Bool { - if (parent == Object && skipParentCollision) + if (parent == object && skipParentCollision) { return false; } - if ((Object is FlxTilemap)) + if ((object is FlxTilemap)) { - return cast(Object, FlxTilemap).overlapsWithCallback(Bullet); + #if (flixel < "5.9.0") + return cast(object, FlxTilemap).overlapsWithCallback(bullet); + #else + return cast(object, FlxTilemap).processOverlaps(bullet); + #end } else { From 423ba2b05c6ee3d913d39776b92c7ddba1690727 Mon Sep 17 00:00:00 2001 From: George FunBook Date: Wed, 5 Jun 2024 17:26:16 -0500 Subject: [PATCH 02/35] prepare for 3.2.4 --- CHANGELOG.md | 7 +++++++ haxelib.json | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7937aac6..669b753e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +3.2.4 (TBD) +------------------------------ +#### Changes and improvements: +- Compatibility with Flixel 5.9.0 ([431](https://github.com/HaxeFlixel/flixel-addons/pull/431)) + - Deprecated `FlxRayCastTilemap` + - Minor upkeep for `FlxTilemapExt`, `FlxOgmo3Loader`, `FlxOgmo3Loader` + 3.2.3 (May 15, 2024) ------------------------------ diff --git a/haxelib.json b/haxelib.json index 9cda487a..137b228a 100644 --- a/haxelib.json +++ b/haxelib.json @@ -4,7 +4,7 @@ "license": "MIT", "tags": ["game", "openfl", "flash", "neko", "cpp", "android", "ios", "cross"], "description": "flixel-addons is a set of useful, additional classes for HaxeFlixel.", - "version": "3.2.3", - "releasenote": "Compatibility with flixel 5.7.0", + "version": "3.2.4", + "releasenote": "Compatibility with flixel 5.9.0", "contributors": ["haxeflixel", "Gama11", "GeoKureli"] } From 83a0984a4fb39bd13f890005c456bebdb2878ba9 Mon Sep 17 00:00:00 2001 From: George Kurelic Date: Thu, 6 Jun 2024 09:48:23 -0500 Subject: [PATCH 03/35] Tilemapext overlaps (#432) * use forEachOverlappingTile after all * rename method --- flixel/addons/tile/FlxTilemapExt.hx | 88 +++++++++-------------------- 1 file changed, 26 insertions(+), 62 deletions(-) diff --git a/flixel/addons/tile/FlxTilemapExt.hx b/flixel/addons/tile/FlxTilemapExt.hx index 538241f3..068518a3 100644 --- a/flixel/addons/tile/FlxTilemapExt.hx +++ b/flixel/addons/tile/FlxTilemapExt.hx @@ -434,79 +434,43 @@ class FlxTilemapExt extends FlxTilemap * recreate the old behavior, here and then make a new tilemap with slopes that uses the new * features to eventually replace it */ - override function processOverlaps(object:TObj, ?processCallback:(FlxTile, TObj)->Bool, ?position:FlxPoint, isCollision = true):Bool + override function objectOverlapsTiles(object:TObj, ?callback:(FlxTile, TObj)->Bool, ?position:FlxPoint, isCollision = true):Bool { - var results:Bool = false; - - var xPos:Float = x; - var yPos:Float = y; - - if (position != null) - { - xPos = position.x; - yPos = position.y; - position.putWeak(); - } - - inline function bindInt(value:Int, min:Int, max:Int) + var results = false; + function each(tile:FlxTile) { - return Std.int(FlxMath.bound(value, min, max)); - } - - // Figure out what tiles we need to check against, and bind them by the map edges - final minTileX:Int = bindInt(Math.floor((object.x - xPos) / scaledTileWidth), 0, widthInTiles); - final minTileY:Int = bindInt(Math.floor((object.y - yPos) / scaledTileHeight), 0, heightInTiles); - final maxTileX:Int = bindInt(Math.ceil((object.x + object.width - xPos) / scaledTileWidth), 0, widthInTiles); - final maxTileY:Int = bindInt(Math.ceil((object.y + object.height - yPos) / scaledTileHeight), 0, heightInTiles); - - // Cache tilemap movement - final deltaX:Float = xPos - last.x; - final deltaY:Float = yPos - last.y; - - // Loop through the range of tiles and call the callback on them, accordingly - for (row in minTileY...maxTileY) - { - for (column in minTileX...maxTileX) + if (tile.solid) { - final mapIndex:Int = (row * widthInTiles) + column; - final dataIndex:Int = _data[mapIndex]; - if (dataIndex < 0) - continue; - - final tile = _tileObjects[dataIndex]; - tile.orientAt(xPos, yPos, column, row); - - if (tile.solid) + var overlapFound = false; + if (callback != null) { - var overlapFound = false; - if (processCallback != null) - { - overlapFound = processCallback(tile, object); - } - else - { - overlapFound = tile.overlapsObject(object); - } + overlapFound = callback(tile, object); + } + else + { + overlapFound = tile.overlapsObject(object); + } - // New generalized slope collisions - if (overlapFound || checkArrays(tile.index)) + // New generalized slope collisions + if (overlapFound || checkArrays(tile.index)) + { + if (tile.callbackFunction != null) { - if ((tile.callbackFunction != null) && ((tile.filter == null) || Std.isOfType(object, tile.filter))) - { - tile.callbackFunction(tile, object); - tile.onCollide.dispatch(tile, object); - } - results = true; + tile.callbackFunction(tile, object); + tile.onCollide.dispatch(tile, object); } - } - else if ((tile.callbackFunction != null) && ((tile.filter == null) || Std.isOfType(object, tile.filter))) - { - tile.callbackFunction(tile, object); - tile.onCollide.dispatch(tile, object); + results = true; } } + else if ((tile.callbackFunction != null) && ((tile.filter == null) || Std.isOfType(object, tile.filter))) + { + tile.callbackFunction(tile, object); + tile.onCollide.dispatch(tile, object); + } } + forEachOverlappingTile(object, each, position); + return results; } #end From ac508d88f48cafc48a96e720d7f73b1659929b00 Mon Sep 17 00:00:00 2001 From: George Kurelic Date: Thu, 6 Jun 2024 12:23:35 -0500 Subject: [PATCH 04/35] fix weapon (#433) --- flixel/addons/weapon/FlxWeapon.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flixel/addons/weapon/FlxWeapon.hx b/flixel/addons/weapon/FlxWeapon.hx index d8c04de5..e701528d 100644 --- a/flixel/addons/weapon/FlxWeapon.hx +++ b/flixel/addons/weapon/FlxWeapon.hx @@ -442,7 +442,7 @@ class FlxTypedWeapon #if (flixel < "5.9.0") return cast(object, FlxTilemap).overlapsWithCallback(bullet); #else - return cast(object, FlxTilemap).processOverlaps(bullet); + return cast(object, FlxTilemap).objectOverlapsTiles(bullet); #end } else From 4ec75fe24fd74aeaa663a4576919278cec0431b5 Mon Sep 17 00:00:00 2001 From: George Kurelic Date: Thu, 13 Jun 2024 14:11:12 -0500 Subject: [PATCH 05/35] FlxTiledSprite honors clipRect (#435) --- flixel/addons/display/FlxTiledSprite.hx | 377 ++++++++++++++---------- 1 file changed, 219 insertions(+), 158 deletions(-) diff --git a/flixel/addons/display/FlxTiledSprite.hx b/flixel/addons/display/FlxTiledSprite.hx index 4fe74730..738699fb 100644 --- a/flixel/addons/display/FlxTiledSprite.hx +++ b/flixel/addons/display/FlxTiledSprite.hx @@ -8,6 +8,7 @@ import flixel.math.FlxMath; import flixel.system.FlxAssets.FlxGraphicAsset; import flixel.util.FlxColor; import flixel.util.FlxDestroyUtil; +import flixel.math.FlxRect; import flixel.util.FlxSpriteUtil; /** @@ -21,44 +22,44 @@ class FlxTiledSprite extends FlxStrip * The x-offset of the texture */ public var scrollX(default, set):Float = 0; - + /** * The y-offset of the texture. */ public var scrollY(default, set):Float = 0; - + /** * Repeat texture on x axis. Default is true */ public var repeatX(default, set):Bool = true; - + /** * Repeat texture on y axis. Default is true */ public var repeatY(default, set):Bool = true; - + /** * Helper sprite, which does actual rendering in blit render mode. */ var renderSprite:FlxSprite; - + var regen:Bool = true; - + var graphicVisible:Bool = true; - - public function new(?Graphic:FlxGraphicAsset, Width:Float, Height:Float, RepeatX:Bool = true, RepeatY:Bool = true) + + public function new(?graphic:FlxGraphicAsset, width:Float, height:Float, repeatX = true, repeatY = true) { super(); - + repeat = true; - + indices[0] = 0; indices[1] = 1; indices[2] = 2; indices[3] = 2; indices[4] = 3; indices[5] = 0; - + uvtData[0] = 0; uvtData[1] = 0; uvtData[2] = 1; @@ -67,58 +68,64 @@ class FlxTiledSprite extends FlxStrip uvtData[5] = 1; uvtData[6] = 0; uvtData[7] = 1; - + vertices[0] = 0; vertices[1] = 0; - vertices[2] = Width; + vertices[2] = width; vertices[3] = 0; - vertices[4] = Width; - vertices[5] = Height; + vertices[4] = width; + vertices[5] = height; vertices[6] = 0; - vertices[7] = Height; - - width = Width; - height = Height; - - repeatX = RepeatX; - repeatY = RepeatY; - - if (Graphic != null) - loadGraphic(Graphic); + vertices[7] = height; + + this.width = width; + this.height = height; + + this.repeatX = repeatX; + this.repeatY = repeatY; + + if (graphic != null) + loadGraphic(graphic); } - - override public function destroy():Void + + override function destroy():Void { renderSprite = FlxDestroyUtil.destroy(renderSprite); super.destroy(); } - - override public function loadGraphic(Graphic:FlxGraphicAsset, Animated:Bool = false, Width:Int = 0, Height:Int = 0, Unique:Bool = false, - ?Key:String):FlxSprite + + override function loadGraphic(graphic, animated = false, width = 0, height = 0, unique = false, ?key:String):FlxSprite { - graphic = FlxG.bitmap.add(Graphic); + this.graphic = FlxG.bitmap.add(graphic); return this; } - - public function loadFrame(Frame:FlxFrame):FlxTiledSprite + + public function loadFrame(frame:FlxFrame):FlxTiledSprite { - graphic = FlxGraphic.fromFrame(Frame); + graphic = FlxGraphic.fromFrame(frame); return this; } - - override function set_graphic(Value:FlxGraphic):FlxGraphic + + override function set_clipRect(value:FlxRect):FlxRect { - if (graphic != Value) + regen = true; + + return super.set_clipRect(value); + } + + override function set_graphic(value:FlxGraphic):FlxGraphic + { + if (graphic != value) regen = true; - - return super.set_graphic(Value); + + return super.set_graphic(value); } - + function regenGraphic():Void { if (!regen || graphic == null) return; - + if (FlxG.renderBlit) { updateRenderSprite(); @@ -127,69 +134,92 @@ class FlxTiledSprite extends FlxStrip { updateVerticesData(); } - + regen = false; } - - override public function draw():Void + + override function draw():Void { if (regen) regenGraphic(); - - if (!graphicVisible) - return; - - if (FlxG.renderBlit) + + if (graphicVisible) { - renderSprite.x = x; - renderSprite.y = y; - renderSprite.scrollFactor.set(scrollFactor.x, scrollFactor.y); - renderSprite._cameras = _cameras; - renderSprite.draw(); + if (FlxG.renderBlit) + { + renderSprite.x = x; + renderSprite.y = y; + renderSprite.scrollFactor.set(scrollFactor.x, scrollFactor.y); + renderSprite._cameras = _cameras; + renderSprite.draw(); + } + else + { + super.draw(); + } } - else + + #if FLX_DEBUG + if (FlxG.debugger.drawDebug) + drawDebug(); + #end + } + + #if FLX_DEBUG + /** + * Copied exactly from `FlxObject`, to avoid any future changes to `FlxStrip`'s debug drawing + */ + override function drawDebug() + { + if (ignoreDrawDebug) + return; + + final drawPath = path != null && !path.ignoreDrawDebug; + + for (camera in getCamerasLegacy()) { - super.draw(); + drawDebugOnCamera(camera); + + if (drawPath) + { + path.drawDebugOnCamera(camera); + } } } - + #end + function updateRenderSprite():Void { graphicVisible = true; - + if (renderSprite == null) renderSprite = new FlxSprite(); - - var rectX:Float = repeatX ? 0 : scrollX; - var rectWidth:Float = repeatX ? width : graphic.bitmap.width; - - if (!repeatX && (rectX > width || rectX + rectWidth < 0)) + + final drawRect = getDrawRect(); + drawRect.x = Std.int(drawRect.x); + drawRect.y = Std.int(drawRect.y); + drawRect.width = Std.int(drawRect.width); + drawRect.height = Std.int(drawRect.height); + //TODO: rect.int() or smth + + if (drawRect.width * drawRect.height == 0) { graphicVisible = false; + drawRect.put(); return; } - - var rectY:Float = repeatY ? 0 : scrollY; - var rectHeight:Float = repeatY ? height : graphic.bitmap.height; - - if (!repeatY && (rectY > height || rectY + rectHeight < 0)) - { - graphicVisible = false; - return; - } - - if (renderSprite.width != width || renderSprite.height != height) + + if (renderSprite.width != drawRect.width || renderSprite.height != drawRect.height) { - renderSprite.makeGraphic(Std.int(width), Std.int(height), FlxColor.TRANSPARENT, true); + renderSprite.makeGraphic(Std.int(drawRect.width), Std.int(drawRect.height), FlxColor.TRANSPARENT, true); } else { - _flashRect2.setTo(0, 0, width, height); - renderSprite.pixels.fillRect(_flashRect2, FlxColor.TRANSPARENT); + renderSprite.pixels.fillRect(renderSprite.pixels.rect, FlxColor.TRANSPARENT); } - + FlxSpriteUtil.flashGfx.clear(); - + if (scrollX != 0 || scrollY != 0) { _matrix.identity(); @@ -201,119 +231,150 @@ class FlxTiledSprite extends FlxStrip { FlxSpriteUtil.flashGfx.beginBitmapFill(graphic.bitmap); } - - FlxSpriteUtil.flashGfx.drawRect(rectX, rectY, rectWidth, rectHeight); + + FlxSpriteUtil.flashGfx.drawRect(drawRect.x, drawRect.y, drawRect.width, drawRect.height); renderSprite.pixels.draw(FlxSpriteUtil.flashGfxSprite, null, colorTransform); FlxSpriteUtil.flashGfx.clear(); renderSprite.dirty = true; } - + function updateVerticesData():Void { if (graphic == null) return; - - var frame:FlxFrame = graphic.imageFrame.frame; + + final frame:FlxFrame = graphic.imageFrame.frame; graphicVisible = true; - - if (repeatX) + + final drawRect = getDrawRect(); + + if (drawRect.width * drawRect.height == 0) { - vertices[0] = vertices[6] = 0.0; - vertices[2] = vertices[4] = width; - - uvtData[0] = uvtData[6] = -scrollX / frame.sourceSize.x; - uvtData[2] = uvtData[4] = uvtData[0] + width / frame.sourceSize.x; + graphicVisible = false; + drawRect.put(); + return; } - else + + // Texture coordinates (UVs) + final rectUX:Float = (drawRect.x - scrollX) / frame.sourceSize.x; + final rectVX:Float = rectUX + (drawRect.width-drawRect.x) / frame.sourceSize.x; + final rectUY:Float = (drawRect.y - scrollY) / frame.sourceSize.y; + final rectVY:Float = rectUY + (drawRect.height - drawRect.y) / frame.sourceSize.y; + + vertices[0] = drawRect.x; + vertices[2] = drawRect.width; + vertices[4] = drawRect.width; + vertices[6] = drawRect.x; + + uvtData[0] = rectUX; + uvtData[2] = rectVX; + uvtData[4] = rectVX; + uvtData[6] = rectUX; + + vertices[1] = drawRect.y; + vertices[3] = drawRect.y; + vertices[5] = drawRect.height; + vertices[7] = drawRect.height; + + uvtData[1] = rectUY; + uvtData[3] = rectUY; + uvtData[5] = rectVY; + uvtData[7] = rectVY; + + drawRect.put(); + } + + function getDrawRect(?result:FlxRect):FlxRect + { + if (result == null) + result = FlxRect.get(); + + final frame:FlxFrame = graphic.imageFrame.frame; + final sourceSizeX = FlxG.renderBlit ? graphic.bitmap.width : frame.sourceSize.x; + final sourceSizeY = FlxG.renderBlit ? graphic.bitmap.height : frame.sourceSize.y; + + result.x = (repeatX ? 0 : scrollX); + if (clipRect != null) { - vertices[0] = vertices[6] = FlxMath.bound(scrollX, 0, width); - vertices[2] = vertices[4] = FlxMath.bound(scrollX + frame.sourceSize.x, 0, width); - - if (vertices[2] - vertices[0] <= 0) - { - graphicVisible = false; - return; - } - - uvtData[0] = uvtData[6] = (vertices[0] - scrollX) / frame.sourceSize.x; - uvtData[2] = uvtData[4] = uvtData[0] + (vertices[2] - vertices[0]) / frame.sourceSize.x; + result.x += clipRect.x; } - - if (repeatY) + result.x = FlxMath.bound(result.x, 0, width); + + result.width = (repeatX ? result.x + width : scrollX + sourceSizeX); + if (clipRect != null) { - vertices[1] = vertices[3] = 0.0; - vertices[5] = vertices[7] = height; - - uvtData[1] = uvtData[3] = -scrollY / frame.sourceSize.y; - uvtData[5] = uvtData[7] = uvtData[1] + height / frame.sourceSize.y; + result.width = FlxMath.bound(result.width, clipRect.x, clipRect.right); } - else + result.width = FlxMath.bound(result.width, 0, width); + + result.y = (repeatY ? 0 : scrollY); + if (clipRect != null) { - vertices[1] = vertices[3] = FlxMath.bound(scrollY, 0, height); - vertices[5] = vertices[7] = FlxMath.bound(scrollY + frame.sourceSize.y, 0, height); - - if (vertices[5] - vertices[1] <= 0) - { - graphicVisible = false; - return; - } - - uvtData[1] = uvtData[3] = (vertices[1] - scrollY) / frame.sourceSize.y; - uvtData[5] = uvtData[7] = uvtData[1] + (vertices[5] - vertices[1]) / frame.sourceSize.y; + result.y += clipRect.y; } + result.y = FlxMath.bound(result.y, 0, height); + + result.height = (repeatY ? result.y + height : scrollY + sourceSizeY); + if (clipRect != null) + { + result.height = FlxMath.bound(result.height, clipRect.y, clipRect.bottom); + } + result.height = FlxMath.bound(result.height, 0, height); + + return result; } - - override function set_width(Width:Float):Float + + override function set_width(value:Float):Float { - if (Width <= 0) - return Width; - - if (Width != width) + if (value <= 0) + return value; + + if (value != width) regen = true; - - return super.set_width(Width); + + return super.set_width(value); } - - override function set_height(Height:Float):Float + + override function set_height(value:Float):Float { - if (Height <= 0) - return Height; - - if (Height != height) + if (value <= 0) + return value; + + if (value != height) regen = true; - - return super.set_height(Height); + + return super.set_height(value); } - - function set_scrollX(Value:Float):Float + + function set_scrollX(value:Float):Float { - if (Value != scrollX) + if (value != scrollX) regen = true; - - return scrollX = Value; + + return scrollX = value; } - - function set_scrollY(Value:Float):Float + + function set_scrollY(value:Float):Float { - if (Value != scrollY) + if (value != scrollY) regen = true; - - return scrollY = Value; + + return scrollY = value; } - - function set_repeatX(Value:Bool):Bool + + function set_repeatX(value:Bool):Bool { - if (Value != repeatX) + if (value != repeatX) regen = true; - - return repeatX = Value; + + return repeatX = value; } - - function set_repeatY(Value:Bool):Bool + + function set_repeatY(value:Bool):Bool { - if (Value != repeatY) + if (value != repeatY) regen = true; - - return repeatY = Value; + + return repeatY = value; } } From f76d8b22fd5fd25d2b65e92a56393fdf4ae14ece Mon Sep 17 00:00:00 2001 From: George Kurelic Date: Fri, 14 Jun 2024 12:51:44 -0500 Subject: [PATCH 06/35] fix deprec (#436) --- flixel/addons/effects/FlxTrail.hx | 3 ++- flixel/addons/nape/FlxNapeTilemap.hx | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/flixel/addons/effects/FlxTrail.hx b/flixel/addons/effects/FlxTrail.hx index 6f5112b1..e7caef35 100644 --- a/flixel/addons/effects/FlxTrail.hx +++ b/flixel/addons/effects/FlxTrail.hx @@ -244,7 +244,8 @@ class FlxTrail extends #if (flixel < "5.7.0") FlxSpriteGroup #else FlxSpriteCont function cacheValue(array:Array, value:T) { array.unshift(value); - FlxArrayUtil.setLength(array, _trailLength); + if (array.length > _trailLength) + array.resize(_trailLength); } public function resetTrail():Void diff --git a/flixel/addons/nape/FlxNapeTilemap.hx b/flixel/addons/nape/FlxNapeTilemap.hx index 49122efd..613841f9 100644 --- a/flixel/addons/nape/FlxNapeTilemap.hx +++ b/flixel/addons/nape/FlxNapeTilemap.hx @@ -42,7 +42,7 @@ class FlxNapeTilemap extends FlxTilemap { super.loadMapFromCSV(MapData, TileGraphic, TileWidth, TileHeight, AutoTile, StartingIndex, DrawIndex, CollideIndex); _binaryData = new Array(); - FlxArrayUtil.setLength(_binaryData, _data.length); + _binaryData.resize(_data.length); return this; } @@ -51,7 +51,7 @@ class FlxNapeTilemap extends FlxTilemap { super.loadMapFromArray(MapData, WidthInTiles, HeightInTiles, TileGraphic, TileWidth, TileHeight, AutoTile, StartingIndex, DrawIndex, CollideIndex); _binaryData = new Array(); - FlxArrayUtil.setLength(_binaryData, _data.length); + _binaryData.resize(_data.length); return this; } @@ -60,7 +60,7 @@ class FlxNapeTilemap extends FlxTilemap { super.loadMapFrom2DArray(MapData, TileGraphic, TileWidth, TileHeight, AutoTile, StartingIndex, DrawIndex, CollideIndex); _binaryData = new Array(); - FlxArrayUtil.setLength(_binaryData, _data.length); + _binaryData.resize(_data.length); return this; } From cdeb0de4e274bbced42656332a8436c25a398984 Mon Sep 17 00:00:00 2001 From: George Kurelic Date: Sat, 15 Jun 2024 18:58:16 -0500 Subject: [PATCH 07/35] fix Nape tilemap for 5.9.0+ (#437) * fix Nape tilemap for 5.9.0+ * update ci --- .github/workflows/main.yml | 5 ++--- flixel/addons/nape/FlxNapeTilemap.hx | 17 +++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c1dcd0ff..bbc23ba9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,7 +10,7 @@ jobs: build: strategy: matrix: - haxe-version: ["4.2.5", "4.3.3"] + haxe-version: ["4.2.5", "4.3.4"] target: [html5, hl, neko, flash, cpp] fail-fast: false runs-on: ubuntu-latest @@ -29,9 +29,8 @@ jobs: haxelib install haxelib 4.0.3 haxelib dev flixel-addons . - - uses: HaxeFlixel/setup-flixel@v1 + - uses: HaxeFlixel/setup-flixel@master with: - haxe-version: current flixel-versions: dev target: ${{matrix.target}} run-tests: true diff --git a/flixel/addons/nape/FlxNapeTilemap.hx b/flixel/addons/nape/FlxNapeTilemap.hx index 613841f9..bc8f529f 100644 --- a/flixel/addons/nape/FlxNapeTilemap.hx +++ b/flixel/addons/nape/FlxNapeTilemap.hx @@ -1,13 +1,13 @@ package flixel.addons.nape; -import flixel.addons.nape.FlxNapeSpace; import flixel.FlxG; +import flixel.addons.nape.FlxNapeSpace; import flixel.math.FlxPoint; import flixel.math.FlxRect; +import flixel.system.FlxAssets; +import flixel.tile.FlxBaseTilemap; import flixel.tile.FlxTilemap; import flixel.util.FlxArrayUtil; -import flixel.tile.FlxBaseTilemap; -import flixel.system.FlxAssets; import nape.geom.Vec2; import nape.phys.Body; import nape.phys.BodyType; @@ -100,11 +100,12 @@ class FlxNapeTilemap extends FlxTilemap var polygon:Polygon; for (index in tileIndices) { - var coords:Array = getTileCoords(index, false); - if (coords == null) - continue; - - for (point in coords) + #if (flixel >= "5.9.0") + final points = getAllTilePos(index); + #else + final points = getTileCoords(index, false); + #end + for (point in points) { polygon = new Polygon(vertices, mat); polygon.translate(Vec2.get(point.x, point.y)); From 346dd1284ebe9e6087a957a82b5aec733f7d2a33 Mon Sep 17 00:00:00 2001 From: George Kurelic Date: Thu, 11 Jul 2024 10:38:52 -0400 Subject: [PATCH 08/35] Flixel 5.9.0 compat (#440) --- .../addons/display/FlxExtendedMouseSprite.hx | 23 ++++++++++++++----- flixel/addons/ui/FlxSlider.hx | 14 +++++++---- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/flixel/addons/display/FlxExtendedMouseSprite.hx b/flixel/addons/display/FlxExtendedMouseSprite.hx index b501ff05..a2cebd3d 100644 --- a/flixel/addons/display/FlxExtendedMouseSprite.hx +++ b/flixel/addons/display/FlxExtendedMouseSprite.hx @@ -183,6 +183,8 @@ class FlxExtendedMouseSprite extends FlxSprite * Returns how many vertical pixels the mouse pointer is inside this sprite from the top left corner. Returns -1 if outside. */ public var mouseY(get, never):Int; + var viewX(get, never):Int; + var viewY(get, never):Int; #end var _snapOnDrag:Bool = false; @@ -549,14 +551,14 @@ class FlxExtendedMouseSprite extends FlxSprite if (_allowHorizontalDrag) { #if FLX_MOUSE - x = Math.floor(FlxG.mouse.screenX + scrollFactor.x * (FlxG.mouse.x - FlxG.mouse.screenX)) - _dragOffsetX; + x = Math.floor(viewX + scrollFactor.x * (FlxG.mouse.x - viewX)) - _dragOffsetX; #end } if (_allowVerticalDrag) { #if FLX_MOUSE - y = Math.floor(FlxG.mouse.screenY + scrollFactor.y * (FlxG.mouse.y - FlxG.mouse.screenY)) - _dragOffsetY; + y = Math.floor(viewY + scrollFactor.y * (FlxG.mouse.y - viewY)) - _dragOffsetY; #end } @@ -657,8 +659,8 @@ class FlxExtendedMouseSprite extends FlxSprite #if FLX_MOUSE if (_dragFromPoint == false) { - _dragOffsetX = Math.floor(FlxG.mouse.screenX + scrollFactor.x * (FlxG.mouse.x - FlxG.mouse.screenX) - x); - _dragOffsetY = Math.floor(FlxG.mouse.screenY + scrollFactor.y * (FlxG.mouse.y - FlxG.mouse.screenY) - y); + _dragOffsetX = Math.floor(viewX + scrollFactor.x * (FlxG.mouse.x - viewX) - x); + _dragOffsetY = Math.floor(viewY + scrollFactor.y * (FlxG.mouse.y - viewY) - y); } else { @@ -828,8 +830,8 @@ class FlxExtendedMouseSprite extends FlxSprite #if FLX_MOUSE function get_mouseOver():Bool { - return FlxMath.pointInCoordinates(Math.floor(FlxG.mouse.screenX + scrollFactor.x * (FlxG.mouse.x - FlxG.mouse.screenX)), - Math.floor(FlxG.mouse.screenY + scrollFactor.y * (FlxG.mouse.y - FlxG.mouse.screenY)), Math.floor(x), Math.floor(y), Math.floor(width), + return FlxMath.pointInCoordinates(Math.floor(viewX + scrollFactor.x * (FlxG.mouse.x - viewX)), + Math.floor(viewY + scrollFactor.y * (FlxG.mouse.y - viewY)), Math.floor(x), Math.floor(y), Math.floor(width), Math.floor(height)); } @@ -852,6 +854,15 @@ class FlxExtendedMouseSprite extends FlxSprite return -1; } + inline function get_viewX():Int + { + return #if (flixel < version("5.9.0")) FlxG.mouse.screenX #else FlxG.mouse.viewX #end; + } + + inline function get_viewY():Int + { + return #if (flixel < version("5.9.0")) FlxG.mouse.screenY #else FlxG.mouse.viewY #end; + } #end inline function get_rect():FlxRect diff --git a/flixel/addons/ui/FlxSlider.hx b/flixel/addons/ui/FlxSlider.hx index 9522d8e4..c8b97410 100644 --- a/flixel/addons/ui/FlxSlider.hx +++ b/flixel/addons/ui/FlxSlider.hx @@ -271,11 +271,17 @@ class FlxSlider extends #if (flixel < "5.7.0") FlxSpriteGroup #else FlxSpriteCon override public function update(elapsed:Float):Void { // Clicking and sound logic - #if (flixel >= "5.7.0") + #if (flixel >= version("5.7.0")) final camera = getCameras()[0];// else use this.camera #end - final mouse = FlxG.mouse.getScreenPosition(camera); - if (FlxMath.pointInFlxRect(mouse.x, mouse.y, _bounds)) + #if (flixel >= version("5.9.0")) + final viewX = FlxG.mouse.viewX; + final viewY = FlxG.mouse.viewY; + #else + final viewX = FlxG.mouse.screenX; + final viewY = FlxG.mouse.screenY; + #end + if (FlxMath.pointInFlxRect(viewX, viewY, _bounds)) { if (hoverAlpha != 1) { @@ -293,7 +299,7 @@ class FlxSlider extends #if (flixel < "5.7.0") FlxSpriteGroup #else FlxSpriteCon if (FlxG.mouse.pressed) { - handle.x = FlxG.mouse.screenX; + handle.x = viewX; updateValue(); #if FLX_SOUND_SYSTEM From 003353355ec8cdcc65c1ec986c4611b89762dd8e Mon Sep 17 00:00:00 2001 From: rich <87835336+richTrash21@users.noreply.github.com> Date: Mon, 15 Jul 2024 19:22:34 +0400 Subject: [PATCH 09/35] remove deprecation warning on flixel 5.9.0 (#441) --- flixel/addons/transition/FlxTransitionSprite.hx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/flixel/addons/transition/FlxTransitionSprite.hx b/flixel/addons/transition/FlxTransitionSprite.hx index f75b4120..a70b5901 100644 --- a/flixel/addons/transition/FlxTransitionSprite.hx +++ b/flixel/addons/transition/FlxTransitionSprite.hx @@ -143,7 +143,12 @@ class FlxTransitionSprite extends FlxSprite } animation.play(anim); + #if (flixel < version("5.9.0")) animation.finishCallback = onFinishAnim; + #else + if (!animation.onFinish.has(onFinishAnim)) + animation.onFinish.add(onFinishAnim); + #end status = Status; } From 8649eb692a0cfb95b2f0bee2afd094dae13415e8 Mon Sep 17 00:00:00 2001 From: Mihai Alexandru <77043862+MAJigsaw77@users.noreply.github.com> Date: Tue, 3 Sep 2024 16:29:52 +0000 Subject: [PATCH 10/35] Refactor Shader Metadata Handling and Improve Readability. (#442) * Add `FlxRuntimeShaderMacro`. * Improve `FlxRuntimeShader`. * Oops * Oops v2 * More readable `toString`. * Fix grammar. * It doesn't seem to trace anything nice so revert. * Misspell fix --- flixel/addons/display/FlxRuntimeShader.hx | 278 +++++------------- .../system/macros/FlxRuntimeShaderMacro.hx | 78 +++++ 2 files changed, 156 insertions(+), 200 deletions(-) create mode 100644 flixel/addons/system/macros/FlxRuntimeShaderMacro.hx diff --git a/flixel/addons/display/FlxRuntimeShader.hx b/flixel/addons/display/FlxRuntimeShader.hx index 8134f9c5..8f584785 100644 --- a/flixel/addons/display/FlxRuntimeShader.hx +++ b/flixel/addons/display/FlxRuntimeShader.hx @@ -5,7 +5,9 @@ package flixel.addons.display; #error "FlxRuntimeShader isn't available with nme or flash." #end #else +import flixel.addons.system.macros.FlxRuntimeShaderMacro; import flixel.graphics.tile.FlxGraphicsShader; +import flixel.util.FlxStringUtil; #if lime import lime.utils.Float32Array; #end @@ -28,140 +30,6 @@ using StringTools; */ class FlxRuntimeShader extends FlxGraphicsShader { - private static final BASE_VERTEX_HEADER:String = "attribute float openfl_Alpha; - attribute vec4 openfl_ColorMultiplier; - attribute vec4 openfl_ColorOffset; - attribute vec4 openfl_Position; - attribute vec2 openfl_TextureCoord; - - varying float openfl_Alphav; - varying vec4 openfl_ColorMultiplierv; - varying vec4 openfl_ColorOffsetv; - varying vec2 openfl_TextureCoordv; - - uniform mat4 openfl_Matrix; - uniform bool openfl_HasColorTransform; - uniform vec2 openfl_TextureSize;"; - - private static final BASE_VERTEX_BODY:String = "openfl_Alphav = openfl_Alpha; - openfl_TextureCoordv = openfl_TextureCoord; - - if (openfl_HasColorTransform) - { - openfl_ColorMultiplierv = openfl_ColorMultiplier; - openfl_ColorOffsetv = openfl_ColorOffset / 255.0; - } - - gl_Position = openfl_Matrix * openfl_Position;"; - - private static final BASE_VERTEX_SOURCE:String = "#pragma header - - attribute float alpha; - attribute vec4 colorMultiplier; - attribute vec4 colorOffset; - uniform bool hasColorTransform; - - void main(void) - { - #pragma body - - openfl_Alphav = openfl_Alpha * alpha; - - if (hasColorTransform) - { - openfl_ColorOffsetv = colorOffset / 255.0; - openfl_ColorMultiplierv = colorMultiplier; - } - }"; - - private static final BASE_FRAGMENT_HEADER:String = "varying float openfl_Alphav; - varying vec4 openfl_ColorMultiplierv; - varying vec4 openfl_ColorOffsetv; - varying vec2 openfl_TextureCoordv; - - uniform bool openfl_HasColorTransform; - uniform vec2 openfl_TextureSize; - uniform sampler2D bitmap; - - uniform bool hasTransform; - uniform bool hasColorTransform; - - vec4 flixel_texture2D(sampler2D bitmap, vec2 coord) - { - vec4 color = texture2D(bitmap, coord); - - if (!hasTransform) - { - return color; - } - - if (color.a == 0.0) - { - return vec4(0.0, 0.0, 0.0, 0.0); - } - - if (!hasColorTransform) - { - return color * openfl_Alphav; - } - - color = vec4(color.rgb / color.a, color.a); - - mat4 colorMultiplier = mat4(0); - colorMultiplier[0][0] = openfl_ColorMultiplierv.x; - colorMultiplier[1][1] = openfl_ColorMultiplierv.y; - colorMultiplier[2][2] = openfl_ColorMultiplierv.z; - colorMultiplier[3][3] = openfl_ColorMultiplierv.w; - - color = clamp(openfl_ColorOffsetv + (color * colorMultiplier), 0.0, 1.0); - - if (color.a > 0.0) - { - return vec4(color.rgb * color.a * openfl_Alphav, color.a * openfl_Alphav); - } - - return vec4(0.0, 0.0, 0.0, 0.0); - }"; - - private static final BASE_FRAGMENT_BODY:String = "vec4 color = texture2D(bitmap, openfl_TextureCoordv); - - if (color.a == 0.0) - { - gl_FragColor = vec4 (0.0, 0.0, 0.0, 0.0); - } - else if (openfl_HasColorTransform) - { - color = vec4 (color.rgb / color.a, color.a); - - mat4 colorMultiplier = mat4 (0); - colorMultiplier[0][0] = openfl_ColorMultiplierv.x; - colorMultiplier[1][1] = openfl_ColorMultiplierv.y; - colorMultiplier[2][2] = openfl_ColorMultiplierv.z; - colorMultiplier[3][3] = 1.0; // openfl_ColorMultiplierv.w; - - color = clamp (openfl_ColorOffsetv + (color * colorMultiplier), 0.0, 1.0); - - if (color.a > 0.0) - { - gl_FragColor = vec4 (color.rgb * color.a * openfl_Alphav, color.a * openfl_Alphav); - } - else - { - gl_FragColor = vec4 (0.0, 0.0, 0.0, 0.0); - } - } - else - { - gl_FragColor = color * openfl_Alphav; - }"; - - private static final BASE_FRAGMENT_SOURCE:String = "#pragma header - - void main(void) - { - gl_FragColor = flixel_texture2D(bitmap, openfl_TextureCoordv); - }"; - /** * Creates a `FlxRuntimeShader` with specified shader sources. * If none is provided, it will use the default shader sources. @@ -174,12 +42,12 @@ class FlxRuntimeShader extends FlxGraphicsShader if (fragmentSource != null && fragmentSource.length > 0) glFragmentSource = fragmentSource; else - glFragmentSource = BASE_FRAGMENT_SOURCE; + glFragmentSource = FlxRuntimeShaderMacro.retrieveMetadata('glFragmentSource', false); if (vertexSource != null && vertexSource.length > 0) glVertexSource = vertexSource; else - glVertexSource = BASE_VERTEX_SOURCE; + glVertexSource = FlxRuntimeShaderMacro.retrieveMetadata('glVertexSource', false); super(); } @@ -192,15 +60,15 @@ class FlxRuntimeShader extends FlxGraphicsShader */ public function setFloat(name:String, value:Float):Void { - var prop:ShaderParameter = Reflect.field(data, name); + final shaderParameter:ShaderParameter = Reflect.field(data, name); - if (prop == null) + if (shaderParameter == null) { - FlxG.log.warn('Shader float property "$name" not found.'); + FlxG.log.warn('Shader float parameter "$name" not found.'); return; } - prop.value = [value]; + shaderParameter.value = [value]; } /** @@ -210,15 +78,15 @@ class FlxRuntimeShader extends FlxGraphicsShader */ public function getFloat(name:String):Null { - var prop:ShaderParameter = Reflect.field(data, name); + final shaderParameter:ShaderParameter = Reflect.field(data, name); - if (prop == null) + if (shaderParameter == null) { - FlxG.log.warn('Shader float property "$name" not found.'); + FlxG.log.warn('Shader float parameter "$name" not found.'); return null; } - return prop.value[0]; + return shaderParameter.value[0]; } /** @@ -229,15 +97,15 @@ class FlxRuntimeShader extends FlxGraphicsShader */ public function setFloatArray(name:String, value:Array):Void { - var prop:ShaderParameter = Reflect.field(data, name); + final shaderParameter:ShaderParameter = Reflect.field(data, name); - if (prop == null) + if (shaderParameter == null) { - FlxG.log.warn('Shader float[] property "$name" not found.'); + FlxG.log.warn('Shader float[] parameter "$name" not found.'); return; } - prop.value = value; + shaderParameter.value = value; } /** @@ -247,15 +115,15 @@ class FlxRuntimeShader extends FlxGraphicsShader */ public function getFloatArray(name:String):Null> { - var prop:ShaderParameter = Reflect.field(data, name); + final shaderParameter:ShaderParameter = Reflect.field(data, name); - if (prop == null) + if (shaderParameter == null) { - FlxG.log.warn('Shader float[] property "$name" not found.'); + FlxG.log.warn('Shader float[] parameter "$name" not found.'); return null; } - return prop.value; + return shaderParameter.value; } /** @@ -266,15 +134,15 @@ class FlxRuntimeShader extends FlxGraphicsShader */ public function setInt(name:String, value:Int):Void { - var prop:ShaderParameter = Reflect.field(data, name); + final shaderParameter:ShaderParameter = Reflect.field(data, name); - if (prop == null) + if (shaderParameter == null) { - FlxG.log.warn('Shader int property "$name" not found.'); + FlxG.log.warn('Shader int parameter "$name" not found.'); return; } - prop.value = [value]; + shaderParameter.value = [value]; } /** @@ -284,15 +152,15 @@ class FlxRuntimeShader extends FlxGraphicsShader */ public function getInt(name:String):Null { - var prop:ShaderParameter = Reflect.field(data, name); + final shaderParameter:ShaderParameter = Reflect.field(data, name); - if (prop == null) + if (shaderParameter == null) { - FlxG.log.warn('Shader int property "$name" not found.'); + FlxG.log.warn('Shader int parameter "$name" not found.'); return null; } - return prop.value[0]; + return shaderParameter.value[0]; } /** @@ -303,15 +171,15 @@ class FlxRuntimeShader extends FlxGraphicsShader */ public function setIntArray(name:String, value:Array):Void { - var prop:ShaderParameter = Reflect.field(data, name); + final shaderParameter:ShaderParameter = Reflect.field(data, name); - if (prop == null) + if (shaderParameter == null) { - FlxG.log.warn('Shader int[] property "$name" not found.'); + FlxG.log.warn('Shader int[] parameter "$name" not found.'); return; } - prop.value = value; + shaderParameter.value = value; } /** @@ -321,15 +189,15 @@ class FlxRuntimeShader extends FlxGraphicsShader */ public function getIntArray(name:String):Null> { - var prop:ShaderParameter = Reflect.field(data, name); + final shaderParameter:ShaderParameter = Reflect.field(data, name); - if (prop == null) + if (shaderParameter == null) { - FlxG.log.warn('Shader int[] property "$name" not found.'); + FlxG.log.warn('Shader int[] parameter "$name" not found.'); return null; } - return prop.value; + return shaderParameter.value; } /** @@ -340,15 +208,15 @@ class FlxRuntimeShader extends FlxGraphicsShader */ public function setBool(name:String, value:Bool):Void { - var prop:ShaderParameter = Reflect.field(data, name); + final shaderParameter:ShaderParameter = Reflect.field(data, name); - if (prop == null) + if (shaderParameter == null) { - FlxG.log.warn('Shader bool property "$name" not found.'); + FlxG.log.warn('Shader bool parameter "$name" not found.'); return; } - prop.value = [value]; + shaderParameter.value = [value]; } /** @@ -358,15 +226,15 @@ class FlxRuntimeShader extends FlxGraphicsShader */ public function getBool(name:String):Null { - var prop:ShaderParameter = Reflect.field(data, name); + final shaderParameter:ShaderParameter = Reflect.field(data, name); - if (prop == null) + if (shaderParameter == null) { - FlxG.log.warn('Shader bool property "$name" not found.'); + FlxG.log.warn('Shader bool parameter "$name" not found.'); return null; } - return prop.value[0]; + return shaderParameter.value[0]; } /** @@ -377,15 +245,15 @@ class FlxRuntimeShader extends FlxGraphicsShader */ public function setBoolArray(name:String, value:Array):Void { - var prop:ShaderParameter = Reflect.field(data, name); + final shaderParameter:ShaderParameter = Reflect.field(data, name); - if (prop == null) + if (shaderParameter == null) { - FlxG.log.warn('Shader bool[] property "$name" not found.'); + FlxG.log.warn('Shader bool[] parameter "$name" not found.'); return; } - prop.value = value; + shaderParameter.value = value; } /** @@ -395,57 +263,65 @@ class FlxRuntimeShader extends FlxGraphicsShader */ public function getBoolArray(name:String):Null> { - var prop:ShaderParameter = Reflect.field(data, name); + final shaderParameter:ShaderParameter = Reflect.field(data, name); - if (prop == null) + if (shaderParameter == null) { - FlxG.log.warn('Shader bool[] property "$name" not found.'); + FlxG.log.warn('Shader bool[] parameter "$name" not found.'); return null; } - return prop.value; + return shaderParameter.value; } /** - * Modify a bitmap data parameter of the shader. + * Modify a bitmap data input of the shader. * * @param name The name of the parameter to modify. * @param value The new value to use. */ public function setSampler2D(name:String, value:BitmapData):Void { - var prop:ShaderInput = Reflect.field(data, name); + final shaderInput:ShaderInput = Reflect.field(data, name); - if (prop == null) + if (shaderInput == null) { - FlxG.log.warn('Shader sampler2D property "$name" not found.'); + FlxG.log.warn('Shader sampler2D input "$name" not found.'); return; } - prop.input = value; + shaderInput.input = value; } /** - * Retrieve a bitmap data parameter of the shader. + * Retrieve a bitmap data input of the shader. * * @param name The name of the parameter to retrieve. * @return The value of the parameter. */ public function getSampler2D(name:String):Null { - var prop:ShaderInput = Reflect.field(data, name); + final shaderInput:ShaderInput = Reflect.field(data, name); - if (prop == null) + if (shaderInput == null) { - FlxG.log.warn('Shader sampler2D property "$name" not found.'); + FlxG.log.warn('Shader sampler2D input "$name" not found.'); return null; } - return prop.input; + return shaderInput.input; + } + + /** + * Convert the shader to a readable string name. Useful for debugging. + */ + public function toString():String + { + return FlxStringUtil.getDebugString([for (field in Reflect.fields(data)) LabelValuePair.weak(field, Reflect.field(data, field))]); } - // Overrides - @:noCompletion private override function __processGLData(source:String, storageType:String):Void + @:noCompletion + private override function __processGLData(source:String, storageType:String):Void { var lastMatch = 0, position, regex, name, type; @@ -630,10 +506,11 @@ class FlxRuntimeShader extends FlxGraphicsShader } } - @:noCompletion private override function set_glFragmentSource(value:String):String + @:noCompletion + private override function set_glFragmentSource(value:String):String { if (value != null) - value = value.replace("#pragma header", BASE_FRAGMENT_HEADER).replace("#pragma body", BASE_FRAGMENT_BODY); + value = value.replace("#pragma header", FlxRuntimeShaderMacro.retrieveMetadata('glFragmentHeader')).replace("#pragma body", FlxRuntimeShaderMacro.retrieveMetadata('glFragmentBody')); if (value != __glFragmentSource) __glSourceDirty = true; @@ -641,10 +518,11 @@ class FlxRuntimeShader extends FlxGraphicsShader return __glFragmentSource = value; } - @:noCompletion private override function set_glVertexSource(value:String):String + @:noCompletion + private override function set_glVertexSource(value:String):String { if (value != null) - value = value.replace("#pragma header", BASE_VERTEX_HEADER).replace("#pragma body", BASE_VERTEX_BODY); + value = value.replace("#pragma header", FlxRuntimeShaderMacro.retrieveMetadata('glVertexHeader')).replace("#pragma body", FlxRuntimeShaderMacro.retrieveMetadata('glVertexBody')); if (value != __glVertexSource) __glSourceDirty = true; diff --git a/flixel/addons/system/macros/FlxRuntimeShaderMacro.hx b/flixel/addons/system/macros/FlxRuntimeShaderMacro.hx new file mode 100644 index 00000000..91c9630b --- /dev/null +++ b/flixel/addons/system/macros/FlxRuntimeShaderMacro.hx @@ -0,0 +1,78 @@ +package flixel.addons.system.macros; + +import haxe.macro.Context; +import haxe.macro.Expr; +import haxe.macro.Type; + +using haxe.macro.ExprTools; + +class FlxRuntimeShaderMacro +{ + /** + * Retrieves the value of a specified metadata tag (only `String` values) from the current class + * or any of its superclasses. The function searches the fields of the class + * for the specified metadata and returns its value as a macro expression. + * If `overwrite` is set to `false`, it will use the first non-null `String` value + * found and ignore any subsequent values. + * + * @param metaName The name of the metadata tag to retrieve. + * @param overwrite If `true`, the metadata value will be concatenated when found; if `false`, only the first non-null value will be used. + * @return The value of the specified metadata as an expression, or `null` if not found. + */ + public static macro function retrieveMetadata(metaName:String, overwrite:Bool = true):Expr + { + var result:String = null; + + final localClass:ClassType = Context.getLocalClass().get(); + + result = checkClassForMetadata(localClass, metaName, overwrite, result); + + var parent:ClassType = localClass.superClass != null ? localClass.superClass.t.get() : null; + + while (parent != null) + { + result = checkClassForMetadata(parent, metaName, overwrite, result); + + parent = parent.superClass != null ? parent.superClass.t.get() : null; + } + + // Context.info('Retrieving $metaName: $result', Context.currentPos()); + + return macro $v{result}; + } + + #if macro + @:noCompletion + private static function checkClassForMetadata(classType:ClassType, metaName:String, overwrite:Bool, currentResult:String):String + { + var result:String = currentResult; + + for (field in [classType.constructor.get()].concat(classType.fields.get())) + { + for (meta in field.meta.get()) + { + if (meta.name == metaName || meta.name == ':' + metaName) + { + final value:Dynamic = meta.params[0].getValue(); + + if (!(value is String)) + continue; + + if (overwrite) + result = result == null ? value : '$value\n$result'; + else if (result == null) + { + result = value; + break; + } + } + } + + if (!overwrite && result != null) + break; + } + + return result; + } + #end +} From bbb020a19895973e33ea55b5ca0e9c2d6198bc21 Mon Sep 17 00:00:00 2001 From: Vortex <73261680+Vortex2Oblivion@users.noreply.github.com> Date: Fri, 27 Sep 2024 14:46:26 +0000 Subject: [PATCH 11/35] oxipng all assets (#445) --- assets/images/napeDebug.png | Bin 280 -> 143 bytes assets/images/transitions/circle.png | Bin 824 -> 299 bytes .../images/transitions/diagonal_gradient.png | Bin 3812 -> 730 bytes assets/images/transitions/diamond.png | Bin 788 -> 236 bytes assets/images/transitions/square.png | Bin 383 -> 209 bytes 5 files changed, 0 insertions(+), 0 deletions(-) diff --git a/assets/images/napeDebug.png b/assets/images/napeDebug.png index fd7746890a9fe93fd176548ad6d3081e358cbcf7..04e1230525ad684674074e3af692661e838f3f8c 100644 GIT binary patch delta 125 zcmV-@0D}LR0*?WZ8FmB!000A}zpVfO09HvvK~#9!V_;zT4+MW>8Gr!7WYtnNJN7(=w00000NkvXXu0mjfg4r~| delta 264 zcmeBYoWV3fvYw5BfnnvEay1~umgMd30;GZ9r}OT5AjMhW5n0T@z%2~Ij105pNB{-d zOFVsD+3)g*@$*=17M?f(C?uO15>euupPQSSR|4cRFgO>bCYGe8D3oWGWGJ|M`Ua%v zrLqIXYdl>XLnJQup5MsZY#`F|@O8arWCNp-i&;X`nge1z6LfDVcwY#000J1OjJex|NsC0|5beTYybcN0(4SNQ~v{=`V;RB8b*lu9GfCW6Gzzgg(pdbZ^z)66&$bg1?M}Gt47~qkSdo==m9b|;J zFu(}(F?8hFj8WoJFX2ctAd z1~eoEMj_HXv@s-}xgL{93XH;fxFdQThr$Y delta 813 zcmV+|1JeAf0=Nc{7=H)`0000h7Q;0F0004VQb$4nuFf3k0008=NklNv73QnbziiVbaIvRNbDQAU?_U4Hq8Q2_R5I>l<~H>BCD)Kkh+@?ZE_s z6aomei<&@us`afArVlS8--8fQd#?upfGPdSZU72de?BkRM_)fvFZvoiH>9I$M{I_B zH6k}+n?C%QfPYX^fKW;F1mbng=;!v>lx%dsPy`Up zS~njN^?E$E_jRgl{Fz4(8L!d0`7=Y6pAG0j0HM`h;OH4d&Rnli(VpA$S^$qAfYh`N9uYw#;|PQpjzEBL0)NOg(G!SQ%`;!CDC-`KteZeb zyO#!_8v*3J?F8b5J6A)++J%PzM0?NDx zCG#k6w41r%@k~IVhSoRg)lKg1g<*s#%ux>}F!4RufF>q@Ks|eJ+PnW}opA(ockR|5 z96`nQU;~<%00JC2yGV>Og%N=M8!-Txz)VU20a_d_7(MQ9m@NQh9YOW1ebj>^s0j%m rKqe&uP`fGtXvQO`jN0!#qy~V$DG=5Gqx!;;00000NkvXXu0mjf{V#S+ diff --git a/assets/images/transitions/diagonal_gradient.png b/assets/images/transitions/diagonal_gradient.png index 9555ea7d1f3e964097e65ad71352654633cd1272..b14b8fe71cc12f843343f784eb9215af52e509f6 100644 GIT binary patch literal 730 zcmeAS@N?(olHy`uVBq!ia0y~yV6+3W8#tJObvddIOO z$S?T+@9&@AzkdGs{_X3R&!0Yic>nJ0o7b;izIguZ>681r+nejF%Zu}~)05+)!-M_3 z-JR{N&5iZ7)s^L?#fAB~*_j#U3w2ln1FO~3#WAGf*4qn?yayZvj%={h{9`!%@Uxo| zO*i-3wtsuIyXsQL`@F@r8_jPCR}XD!?{@23vmL70-b!vszc9~n5HaNa_9-#slqRzS PW0%3x)z4*}Q$iB}y{N6y literal 3812 zcmW-kc|6nq1IITxw$PBHlns4dNnsT~<=hxjxyqd@$DFyTkuMW-Bv(Y_h*Dbagdt~g z<(6_xu8EAW`3k?!XaDT++H=o6AMd>%pMOR&zJcRCDtZ(Gf$$pWV@)9ts0OejVVuBg zYBI;a5XezAJO*QI?Cu-r8{qDHPuu{55x?i}>x%bsfk5<0xlcpP&Bujf2Ph%;3;GlV z!gG1kz?qK6%vJP{JL0nA?+wh&csKO6_W8Wkq)1bPsH=v9Ry8G z!qAns0~Z!3nVB;vw{XuF6o$IndiYp9EbzH0th%R#XHZn5I7SG~=BYtFPx?v}Y+ z&1-tLHubMRkGa;4jp;3Ry4nk^H2WM}Cp~D;e;=jE;3?b=uh`G9zpoBSv@-DyCRB8+ zbL2atA)AcmiHis}ak&+ny%q~b0clCfK>Tw#TB*Cg|MH^0W#?SfLBS!7uCg`CNbH~; z$Reh4(^>>ejxNvDR}7gA#}Mwja;9|@oZ1hIJM^2if6=B$OlzSAgcio#8%*~LBNYb! znXrYbe#56q4qI!?T(Rvni#5!HZtlqo$C&1ah**N80Sg9-#_RUg?ORC!2H&PZVXf@3GTZ8qbcWTR+*G&gnao{%j9 z75$ycO%GyTzRIQ<>&73+$1hs==!67MJ1-ntn8Hp>F2ls97`{Z}wdH|B@eMTg13^?qC9Zh`96huCg|5U-IcB3-jTJKz5FwSq-C!_ z{(6C_I3J9?&Wv7i(Ts!Q2~j;R=je@2tYfN@r($u|e%9^YuwHRj9&|#7lTbOQC6|}@ zQ<9KFLivM=uJWaF%!J>n&1wEu@#wCwxkA6IwotM_h+v4Y3Nfdp?`JXHI`j%bJTGaW zBa?cHZpVcFRgK6Kzy4K1m9G`nO-v%5)#0WJP$j5BDf;FzlLFBs+c{1rp$*lIqkiek z$Nyl4WIm=i>FW#y4>=Bn4XF>wD?cl{9xRPZB!*-Y7=<~+AzS1{L0o*Fk7?U=dU zb-AnH(&iFy*Yobc=f_|9vM=|=J~fmt%FUlDpk$go4M_R<**ncM2D9eJ!Emz z#JVU@zw{>lww3O;YyZQ9z2DSbzzb!^R~c3s#(c5Lkh>NCrs%9ijn4M-6?FZ%shB*& z_l1nFZX@XedwNfJwDU{z;qaE7dYV^Ff5b&A{v+=X7wGudShbW z)%WfTr-vgE{-yn<{X>t6osX>?Gm2G<<;T@KKmV!S#V>P7ro@ageB6!Ktu~2L{ zT4j$?rUh?B_+$Wdgn`l$MG^&EA##zgv6i8{>?ny%3HTXcM%74S9apy3=NiAI28W z7Q&%%bO>%Ow&koSttwk5&BVu9=||}M%1T|lyyd=}qc~n(S zv+TBXUF}v4w8j1ytV8r_xvB?To|cKQ|I5>pR1>@Xe65%4aMSO!>cVppdn|F2*o}>C zw&Wr zBweX;(r5ekD4L)d;Vhm0QMt-YOK9I{8y*ys6H{dM*y@s%Z&h2>%|-nsy8nOv+W{XI zZp?=*hBt85JgOPvnJ?Qe$d9R`f<;)3$~g~pFG=Al88xiryibFRFJ(8 zN|AFivncSVK5DJ#yOWcX@J~Ebx6Nkt!-$Wr_kz#bjBADWdhN}Q)j3b85~&O+l%ZAe zc$3mz$x2Sl8vOfSPg&2g)t1%SwYsWd{8EZPZL@K+!VcOnDZeb#A@n|^>vxki-pZ;W zwj5XI_VP>fn}GL=(_#-a&1G)Qkp14_r(RY2esB7?zq*g%dXA_bIXnJzq)GF$dgzD# zw`9tlhNexvMdPu8SG-hS%8YW8w}-jcIsD(ytdP)o{m&_R(m5q1MTWSZY^tl{pOK0z zXO*UaLvmHe>tb@on6>}u(;~=+JK;YVAvc)0%NpIP-!`Mi5POrd-W_Yk4}A8FaHd`Q zZstp~ax-RAb~|?7nxcoH%<4&6HoDU7OTR$BaGsrNW{A%Yp>vnUO%my>cWyx0CN_q? zm8pAmm^xD|pQ(Pqel>`u9@0VmLVFu*ansJ(_E()xIE6Cs=KY$?+ZU7nz1#cF<;AJy zJ2Aa1YO59+{29O8dYzGz>AU-*KH|Z*wNF=i)_;gSK8gI;({v^5!uE8}o)u#W zM^US<#PU40Qn5^j3v2X|qD&ZS^`%&zL?Ji|#qu0kBVR19032mxu{ZkiHN*m0H_0o9|)p} z2qX&tMg$1bh=|`H5Ce>05NHz-J}jWmoOK4lCn92c958YL!y5z!M8q8y0E~wq=q4f# z#sI?(Fg^r_V%H^Gxn^qG&fFIf&{&SeZJn1Utdhl$gYtYD!JwA`Lp68+Jf4^=25K&? zT|VFyKw+pWcz|I_&AmLdR81|R?h)*1X-yWBy67lt|m7A{K=62ZcEpujo< zx)o=01}&S^1h3#I1_)G%bicPCXoI0Xus}L}BZURvsCDp%s>aYa zSmzjqq29AV27QCo7>1)Bvd%%IZX1K%z*L3idK87seRz6Shz Og&64Gz>;+wqW%wRQEsFF diff --git a/assets/images/transitions/diamond.png b/assets/images/transitions/diamond.png index 4abb5cc8869a3ffa7fe7d12fb5a015137da0f007..87f8100ab8dbc19b3fad33f36e6f6604111eada1 100644 GIT binary patch delta 220 zcmbQj_J(nSL_H%j0|SHLjleP>#TMWb;`$#9LTkR}07aNeg8YL2Gd$gH;05GO_H=O! zskpWE+D6_M0|C~Hjw~%x95kn}Ee+&S6%bPR=bCZYS;~er;{2wkrj?gX)sN4}sb$)k zV3%-b0lUKgUDKb;nN;g>P0w6M-N%|oyM#gG=;Y8K8%|eMk*NV8PJtKoFUZ{xcFl{_YcORvy~=E{XS9eSYFTf&JBe%k>}aKW`YtQ0J@1USKjm`x*0_dh7WW zeN$ySpRY(MvpF7e>`J!9SGikH>t7U#2r!7+-LLuo(KB6umBm7wZIRjJ8@CJ7rt`2Vo&WK4KQk9cff|p?`5dF}#)$K23UM7wOji;W zvWz?T%BGi{Oi=i==ijIMjI1mx4mx}}qqbS1<7*BZQ~%7c`t!k@`9tSq4t9rJFch%s-R zch-S{e{sVcUgp5ro^Re-Z1!ejo_PFe|8<}kH}gf~*=Ldzu5Fg&c#x{0@I3+9MLYg9 zCW=h3LUJ{O&8e5HEsZPAs(dS(b5pgs@x~ZH_va&ER$eeh|`sDTb>qqWQoo~Bw zyAj0uJu9ylyt3VL`oBPfcwrUe%qOpBzn_2S_vHJk-|x-zP4k_*ce3eM^Ep-g{$hfv z91<>!JK33o;qIL5{*$3C(BWKb<4d4oLxa~hd3Zh;iA>m>m;evCgijjs6}DU)s|*Zm zH=opDOS7Hb$SCK=cu-bi20Y+q*qmZN7U)o*#p45xg2?k}2_LLP1m^Id+Sb6tB$Aj= zl{Pt&=S-CubMx^)hXyMipIo(#+aI6NljQM{dz#EFBJjXRVg@*LH_tnJU=Jk1m%$@k z?fmQ0$4fO87_yL@B%SCs$& diff --git a/assets/images/transitions/square.png b/assets/images/transitions/square.png index a6667f2c76b07cdfd9cf702f8b6b70fc53df780a..be99972044382c2fb9b491e78f12d64e16dda47e 100644 GIT binary patch delta 193 zcmey*bdhm_L_H%j0|SHLjleP>#TMWb;`$#9LTkR}07aNeg8YL2Gd$gH;05GWc)B=- zRNOjxZKEKApor_mY!)X~4cE*m%S2Q;SdZlinlETDZhmiDQ^c6iz~`vQyvRvSrB&wy z*UbQtq6Jz{oQgR-maupBXiS``vT2h`*~Akog{*eIWlY-knEzV*MtL*)Z|~(7^fSqO r*~!%g{66*J>C@~h;=BGw9pK-kJIklw(Ut8$M=*H0`njxgN@xNAiv3Lf delta 368 zcmcb}_@8NlL_G%^0|SG$*kMy3#aJBV?!>U}oXkrg+tSm;F{EP7+q;%RhYSQ<9T)8Q zKh?K|nfcf!Gvl!DtV`bP*J9npf4G2|VVAHJ!}$}385a}>3KsBNm8&=~ytsQ)P{8h= zB!>Wlk%cx>PrVQmOT+fX$_IWJ3n?({lo4e-Ha~=gfkF@T8G|mb=P>xk zFh#-P+H8=jhE}dFl<>Zr@-Lgcy)e)O*M#SR+;pJv0*BUhwmfyhD$(G zGLP^x%;pr(60~O!S9C~_{K&jPnUU#dr~HE=77hdVKMd^x3Jzh9*!6rG7;1#<3k(>U zCUpN;$PM(4`NzYVEF27y9rMoty;-GR#{{H0F6aK)!*IAyq}kb3cm^;`89ZJ6T-G@y GGywn@-GImd From 34553216f635bd450a33a1edd243b5aedfd52ed3 Mon Sep 17 00:00:00 2001 From: George Kurelic Date: Mon, 30 Sep 2024 11:29:12 -0500 Subject: [PATCH 12/35] Refactor FlxPieDial, add FlxRadialGauge (#444) * refactor FlxPieDial, add FlxPieGauge * add FlxPieGuageShape, rename makePieDialGraphic * remove guages on flash * fix spelling and rename FlxPieGuage to FlxRadialGauge * rename makePieDialGraphic to makeShapeGraphic * use floats * improve doc --- flixel/addons/display/FlxPieDial.hx | 522 ++++++++++++++---------- flixel/addons/display/FlxRadialGauge.hx | 155 +++++++ 2 files changed, 462 insertions(+), 215 deletions(-) create mode 100644 flixel/addons/display/FlxRadialGauge.hx diff --git a/flixel/addons/display/FlxPieDial.hx b/flixel/addons/display/FlxPieDial.hx index 0c50c9da..e5e8d382 100644 --- a/flixel/addons/display/FlxPieDial.hx +++ b/flixel/addons/display/FlxPieDial.hx @@ -1,18 +1,23 @@ package flixel.addons.display; import flixel.FlxSprite; +import flixel.graphics.FlxGraphic; +import flixel.graphics.tile.FlxGraphicsShader; import flixel.math.FlxMath; import flixel.math.FlxPoint; +import flixel.util.FlxBitmapDataPool; import flixel.util.FlxColor; +import flixel.util.FlxSpriteUtil; import openfl.display.BitmapData; import openfl.display.BitmapDataChannel; import openfl.display.BlendMode; +import openfl.geom.Point; +import openfl.geom.Rectangle; using flixel.util.FlxSpriteUtil; /** * A dynamic shape that fills up the way a pie chart does. Useful for timers and other things. - * @author larsiusprime */ class FlxPieDial extends FlxSprite { @@ -20,269 +25,356 @@ class FlxPieDial extends FlxSprite * A value between 0.0 (empty) and 1.0 (full) */ public var amount(default, set):Float; - - var pieFrames:Int = 0; - - public function new(X:Float, Y:Float, Radius:Int, Color:FlxColor = FlxColor.WHITE, Frames:Int = 36, ?Shape:FlxPieDialShape, Clockwise:Bool = true, - InnerRadius:Int = 0) + + public function new(x = 0.0, y = 0.0, radius:Int, color = FlxColor.WHITE, frames = 36, ?shape:FlxPieDialShape, clockwise = true, innerRadius = 0) { - if (Shape == null) - Shape = CIRCLE; - super(X, Y); - makePieDialGraphic(Radius, Color, Frames, Shape, Clockwise, InnerRadius); + if (shape == null) + shape = CIRCLE; + + super(x, y); + getPieDialGraphic(radius, color, frames, shape, clockwise, innerRadius); amount = 1.0; } override public function draw():Void { - if (amount == 0) + if (amount * animation.numFrames < 1) return; + super.draw(); } - - function makePieDialGraphic(Radius:Int, Color:FlxColor, Frames:Int, Shape:FlxPieDialShape, Clockwise:Bool, InnerRadius:Int) + + function getPieDialGraphic(radius:Int, color:FlxColor, frames:Int, shape:FlxPieDialShape, clockwise:Bool, innerRadius:Int) { - pieFrames = Frames; - var key:String = "pie_dial_" + Color.toHexString() + "_" + Radius + "_" + Frames + "_" + Shape + "_" + Clockwise + "_" + InnerRadius; - var W = Radius * 2; - var H = Radius * 2; - if (!FlxG.bitmap.checkCache(key)) - { - var bmp = makePieDialGraphicSub(Radius, Color, Frames, Shape, Clockwise, InnerRadius); - FlxG.bitmap.add(bmp, true, key); - } - - loadGraphic(key, true, W, H); + final graphic = FlxPieDialUtils.getPieDialGraphic(radius, color, frames, shape, clockwise, innerRadius); + loadGraphic(graphic, true, radius * 2, radius * 2); } - - function makePieDialGraphicSub(Radius:Int, Color:Int, Frames:Int, Shape:FlxPieDialShape, Clockwise:Bool, InnerRadius):BitmapData + + function set_amount(f:Float):Float { - var W = Radius * 2; - var H = Radius * 2; - - var rows:Int = Math.ceil(Math.sqrt(Frames)); - var cols:Int = Math.ceil((Frames) / rows); - - var back = Clockwise ? FlxColor.BLACK : FlxColor.WHITE; - var fore = Clockwise ? FlxColor.WHITE : FlxColor.BLACK; - - var fullFrame = makeFullFrame(Radius, Color, Frames, Shape, Clockwise, InnerRadius); - var nextFrame = new FlxSprite().makeGraphic(W, H, back, false); - - var bmp:BitmapData = new BitmapData(W * cols, H * rows, false, back); - var i:Int = 0; - _flashPoint.setTo(0, 0); - var p:FlxPoint = FlxPoint.get(0, -1); - var degrees:Float = 360 / (Frames); - if (!Clockwise) + amount = FlxMath.bound(f, 0.0, 1.0); + var frame:Int = Std.int(f * animation.numFrames); + animation.frameIndex = frame; + if (amount == 1.0) { - degrees *= -1; + animation.frameIndex = 0; // special case for full frame } + return amount; + } +} - var sweep:Float = Clockwise ? 0 : 360; - var bmp2 = new BitmapData(bmp.width, bmp.height, true, FlxColor.TRANSPARENT); - var fullBmp:BitmapData = fullFrame.pixels.clone(); +enum FlxPieDialShape +{ + CIRCLE; + SQUARE; +} - var polygon:Array = [FlxPoint.get(), FlxPoint.get(), FlxPoint.get(), FlxPoint.get(), FlxPoint.get()]; - for (r in 0...rows) +/** + * Set of tools for drawing pie dial graphics + * @since 5.9.0 + */ +class FlxPieDialUtils +{ + static final _rect = new Rectangle(); + static final _zero = new Point(); + static final _point = new Point(); + static var flashGfx = FlxSpriteUtil.flashGfx; + + public static function getPieDialGraphic(radius:Int, color:FlxColor, frames:Int, shape:FlxPieDialShape, clockwise:Bool, innerRadius:Int) + { + final key = 'pie_dial_${color.toHexString()}_${radius}_${frames}_${shape}_${clockwise}_$innerRadius'; + + if (!FlxG.bitmap.checkCache(key)) { - for (c in 0...cols) - { - if (i >= Frames) - { - break; - } - - _flashPoint.setTo(c * W, r * H); - bmp2.copyPixels(fullBmp, fullBmp.rect, _flashPoint); - - if (i <= 0) - { - bmp.fillRect(fullBmp.rect, FlxColor.WHITE); - } - else - { - nextFrame.pixels.copyPixels(fullFrame.pixels, fullFrame.pixels.rect, _flashPointZero); - _flashPoint.setTo(c * W, r * H); - drawSweep(sweep, p, nextFrame, polygon, W, H, back, fore); - bmp.copyPixels(nextFrame.pixels, nextFrame.pixels.rect, _flashPoint); - } - - sweep += degrees; - p.rotateByDegrees(degrees); - - i++; - } - - if (i >= Frames) - { - break; - } + final bmp = renderPieDial(shape, radius, innerRadius, frames, clockwise, color); + FlxG.bitmap.add(bmp, true, key); } - - fullBmp.dispose(); - fullFrame.destroy(); - nextFrame.destroy(); - - var shapeChannel = new BitmapData(bmp.width, bmp.height, false); - shapeChannel.copyChannel(bmp2, bmp2.rect, _flashPointZero, BitmapDataChannel.ALPHA, BitmapDataChannel.RED); - shapeChannel.copyChannel(bmp2, bmp2.rect, _flashPointZero, BitmapDataChannel.ALPHA, BitmapDataChannel.GREEN); - shapeChannel.copyChannel(bmp2, bmp2.rect, _flashPointZero, BitmapDataChannel.ALPHA, BitmapDataChannel.BLUE); - - shapeChannel.draw(bmp, null, null, BlendMode.MULTIPLY, null, true); - bmp2.copyChannel(shapeChannel, shapeChannel.rect, _flashPointZero, BitmapDataChannel.RED, BitmapDataChannel.ALPHA); - - shapeChannel.dispose(); - bmp.dispose(); - - return bmp2; + + return FlxG.bitmap.get(key); } - - function makeFullFrame(Radius:Int, Color:Int, Frames:Int, Shape:FlxPieDialShape, Clockwise:Bool, InnerRadius):FlxSprite + + public static function getRadialGaugeGraphic(shape:FlxPieDialShape, radius:Int, innerRadius = 0, color = FlxColor.WHITE) { - var W = Radius * 2; - var H = Radius * 2; - - var fullFrame = new FlxSprite().makeGraphic(W, H, FlxColor.TRANSPARENT, true); - if (InnerRadius > Radius) - { - InnerRadius = 0; - } - - var dR = Radius - InnerRadius; - - if (Shape == SQUARE) + final key = 'radial_gauge_${shape}_${color.toHexString()}_${radius}_$innerRadius'; + + if (!FlxG.bitmap.checkCache(key)) { - fullFrame.pixels.fillRect(fullFrame.pixels.rect, Color); - if (InnerRadius > 0) - { - _flashRect.setTo(dR, dR, InnerRadius * 2, InnerRadius * 2); - fullFrame.pixels.fillRect(_flashRect, FlxColor.TRANSPARENT); - } + final bmp = renderRadialGauge(shape, radius, innerRadius, color); + FlxG.bitmap.add(bmp, true, key); } - else if (Shape == CIRCLE) + + return FlxG.bitmap.get(key); + } + + /** + * Draws an animated pie dial graphic where each frame shows a more full amount, + * however the full gauge frame is on frame 0 + * + * @param radius The radius of the shape + * @param color The color of the shape + * @param shape The shape, Either `SQUARE` or `CIRCLE` + * @param innerRadius The radius of the inner hollow portion, where `0` means completely filled + */ + public static function renderRadialGauge(shape:FlxPieDialShape, radius:Int, innerRadius = 0, color = FlxColor.WHITE):BitmapData + { + return renderPieDial(shape, radius, innerRadius, 1, true, color); + } + + /** + * Draws an animated pie dial graphic where each frame shows a more full amount, + * however the full gauge frame is on frame 0 + * + * @param radius The radius of the shape + * @param color The color of the shape + * @param frames + * @param shape The shape, Either `SQUARE` or `CIRCLE` + * @param clockwise The direction the gauge + * @param innerRadius The radius of the inner hollow portion, where `0` means completely filled + */ + public static function renderPieDial(shape:FlxPieDialShape, radius:Int, innerRadius:Int, frames:Int, clockwise = true, color = FlxColor.WHITE):BitmapData + { + final W = radius * 2; + final H = radius * 2; + + final rows = Math.ceil(Math.sqrt(frames)); + final cols = Math.ceil(frames / rows); + + final maskFrame = FlxBitmapDataPool.get(W, H, true, FlxColor.TRANSPARENT, true); + final fullFrame = FlxBitmapDataPool.get(W, H, true, FlxColor.TRANSPARENT, true); + FlxPieDialUtils.drawShape(fullFrame, radius, color, shape, innerRadius); + + final result = new BitmapData(W * cols, H * rows, true, FlxColor.TRANSPARENT); + final p = FlxPoint.get(); + final degreeInterval = (clockwise ? 1 : -1) * 360 / frames; + + final mask = FlxBitmapDataPool.get(result.width, result.height, result.transparent, FlxColor.TRANSPARENT, true); + + final polygon:Array = [FlxPoint.get(), FlxPoint.get(), FlxPoint.get(), FlxPoint.get(), FlxPoint.get()]; + for (i in 0...frames) { - if (InnerRadius > 0) + _point.setTo((i % cols) * W, Std.int(i / cols) * H); + result.copyPixels(fullFrame, fullFrame.rect, _point);//, null, null, true); + if (i <= 0) { - var alpha = new BitmapData(fullFrame.pixels.width, fullFrame.pixels.height, false, FlxColor.BLACK); - fullFrame.pixels.fillRect(_flashRect, FlxColor.BLACK); - fullFrame.drawCircle(-1, -1, Radius, FlxColor.WHITE, null, {smoothing: true}); - fullFrame.drawCircle(-1, -1, InnerRadius, FlxColor.BLACK, null, {smoothing: true}); - - alpha.copyPixels(fullFrame.pixels, fullFrame.pixels.rect, _flashPointZero, null, null, true); - - fullFrame.pixels.fillRect(fullFrame.pixels.rect, Color); - fullFrame.pixels.copyChannel(alpha, alpha.rect, _flashPointZero, BitmapDataChannel.RED, BitmapDataChannel.ALPHA); - - alpha.dispose(); + mask.fillRect(fullFrame.rect, FlxColor.WHITE); } else { - fullFrame.drawCircle(-1, -1, Radius, Color); + final angle = degreeInterval * i; + maskFrame.fillRect(maskFrame.rect, FlxColor.TRANSPARENT); + FlxPieDialUtils.drawSweep(maskFrame, angle); + mask.copyPixels(maskFrame, maskFrame.rect, _point, null, null, true); } } - return fullFrame; + + result.copyPixels(result, result.rect, _zero, mask); + FlxBitmapDataPool.put(mask); + FlxBitmapDataPool.put(maskFrame); + FlxBitmapDataPool.put(fullFrame); + + return result; } - - function drawSweep(sweep:Float, p:FlxPoint, nextFrame:FlxSprite, polygon:Array, W:Int, H:Int, back:FlxColor, fore:FlxColor) + + /** + * Draws the specified shape onto the bitmap + * + * @param dest The bitmap to draw to + * @param radius The radius of the shape + * @param color The color of the shape + * @param shape The shape, Either `SQUARE` or `CIRCLE` + * @param innerRadius The radius of the inner hollow portion, where `0` means completely filled + */ + public static inline function drawShape(dest:BitmapData, radius:Int, color:FlxColor, shape:FlxPieDialShape, innerRadius = 0):BitmapData { - var halfW = W / 2; - var halfH = H / 2; - - nextFrame.pixels.fillRect(nextFrame.pixels.rect, back); - polygon[0].set(halfW, halfH); - - if (sweep < 45) + final W = radius << 1; + final H = radius << 1; + + switch (shape) { - polygon[1].set(halfW, 0); - polygon[2].set(halfW + W * p.x, halfH + H * p.y); - polygon[3].set(halfW, halfH); + case SQUARE if (innerRadius > 0 && innerRadius < radius): + final thickness = radius - innerRadius; + _rect.setTo(0, 0, W, thickness); + dest.fillRect(_rect, color); + _rect.setTo(0, 0, thickness, H); + dest.fillRect(_rect, color); + _rect.setTo(W - thickness, 0, thickness, H); + dest.fillRect(_rect, color); + _rect.setTo(0, H - thickness, W, thickness); + dest.fillRect(_rect, color); + + case SQUARE: + dest.fillRect(dest.rect, color); + + case CIRCLE if (innerRadius > 0 && innerRadius < radius): + final alpha = FlxBitmapDataPool.get(W, H, false, FlxColor.BLACK, true); + alpha.fillRect(alpha.rect, FlxColor.BLACK); + drawCircle(alpha, radius, FlxColor.WHITE, null, {smoothing: true}); + drawCircle(alpha, innerRadius, FlxColor.BLACK, null, {smoothing: true}); + + alpha.copyPixels(dest, dest.rect, _zero, null, null, true); + + dest.fillRect(dest.rect, color); + dest.copyChannel(alpha, alpha.rect, _zero, BitmapDataChannel.RED, BitmapDataChannel.ALPHA); + + FlxBitmapDataPool.put(alpha); + + case CIRCLE: + drawCircle(dest, radius, color); } - else if (sweep < 90) + return dest; + } + + /** + * Used via `drawSweep` + */ + static final sweepPoints = [for (i in 0...4) FlxPoint.get()]; + + /** + * Draws a wedge section of a bitmap, used in `FlxPieDial` + * @param dest The btimap to draw to + * @param degrees The angle of the wedge + * @param color The color to fill the wedge + */ + public static function drawSweep(dest:BitmapData, degrees:Float, color = FlxColor.WHITE) + { + degrees %= 360; + final p = sweepPoints; + final radius = dest.width >> 1; + final center = p[0].set(radius, radius); + final cornerLength = center.length; + + if (degrees >= 270) { - polygon[1].set(halfW, 0); - polygon[2].set(W, 0); - polygon[3].set(halfW + W * p.x, halfH + H * p.y); + // fill right half + _rect.setTo(radius, 0, radius, dest.height); + dest.fillRect(_rect, color); + // fill bottom-left quadrant + _rect.setTo(0, radius, radius, radius); + dest.fillRect(_rect, color); } - else if (sweep < 135) + else if (degrees >= 180) { - _flashRect.setTo(halfW, 0, halfW, halfH); - nextFrame.pixels.fillRect(_flashRect, fore); - - polygon[1].set(W, halfH); - polygon[2].set(halfW + W * p.x, halfH + H * p.y); - polygon[3].set(halfW, halfH); + // fill right half + _rect.setTo(radius, 0, radius, dest.height); + dest.fillRect(_rect, color); } - else if (sweep < 180) + else if (degrees >= 90) { - _flashRect.setTo(halfW, 0, halfW, halfH); - nextFrame.pixels.fillRect(_flashRect, fore); - - polygon[1].set(W, halfH); - polygon[2].set(W, H); - polygon[3].set(halfW + W * p.x, halfH + H * p.y); + // fill top-right quadrant + _rect.setTo(radius, 0, radius, radius); + dest.fillRect(_rect, color); } - else if (sweep < 225) + else if (degrees <= -270) { - _flashRect.setTo(halfW, 0, halfW, H); - nextFrame.pixels.fillRect(_flashRect, fore); - - polygon[1].set(halfW, H); - polygon[2].set(halfW + W * p.x, halfH + H * p.y); - polygon[3].set(halfW, halfH); + // fill left half + _rect.setTo(0, 0, radius, dest.height); + dest.fillRect(_rect, color); + // fill bottom-right quadrant + _rect.setTo(radius, radius, radius, radius); + dest.fillRect(_rect, color); } - else if (sweep < 270) + else if (degrees <= -180) { - _flashRect.setTo(halfW, 0, halfW, H); - nextFrame.pixels.fillRect(_flashRect, fore); - - polygon[1].set(halfW, H); - polygon[2].set(0, H); - polygon[3].set(halfW + W * p.x, halfH + H * p.y); + // fill left half + _rect.setTo(0, 0, radius, dest.height); + dest.fillRect(_rect, color); } - else if (sweep < 315) + else if (degrees <= -90) { - _flashRect.setTo(halfW, 0, halfW, H); - nextFrame.pixels.fillRect(_flashRect, fore); - _flashRect.setTo(0, halfH, halfW, halfH); - nextFrame.pixels.fillRect(_flashRect, fore); - - polygon[1].set(0, halfH); - polygon[2].set(halfW + W * p.x, halfH + H * p.y); - polygon[3].set(halfW, halfH); + // fill top-left quadrant + _rect.setTo(0, 0, radius, radius); + dest.fillRect(_rect, color); } - else if (sweep < 360) + + // draw the interesting quadrant + if (Math.abs(degrees % 90) < 45) { - _flashRect.setTo(halfW, 0, halfW, H); - nextFrame.pixels.fillRect(_flashRect, fore); - _flashRect.setTo(0, halfH, halfW, halfH); - nextFrame.pixels.fillRect(_flashRect, fore); - - polygon[1].set(0, halfH); - polygon[2].set(0, 0); - polygon[3].set(halfW + W * p.x, halfH + H * p.y); + p[1].setPolarDegrees(radius, -90 + Std.int(degrees / 90) * 90).addPoint(center); + p[2].setPolarDegrees(cornerLength, -90 + degrees).addPoint(center); + p[3].copyFrom(center); } - - polygon[4].set(halfW, halfH); - - nextFrame.drawPolygon(polygon, fore); + else + { + final quadDegreesStart = Std.int(degrees / 90) * 90; + final cornerDegrees = quadDegreesStart + (degrees < 0 ? -45 : 45); + p[1].setPolarDegrees(radius, -90 + quadDegreesStart).addPoint(center); + p[2].setPolarDegrees(cornerLength, -90 + cornerDegrees).addPoint(center); + p[3].setPolarDegrees(cornerLength, -90 + degrees).addPoint(center); + } + + drawPolygon(dest, p, color); } - - function set_amount(f:Float):Float + + /** + * This function draws a circle on a FlxSprite at position X,Y with the specified color. + * + * @param bitmap The BitmapData to manipulate + * @param X X coordinate of the circle's center (automatically centered on the sprite if -1) + * @param Y Y coordinate of the circle's center (automatically centered on the sprite if -1) + * @param radius Radius of the circle (makes sure the circle fully fits on the sprite's graphic if < 1, assuming and and y are centered) + * @param color The ARGB color to fill this circle with. FlxColor.TRANSPARENT (0x0) means no fill. + * @param lineStyle A LineStyle typedef containing the params of Graphics.lineStyle() + * @param drawStyle A DrawStyle typedef containing the params of BitmapData.draw() + * @return The FlxSprite for chaining + */ + public static function drawCircle(bitmap:BitmapData, ?radius:Float, color = FlxColor.WHITE, ?lineStyle:LineStyle, ?drawStyle:DrawStyle):BitmapData { - amount = FlxMath.bound(f, 0.0, 1.0); - var frame:Int = Std.int(f * pieFrames); - animation.frameIndex = frame; - if (amount == 1.0) + final x = bitmap.width * 0.5; + final y = bitmap.height * 0.5; + + if (radius == null) + radius = Math.min(bitmap.width, bitmap.height) * 0.5; + + beginDraw(color, lineStyle); + flashGfx.drawCircle(x, y, radius); + endDraw(bitmap, drawStyle); + return bitmap; + } + + /** + * This function draws a polygon on a FlxSprite. + * + * @param graphic The FlxSprite to manipulate + * @param Vertices Array of Vertices to use for drawing the polygon + * @param FillColor The ARGB color to fill this polygon with. FlxColor.TRANSPARENT (0x0) means no fill. + * @param lineStyle A LineStyle typedef containing the params of Graphics.lineStyle() + * @param drawStyle A DrawStyle typedef containing the params of BitmapData.draw() + * @return The FlxSprite for chaining + */ + public static function drawPolygon(bitmap:BitmapData, vertices:Array, fillColor = FlxColor.WHITE, ?lineStyle:LineStyle, + ?drawStyle:DrawStyle):BitmapData + { + beginDraw(fillColor, lineStyle); + final p:FlxPoint = vertices.shift(); + flashGfx.moveTo(p.x, p.y); + for (p in vertices) { - animation.frameIndex = 0; // special case for full frame + flashGfx.lineTo(p.x, p.y); } - return amount; + endDraw(bitmap, drawStyle); + vertices.unshift(p); + return bitmap; } -} - -enum FlxPieDialShape -{ - CIRCLE; - SQUARE; -} + + static inline function beginDraw(color:FlxColor, ?lineStyle:LineStyle):Void + { + flashGfx.clear(); + FlxSpriteUtil.setLineStyle(lineStyle); + + if (color != FlxColor.TRANSPARENT) + flashGfx.beginFill(color.rgb, color.alphaFloat); + } + + static inline function endDraw(bitmap:BitmapData, ?style:DrawStyle):BitmapData + { + flashGfx.endFill(); + if (style == null) + style = {smoothing: false}; + else if (style.smoothing == null) + style.smoothing = false; + + final sprite = FlxSpriteUtil.flashGfxSprite; + bitmap.draw(sprite, style.matrix, style.colorTransform, style.blendMode, style.clipRect, style.smoothing); + return bitmap; + } +} \ No newline at end of file diff --git a/flixel/addons/display/FlxRadialGauge.hx b/flixel/addons/display/FlxRadialGauge.hx new file mode 100644 index 00000000..67ba25e4 --- /dev/null +++ b/flixel/addons/display/FlxRadialGauge.hx @@ -0,0 +1,155 @@ +package flixel.addons.display; + +import flixel.FlxSprite; +import flixel.addons.display.FlxPieDial; +import flixel.util.FlxColor; + +#if !flash +/** + * A dynamic shape that fills up radially (like a pie chart). Useful for timers and other things. + * `FlxRadialGauge` uses `FlxRadialWipeShader` to fill the gauge portion, where `FlxPieDial` + * creates an animation. This also works with any graphic, unlike `FlxPieDial` + * @since 5.9.0 + */ +class FlxRadialGauge extends FlxSprite +{ + /** A value between 0.0 (empty) and 1.0 (full) */ + public var amount(get, set):Float; + inline function get_amount():Float + { + return _sweepShader.amount; + } + inline function set_amount(value:Float):Float + { + return _sweepShader.amount = value; + } + + /** The angle in degrees to start the dial fill */ + public var start(get, set):Float; + inline function get_start():Float + { + return _sweepShader.start; + } + inline function set_start(value:Float):Float + { + return _sweepShader.start = value; + } + + /** The angle in degrees to end the dial fill */ + public var end(get, set):Float; + inline function get_end():Float + { + return _sweepShader.end; + } + inline function set_end(value:Float):Float + { + return _sweepShader.end = value; + } + + var _sweepShader(get, never):FlxRadialWipeShader; + inline function get__sweepShader() return cast shader; + + public function new(x = 0.0, y = 0.0, ?simpleGraphic) + { + super(x, y, simpleGraphic); + + shader = new FlxRadialWipeShader(); + this.amount = 1; + } + + public function makeShapeGraphic(shape:FlxRadialGaugeShape, radius:Int, innerRadius = 0, color = FlxColor.WHITE) + { + final graphic = FlxPieDialUtils.getRadialGaugeGraphic(shape, radius, innerRadius, color); + loadGraphic(graphic, true, radius * 2, radius * 2); + } + + public function setOrientation(start = -90.0, end = 270.0) + { + this.start = start; + this.end = end; + } +} + +typedef FlxRadialGaugeShape = FlxPieDialShape; + +/** + * A shader that masks a static sprite radially, based on the `start` and `end` angles + */ +class FlxRadialWipeShader extends flixel.system.FlxAssets.FlxShader +{ + /** The current fill amount, where `0.0` is empty and `1.0` is full */ + public var amount(get, set):Float; + inline function get_amount():Float return _amount.value[0]; + inline function set_amount(value:Float):Float + { + _amount.value = [value]; + return value; + } + + /** The angle in degrees to start the dial fill */ + public var start(get, set):Float; + inline function get_start():Float return _start.value[0]; + inline function set_start(value:Float):Float + { + _start.value = [value]; + return value; + } + + /** The angle in degrees to end the dial fill */ + public var end(get, set):Float; + inline function get_end():Float return _end.value[0]; + inline function set_end(value:Float):Float + { + _end.value = [value]; + return value; + } + + @:glFragmentSource(' + #pragma header + + const float TAU = 6.2831853072; + + uniform float _amount; + uniform float _start; + uniform float _end; + + float getGradiant(in vec2 dist) + { + float start = _start / 360.0; + float delta = (_end - _start) / 360.0; + float angle = atan(dist.y, dist.x) / TAU; + if (_end > _start) + return mod(angle - start, 1.0) / delta; + else + return mod(start - angle, 1.0) / -delta; + } + + float wedge(in vec2 uv, in float ratio) + { + vec2 dist = uv - vec2(0.5); + float grad = getGradiant(dist); + return step(ratio, grad < 0.0 ? 1.0 : grad); + } + + void main() + { + if (_amount > 0.0) + { + float amount = min(1.0, max(0.0, _amount)); + vec4 bitmap = flixel_texture2D(bitmap, openfl_TextureCoordv); + gl_FragColor = mix(bitmap, vec4(0.0), wedge(openfl_TextureCoordv, amount)); + } + else + gl_FragColor = vec4(0.0); + }') + public function new() + { + super(); + amount = 1.0; + start = -90; + end = 270; + } +} +#elseif FLX_NO_COVERAGE_TEST +#error "FlxRadialGauge is not supported on flash targets" +#end \ No newline at end of file From 07c3f07581ce8698fcbac4adbe64fcc3b7572ecc Mon Sep 17 00:00:00 2001 From: George Kurelic Date: Wed, 2 Oct 2024 11:14:41 -0500 Subject: [PATCH 13/35] break update into separate methods + general cleanup (#447) --- flixel/addons/effects/FlxTrail.hx | 246 +++++++++++++++--------------- 1 file changed, 120 insertions(+), 126 deletions(-) diff --git a/flixel/addons/effects/FlxTrail.hx b/flixel/addons/effects/FlxTrail.hx index e7caef35..2969fe5f 100644 --- a/flixel/addons/effects/FlxTrail.hx +++ b/flixel/addons/effects/FlxTrail.hx @@ -95,28 +95,28 @@ class FlxTrail extends #if (flixel < "5.7.0") FlxSpriteGroup #else FlxSpriteCont /** * Creates a new FlxTrail effect for a specific FlxSprite. * - * @param Target The FlxSprite the trail is attached to. - * @param Graphic The image to use for the trailsprites. Optional, uses the sprite's graphic if null. - * @param Length The amount of trailsprites to create. - * @param Delay How often to update the trail. 0 updates every frame. - * @param Alpha The alpha value for the very first trailsprite. - * @param Diff How much lower the alpha of the next trailsprite is. + * @param target The FlxSprite the trail is attached to. + * @param graphic The image to use for the trailsprites. Optional, uses the sprite's graphic if null. + * @param length The amount of trailsprites to create. + * @param delay How often to update the trail. 0 updates every frame. + * @param alpha The alpha value for the very first trailsprite. + * @param diff How much lower the alpha of the next trailsprite is. */ - public function new(Target:FlxSprite, ?Graphic:FlxGraphicAsset, Length:Int = 10, Delay:Int = 3, Alpha:Float = 0.4, Diff:Float = 0.05):Void + public function new(target:FlxSprite, ?graphic:FlxGraphicAsset, length = 10, delay = 3, alpha = 0.4, diff = 0.05):Void { super(); - _spriteOrigin = FlxPoint.get().copyFrom(Target.origin); + _spriteOrigin = FlxPoint.get().copyFrom(target.origin); // Sync the vars - target = Target; - delay = Delay; - _graphic = Graphic; - _transp = Alpha; - _difference = Diff; + this.target = target; + this.delay = delay; + _graphic = graphic; + _transp = alpha; + _difference = diff; // Create the initial trailsprites - increaseLength(Length); + increaseLength(length); solid = false; } @@ -147,100 +147,94 @@ class FlxTrail extends #if (flixel < "5.7.0") FlxSpriteGroup #else FlxSpriteCont { // Count the frames _counter++; - + // Update the trail in case the intervall and there actually is one. if (_counter >= delay && _trailLength >= 1) { _counter = 0; - - // Push the current position into the positons array and drop one. - var spritePosition:FlxPoint = null; - if (_recentPositions.length == _trailLength) - { - spritePosition = _recentPositions.pop(); - } - else - { - spritePosition = FlxPoint.get(); - } - - spritePosition.set(target.x - target.offset.x, target.y - target.offset.y); - _recentPositions.unshift(spritePosition); - - // Also do the same thing for the Sprites angle if rotationsEnabled + addTrailFrame(); + + // Now we need to update the all the Trailsprites' values + redrawTrailSprites(); + } + + super.update(elapsed); + } + + inline function recyclePoint(list:Array, x:Float, y:Float) + { + final pos = if (list.length >= _trailLength) + list.pop().set(x, y); + else + FlxPoint.get(x, y); + + list.unshift(pos); + } + + function addTrailFrame() + { + // Push the current position into the positons array and drop one. + recyclePoint(_recentPositions, target.x - target.offset.x, target.y - target.offset.y); + + // Also do the same thing for the Sprites angle if rotationsEnabled + if (rotationsEnabled) + { + cacheValue(_recentAngles, target.angle); + } + + // Again the same thing for Sprites scales if scalesEnabled + if (scalesEnabled) + { + recyclePoint(_recentScales, target.scale.x, target.scale.y); + } + + // Again the same thing for Sprites frames if framesEnabled + if (framesEnabled && _graphic == null) + { + cacheValue(_recentFrames, target.animation.frameIndex); + cacheValue(_recentFlipX, target.flipX); + cacheValue(_recentFlipY, target.flipY); + cacheValue(_recentAnimations, target.animation.curAnim); + } + } + + function redrawTrailSprites() + { + for (i in 0..._recentPositions.length) + { + final trailSprite = members[i]; + trailSprite.x = _recentPositions[i].x; + trailSprite.y = _recentPositions[i].y; + + // And the angle... if (rotationsEnabled) { - cacheValue(_recentAngles, target.angle); + trailSprite.angle = _recentAngles[i]; + trailSprite.origin.x = _spriteOrigin.x; + trailSprite.origin.y = _spriteOrigin.y; } - - // Again the same thing for Sprites scales if scalesEnabled + + // the scale... if (scalesEnabled) { - var spriteScale:FlxPoint = null; // sprite.scale; - if (_recentScales.length == _trailLength) - { - spriteScale = _recentScales.pop(); - } - else - { - spriteScale = FlxPoint.get(); - } - - spriteScale.set(target.scale.x, target.scale.y); - _recentScales.unshift(spriteScale); + trailSprite.scale.copyFrom(_recentScales[i]); } - - // Again the same thing for Sprites frames if framesEnabled + + // and frame... if (framesEnabled && _graphic == null) { - cacheValue(_recentFrames, target.animation.frameIndex); - cacheValue(_recentFlipX, target.flipX); - cacheValue(_recentFlipY, target.flipY); - cacheValue(_recentAnimations, target.animation.curAnim); - } - - // Now we need to update the all the Trailsprites' values - var trailSprite:FlxSprite; - - for (i in 0..._recentPositions.length) - { - trailSprite = members[i]; - trailSprite.x = _recentPositions[i].x; - trailSprite.y = _recentPositions[i].y; - - // And the angle... - if (rotationsEnabled) - { - trailSprite.angle = _recentAngles[i]; - trailSprite.origin.x = _spriteOrigin.x; - trailSprite.origin.y = _spriteOrigin.y; - } - - // the scale... - if (scalesEnabled) - { - trailSprite.scale.x = _recentScales[i].x; - trailSprite.scale.y = _recentScales[i].y; - } - - // and frame... - if (framesEnabled && _graphic == null) - { - trailSprite.animation.frameIndex = _recentFrames[i]; - trailSprite.flipX = _recentFlipX[i]; - trailSprite.flipY = _recentFlipY[i]; - - trailSprite.animation.curAnim = _recentAnimations[i]; - } - - // Is the trailsprite even visible? - trailSprite.exists = true; + trailSprite.animation.frameIndex = _recentFrames[i]; + trailSprite.flipX = _recentFlipX[i]; + trailSprite.flipY = _recentFlipY[i]; + + trailSprite.animation.curAnim = _recentAnimations[i]; } + + // Is the trailsprite even visible? + trailSprite.exists = true; } - - super.update(elapsed); } - + function cacheValue(array:Array, value:T) { array.unshift(value); @@ -250,13 +244,13 @@ class FlxTrail extends #if (flixel < "5.7.0") FlxSpriteGroup #else FlxSpriteCont public function resetTrail():Void { - _recentPositions.splice(0, _recentPositions.length); - _recentAngles.splice(0, _recentAngles.length); - _recentScales.splice(0, _recentScales.length); - _recentFrames.splice(0, _recentFrames.length); - _recentFlipX.splice(0, _recentFlipX.length); - _recentFlipY.splice(0, _recentFlipY.length); - _recentAnimations.splice(0, _recentAnimations.length); + FlxDestroyUtil.putArray(_recentPositions); + FlxDestroyUtil.putArray(_recentScales); + _recentAngles.resize(0); + _recentFrames.resize(0); + _recentFlipX.resize(0); + _recentFlipY.resize(0); + _recentAnimations.resize(0); for (i in 0...members.length) { @@ -266,27 +260,27 @@ class FlxTrail extends #if (flixel < "5.7.0") FlxSpriteGroup #else FlxSpriteCont } } } - + /** * A function to add a specific number of sprites to the trail to increase its length. * - * @param Amount The amount of sprites to add to the trail. + * @param amount The amount of sprites to add to the trail. */ - public function increaseLength(Amount:Int):Void + public function increaseLength(amount:Int):Void { // Can't create less than 1 sprite obviously - if (Amount <= 0) + if (amount <= 0) { return; } - - _trailLength += Amount; - + + _trailLength += amount; + // Create the trail sprites - for (i in 0...Amount) + for (i in 0...amount) { - var trailSprite = new FlxSprite(0, 0); - + final trailSprite = new FlxSprite(0, 0); + if (_graphic == null) { trailSprite.loadGraphicFromSprite(target); @@ -301,42 +295,42 @@ class FlxTrail extends #if (flixel < "5.7.0") FlxSpriteGroup #else FlxSpriteCont trailSprite.alpha = _transp; _transp -= _difference; trailSprite.solid = solid; - + if (trailSprite.alpha <= 0) { trailSprite.kill(); } } } - + /** * In case you want to change the trailsprite image in runtime... * - * @param Image The image the sprites should load + * @param image The image the sprites should load */ - public function changeGraphic(Image:Dynamic):Void + public function changeGraphic(image:Dynamic):Void { - _graphic = Image; - + _graphic = image; + for (i in 0..._trailLength) { - members[i].loadGraphic(Image); + members[i].loadGraphic(image); } } /** * Handy little function to change which events affect the trail. * - * @param Angle Whether the trail reacts to angle changes or not. - * @param X Whether the trail reacts to x changes or not. - * @param Y Whether the trail reacts to y changes or not. - * @param Scale Wheater the trail reacts to scale changes or not. + * @param angle Whether the trail reacts to angle changes or not. + * @param x Whether the trail reacts to x changes or not. + * @param y Whether the trail reacts to y changes or not. + * @param scale Wheater the trail reacts to scale changes or not. */ - public function changeValuesEnabled(Angle:Bool, X:Bool = true, Y:Bool = true, Scale:Bool = true):Void + public function changeValuesEnabled(angle:Bool, x = true, y = true, scale = true):Void { - rotationsEnabled = Angle; - xEnabled = X; - yEnabled = Y; - scalesEnabled = Scale; + rotationsEnabled = angle; + xEnabled = x; + yEnabled = y; + scalesEnabled = scale; } } From 0a790968e85ad778640b92197ca93d0d144e2640 Mon Sep 17 00:00:00 2001 From: Ahmet Kaya <88967833+neondev27@users.noreply.github.com> Date: Wed, 2 Oct 2024 19:21:35 +0300 Subject: [PATCH 14/35] Turkish README.md (#446) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Create README_TR.md * Update README_TR.md * Update README_TR.md * Update README_TR.md * Update README_TR.md * Update README.md * Update README_TR.md Completely Turkish README * turkish -> türkçe * orijinal -> english --------- Co-authored-by: George Kurelic --- README.md | 2 +- README_TR.md | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 README_TR.md diff --git a/README.md b/README.md index ea60016a..68035f91 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ![](https://raw.github.com/HaxeFlixel/haxeflixel.com/master/src/files/images/flixel-logos/flixel-addons.png) -[flixel](https://github.com/HaxeFlixel/flixel) | [addons](https://github.com/HaxeFlixel/flixel-addons) | [ui](https://github.com/HaxeFlixel/flixel-ui) | [demos](https://github.com/HaxeFlixel/flixel-demos) | [tools](https://github.com/HaxeFlixel/flixel-tools) | [templates](https://github.com/HaxeFlixel/flixel-templates) | [docs](https://github.com/HaxeFlixel/flixel-docs) | [haxeflixel.com](https://github.com/HaxeFlixel/haxeflixel.com) +[flixel](https://github.com/HaxeFlixel/flixel) | [addons](https://github.com/HaxeFlixel/flixel-addons) | [ui](https://github.com/HaxeFlixel/flixel-ui) | [demos](https://github.com/HaxeFlixel/flixel-demos) | [tools](https://github.com/HaxeFlixel/flixel-tools) | [templates](https://github.com/HaxeFlixel/flixel-templates) | [docs](https://github.com/HaxeFlixel/flixel-docs) | [haxeflixel.com](https://github.com/HaxeFlixel/haxeflixel.com) | [türkçe](/README_TR.md) [![CI](https://img.shields.io/github/actions/workflow/status/HaxeFlixel/flixel-addons/main.yml?branch=dev&logo=github)](https://github.com/HaxeFlixel/flixel/actions?query=workflow%3ACI) [![Discord](https://img.shields.io/discord/162395145352904705.svg?logo=discord)](https://discordapp.com/invite/rqEBAgF) diff --git a/README_TR.md b/README_TR.md new file mode 100644 index 00000000..2b06d9dd --- /dev/null +++ b/README_TR.md @@ -0,0 +1,28 @@ +![](https://raw.github.com/HaxeFlixel/haxeflixel.com/master/src/files/images/flixel-logos/flixel-addons.png) + +[flixel](https://github.com/HaxeFlixel/flixel) | [uzantılar](https://github.com/HaxeFlixel/flixel-addons) | [ui](https://github.com/HaxeFlixel/flixel-ui) | [demolar](https://github.com/HaxeFlixel/flixel-demos) | [araçlar](https://github.com/HaxeFlixel/flixel-tools) | [şablonlar](https://github.com/HaxeFlixel/flixel-templates) | [dökümanlar](https://github.com/HaxeFlixel/flixel-docs) | [haxeflixel.com](https://github.com/HaxeFlixel/haxeflixel.com) | [english](/README.md) + +[![CI](https://img.shields.io/github/actions/workflow/status/HaxeFlixel/flixel-addons/main.yml?branch=dev&logo=github)](https://github.com/HaxeFlixel/flixel/actions?query=workflow%3ACI) +[![Discord](https://img.shields.io/discord/162395145352904705.svg?logo=discord)](https://discordapp.com/invite/rqEBAgF) +[![Haxelib Version](https://badgen.net/haxelib/v/flixel-addons)](https://lib.haxe.org/p/flixel-addons) +[![Haxelib Downloads](https://badgen.net/haxelib/d/flixel-addons?color=blue)](https://lib.haxe.org/p/flixel-addons) +[![Haxelib License](https://badgen.net/haxelib/license/flixel-addons)](LICENSE.md) +[![Patreon](https://img.shields.io/badge/donate-patreon-blue.svg)](https://www.patreon.com/haxeflixel) + + + +## Hakkında + +[HaxeFlixel](https://github.com/HaxeFlixel/flixel) | [HaxeFlixel](https://github.com/HaxeFlixel/flixel) için kullanışlı ancak isteğe bağlı, topluluk tarafından oluşturulan bir takım sınıf seti. [Flixel Power Tools](https://github.com/photonstorm/Flixel-Power-Tools)'tan bazı sınıflar dahildir. + +## Geliştiriciler için + +Eğer katkıda bulunmak isterseniz, aşağıdaki dökümanları inceleyin (İngilizce): + +- [Kod katkıları](http://haxeflixel.com/documentation/code-contributions) +- [Kod Tarzı](http://haxeflixel.com/documentation/code-style) +- [Geliştirici flixel'i indirin](http://haxeflixel.com/documentation/install-development-flixel/) + +Eğer bir sorunuz varsa veya daha önce hiç Github'dan katkıda bulunmadıysanız, toplulukta [forumlarda](http://haxeflixel.com/documentation/community/) yardım edecek arkadaş canlısı insanlar var. + +Git'i Github ile kullanmak için, değişikliklerinizi yönetebileceğiniz [SourceTree](http://www.sourcetreeapp.com/) gibi bir GUI kullanmanızı öneririz. From 73856c9610dadc404774cd7642d3cc65f814f19c Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Mon, 7 Oct 2024 12:02:56 -0400 Subject: [PATCH 15/35] fix: add "Point" objectType to TiledObject from Tiled 1.1 update (#448) --- flixel/addons/editors/tiled/TiledObject.hx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/flixel/addons/editors/tiled/TiledObject.hx b/flixel/addons/editors/tiled/TiledObject.hx index d0abac4b..c6e52962 100644 --- a/flixel/addons/editors/tiled/TiledObject.hx +++ b/flixel/addons/editors/tiled/TiledObject.hx @@ -27,6 +27,7 @@ class TiledObject public static inline var POLYGON = 2; public static inline var POLYLINE = 3; public static inline var TILE = 4; + public static inline var POINT = 5; public var x:Int; public var y:Int; @@ -148,6 +149,10 @@ class TiledObject objectType = POLYLINE; getPoints(source.node.polyline); } + else if (source.hasNode.point) + { + objectType = POINT; + } } function getPoints(node:Access):Void From 0d0775252726a8f20f7da95d74073fdcc3778878 Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Mon, 7 Oct 2024 17:47:22 -0400 Subject: [PATCH 16/35] fix: use `parallaxx` and `parallaxy` from the tiled tmx (#449) parallax typo fix --- flixel/addons/editors/tiled/TiledLayer.hx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/flixel/addons/editors/tiled/TiledLayer.hx b/flixel/addons/editors/tiled/TiledLayer.hx index ca39fe80..38e07724 100644 --- a/flixel/addons/editors/tiled/TiledLayer.hx +++ b/flixel/addons/editors/tiled/TiledLayer.hx @@ -1,7 +1,7 @@ package flixel.addons.editors.tiled; -import openfl.utils.ByteArray; import haxe.xml.Access; +import openfl.utils.ByteArray; /** * Base class for Tiled object and tile layers @@ -24,6 +24,9 @@ class TiledLayer /** @since 2.1.0 */ public var offsetY:Float; + public var parallaxX:Float; + public var parallaxY:Float; + function new(source:Access, parent:TiledMap) { properties = new TiledPropertySet(); @@ -33,6 +36,8 @@ class TiledLayer opacity = (source.has.opacity) ? Std.parseFloat(source.att.opacity) : 1.0; offsetX = (source.has.offsetx) ? Std.parseFloat(source.att.offsetx) : 0.0; offsetY = (source.has.offsety) ? Std.parseFloat(source.att.offsety) : 0.0; + parallaxX = (source.has.parallaxx) ? Std.parseFloat(source.att.parallaxx) : 1.0; + parallaxY = (source.has.parallaxy) ? Std.parseFloat(source.att.parallaxy) : 1.0; loadProperties(source); } From 4d9dc50ff6d38808defb7ca72aa7086f73ced230 Mon Sep 17 00:00:00 2001 From: George Kurelic Date: Mon, 9 Dec 2024 15:04:40 -0600 Subject: [PATCH 17/35] remove implicit casts of int to/from directions (#451) --- flixel/addons/display/FlxExtendedMouseSprite.hx | 16 ++++++++-------- flixel/addons/display/FlxNestedSprite.hx | 3 ++- flixel/addons/effects/FlxClothSprite.hx | 8 ++++---- .../addons/plugin/control/FlxControlHandler.hx | 6 ++++-- flixel/addons/util/FlxScene.hx | 3 ++- 5 files changed, 20 insertions(+), 16 deletions(-) diff --git a/flixel/addons/display/FlxExtendedMouseSprite.hx b/flixel/addons/display/FlxExtendedMouseSprite.hx index a2cebd3d..eaf5e7b4 100644 --- a/flixel/addons/display/FlxExtendedMouseSprite.hx +++ b/flixel/addons/display/FlxExtendedMouseSprite.hx @@ -455,11 +455,11 @@ class FlxExtendedMouseSprite extends FlxSprite if (acceleration.x < 0) { // Gravity is pulling them left - if ((touching & WALL) != 0) + if (touching.has(WALL)) { drag.y = frictionY; - if ((wasTouching & WALL) == 0) + if (!wasTouching.has(WALL)) { if (velocity.x < toleranceX) { @@ -475,12 +475,12 @@ class FlxExtendedMouseSprite extends FlxSprite else if (acceleration.x > 0) { // Gravity is pulling them right - if ((touching & WALL) != 0) + if (touching.has(WALL)) { // Stop them sliding like on ice drag.y = frictionY; - if ((wasTouching & WALL) == 0) + if (!wasTouching.has(WALL)) { if (velocity.x > -toleranceX) { @@ -501,11 +501,11 @@ class FlxExtendedMouseSprite extends FlxSprite if (acceleration.y < 0) { // Gravity is pulling them up (velocity is negative) - if ((touching & CEILING) != 0) + if (touching.has(CEILING)) { drag.x = frictionX; - if ((wasTouching & CEILING) == 0) + if (!wasTouching.has(CEILING)) { if (velocity.y < toleranceY) { @@ -521,12 +521,12 @@ class FlxExtendedMouseSprite extends FlxSprite else if (acceleration.y > 0) { // Gravity is pulling them down (velocity is positive) - if ((touching & FLOOR) != 0) + if (touching.has(FLOOR)) { // Stop them sliding like on ice drag.x = frictionX; - if ((wasTouching & FLOOR) == 0) + if (!wasTouching.has(FLOOR)) { if (velocity.y > -toleranceY) { diff --git a/flixel/addons/display/FlxNestedSprite.hx b/flixel/addons/display/FlxNestedSprite.hx index 1d71abb0..a6c91ce3 100644 --- a/flixel/addons/display/FlxNestedSprite.hx +++ b/flixel/addons/display/FlxNestedSprite.hx @@ -1,5 +1,6 @@ package flixel.addons.display; +import flixel.util.FlxDirectionFlags; import openfl.geom.ColorTransform; import flixel.FlxBasic; import flixel.FlxG; @@ -401,7 +402,7 @@ class FlxNestedSprite extends FlxSprite return color; } - override function set_facing(Direction:Int):Int + override function set_facing(Direction:FlxDirectionFlags):FlxDirectionFlags { super.set_facing(Direction); if (children != null) diff --git a/flixel/addons/effects/FlxClothSprite.hx b/flixel/addons/effects/FlxClothSprite.hx index 500d1677..28f558ef 100644 --- a/flixel/addons/effects/FlxClothSprite.hx +++ b/flixel/addons/effects/FlxClothSprite.hx @@ -303,10 +303,10 @@ class FlxClothSprite extends FlxSprite y: r * heightInTiles, oldx: c * widthInTiles, oldy: r * heightInTiles, - pinned: ((r == 0 && pinnedSide & UP != 0) - || (r == rows - 1 && pinnedSide & DOWN != 0) - || (c == 0 && pinnedSide & LEFT != 0) - || (c == columns - 1 && pinnedSide & RIGHT != 0)) + pinned: ((r == 0 && pinnedSide.has(UP)) + || (r == rows - 1 && pinnedSide.has(DOWN)) + || (c == 0 && pinnedSide.has(LEFT)) + || (c == columns - 1 && pinnedSide.has(RIGHT))) }); _vertices.push(c * widthInTiles); diff --git a/flixel/addons/plugin/control/FlxControlHandler.hx b/flixel/addons/plugin/control/FlxControlHandler.hx index 8cdb4c42..70d28401 100644 --- a/flixel/addons/plugin/control/FlxControlHandler.hx +++ b/flixel/addons/plugin/control/FlxControlHandler.hx @@ -12,6 +12,7 @@ import flixel.sound.FlxSound; #else import flixel.system.FlxSound; #end +import flixel.util.FlxDirectionFlags; /** * @@ -173,7 +174,7 @@ class FlxControlHandler // Internal time of when they last collided with a valid jumpSurface var _extraSurfaceTime:Int; // The surfaces they can jump from (i.e. FLOOR) - var _jumpSurface:Int; + var _jumpSurface:FlxDirectionFlags; // A function to call every time they jump var _jumpCallback:Void->Void; @@ -612,7 +613,8 @@ class FlxControlHandler * @param callback A user defined function to call when the Sprite jumps * @param altKey Specify an alternative jump key that works AS WELL AS the primary jump key (TODO) */ - public function setJumpButton(key:String, keymode:Int, height:Int, surface:Int, repeatDelay:Int = 250, jumpFromFall:Int = 0, ?callback:Void->Void, + public function setJumpButton(key:String, keymode:Int, height:Int, surface:FlxDirectionFlags, repeatDelay:Int = 250, jumpFromFall:Int = 0, + ?callback:Void->Void, altKey:String = ""):Void { _jumpKey = key; diff --git a/flixel/addons/util/FlxScene.hx b/flixel/addons/util/FlxScene.hx index c4e6151b..910726a5 100644 --- a/flixel/addons/util/FlxScene.hx +++ b/flixel/addons/util/FlxScene.hx @@ -10,6 +10,7 @@ import flixel.tile.FlxTilemap; import flixel.ui.FlxButton; import flixel.util.FlxAxes; import flixel.util.FlxColor; +import flixel.util.FlxDirectionFlags; import haxe.xml.Parser; import openfl.Assets; @@ -250,7 +251,7 @@ class FlxScene case "tile": var id = Std.parseInt(element.att.id); - var collision = Std.parseInt(element.att.collision); + var collision:FlxDirectionFlags = cast Std.parseInt(element.att.collision); tilemap.setTileProperties(id, collision); } From 8eac8160b25bc3654ed362ab5cc96437938cefee Mon Sep 17 00:00:00 2001 From: George FunBook Date: Mon, 9 Dec 2024 15:05:48 -0600 Subject: [PATCH 18/35] update changelog --- CHANGELOG.md | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 669b753e..e0f72459 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,22 @@ -3.2.4 (TBD) +3.3.0 (TBD) ------------------------------ #### Changes and improvements: -- Compatibility with Flixel 5.9.0 ([431](https://github.com/HaxeFlixel/flixel-addons/pull/431)) +- Compatibility with Flixel 5.9.0 ([431](https://github.com/HaxeFlixel/flixel-addons/pull/431))([432](https://github.com/HaxeFlixel/flixel-addons/pull/432))([433](https://github.com/HaxeFlixel/flixel-addons/pull/433))([436](https://github.com/HaxeFlixel/flixel-addons/pull/436))([437](https://github.com/HaxeFlixel/flixel-addons/pull/437))([440](https://github.com/HaxeFlixel/flixel-addons/pull/440))([441](https://github.com/HaxeFlixel/flixel-addons/pull/441)) - Deprecated `FlxRayCastTilemap` - - Minor upkeep for `FlxTilemapExt`, `FlxOgmo3Loader`, `FlxOgmo3Loader` + - Minor upkeep for `FlxTilemapExt`, `FlxOgmo3Loader`, `FlxOgmo3Loader`, `FlxWeapon`, `FlxNapeTilemap`, `FlxTrail`, `FlxExtendedMouseSprite`, `FlxSlider`, `FlxTransitionSprite` +- `FlxTiledSprite`: Honor `clipRect` ([435](https://github.com/HaxeFlixel/flixel-addons/pull/435)) +- `FlxRuntimeShader`: Refactor and improve readibility ([442](https://github.com/HaxeFlixel/flixel-addons/pull/442)) +- Assets: Ran oxipng on all images ([445](https://github.com/HaxeFlixel/flixel-addons/pull/445)) +- `FlxTrail`: Organize logic into various methods to allow overriding particular behavior ([447](https://github.com/HaxeFlixel/flixel-addons/pull/447)) +- `TiledObject`: Add `POINT` type ([448](https://github.com/HaxeFlixel/flixel-addons/pull/448)) +- `TiledLayer`: Add `parallaxX` and `parallaxY` ([449](https://github.com/HaxeFlixel/flixel-addons/pull/449)) +- Remove all implicit `Int` casts from/to `FlxDirectionFlags` ([451](https://github.com/HaxeFlixel/flixel-addons/pull/451)) + +#### New Features: +- `FlxRadialGauge`: Refactor `FlxPieDial` add replacement ([444](https://github.com/HaxeFlixel/flixel-addons/pull/444)) + - `FlxRadialWipeShader`: Shader that masks sprite radially, can be applied to of any static sprite (doesn't work with animations, yet, but neither did FlxPieDial). Shaders only work on non-Flash targets + - `FlxRadialGauge`: Same as `FlxPieDial` but uses less memory, shows more percentages, and performs better + - `FlxPieDialUtils`: Moved all logic from `FlxPieDial` to a shared util 3.2.3 (May 15, 2024) ------------------------------ From fb8d7d6a621efa51f1f3cdd9b94ae14947c9496e Mon Sep 17 00:00:00 2001 From: George FunBook Date: Mon, 9 Dec 2024 15:06:23 -0600 Subject: [PATCH 19/35] update haxelib.json --- haxelib.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/haxelib.json b/haxelib.json index 137b228a..481c1b70 100644 --- a/haxelib.json +++ b/haxelib.json @@ -4,7 +4,7 @@ "license": "MIT", "tags": ["game", "openfl", "flash", "neko", "cpp", "android", "ios", "cross"], "description": "flixel-addons is a set of useful, additional classes for HaxeFlixel.", - "version": "3.2.4", + "version": "3.3.0", "releasenote": "Compatibility with flixel 5.9.0", "contributors": ["haxeflixel", "Gama11", "GeoKureli"] } From 2e10d0c3cad4500339c8e70e0dd6291be6440cd0 Mon Sep 17 00:00:00 2001 From: George Kurelic Date: Tue, 10 Dec 2024 09:15:36 -0600 Subject: [PATCH 20/35] FlxTypeText resetText to prefix (#395) --- flixel/addons/text/FlxTypeText.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flixel/addons/text/FlxTypeText.hx b/flixel/addons/text/FlxTypeText.hx index 2774ef5f..237b1c64 100644 --- a/flixel/addons/text/FlxTypeText.hx +++ b/flixel/addons/text/FlxTypeText.hx @@ -325,7 +325,7 @@ class FlxTypeText extends FlxText */ public function resetText(Text:String):Void { - text = ""; + text = prefix; _finalText = Text; _typing = false; _erasing = false; From b35055352e43d57bb80db178c8a5ea4e3a7377a2 Mon Sep 17 00:00:00 2001 From: George FunBook Date: Tue, 10 Dec 2024 09:21:36 -0600 Subject: [PATCH 21/35] changelog --- CHANGELOG.md | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e0f72459..5d3a9c8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ -3.3.0 (TBD) +3.3.0 (December 10, 2024) ------------------------------ +#### New Features: +- `FlxRadialGauge`: Refactor `FlxPieDial` add replacement ([444](https://github.com/HaxeFlixel/flixel-addons/pull/444)) + - `FlxRadialWipeShader`: Shader that masks sprite radially, can be applied to of any static sprite (doesn't work with animations, yet, but neither did FlxPieDial). Shaders only work on non-Flash targets + - `FlxRadialGauge`: Same as `FlxPieDial` but uses less memory, shows more percentages, and performs better + - `FlxPieDialUtils`: Moved all logic from `FlxPieDial` to a shared util + #### Changes and improvements: - Compatibility with Flixel 5.9.0 ([431](https://github.com/HaxeFlixel/flixel-addons/pull/431))([432](https://github.com/HaxeFlixel/flixel-addons/pull/432))([433](https://github.com/HaxeFlixel/flixel-addons/pull/433))([436](https://github.com/HaxeFlixel/flixel-addons/pull/436))([437](https://github.com/HaxeFlixel/flixel-addons/pull/437))([440](https://github.com/HaxeFlixel/flixel-addons/pull/440))([441](https://github.com/HaxeFlixel/flixel-addons/pull/441)) - Deprecated `FlxRayCastTilemap` @@ -12,11 +18,8 @@ - `TiledLayer`: Add `parallaxX` and `parallaxY` ([449](https://github.com/HaxeFlixel/flixel-addons/pull/449)) - Remove all implicit `Int` casts from/to `FlxDirectionFlags` ([451](https://github.com/HaxeFlixel/flixel-addons/pull/451)) -#### New Features: -- `FlxRadialGauge`: Refactor `FlxPieDial` add replacement ([444](https://github.com/HaxeFlixel/flixel-addons/pull/444)) - - `FlxRadialWipeShader`: Shader that masks sprite radially, can be applied to of any static sprite (doesn't work with animations, yet, but neither did FlxPieDial). Shaders only work on non-Flash targets - - `FlxRadialGauge`: Same as `FlxPieDial` but uses less memory, shows more percentages, and performs better - - `FlxPieDialUtils`: Moved all logic from `FlxPieDial` to a shared util +#### Bugfixes: +- `FlxTypeText`: Honors `prefix` on `reset` calls ([395](https://github.com/HaxeFlixel/flixel-addons/pull/395)) 3.2.3 (May 15, 2024) ------------------------------ From 80e115c9a9674faa88b3be8eb40571a0330f9e25 Mon Sep 17 00:00:00 2001 From: Vortex <73261680+Vortex2Oblivion@users.noreply.github.com> Date: Sun, 22 Dec 2024 20:01:14 +0000 Subject: [PATCH 22/35] Update haxelib.json (#452) --- haxelib.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/haxelib.json b/haxelib.json index 481c1b70..1945d6de 100644 --- a/haxelib.json +++ b/haxelib.json @@ -6,5 +6,8 @@ "description": "flixel-addons is a set of useful, additional classes for HaxeFlixel.", "version": "3.3.0", "releasenote": "Compatibility with flixel 5.9.0", - "contributors": ["haxeflixel", "Gama11", "GeoKureli"] + "contributors": ["haxeflixel", "Gama11", "GeoKureli"], + "dependencies": { + "flixel": "" + } } From 671ad890e71628bfe43403241ede0d933513e6cf Mon Sep 17 00:00:00 2001 From: George Kurelic Date: Sun, 12 Jan 2025 14:31:10 -0600 Subject: [PATCH 23/35] Fix logo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 68035f91..b799cd0a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![](https://raw.github.com/HaxeFlixel/haxeflixel.com/master/src/files/images/flixel-logos/flixel-addons.png) +![](https://github.com/HaxeFlixel/haxeflixel.com/blob/dev/content/_static/images/flixel-logos/flixel-addons.png?raw=true) [flixel](https://github.com/HaxeFlixel/flixel) | [addons](https://github.com/HaxeFlixel/flixel-addons) | [ui](https://github.com/HaxeFlixel/flixel-ui) | [demos](https://github.com/HaxeFlixel/flixel-demos) | [tools](https://github.com/HaxeFlixel/flixel-tools) | [templates](https://github.com/HaxeFlixel/flixel-templates) | [docs](https://github.com/HaxeFlixel/flixel-docs) | [haxeflixel.com](https://github.com/HaxeFlixel/haxeflixel.com) | [türkçe](/README_TR.md) From 8595a752f0f95ee1b13f96d368b6d83b50e1d257 Mon Sep 17 00:00:00 2001 From: George Kurelic Date: Fri, 31 Jan 2025 08:43:21 -0600 Subject: [PATCH 24/35] check correct lib versions (#454) * check correct versions * D'oh --- flixel/addons/display/FlxBackdrop.hx | 4 ++-- flixel/addons/display/FlxShaderMaskCamera.hx | 2 +- flixel/addons/editors/ogmo/FlxOgmo3Loader.hx | 2 +- flixel/addons/editors/spine/FlxSpine.hx | 9 --------- flixel/addons/effects/FlxTrail.hx | 2 +- flixel/addons/effects/chainable/FlxEffectSprite.hx | 2 +- flixel/addons/nape/FlxNapeSpace.hx | 2 +- flixel/addons/nape/FlxNapeTilemap.hx | 2 +- flixel/addons/plugin/control/FlxControlHandler.hx | 2 +- flixel/addons/plugin/screengrab/FlxScreenGrab.hx | 2 -- flixel/addons/system/macros/FlxAddonDefines.hx | 4 ++-- flixel/addons/text/FlxTypeText.hx | 2 +- flixel/addons/tile/FlxTilemapExt.hx | 4 ++-- flixel/addons/transition/FlxTransitionableState.hx | 2 +- flixel/addons/transition/TransitionEffect.hx | 2 +- flixel/addons/ui/FlxButtonPlus.hx | 2 +- flixel/addons/ui/FlxClickArea.hx | 2 +- flixel/addons/ui/FlxSlider.hx | 2 +- flixel/addons/weapon/FlxWeapon.hx | 4 ++-- 19 files changed, 21 insertions(+), 32 deletions(-) diff --git a/flixel/addons/display/FlxBackdrop.hx b/flixel/addons/display/FlxBackdrop.hx index fa12b5a9..5db02afe 100644 --- a/flixel/addons/display/FlxBackdrop.hx +++ b/flixel/addons/display/FlxBackdrop.hx @@ -115,7 +115,7 @@ class FlxBackdrop extends FlxSprite drawToLargestCamera(); } - #if (flixel >= "5.7.0") + #if (flixel >= version("5.7.0")) final cameras = getCamerasLegacy(); #end for (camera in cameras) @@ -161,7 +161,7 @@ class FlxBackdrop extends FlxSprite { var largest:FlxCamera = null; var largestArea = 0.0; - #if (flixel >= "5.7.0") + #if (flixel >= version("5.7.0")) final cameras = getCamerasLegacy(); // else use this.cameras #end for (camera in cameras) diff --git a/flixel/addons/display/FlxShaderMaskCamera.hx b/flixel/addons/display/FlxShaderMaskCamera.hx index 456895b3..846375e6 100644 --- a/flixel/addons/display/FlxShaderMaskCamera.hx +++ b/flixel/addons/display/FlxShaderMaskCamera.hx @@ -1,6 +1,6 @@ package flixel.addons.display; -#if (openfl >= "8.0.0") +#if (openfl >= version("8.0.0")) import flixel.FlxBasic; import flixel.FlxCamera; import flixel.FlxG; diff --git a/flixel/addons/editors/ogmo/FlxOgmo3Loader.hx b/flixel/addons/editors/ogmo/FlxOgmo3Loader.hx index b5702fa0..76152a57 100644 --- a/flixel/addons/editors/ogmo/FlxOgmo3Loader.hx +++ b/flixel/addons/editors/ogmo/FlxOgmo3Loader.hx @@ -284,7 +284,7 @@ class FlxOgmo3Loader for (i in 0...tileFlags.length) { var flag = tileFlags[i]; - #if (flixel < "5.9.0") + #if (flixel = "4.0.0") wrapper.vertices.length = verticesLength; for (i in 0...verticesLength) { wrapper.vertices[i] = worldVertices[i]; } - #else - if (worldVertices.length - verticesLength > 0) - { - worldVertices.splice(verticesLength, worldVertices.length - verticesLength); - } - - wrapper.vertices = worldVertices; - #end wrapper.indices = Vector.ofArray(triangles); wrapper.uvtData = Vector.ofArray(uvtData); diff --git a/flixel/addons/effects/FlxTrail.hx b/flixel/addons/effects/FlxTrail.hx index 2969fe5f..e9264e26 100644 --- a/flixel/addons/effects/FlxTrail.hx +++ b/flixel/addons/effects/FlxTrail.hx @@ -17,7 +17,7 @@ import flixel.math.FlxPoint; * Feel free to use this class and adjust it to your needs. * @author Gama11 */ -class FlxTrail extends #if (flixel < "5.7.0") FlxSpriteGroup #else FlxSpriteContainer #end +class FlxTrail extends #if (flixel < version("5.7.0")) FlxSpriteGroup #else FlxSpriteContainer #end { /** * Stores the FlxSprite the trail is attached to. diff --git a/flixel/addons/effects/chainable/FlxEffectSprite.hx b/flixel/addons/effects/chainable/FlxEffectSprite.hx index cfc87a99..05f4796a 100644 --- a/flixel/addons/effects/chainable/FlxEffectSprite.hx +++ b/flixel/addons/effects/chainable/FlxEffectSprite.hx @@ -2,7 +2,7 @@ package flixel.addons.effects.chainable; // TODO: remove this check when min flixel version is 5.6.0, // So that FlxAddonDefines will handle this -#if (flixel < "5.3.0") +#if (flixel < version("5.3.0")) #error "Flixel-Addons is not compatible with flixel versions older than 5.3.0"; #end diff --git a/flixel/addons/nape/FlxNapeSpace.hx b/flixel/addons/nape/FlxNapeSpace.hx index 054aea43..e8f45de1 100644 --- a/flixel/addons/nape/FlxNapeSpace.hx +++ b/flixel/addons/nape/FlxNapeSpace.hx @@ -64,7 +64,7 @@ class FlxNapeSpace extends FlxBasic */ public static function init():Void { - #if (flixel < "5.6.0") + #if (flixel < version("5.6.0")) FlxG.plugins.add(new FlxNapeSpace()); #else FlxG.plugins.addPlugin(new FlxNapeSpace()); diff --git a/flixel/addons/nape/FlxNapeTilemap.hx b/flixel/addons/nape/FlxNapeTilemap.hx index bc8f529f..30cf8f96 100644 --- a/flixel/addons/nape/FlxNapeTilemap.hx +++ b/flixel/addons/nape/FlxNapeTilemap.hx @@ -100,7 +100,7 @@ class FlxNapeTilemap extends FlxTilemap var polygon:Polygon; for (index in tileIndices) { - #if (flixel >= "5.9.0") + #if (flixel >= version("5.9.0")) final points = getAllTilePos(index); #else final points = getTileCoords(index, false); diff --git a/flixel/addons/plugin/control/FlxControlHandler.hx b/flixel/addons/plugin/control/FlxControlHandler.hx index 70d28401..8a6c0150 100644 --- a/flixel/addons/plugin/control/FlxControlHandler.hx +++ b/flixel/addons/plugin/control/FlxControlHandler.hx @@ -7,7 +7,7 @@ import flixel.FlxSprite; import flixel.math.FlxMath; import flixel.math.FlxPoint; import flixel.math.FlxVelocity; -#if (flixel >= "5.3.0") +#if (flixel >= version("5.3.0")) import flixel.sound.FlxSound; #else import flixel.system.FlxSound; diff --git a/flixel/addons/plugin/screengrab/FlxScreenGrab.hx b/flixel/addons/plugin/screengrab/FlxScreenGrab.hx index 663d9098..2d1eb344 100644 --- a/flixel/addons/plugin/screengrab/FlxScreenGrab.hx +++ b/flixel/addons/plugin/screengrab/FlxScreenGrab.hx @@ -10,11 +10,9 @@ import flixel.addons.util.PNGEncoder; import flixel.FlxG; import flixel.input.keyboard.FlxKey; #if sys -#if (!lime_legacy || lime < "2.9.0") import lime.ui.FileDialog; import lime.ui.FileDialogType; import openfl.display.PNGEncoderOptions; -#end #else import openfl.net.FileReference; #end diff --git a/flixel/addons/system/macros/FlxAddonDefines.hx b/flixel/addons/system/macros/FlxAddonDefines.hx index 8a7f9168..7581d1d4 100644 --- a/flixel/addons/system/macros/FlxAddonDefines.hx +++ b/flixel/addons/system/macros/FlxAddonDefines.hx @@ -41,7 +41,7 @@ class FlxAddonDefines * When the minimum version of flixel is changed to 5.6.0 or greater, remove the above * checks and this comment. */ - #if (flixel < "5.3.0") + #if (flixel < version("5.3.0")) FlxDefines.abortVersion("Flixel", "5.3.0 or newer", "flixel", (macro null).pos); #end } @@ -61,4 +61,4 @@ class FlxAddonDefines Context.fatalError(message, pos); } } -#end \ No newline at end of file +#end diff --git a/flixel/addons/text/FlxTypeText.hx b/flixel/addons/text/FlxTypeText.hx index 237b1c64..3af3592b 100644 --- a/flixel/addons/text/FlxTypeText.hx +++ b/flixel/addons/text/FlxTypeText.hx @@ -2,7 +2,7 @@ package flixel.addons.text; // TODO: remove this check when min flixel version is 5.6.0, // So that FlxAddonDefines will handle this -#if (flixel < "5.3.0") +#if (flixel < version("5.3.0")) #error "Flixel-Addons is not compatible with flixel versions older than 5.3.0"; #end diff --git a/flixel/addons/tile/FlxTilemapExt.hx b/flixel/addons/tile/FlxTilemapExt.hx index 068518a3..b9807224 100644 --- a/flixel/addons/tile/FlxTilemapExt.hx +++ b/flixel/addons/tile/FlxTilemapExt.hx @@ -139,7 +139,7 @@ class FlxTilemapExt extends FlxTilemap } // Copy tile images into the tile buffer - #if (flixel < "5.2.0") + #if (flixel < version("5.2.0")) _point.x = (camera.scroll.x * scrollFactor.x) - x - offset.x + camera.viewOffsetX; // modified from getScreenPosition() _point.y = (camera.scroll.y * scrollFactor.y) - y - offset.y + camera.viewOffsetY; #else @@ -322,7 +322,7 @@ class FlxTilemapExt extends FlxTilemap } } - #if (flixel < "5.9.0") + #if (flixel < version("5.9.0")) /** * THIS IS A COPY FROM FlxTilemap BUT IT SOLVES SLOPE COLLISION TOO * Checks if the Object overlaps any tiles with any collision flags set, diff --git a/flixel/addons/transition/FlxTransitionableState.hx b/flixel/addons/transition/FlxTransitionableState.hx index 3dea1507..3c0a2571 100644 --- a/flixel/addons/transition/FlxTransitionableState.hx +++ b/flixel/addons/transition/FlxTransitionableState.hx @@ -2,7 +2,7 @@ package flixel.addons.transition; // TODO: remove this check when min flixel version is 5.6.0, // So that FlxAddonDefines will handle this -#if (flixel < "5.3.0") +#if (flixel < version("5.3.0")) #error "Flixel-Addons is not compatible with flixel versions older than 5.3.0"; #end diff --git a/flixel/addons/transition/TransitionEffect.hx b/flixel/addons/transition/TransitionEffect.hx index 281d7af7..62b4b5b3 100644 --- a/flixel/addons/transition/TransitionEffect.hx +++ b/flixel/addons/transition/TransitionEffect.hx @@ -10,7 +10,7 @@ import flixel.util.FlxTimer; * @author larsiusprime */ @:allow(flixel.addons.transition.Transition) -class TransitionEffect extends #if (flixel < "5.7.0") FlxSpriteGroup #else FlxSpriteContainer #end +class TransitionEffect extends #if (flixel < version("5.7.0")) FlxSpriteGroup #else FlxSpriteContainer #end { public var finishCallback:Void->Void; public var finished(default, null):Bool = false; diff --git a/flixel/addons/ui/FlxButtonPlus.hx b/flixel/addons/ui/FlxButtonPlus.hx index a2d2b93c..a35ae40c 100644 --- a/flixel/addons/ui/FlxButtonPlus.hx +++ b/flixel/addons/ui/FlxButtonPlus.hx @@ -24,7 +24,7 @@ import flixel.math.FlxMath; * @link http://www.photonstorm.com * @author Richard Davey / Photon Storm */ -class FlxButtonPlus extends #if (flixel < "5.7.0") FlxSpriteGroup #else FlxSpriteContainer #end +class FlxButtonPlus extends #if (flixel < version("5.7.0")) FlxSpriteGroup #else FlxSpriteContainer #end { public static inline var NORMAL:Int = 0; public static inline var HIGHLIGHT:Int = 1; diff --git a/flixel/addons/ui/FlxClickArea.hx b/flixel/addons/ui/FlxClickArea.hx index bc18acb1..0736ba7c 100644 --- a/flixel/addons/ui/FlxClickArea.hx +++ b/flixel/addons/ui/FlxClickArea.hx @@ -133,7 +133,7 @@ class FlxClickArea extends FlxObject if (continueUpdate) { var offAll:Bool = true; - #if (flixel >= "5.7.0") + #if (flixel >= version("5.7.0")) final cameras = getCameras(); // else use this.cameras #end for (camera in cameras) diff --git a/flixel/addons/ui/FlxSlider.hx b/flixel/addons/ui/FlxSlider.hx index c8b97410..f0040924 100644 --- a/flixel/addons/ui/FlxSlider.hx +++ b/flixel/addons/ui/FlxSlider.hx @@ -16,7 +16,7 @@ import flixel.util.FlxSpriteUtil; * A slider GUI element for float and integer manipulation. * @author Gama11 */ -class FlxSlider extends #if (flixel < "5.7.0") FlxSpriteGroup #else FlxSpriteContainer #end +class FlxSlider extends #if (flixel < version("5.7.0")) FlxSpriteGroup #else FlxSpriteContainer #end { /** * The horizontal line in the background. diff --git a/flixel/addons/weapon/FlxWeapon.hx b/flixel/addons/weapon/FlxWeapon.hx index e701528d..733d386b 100644 --- a/flixel/addons/weapon/FlxWeapon.hx +++ b/flixel/addons/weapon/FlxWeapon.hx @@ -2,7 +2,7 @@ package flixel.addons.weapon; // TODO: remove this check when min flixel version is 5.6.0, // So that FlxAddonDefines will handle this -#if (flixel < "5.3.0") +#if (flixel < version("5.3.0")) #error "Flixel-Addons is not compatible with flixel versions older than 5.3.0"; #end @@ -439,7 +439,7 @@ class FlxTypedWeapon if ((object is FlxTilemap)) { - #if (flixel < "5.9.0") + #if (flixel < version("5.9.0")) return cast(object, FlxTilemap).overlapsWithCallback(bullet); #else return cast(object, FlxTilemap).objectOverlapsTiles(bullet); From c2b8e68904eda35183dde4f880752fd86274435f Mon Sep 17 00:00:00 2001 From: George FunBook Date: Fri, 31 Jan 2025 10:05:23 -0600 Subject: [PATCH 25/35] fix dox --- flixel/addons/display/FlxRadialGauge.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flixel/addons/display/FlxRadialGauge.hx b/flixel/addons/display/FlxRadialGauge.hx index 67ba25e4..b0ae39b3 100644 --- a/flixel/addons/display/FlxRadialGauge.hx +++ b/flixel/addons/display/FlxRadialGauge.hx @@ -150,6 +150,6 @@ class FlxRadialWipeShader extends flixel.system.FlxAssets.FlxShader end = 270; } } -#elseif FLX_NO_COVERAGE_TEST +#elseif (FLX_NO_COVERAGE_TEST && !dox) #error "FlxRadialGauge is not supported on flash targets" #end \ No newline at end of file From 321b9e461ec328c7b1a3536ba65ae0cde519db10 Mon Sep 17 00:00:00 2001 From: George FunBook Date: Fri, 31 Jan 2025 10:12:43 -0600 Subject: [PATCH 26/35] release 3.3.1 --- CHANGELOG.md | 4 ++++ haxelib.json | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d3a9c8f..e04d84fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +3.3.1 (January 31, 2025) +------------------------------ +- fix dox + 3.3.0 (December 10, 2024) ------------------------------ #### New Features: diff --git a/haxelib.json b/haxelib.json index 1945d6de..04ab490d 100644 --- a/haxelib.json +++ b/haxelib.json @@ -4,8 +4,8 @@ "license": "MIT", "tags": ["game", "openfl", "flash", "neko", "cpp", "android", "ios", "cross"], "description": "flixel-addons is a set of useful, additional classes for HaxeFlixel.", - "version": "3.3.0", - "releasenote": "Compatibility with flixel 5.9.0", + "version": "3.3.1", + "releasenote": "Fix dox", "contributors": ["haxeflixel", "Gama11", "GeoKureli"], "dependencies": { "flixel": "" From 1d2d2a31078bdf747e3d0fd4b30f9e167cb29c5e Mon Sep 17 00:00:00 2001 From: George FunBook Date: Fri, 31 Jan 2025 10:58:55 -0600 Subject: [PATCH 27/35] fix dox take-2 --- flixel/addons/display/FlxRadialGauge.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flixel/addons/display/FlxRadialGauge.hx b/flixel/addons/display/FlxRadialGauge.hx index b0ae39b3..8c79c70c 100644 --- a/flixel/addons/display/FlxRadialGauge.hx +++ b/flixel/addons/display/FlxRadialGauge.hx @@ -150,6 +150,6 @@ class FlxRadialWipeShader extends flixel.system.FlxAssets.FlxShader end = 270; } } -#elseif (FLX_NO_COVERAGE_TEST && !dox) +#elseif (FLX_NO_COVERAGE_TEST && !doc_gen) #error "FlxRadialGauge is not supported on flash targets" #end \ No newline at end of file From cff2640a6db35544eb3faf3655de5e57a709cc2a Mon Sep 17 00:00:00 2001 From: George FunBook Date: Fri, 31 Jan 2025 11:39:13 -0600 Subject: [PATCH 28/35] 3.3.2 --- CHANGELOG.md | 6 +++++- haxelib.json | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e04d84fd..07a4714e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ +3.3.2 (January 31, 2025) +------------------------------ +- Fix dox, attempt 2 + 3.3.1 (January 31, 2025) ------------------------------ -- fix dox +- Fix dox 3.3.0 (December 10, 2024) ------------------------------ diff --git a/haxelib.json b/haxelib.json index 04ab490d..2193ebc9 100644 --- a/haxelib.json +++ b/haxelib.json @@ -4,8 +4,8 @@ "license": "MIT", "tags": ["game", "openfl", "flash", "neko", "cpp", "android", "ios", "cross"], "description": "flixel-addons is a set of useful, additional classes for HaxeFlixel.", - "version": "3.3.1", - "releasenote": "Fix dox", + "version": "3.3.2", + "releasenote": "Fix dox, attempt 2", "contributors": ["haxeflixel", "Gama11", "GeoKureli"], "dependencies": { "flixel": "" From ef0abbc19c64704f76c1d1be6072f3ed04f9ace7 Mon Sep 17 00:00:00 2001 From: George Kurelic Date: Sat, 1 Feb 2025 12:36:04 -0600 Subject: [PATCH 29/35] Remove more deprecated refs (#455) * remove dir int cast * remove deprecated refs * remove FlxMouseControl and FlxRaycastTilemap * prepare for 4.0.0 --- CHANGELOG.md | 7 +- flixel/addons/plugin/FlxMouseControl.hx | 274 ------------------------ flixel/addons/tile/FlxRayCastTilemap.hx | 49 +++-- flixel/addons/tile/FlxTilemapExt.hx | 2 +- haxelib.json | 4 +- 5 files changed, 37 insertions(+), 299 deletions(-) delete mode 100644 flixel/addons/plugin/FlxMouseControl.hx diff --git a/CHANGELOG.md b/CHANGELOG.md index 07a4714e..88123261 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ -3.3.2 (January 31, 2025) +# 4.0.0 (TBD) +Removed deprecated classes +- `FlxRayCastTilemap`: `FlxBaseTilemap` has an all-around better `ray()` method ([#455](https://github.com/HaxeFlixel/flixel-addons/pull/455)) +- `FlxMouseControl`: Use `FlxMouseEvent`, instead ([#455](https://github.com/HaxeFlixel/flixel-addons/pull/455)) + +## 3.3.2 (January 31, 2025) ------------------------------ - Fix dox, attempt 2 diff --git a/flixel/addons/plugin/FlxMouseControl.hx b/flixel/addons/plugin/FlxMouseControl.hx deleted file mode 100644 index b2604f74..00000000 --- a/flixel/addons/plugin/FlxMouseControl.hx +++ /dev/null @@ -1,274 +0,0 @@ -package flixel.addons.plugin; - -#if FLX_MOUSE -import flixel.addons.display.FlxExtendedMouseSprite; -import flixel.FlxBasic; -import flixel.FlxG; -import flixel.math.FlxMath; -import flixel.math.FlxPoint; -import flixel.math.FlxRect; -import flixel.util.FlxDestroyUtil; - -/** - * FlxMouseControl - * - * @link http://www.photonstorm.com - * @author Richard Davey / Photon Storm - */ -@:deprecated("FlxMouseControl is deprecated, use flixel.input.mouse.FlxMouseEvent") // since 3.1.2 -class FlxMouseControl extends FlxBasic -{ - /** - * Use with sort() to sort in ascending order. - */ - public static inline var ASCENDING:Int = -1; - - /** - * Use with sort() to sort in descending order. - */ - public static inline var DESCENDING:Int = 1; - - /** - * The value that the FlxExtendedMouseSprites are sorted by before deciding which is "on-top" for click select - */ - public static var sortIndex:String = "y"; - - /** - * The sorting order. If the sortIndex is "y" and the order is ASCENDING then a sprite with a Y value of 200 would be "on-top" of one with a Y value of 100. - */ - public static var sortOrder:Int = ASCENDING; - - /** - * Is the mouse currently dragging a sprite? If you have just clicked but NOT yet moved the mouse then this might return false. - */ - public static var isDragging:Bool = false; - - /** - * The FlxExtendedMouseSprite that is currently being dragged, if any. - */ - public static var dragTarget:FlxExtendedMouseSprite; - - public static var clickTarget:FlxExtendedMouseSprite; - - /** - * The speed the mouse is moving on the X axis in pixels per frame - */ - public static var speedX:Int; - - /** - * The speed the mouse is moving on the Y axis in pixels per frame - */ - public static var speedY:Int; - - /** - * The mouse can be set to only be active within a specific FlxRect region of the game world. - * If outside this FlxRect no clicks, drags or throws will be processed. - * If the mouse leaves this region while still dragging then the sprite is automatically dropped and its release handler is called. - * Set the FlxRect to null to disable the zone. - */ - public static var mouseZone:FlxRect; - - /** - * Instead of using a mouseZone (which is calculated in world coordinates) you can limit the mouse to the FlxG.camera.deadzone area instead. - * If set to true the mouse will use the camera deadzone. If false (or the deadzone is null) no check will take place. - * Note that this takes priority over the mouseZone above. If the mouseZone and deadzone are set, the deadzone is used. - */ - public static var linkToDeadZone:Bool = false; - - /** - * The FlxExtendedMouseSprite that currently has the mouse button pressed on it - */ - static var _clickStack:Array = new Array(); - - static var _clickCoords:FlxPoint; - static var _hasClickTarget:Bool = false; - - static var _oldX:Int = 0; - static var _oldY:Int = 0; - - public function new() - { - super(); - - _clickCoords = FlxPoint.get(); - } - - /** - * Adds the given FlxExtendedMouseSprite to the stack of potential sprites that were clicked, the stack is then sorted and the final sprite is selected from that - * - * @param Item The FlxExtendedMouseSprite that was clicked by the mouse - */ - public static function addToStack(Item:FlxExtendedMouseSprite):Void - { - if (mouseZone != null) - { - if (FlxMath.pointInFlxRect(Math.floor(FlxG.mouse.x), Math.floor(FlxG.mouse.y), mouseZone) == true) - { - _clickStack.push(Item); - } - } - else - { - _clickStack.push(Item); - } - } - - /** - * Removes all references to any click / drag targets and resets this class - */ - public static function clear():Void - { - _clickCoords = FlxDestroyUtil.put(_clickCoords); - _hasClickTarget = false; - - if (clickTarget != null) - { - clickTarget.mouseReleasedHandler(); - } - - clickTarget = null; - - isDragging = false; - - if (dragTarget != null) - { - dragTarget.stopDrag(); - } - - speedX = 0; - speedY = 0; - dragTarget = null; - mouseZone = null; - linkToDeadZone = false; - } - - /** - * Main Update Loop - checks mouse status and updates FlxExtendedMouseSprites accordingly - */ - override public function update(elapsed:Float):Void - { - // Update mouse speed - speedX = FlxG.mouse.screenX - _oldX; - speedY = FlxG.mouse.screenY - _oldY; - - _oldX = FlxG.mouse.screenX; - _oldY = FlxG.mouse.screenY; - - // Is the mouse currently pressed down on a target? - if (_hasClickTarget) - { - if (FlxG.mouse.pressed) - { - // Has the mouse moved? If so then we're candidate for a drag - if (isDragging == false - && clickTarget.draggable == true - && (_clickCoords.x != FlxG.mouse.x || _clickCoords.y != FlxG.mouse.y)) - { - // Drag on - isDragging = true; - - dragTarget = clickTarget; - - dragTarget.startDrag(); - } - } - else - { - releaseMouse(); - } - - if (linkToDeadZone == true) - { - if (FlxMath.mouseInFlxRect(false, FlxG.camera.deadzone) == false) - { - releaseMouse(); - } - } - else if (FlxMath.mouseInFlxRect(true, mouseZone) == false) - { - // Is a mouse zone enabled? In which case check if we're still in it - releaseMouse(); - } - } - else - { - // If you are wondering how the brand new array can have anything in it by now, it's because FlxExtendedMouseSprite - // adds itself to the clickStack - if (FlxG.mouse.pressed && _clickStack.length > 0) - { - assignClickedSprite(); - } - } - } - - /** - * Internal function used to release the click / drag targets and reset the mouse state - */ - function releaseMouse():Void - { - // Mouse is no longer down, so tell the click target it's free - this will also stop dragging if happening - clickTarget.mouseReleasedHandler(); - - _hasClickTarget = false; - clickTarget = null; - - isDragging = false; - dragTarget = null; - } - - /** - * Once the clickStack is created this sorts it and then picks the sprite with the highest priority (based on sortIndex and sortOrder) - */ - function assignClickedSprite():Void - { - // If there is more than one potential target then sort them - if (_clickStack.length > 1) - { - _clickStack.sort(sortHandler); - } - - clickTarget = _clickStack.pop(); - - _clickCoords = FlxG.mouse.getWorldPosition(null, _clickCoords); - - _hasClickTarget = true; - - clickTarget.mousePressedHandler(); - - _clickStack = []; - } - - /** - * Helper function for the sort process. - * - * @param Item1 The first object being sorted. - * @param Item2 The second object being sorted. - * - * @return An integer value: -1 (item1 before item2), 0 (same), or 1 (item1 after item2) - */ - function sortHandler(Item1:FlxExtendedMouseSprite, Item2:FlxExtendedMouseSprite):Int - { - var prop1 = Reflect.getProperty(Item1, sortIndex); - var prop2 = Reflect.getProperty(Item2, sortIndex); - - if (prop1 < prop2) - { - return sortOrder; - } - else if (prop1 > prop2) - { - return -sortOrder; - } - - return 0; - } - - /** - * Runs when this plugin is destroyed - */ - override public function destroy():Void - { - clear(); - } -} -#end diff --git a/flixel/addons/tile/FlxRayCastTilemap.hx b/flixel/addons/tile/FlxRayCastTilemap.hx index b708ba1b..7aa55708 100644 --- a/flixel/addons/tile/FlxRayCastTilemap.hx +++ b/flixel/addons/tile/FlxRayCastTilemap.hx @@ -3,10 +3,11 @@ package flixel.addons.tile; import flixel.tile.FlxTilemap; import flixel.math.FlxPoint; +#if (flixel < version("5.9.0")) /** * @author greglieberman */ -@:deprecated("FlxRayCastTilemap is deprecated, use FlxTilemap.ray or rayStep, instead")// for flixel 5.9.0 +@:deprecated("FlxRayCastTilemap is deprecated, use FlxTilemap.ray or rayStep, instead") class FlxRayCastTilemap extends FlxTilemap { /** @@ -74,8 +75,8 @@ class FlxRayCastTilemap extends FlxTilemap } // Find the tile at the start position of the ray - cx = coordsToTileX(Start.x); - cy = coordsToTileY(Start.y); + cx = getColumnAt(Start.x); + cy = getRowAt(Start.y); if (!inTileRange(cx, cy)) { @@ -86,7 +87,7 @@ class FlxRayCastTilemap extends FlxTilemap return false; } - if (getTile(Std.int(cx), Std.int(cy)) > 0) + if (getTileIndex(Std.int(cx), Std.int(cy)) > 0) { // start point is inside a block Result.x = Start.x; @@ -155,7 +156,7 @@ class FlxRayCastTilemap extends FlxTilemap if (tMaxX < tMaxY) { cx = cx + stepX; - if (getTile(Std.int(cx), Std.int(cy)) > 0) + if (getTileIndex(Std.int(cx), Std.int(cy)) > 0) { hitTile = true; break; @@ -173,7 +174,7 @@ class FlxRayCastTilemap extends FlxTilemap { cy = cy + stepY; - if (getTile(Std.int(cx), Std.int(cy)) > 0) + if (getTileIndex(Std.int(cx), Std.int(cy)) > 0) { hitTile = true; break; @@ -210,36 +211,42 @@ class FlxRayCastTilemap extends FlxTilemap return (TileX >= 0 && TileX < widthInTiles && TileY >= 0 && TileY < heightInTiles); } - public function tileAt(CoordX:Float, CoordY:Float):Int + @:deprecated("tileAt is deprecated, use getTileIndexAt, instead") + public function tileAt(worldX:Float, worldY:Float):Int { - return getTile(Std.int((CoordX - x) / scaledTileWidth), Std.int((CoordY - y) / scaledTileHeight)); + return getTileIndexAt(worldX, worldY); } - public function tileIndexAt(CoordX:Float, CoordY:Float):Int + @:deprecated("tileIndexAt is deprecated, use getMapIndexAt, instead") + public function tileIndexAt(worldX:Float, worldY:Float):Int { - var X:Int = Std.int((CoordX - x) / scaledTileWidth); - var Y:Int = Std.int((CoordY - y) / scaledTileHeight); - - return Y * widthInTiles + X; + return getMapIndexAt(worldX, worldY); } - public function coordsToTileX(CoordX:Float):Float + @:deprecated("coordsToTileX is deprecated, use getColumnAt, instead") + public function coordsToTileX(worldX:Float):Float { - return Std.int((CoordX - x) / scaledTileWidth); + return getColumnAt(worldX); } - public function coordsToTileY(CoordY:Float):Float + @:deprecated("coordsToTileY is deprecated, use getRowAt, instead") + public function coordsToTileY(worldY:Float):Float { - return Std.int((CoordY - y) / scaledTileHeight); + return getRowAt(worldY); } - public function indexToCoordX(Index:Int):Float + @:deprecated("indexToCoordX is deprecated, use getColumnPos(getColumn(mapIndex)), instead") + public function indexToCoordX(mapIndex:Int):Float { - return (Index % widthInTiles) * scaledTileWidth + scaledTileWidth / 2; + return getColumnPos(getColumn(mapIndex)); } - public function indexToCoordY(Index:Int):Float + @:deprecated("indexToCoordY is deprecated, use getRowPos(getRow(mapIndex)), instead") + public function indexToCoordY(mapIndex:Int):Float { - return Std.int(Index / widthInTiles) * scaledTileHeight + scaledTileHeight / 2; + return getRowPos(getRow(mapIndex)); } } +#elseif FLX_NO_COVERAGE_TEST +#error "FlxRayCastTilemap has been removed in flixel-addons 4.0.0, use FlxTilemap.ray or rayStep, instead" +#end \ No newline at end of file diff --git a/flixel/addons/tile/FlxTilemapExt.hx b/flixel/addons/tile/FlxTilemapExt.hx index b9807224..959f0696 100644 --- a/flixel/addons/tile/FlxTilemapExt.hx +++ b/flixel/addons/tile/FlxTilemapExt.hx @@ -203,7 +203,7 @@ class FlxTilemapExt extends FlxTilemap { if (tile != null) { - if (tile.allowCollisions <= NONE) + if (tile.allowCollisions == NONE) { debugTile = _debugTileNotSolid; } diff --git a/haxelib.json b/haxelib.json index 2193ebc9..22cb3177 100644 --- a/haxelib.json +++ b/haxelib.json @@ -4,8 +4,8 @@ "license": "MIT", "tags": ["game", "openfl", "flash", "neko", "cpp", "android", "ios", "cross"], "description": "flixel-addons is a set of useful, additional classes for HaxeFlixel.", - "version": "3.3.2", - "releasenote": "Fix dox, attempt 2", + "version": "4.0.0", + "releasenote": "Remove deprecated FlxRayCastTilemap and FlxMouseControl", "contributors": ["haxeflixel", "Gama11", "GeoKureli"], "dependencies": { "flixel": "" From be705ffd4070f6a1f72c4c67b31ca662c51e15f5 Mon Sep 17 00:00:00 2001 From: LeonGamerPS4 <108237023+LeonGamerPS1@users.noreply.github.com> Date: Sat, 22 Feb 2025 22:03:16 +0100 Subject: [PATCH 30/35] Fix Typos in FlxGlitchEffect.hx, FlxWaveEffect.hx, FlxRainbowEffect.hx (#457) * Update FlxRainbowEffect.hx to fix a typo (From FlxEffectRainbow to FlxRainbowEffect) * Update FlxWaveEffect.hx to remove typo * Update FlxGlitchEffect.hx --- flixel/addons/effects/chainable/FlxGlitchEffect.hx | 2 +- flixel/addons/effects/chainable/FlxRainbowEffect.hx | 2 +- flixel/addons/effects/chainable/FlxWaveEffect.hx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/flixel/addons/effects/chainable/FlxGlitchEffect.hx b/flixel/addons/effects/chainable/FlxGlitchEffect.hx index c6666780..cfd5789a 100644 --- a/flixel/addons/effects/chainable/FlxGlitchEffect.hx +++ b/flixel/addons/effects/chainable/FlxGlitchEffect.hx @@ -59,7 +59,7 @@ class FlxGlitchEffect implements IFlxEffect var _pixels:BitmapData; /** - * Creates a new FlxGlitchSprite, which applies a Glitch-distortion effect. + * Creates a new FlxGlitchEffect, which applies a Glitch-distortion effect. * This effect is non-destructive to the target's pixels, and can be used on animated FlxSprites. * * @param Strength How strong you want the effect. diff --git a/flixel/addons/effects/chainable/FlxRainbowEffect.hx b/flixel/addons/effects/chainable/FlxRainbowEffect.hx index 4df1d5d4..14d1a819 100644 --- a/flixel/addons/effects/chainable/FlxRainbowEffect.hx +++ b/flixel/addons/effects/chainable/FlxRainbowEffect.hx @@ -54,7 +54,7 @@ class FlxRainbowEffect implements IFlxEffect var _pixels:BitmapData; /** - * Creates a new FlxEffectRainbow, which applies a color-cycling effect, using the target's bitmap as a mask. + * Creates a new FlxRainbowEffect, which applies a color-cycling effect, using the target's bitmap as a mask. * * @param Alpha A number between 0 and 1 to change the opacity of the effect. * @param Brightness A number between 0 and 1, indicating how bright the color should be. diff --git a/flixel/addons/effects/chainable/FlxWaveEffect.hx b/flixel/addons/effects/chainable/FlxWaveEffect.hx index 18d97123..f29a34eb 100644 --- a/flixel/addons/effects/chainable/FlxWaveEffect.hx +++ b/flixel/addons/effects/chainable/FlxWaveEffect.hx @@ -76,7 +76,7 @@ class FlxWaveEffect implements IFlxEffect var _pixels:BitmapData; /** - * Creates a new FlxEffectWave, which applies a wave-distortion effect. + * Creates a new FlxWaveEffect, which applies a wave-distortion effect. * * @param Mode Which Mode you would like to use for the effect. ALL = applies a constant distortion throughout the image, END = makes the effect get stronger towards the bottom of the image, and START = the reverse of END. * @param Strength How strong you want the effect. From e7350a9af0b40681bde04403c3b08d18d1a18fc4 Mon Sep 17 00:00:00 2001 From: data5 <99661153+FixedData@users.noreply.github.com> Date: Thu, 27 Mar 2025 08:18:21 -0600 Subject: [PATCH 31/35] Update FlxSlider.hx (#458) --- flixel/addons/ui/FlxSlider.hx | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/flixel/addons/ui/FlxSlider.hx b/flixel/addons/ui/FlxSlider.hx index f0040924..801678e4 100644 --- a/flixel/addons/ui/FlxSlider.hx +++ b/flixel/addons/ui/FlxSlider.hx @@ -271,17 +271,14 @@ class FlxSlider extends #if (flixel < version("5.7.0")) FlxSpriteGroup #else Flx override public function update(elapsed:Float):Void { // Clicking and sound logic - #if (flixel >= version("5.7.0")) - final camera = getCameras()[0];// else use this.camera - #end - #if (flixel >= version("5.9.0")) - final viewX = FlxG.mouse.viewX; - final viewY = FlxG.mouse.viewY; + #if (flixel >= "5.7.0") + final cam = getDefaultCamera(); #else - final viewX = FlxG.mouse.screenX; - final viewY = FlxG.mouse.screenY; + final cam = this.camera; #end - if (FlxMath.pointInFlxRect(viewX, viewY, _bounds)) + final mousePosition = FlxG.mouse.getViewPosition(cam); + + if (FlxMath.pointInFlxRect(mousePosition.x, mousePosition.y, _bounds)) { if (hoverAlpha != 1) { @@ -299,7 +296,7 @@ class FlxSlider extends #if (flixel < version("5.7.0")) FlxSpriteGroup #else Flx if (FlxG.mouse.pressed) { - handle.x = viewX; + handle.x = mousePosition.x; updateValue(); #if FLX_SOUND_SYSTEM @@ -326,7 +323,7 @@ class FlxSlider extends #if (flixel < version("5.7.0")) FlxSpriteGroup #else Flx } // Update the target value whenever the slider is being used - if ((FlxG.mouse.pressed) && (FlxMath.mouseInFlxRect(false, _bounds))) + if ((FlxG.mouse.pressed) && (FlxMath.pointInFlxRect(mousePosition.x, mousePosition.y, _bounds))) { updateValue(); } @@ -346,6 +343,9 @@ class FlxSlider extends #if (flixel < version("5.7.0")) FlxSpriteGroup #else Flx // Finally, update the valueLabel valueLabel.text = Std.string(FlxMath.roundDecimal(value, decimals)); + mousePosition.put(); + + super.update(elapsed); } From 24dafc6facd6f1b2affe88d45962bccc9db593ad Mon Sep 17 00:00:00 2001 From: GeoKureli-BlackbookPro Date: Mon, 28 Apr 2025 10:27:13 -0500 Subject: [PATCH 32/35] 6.1.0 upkeep, non null colorTransform --- flixel/addons/display/FlxNestedSprite.hx | 32 ++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/flixel/addons/display/FlxNestedSprite.hx b/flixel/addons/display/FlxNestedSprite.hx index a6c91ce3..f1fc1973 100644 --- a/flixel/addons/display/FlxNestedSprite.hx +++ b/flixel/addons/display/FlxNestedSprite.hx @@ -1,7 +1,5 @@ package flixel.addons.display; -import flixel.util.FlxDirectionFlags; -import openfl.geom.ColorTransform; import flixel.FlxBasic; import flixel.FlxG; import flixel.FlxSprite; @@ -12,6 +10,8 @@ import flixel.math.FlxVelocity; import flixel.system.FlxAssets.FlxGraphicAsset; import flixel.util.FlxColor; import flixel.util.FlxDestroyUtil; +import flixel.util.FlxDirectionFlags; +import openfl.geom.ColorTransform; using flixel.util.FlxArrayUtil; @@ -297,6 +297,7 @@ class FlxNestedSprite extends FlxSprite var green:Float = (color >> 8 & 0xff) * _parentGreen / 255; var blue:Float = (color & 0xff) * _parentBlue / 255; + #if (flixel < version("6.1.0")) if (colorTransform == null) { colorTransform = new ColorTransform(red, green, blue, alpha); @@ -309,9 +310,16 @@ class FlxNestedSprite extends FlxSprite colorTransform.alphaMultiplier = alpha; } useColorTransform = true; + #else + colorTransform.redMultiplier = red; + colorTransform.greenMultiplier = green; + colorTransform.blueMultiplier = blue; + colorTransform.alphaMultiplier = alpha; + #end } else { + #if (flixel < version("6.1.0")) if (colorTransform != null) { colorTransform.redMultiplier = 1; @@ -320,6 +328,12 @@ class FlxNestedSprite extends FlxSprite colorTransform.alphaMultiplier = 1; } useColorTransform = false; + #else + colorTransform.redMultiplier = 1; + colorTransform.greenMultiplier = 1; + colorTransform.blueMultiplier = 1; + colorTransform.alphaMultiplier = 1; + #end } dirty = true; @@ -348,6 +362,7 @@ class FlxNestedSprite extends FlxSprite color = combinedColor; if ((alpha != 1) || (color != 0x00ffffff)) { + #if (flixel < version("6.1.0")) if (colorTransform == null) { colorTransform = new ColorTransform(combinedRed, combinedGreen, combinedBlue, alpha); @@ -360,9 +375,16 @@ class FlxNestedSprite extends FlxSprite colorTransform.alphaMultiplier = alpha; } useColorTransform = true; + #else + colorTransform.redMultiplier = combinedRed; + colorTransform.greenMultiplier = combinedGreen; + colorTransform.blueMultiplier = combinedBlue; + colorTransform.alphaMultiplier = alpha; + #end } else { + #if (flixel < version("6.1.0")) if (colorTransform != null) { colorTransform.redMultiplier = 1; @@ -371,6 +393,12 @@ class FlxNestedSprite extends FlxSprite colorTransform.alphaMultiplier = 1; } useColorTransform = false; + #else + colorTransform.redMultiplier = 1; + colorTransform.greenMultiplier = 1; + colorTransform.blueMultiplier = 1; + colorTransform.alphaMultiplier = 1; + #end } dirty = true; From dcd3895f404fece5580d28f2d47c3cb12b279a2b Mon Sep 17 00:00:00 2001 From: ACrazyTown <47027981+ACrazyTown@users.noreply.github.com> Date: Mon, 30 Jun 2025 20:14:22 +0200 Subject: [PATCH 33/35] FlxGridOverlay: Prevent freeze when passing invalid cell size values (#462) * FlxGridOverlay: Prevent freeze when passing invalid cell size values * Throw instead of returning null * Docs --- flixel/addons/display/FlxGridOverlay.hx | 30 +++++++++++++------------ 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/flixel/addons/display/FlxGridOverlay.hx b/flixel/addons/display/FlxGridOverlay.hx index 949ea9f9..227e46f9 100644 --- a/flixel/addons/display/FlxGridOverlay.hx +++ b/flixel/addons/display/FlxGridOverlay.hx @@ -22,10 +22,10 @@ class FlxGridOverlay * If false each row will be the same colour, creating a striped-pattern effect. * So to create an 8x8 grid you'd call create(8,8) * - * @param CellWidth The grid cell width - * @param CellHeight The grid cell height - * @param Width The width of the FlxSprite. If -1 it will be the size of the game (FlxG.width) - * @param Height The height of the FlxSprite. If -1 it will be the size of the game (FlxG.height) + * @param CellWidth The grid cell width. Must be greater than 0. + * @param CellHeight The grid cell height. Must be greater than 0. + * @param Width The width of the FlxSprite. If -1 it will be the size of the game (FlxG.width). This value cannot be smaller than the `CellWidth` + * @param Height The height of the FlxSprite. If -1 it will be the size of the game (FlxG.height). This value cannot be smaller than the `CellHeight` * @param Alternate Should the pattern alternate on each new row? Default true = checkerboard effect. False = vertical stripes * @param Color1 The first fill colour in 0xAARRGGBB format * @param Color2 The second fill colour in 0xAARRGGBB format @@ -45,9 +45,10 @@ class FlxGridOverlay } if (Width < CellWidth || Height < CellHeight) - { - return null; - } + throw "The width and height of a grid cannot be smaller than the cell's width and height!"; + + if (CellWidth <= 0 || CellHeight <= 0) + throw "Grid cell width/height cannot be less or equal to 0"; var grid:BitmapData = createGrid(CellWidth, CellHeight, Width, Height, Alternate, Color1, Color2); @@ -67,10 +68,10 @@ class FlxGridOverlay * So to create an 8x8 grid you'd call create(8,8, * * @param Sprite The FlxSprite you wish to draw the grid on-top of. This updates its pixels value, not just the current frame (don't use animated sprites!) - * @param CellWidth The grid cell width - * @param CellHeight The grid cell height - * @param Width The width of the FlxSprite. If -1 it will be the size of the game (FlxG.width) - * @param Height The height of the FlxSprite. If -1 it will be the size of the game (FlxG.height) + * @param CellWidth The grid cell width. Must be greater than 0. + * @param CellHeight The grid cell height. Must be greater than 0. + * @param Width The width of the FlxSprite. If -1 it will be the size of the game (FlxG.width). This value cannot be smaller than the `CellWidth` + * @param Height The height of the FlxSprite. If -1 it will be the size of the game (FlxG.height). This value cannot be smaller than the `CellHeight` * @param Alternate Should the pattern alternate on each new row? Default true = checkerboard effect. False = vertical stripes * @param Color1 The first fill colour in 0xAARRGGBB format * @param Color2 The second fill colour in 0xAARRGGBB format @@ -90,9 +91,10 @@ class FlxGridOverlay } if (Width < CellWidth || Height < CellHeight) - { - return null; - } + throw "The width and height of a grid cannot be smaller than the cell's width and height!"; + + if (CellWidth <= 0 || CellHeight <= 0) + throw "Grid cell width/height cannot be less or equal to 0"; var grid:BitmapData = createGrid(CellWidth, CellHeight, Width, Height, Alternate, Color1, Color2); Sprite.pixels.copyPixels(grid, new Rectangle(0, 0, Width, Height), new Point(0, 0), null, null, true); From 8c97faed320d507908fc33920580c8d2f801e55b Mon Sep 17 00:00:00 2001 From: MAJigsaw77 <77043862+MAJigsaw77@users.noreply.github.com> Date: Sun, 12 Oct 2025 11:51:47 +0300 Subject: [PATCH 34/35] Use the `clipRect` impl on `FlxTiledSprite` from `flixel`. --- flixel/addons/display/FlxTiledSprite.hx | 150 +++++++++++++++--------- 1 file changed, 92 insertions(+), 58 deletions(-) diff --git a/flixel/addons/display/FlxTiledSprite.hx b/flixel/addons/display/FlxTiledSprite.hx index b23712b6..2f9f643b 100644 --- a/flixel/addons/display/FlxTiledSprite.hx +++ b/flixel/addons/display/FlxTiledSprite.hx @@ -105,20 +105,19 @@ class FlxTiledSprite extends FlxStrip graphic = FlxGraphic.fromFrame(frame); return this; } - - override function set_clipRect(Value:FlxRect):FlxRect + + override function set_clipRect(value:FlxRect):FlxRect { - if (Value != clipRect) - regen = true; - - return super.set_clipRect(Value); + regen = true; + + return super.set_clipRect(value); } - - override function set_graphic(Value:FlxGraphic):FlxGraphic + + override function set_graphic(value:FlxGraphic):FlxGraphic { if (graphic != value) regen = true; - + return super.set_graphic(value); } @@ -126,7 +125,7 @@ class FlxTiledSprite extends FlxStrip { if (!regen || graphic == null) return; - + if (FlxG.renderBlit) { updateRenderSprite(); @@ -143,7 +142,7 @@ class FlxTiledSprite extends FlxStrip { if (regen) regenGraphic(); - + if (graphicVisible) { if (FlxG.renderBlit) @@ -174,7 +173,7 @@ class FlxTiledSprite extends FlxStrip { if (ignoreDrawDebug) return; - + final drawPath = path != null && !path.ignoreDrawDebug; for (camera in getCamerasLegacy()) @@ -195,13 +194,13 @@ class FlxTiledSprite extends FlxStrip if (renderSprite == null) renderSprite = new FlxSprite(); - + final drawRect = getDrawRect(); drawRect.x = Std.int(drawRect.x); drawRect.y = Std.int(drawRect.y); drawRect.width = Std.int(drawRect.width); drawRect.height = Std.int(drawRect.height); - //TODO: rect.int() or smth + // TODO: rect.int() or smth if (drawRect.width * drawRect.height == 0) { @@ -243,61 +242,96 @@ class FlxTiledSprite extends FlxStrip { if (graphic == null) return; - + final frame:FlxFrame = graphic.imageFrame.frame; graphicVisible = true; - - var rectX:Float = (repeatX ? 0 : scrollX); - rectX = FlxMath.bound(rectX, 0, width); - if (clipRect != null) rectX += clipRect.x; - - var rectWidth:Float = (repeatX ? rectX + width : scrollX + frame.sourceSize.x); - if (clipRect != null) rectWidth = FlxMath.bound(rectWidth, clipRect.x, clipRect.x + clipRect.width); - + + final drawRect = getDrawRect(); + + if (drawRect.width * drawRect.height == 0) + { + graphicVisible = false; + drawRect.put(); + return; + } + // Texture coordinates (UVs) - var rectUX:Float = (rectX - scrollX) / frame.sourceSize.x; - var rectVX:Float = rectUX + (rectWidth-rectX) / frame.sourceSize.x; - - vertices[0] = rectX; - vertices[2] = rectWidth; - vertices[4] = rectWidth; - vertices[6] = rectX; - + final rectUX:Float = (drawRect.x - scrollX) / frame.sourceSize.x; + final rectVX:Float = rectUX + (drawRect.width - drawRect.x) / frame.sourceSize.x; + final rectUY:Float = (drawRect.y - scrollY) / frame.sourceSize.y; + final rectVY:Float = rectUY + (drawRect.height - drawRect.y) / frame.sourceSize.y; + + vertices[0] = drawRect.x; + vertices[2] = drawRect.width; + vertices[4] = drawRect.width; + vertices[6] = drawRect.x; + uvtData[0] = rectUX; uvtData[2] = rectVX; uvtData[4] = rectVX; uvtData[6] = rectUX; - - var rectY:Float = (repeatY ? 0 : scrollY); - rectY = FlxMath.bound(rectY, 0, height); - if (clipRect != null) rectY += clipRect.y; - - var rectHeight:Float = (repeatY ? rectY + height : scrollY + frame.sourceSize.y); - if (clipRect != null) rectHeight = FlxMath.bound(rectHeight, clipRect.y, clipRect.y + clipRect.height); - - // Texture coordinates (UVs) - var rectUY:Float = (rectY - scrollY) / frame.sourceSize.y; - var rectVY:Float = rectUY + (rectHeight-rectY) / frame.sourceSize.y; - - vertices[1] = rectY; - vertices[3] = rectY; - vertices[5] = rectHeight; - vertices[7] = rectHeight; - + + vertices[1] = drawRect.y; + vertices[3] = drawRect.y; + vertices[5] = drawRect.height; + vertices[7] = drawRect.height; + uvtData[1] = rectUY; uvtData[3] = rectUY; uvtData[5] = rectVY; uvtData[7] = rectVY; + + drawRect.put(); } - - override function set_width(Width:Float):Float + + function getDrawRect(?result:FlxRect):FlxRect + { + if (result == null) + result = FlxRect.get(); + + final frame:FlxFrame = graphic.imageFrame.frame; + final sourceSizeX = FlxG.renderBlit ? graphic.bitmap.width : frame.sourceSize.x; + final sourceSizeY = FlxG.renderBlit ? graphic.bitmap.height : frame.sourceSize.y; + + result.x = (repeatX ? 0 : scrollX); + if (clipRect != null) + { + result.x += clipRect.x; + } + result.x = FlxMath.bound(result.x, 0, width); + + result.width = (repeatX ? result.x + width : scrollX + sourceSizeX); + if (clipRect != null) + { + result.width = FlxMath.bound(result.width, clipRect.x, clipRect.right); + } + result.width = FlxMath.bound(result.width, 0, width); + + result.y = (repeatY ? 0 : scrollY); + if (clipRect != null) + { + result.y += clipRect.y; + } + result.y = FlxMath.bound(result.y, 0, height); + + result.height = (repeatY ? result.y + height : scrollY + sourceSizeY); + if (clipRect != null) + { + result.height = FlxMath.bound(result.height, clipRect.y, clipRect.bottom); + } + result.height = FlxMath.bound(result.height, 0, height); + + return result; + } + + override function set_width(value:Float):Float { if (value <= 0) return value; - + if (value != width) regen = true; - + return super.set_width(value); } @@ -305,10 +339,10 @@ class FlxTiledSprite extends FlxStrip { if (value <= 0) return value; - + if (value != height) regen = true; - + return super.set_height(value); } @@ -316,7 +350,7 @@ class FlxTiledSprite extends FlxStrip { if (value != scrollX) regen = true; - + return scrollX = value; } @@ -324,7 +358,7 @@ class FlxTiledSprite extends FlxStrip { if (value != scrollY) regen = true; - + return scrollY = value; } @@ -332,7 +366,7 @@ class FlxTiledSprite extends FlxStrip { if (value != repeatX) regen = true; - + return repeatX = value; } @@ -340,7 +374,7 @@ class FlxTiledSprite extends FlxStrip { if (value != repeatY) regen = true; - + return repeatY = value; } } From a54bb20361979a8e51c62896afddbdd1cc42334e Mon Sep 17 00:00:00 2001 From: MAJigsaw77 <77043862+MAJigsaw77@users.noreply.github.com> Date: Sun, 12 Oct 2025 12:08:49 +0300 Subject: [PATCH 35/35] Change `to24Bit()` to `rgb` to fix deprecation warnings. --- flixel/addons/display/FlxNestedSprite.hx | 2 +- flixel/addons/display/FlxShaderMaskCamera.hx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/flixel/addons/display/FlxNestedSprite.hx b/flixel/addons/display/FlxNestedSprite.hx index f1fc1973..16cc988b 100644 --- a/flixel/addons/display/FlxNestedSprite.hx +++ b/flixel/addons/display/FlxNestedSprite.hx @@ -348,7 +348,7 @@ class FlxNestedSprite extends FlxSprite override function set_color(Color:FlxColor):FlxColor { - Color = Color.to24Bit(); + Color = Color.rgb; var combinedRed:Float = (Color >> 16) * _parentRed / 255; var combinedGreen:Float = (Color >> 8 & 0xff) * _parentGreen / 255; diff --git a/flixel/addons/display/FlxShaderMaskCamera.hx b/flixel/addons/display/FlxShaderMaskCamera.hx index 846375e6..d935be62 100644 --- a/flixel/addons/display/FlxShaderMaskCamera.hx +++ b/flixel/addons/display/FlxShaderMaskCamera.hx @@ -111,7 +111,7 @@ class FlxShaderMaskCamera extends FlxCamera { // clear our duplicate canvas shaderCanvas.graphics.clear(); - super.fill(bgColor.to24Bit(), useBgAlphaBlending, bgColor.alphaFloat, shaderCanvas.graphics); + super.fill(bgColor.rgb, useBgAlphaBlending, bgColor.alphaFloat, shaderCanvas.graphics); // iterate over draw items, but draw them to both canvases var currItem:FlxDrawBaseItem = _headOfDrawStack; var oldCanvas:Sprite = canvas;