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": ""