From 4d9dc50ff6d38808defb7ca72aa7086f73ced230 Mon Sep 17 00:00:00 2001 From: George Kurelic Date: Mon, 9 Dec 2024 15:04:40 -0600 Subject: [PATCH] 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); }