diff --git a/CHANGELOG.md b/CHANGELOG.md index e6f4ec4c0f..f45ed1bd13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,9 +54,16 @@ We removed many features and utilities that were previously deprecated - `FlxRect`: Add `clipTo` and fix `intersection` bug ([#3190](https://github.com/HaxeFlixel/flixel/pull/3190)) - `FlxPointer`: Add `getGamePosition`, `gameX/Y`, `getViewPosition`, and `viewX/Y`, to replace "screen" fields ([#3210](https://github.com/HaxeFlixel/flixel/pull/3210)) - `FlxAnimationController`: Add `onLoop`, `onFrameChange` and `onFinish`, to replace `callback` and `finishCallback` ([#3205](https://github.com/HaxeFlixel/flixel/pull/3205)) ([#3216](https://github.com/HaxeFlixel/flixel/pull/3216)) -- `FlxStrip`: Add support for blendmodes ([3213](https://github.com/HaxeFlixel/flixel/pull/3213)) -- `FlxTextBorderStyle`: Add SHADOW_XY, prevent border clipping ([3236](https://github.com/HaxeFlixel/flixel/pull/3236)) -- `LogStyle`: add `callback` to replace `callbackFunction` ([3239](https://github.com/HaxeFlixel/flixel/pull/3239)) +- `FlxStrip`: Add support for blendmodes ([#3213](https://github.com/HaxeFlixel/flixel/pull/3213)) +- `FlxTextBorderStyle`: Add SHADOW_XY, prevent border clipping ([#3236](https://github.com/HaxeFlixel/flixel/pull/3236)) +- `LogStyle`: Add `callback` to replace `callbackFunction` ([#3239](https://github.com/HaxeFlixel/flixel/pull/3239)) +- `FlxBar`: Add custom border sizes ([#3234](https://github.com/HaxeFlixel/flixel/pull/3234)) +- Gamepads: Add `acceptMode` and "mapped inputs" ([#3276](https://github.com/HaxeFlixel/flixel/pull/3276)) ([#3280](https://github.com/HaxeFlixel/flixel/pull/3280)) + - Add `ACCEPT` and `CANCEL` input IDs that conditionally map to either `A` or `B` depending on `FlxG.gamepads.acceptMode` + - Add `gamepad.getMappedInput` to get an anum value of every possible gamepad input from various devices, i.e. `PS4(PS4ID.X)` +- `FlxG.assets`: A way to overwrite and customize the way HaxeFlixel fetches or produces assets from ids ([#2982](https://github.com/HaxeFlixel/flixel/pull/2982)) +- `FlxG.cameras`: Add `insert` method ([#3290](https://github.com/HaxeFlixel/flixel/pull/3290)) +- `FlxSave`: Allow custom handling of parsing errors ([#3286](https://github.com/HaxeFlixel/flixel/pull/3286)) #### Changes and improvements: - `FlxKey`: Add `NONE` to `fromStringMap` and `toStringMap` ([#3119](https://github.com/HaxeFlixel/flixel/pull/3119)) @@ -88,6 +95,12 @@ We removed many features and utilities that were previously deprecated - Debugging: Check alpha when point-selecting sprites ([#3184](https://github.com/HaxeFlixel/flixel/pull/3184)) - `FlxBitmapText`: Ignore border outline when computing field size ([#3193](https://github.com/HaxeFlixel/flixel/pull/3193)) - `FlxDebugger`: Improve console code completion ([#3222](https://github.com/HaxeFlixel/flixel/pull/3222)) +- `FlxGraphicsShader`: Optimize color math ([#3227](https://github.com/HaxeFlixel/flixel/pull/3227)) +- Improve android config on lime 8.2.0 ([#3253](https://github.com/HaxeFlixel/flixel/pull/3253)) +- Debug Watch: Resize the watch window when watchers are added or removed ([#3251](https://github.com/HaxeFlixel/flixel/pull/3251)) +- Reduce memory of Flixel's embedded assets via oxipng ([#3257](https://github.com/HaxeFlixel/flixel/pull/3257)) +- Debug Stats: Improve accuracy of "Total Memory" in OpenFL 9.4.0 ([#3266](https://github.com/HaxeFlixel/flixel/pull/3266)) +- `FlxGraphic`: Improve checks for max texture size ([#3279](https://github.com/HaxeFlixel/flixel/pull/3279)) #### Bugfixes: - `FlxFlickerTween`: Fix "Unsupported recursive type" error on hl ([#3170](https://github.com/HaxeFlixel/flixel/pull/3170)) @@ -97,6 +110,9 @@ We removed many features and utilities that were previously deprecated - `FlxCamera`: Fix blending issue ([#3217](https://github.com/HaxeFlixel/flixel/pull/3217)) ([#3255](https://github.com/HaxeFlixel/flixel/pull/3255)) - `FlxStrip`: Fix `color` preventing other strips from drawing ([#3220](https://github.com/HaxeFlixel/flixel/pull/3220)) - `FlxButton`: Fix `label` position when moves is false ([#3232](https://github.com/HaxeFlixel/flixel/pull/3232)) +- Debug Console: Fix arrow keys ([#3247](https://github.com/HaxeFlixel/flixel/pull/3247)) +- `FlxGame`: Fix `ACTIVATE` and `DEACTIVATE` event dispatches ([#3260](https://github.com/HaxeFlixel/flixel/pull/3260)) +- `FlxAction`: Fix bug where multiple `check` calls wipe analog fields ([#3277](https://github.com/HaxeFlixel/flixel/pull/3277)) 5.8.0 (April 19, 2024) ------------------------------ diff --git a/assets/images/debugger/buttons/arrowLeft.png b/assets/images/debugger/buttons/arrowLeft.png index dd4f2b5d5d..9db907b742 100644 Binary files a/assets/images/debugger/buttons/arrowLeft.png and b/assets/images/debugger/buttons/arrowLeft.png differ diff --git a/assets/images/debugger/buttons/bitmapLog.png b/assets/images/debugger/buttons/bitmapLog.png index 3772a3bf52..01b92ea131 100644 Binary files a/assets/images/debugger/buttons/bitmapLog.png and b/assets/images/debugger/buttons/bitmapLog.png differ diff --git a/assets/images/debugger/buttons/close.png b/assets/images/debugger/buttons/close.png index 97435a31fc..ee3f129222 100644 Binary files a/assets/images/debugger/buttons/close.png and b/assets/images/debugger/buttons/close.png differ diff --git a/assets/images/debugger/buttons/console.png b/assets/images/debugger/buttons/console.png index c01b4820c7..886391def9 100644 Binary files a/assets/images/debugger/buttons/console.png and b/assets/images/debugger/buttons/console.png differ diff --git a/assets/images/debugger/buttons/eraser.png b/assets/images/debugger/buttons/eraser.png index 3afeb609e1..c1a66b2090 100644 Binary files a/assets/images/debugger/buttons/eraser.png and b/assets/images/debugger/buttons/eraser.png differ diff --git a/assets/images/debugger/buttons/interactive.png b/assets/images/debugger/buttons/interactive.png index 07c0e2153f..d5be49d4f0 100644 Binary files a/assets/images/debugger/buttons/interactive.png and b/assets/images/debugger/buttons/interactive.png differ diff --git a/assets/images/debugger/buttons/log.png b/assets/images/debugger/buttons/log.png index 22c7e58cc4..23c84b11a9 100644 Binary files a/assets/images/debugger/buttons/log.png and b/assets/images/debugger/buttons/log.png differ diff --git a/assets/images/debugger/buttons/maximize.png b/assets/images/debugger/buttons/maximize.png index a7a091d165..efea3b550f 100644 Binary files a/assets/images/debugger/buttons/maximize.png and b/assets/images/debugger/buttons/maximize.png differ diff --git a/assets/images/debugger/buttons/minimize.png b/assets/images/debugger/buttons/minimize.png index 6be4754d3d..76db33fa59 100644 Binary files a/assets/images/debugger/buttons/minimize.png and b/assets/images/debugger/buttons/minimize.png differ diff --git a/assets/images/debugger/buttons/mover.png b/assets/images/debugger/buttons/mover.png index 9d6f8dd64d..736ca774a7 100644 Binary files a/assets/images/debugger/buttons/mover.png and b/assets/images/debugger/buttons/mover.png differ diff --git a/assets/images/debugger/buttons/pause.png b/assets/images/debugger/buttons/pause.png index 5982e37446..33be064d2d 100644 Binary files a/assets/images/debugger/buttons/pause.png and b/assets/images/debugger/buttons/pause.png differ diff --git a/assets/images/debugger/buttons/pointer.png b/assets/images/debugger/buttons/pointer.png index 1443e67b91..1f6da7ec0d 100644 Binary files a/assets/images/debugger/buttons/pointer.png and b/assets/images/debugger/buttons/pointer.png differ diff --git a/assets/images/debugger/buttons/stats.png b/assets/images/debugger/buttons/stats.png index 5c4a7173e0..843b489905 100644 Binary files a/assets/images/debugger/buttons/stats.png and b/assets/images/debugger/buttons/stats.png differ diff --git a/assets/images/debugger/buttons/toggleSize.png b/assets/images/debugger/buttons/toggleSize.png index a215e49877..57cf4ab4be 100644 Binary files a/assets/images/debugger/buttons/toggleSize.png and b/assets/images/debugger/buttons/toggleSize.png differ diff --git a/assets/images/debugger/buttons/transform.png b/assets/images/debugger/buttons/transform.png index a81710440c..0fb049a1a4 100644 Binary files a/assets/images/debugger/buttons/transform.png and b/assets/images/debugger/buttons/transform.png differ diff --git a/assets/images/debugger/buttons/watch.png b/assets/images/debugger/buttons/watch.png index a0f9056b7b..39abf456bf 100644 Binary files a/assets/images/debugger/buttons/watch.png and b/assets/images/debugger/buttons/watch.png differ diff --git a/assets/images/debugger/cursorCross.png b/assets/images/debugger/cursorCross.png index 21275c359b..a9a743d8cc 100644 Binary files a/assets/images/debugger/cursorCross.png and b/assets/images/debugger/cursorCross.png differ diff --git a/assets/images/debugger/cursors/transformRotate.png b/assets/images/debugger/cursors/transformRotate.png index 3737f9c6f6..a70aafc1d6 100644 Binary files a/assets/images/debugger/cursors/transformRotate.png and b/assets/images/debugger/cursors/transformRotate.png differ diff --git a/assets/images/debugger/cursors/transformScaleX.png b/assets/images/debugger/cursors/transformScaleX.png index 8422ad04f2..c1490b315f 100644 Binary files a/assets/images/debugger/cursors/transformScaleX.png and b/assets/images/debugger/cursors/transformScaleX.png differ diff --git a/assets/images/debugger/cursors/transformScaleXY.png b/assets/images/debugger/cursors/transformScaleXY.png index 60349c8145..cafeec9172 100644 Binary files a/assets/images/debugger/cursors/transformScaleXY.png and b/assets/images/debugger/cursors/transformScaleXY.png differ diff --git a/assets/images/debugger/cursors/transformScaleY.png b/assets/images/debugger/cursors/transformScaleY.png index 05a8d5c1ff..7826244114 100644 Binary files a/assets/images/debugger/cursors/transformScaleY.png and b/assets/images/debugger/cursors/transformScaleY.png differ diff --git a/assets/images/debugger/flixel.png b/assets/images/debugger/flixel.png index 7a5fafd825..8d3764299c 100644 Binary files a/assets/images/debugger/flixel.png and b/assets/images/debugger/flixel.png differ diff --git a/assets/images/logo/default.png b/assets/images/logo/default.png index e0376d6b21..7a684e86df 100644 Binary files a/assets/images/logo/default.png and b/assets/images/logo/default.png differ diff --git a/assets/images/logo/logo.png b/assets/images/logo/logo.png index e6a78d18cf..03b6adde02 100644 Binary files a/assets/images/logo/logo.png and b/assets/images/logo/logo.png differ diff --git a/assets/images/tile/autotiles_full.png b/assets/images/tile/autotiles_full.png index e2f2458321..f1886f6f02 100644 Binary files a/assets/images/tile/autotiles_full.png and b/assets/images/tile/autotiles_full.png differ diff --git a/assets/images/ui/button.png b/assets/images/ui/button.png index 3a39af5069..0df1ba2b6f 100644 Binary files a/assets/images/ui/button.png and b/assets/images/ui/button.png differ diff --git a/assets/images/ui/virtual-input.png b/assets/images/ui/virtual-input.png index b0fe0ef6d7..916236b5c6 100644 Binary files a/assets/images/ui/virtual-input.png and b/assets/images/ui/virtual-input.png differ diff --git a/checkstyle.json b/checkstyle.json index 60a10dcb3d..d350375773 100644 --- a/checkstyle.json +++ b/checkstyle.json @@ -19,7 +19,8 @@ "exclude": { "all": [ "TestSuite", - "/export/" + "/export/", + "tests/unit/bin/" ], "AvoidStarImport": [ "flixel.math.FlxRandomTest" diff --git a/flixel/FlxG.hx b/flixel/FlxG.hx index 55830cbe73..2e65a37dfc 100644 --- a/flixel/FlxG.hx +++ b/flixel/FlxG.hx @@ -6,6 +6,7 @@ import flixel.math.FlxRandom; import flixel.math.FlxRect; import flixel.system.FlxQuadTree; import flixel.system.FlxVersion; +import flixel.system.frontEnds.AssetFrontEnd; import flixel.system.frontEnds.BitmapFrontEnd; import flixel.system.frontEnds.BitmapLogFrontEnd; import flixel.system.frontEnds.CameraFrontEnd; @@ -335,6 +336,12 @@ class FlxG */ public static var signals(default, null):SignalFrontEnd = new SignalFrontEnd(); + /** + * Contains helper functions relating to retrieving assets + * @since 5.9.0 + */ + public static var assets(default, null):AssetFrontEnd = new AssetFrontEnd(); + /** * Resizes the game within the window by reapplying the current scale mode. */ diff --git a/flixel/FlxGame.hx b/flixel/FlxGame.hx index 10b1482e4b..94dc171d17 100644 --- a/flixel/FlxGame.hx +++ b/flixel/FlxGame.hx @@ -359,6 +359,9 @@ class FlxGame extends Sprite #if (desktop && openfl <= "4.0.0") stage.addEventListener(FocusEvent.FOCUS_OUT, onFocusLost); stage.addEventListener(FocusEvent.FOCUS_IN, onFocus); + #elseif (sys && openfl >= "9.3.0") + stage.nativeWindow.addEventListener(Event.DEACTIVATE, onFocusLost); + stage.nativeWindow.addEventListener(Event.ACTIVATE, onFocus); #else stage.addEventListener(Event.DEACTIVATE, onFocusLost); stage.addEventListener(Event.ACTIVATE, onFocus); @@ -919,4 +922,4 @@ private class FlxIntroSplash extends FlxSplash FlxG.game._gameJustStarted = true; super.startOutro(onOutroComplete); } -} \ No newline at end of file +} diff --git a/flixel/graphics/FlxGraphic.hx b/flixel/graphics/FlxGraphic.hx index 18ff89f271..35c40a3e2d 100644 --- a/flixel/graphics/FlxGraphic.hx +++ b/flixel/graphics/FlxGraphic.hx @@ -40,7 +40,7 @@ class FlxGraphic implements IFlxDestroyable if (!Cache) { - bitmap = FlxAssets.getBitmapData(Source); + bitmap = FlxG.assets.getBitmapData(Source); if (bitmap == null) return null; return createGraphic(bitmap, Key, Unique, Cache); @@ -51,7 +51,7 @@ class FlxGraphic implements IFlxDestroyable if (graphic != null) return graphic; - bitmap = FlxAssets.getBitmapData(Source); + bitmap = FlxG.assets.getBitmapData(Source); if (bitmap == null) return null; @@ -564,7 +564,7 @@ class FlxGraphic implements IFlxDestroyable if (assetsClass != null) newBitmap = FlxAssets.getBitmapFromClass(assetsClass); else if (assetsKey != null) - newBitmap = FlxAssets.getBitmapData(assetsKey); + newBitmap = FlxG.assets.getBitmapData(assetsKey); if (newBitmap != null) return FlxGraphic.getBitmap(newBitmap, unique); @@ -634,6 +634,15 @@ class FlxGraphic implements IFlxDestroyable bitmap = value; width = bitmap.width; height = bitmap.height; + + #if FLX_OPENGL_AVAILABLE + var max:Int = FlxG.bitmap.maxTextureSize; + if (max != -1) + { + if (width > max || height > max) + FlxG.log.warn('Graphic dimensions (${width}x${height}) exceed the maximum allowed size (${max}x${max}), which may cause rendering issues.'); + } + #end } return value; diff --git a/flixel/graphics/frames/FlxAtlasFrames.hx b/flixel/graphics/frames/FlxAtlasFrames.hx index b1f3245c74..161d3698d1 100644 --- a/flixel/graphics/frames/FlxAtlasFrames.hx +++ b/flixel/graphics/frames/FlxAtlasFrames.hx @@ -9,7 +9,6 @@ import flixel.math.FlxPoint; import flixel.math.FlxRect; import flixel.system.FlxAssets; import haxe.xml.Access; -import openfl.Assets; import openfl.geom.Rectangle; /** @@ -40,7 +39,7 @@ class FlxAtlasFrames extends FlxFramesCollection * * @param source The image source (can be `FlxGraphic`, `String`, or `BitmapData`). * @param description Contents of JSON file with atlas description. - * You can get it with `Assets.getText(path/to/description.json)`. + * You can get it with `FlxG.assets.getText(path/to/description.json)`. * Or you can just a pass path to the JSON file in the assets directory. * You can also directly pass in the parsed object. * @return Newly created `FlxAtlasFrames` collection. @@ -56,7 +55,7 @@ class FlxAtlasFrames extends FlxFramesCollection * * @param source The image source (can be `FlxGraphic`, `String`, or `BitmapData`). * @param description Contents of JSON file with atlas description. - * You can get it with `Assets.getText(path/to/description.json)`. + * You can get it with `FlxG.assets.getText(path/to/description.json)`. * Or you can just a pass path to the JSON file in the assets directory. * You can also directly pass in the parsed object. * @param useFrameDuration If true, any frame durations defined in the JSON will override the @@ -132,7 +131,7 @@ class FlxAtlasFrames extends FlxFramesCollection * * @param source The image source (can be `FlxGraphic`, `String` or `BitmapData`). * @param description Contents of the file with atlas description. - * You can get it with `Assets.getText(path/to/description/file)`. + * You can get it with `FlxG.assets.getText(path/to/description/file)`. * Or you can just pass path to the description file in the assets directory. * @return Newly created `FlxAtlasFrames` collection. */ @@ -152,8 +151,8 @@ class FlxAtlasFrames extends FlxFramesCollection frames = new FlxAtlasFrames(graphic); - if (Assets.exists(description)) - description = Assets.getText(description); + if (FlxG.assets.exists(description)) + description = FlxG.assets.getTextUnsafe(description); var pack:String = StringTools.trim(description); var lines:Array = pack.split("\n"); @@ -358,7 +357,7 @@ class FlxAtlasFrames extends FlxFramesCollection * * @param Source The image source (can be `FlxGraphic`, `String` or `BitmapData`). * @param Description Contents of the file with atlas description. - * You can get it with `Assets.getText(path/to/description/file)`. + * You can get it with `FlxG.assets.getText(path/to/description/file)`. * Or you can just pass a path to the description file in the assets directory. * @return Newly created `FlxAtlasFrames` collection. */ @@ -378,8 +377,8 @@ class FlxAtlasFrames extends FlxFramesCollection frames = new FlxAtlasFrames(graphic); - if (Assets.exists(Description)) - Description = Assets.getText(Description); + if (FlxG.assets.exists(Description)) + Description = FlxG.assets.getTextUnsafe(Description); var pack = StringTools.trim(Description); var lines:Array = pack.split("\n"); diff --git a/flixel/graphics/tile/FlxGraphicsShader.hx b/flixel/graphics/tile/FlxGraphicsShader.hx index 080608368e..e433b45a86 100644 --- a/flixel/graphics/tile/FlxGraphicsShader.hx +++ b/flixel/graphics/tile/FlxGraphicsShader.hx @@ -6,18 +6,18 @@ class FlxGraphicsShader extends GraphicsShader { @:glVertexSource(" #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; @@ -48,13 +48,7 @@ class FlxGraphicsShader extends GraphicsShader 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); + color = clamp(openfl_ColorOffsetv + (color * openfl_ColorMultiplierv), 0.0, 1.0); if (color.a > 0.0) { @@ -65,7 +59,7 @@ class FlxGraphicsShader extends GraphicsShader ") @:glFragmentSource(" #pragma header - + void main(void) { gl_FragColor = flixel_texture2D(bitmap, openfl_TextureCoordv); diff --git a/flixel/input/actions/FlxAction.hx b/flixel/input/actions/FlxAction.hx index 48237e9046..27e37d06a0 100644 --- a/flixel/input/actions/FlxAction.hx +++ b/flixel/input/actions/FlxAction.hx @@ -342,6 +342,7 @@ class FlxAction implements IFlxDestroyable var _y:Null = null; var _timestamp:Int = 0; + @:deprecated("_checked is deprecated, use triggered, instead") var _checked:Bool = false; /** @@ -435,40 +436,33 @@ class FlxAction implements IFlxDestroyable */ public function check():Bool { + if (_timestamp == FlxG.game.ticks) + return triggered; // run no more than once per frame + _x = null; _y = null; - - if (_timestamp == FlxG.game.ticks) - { - triggered = _checked; - return _checked; // run no more than once per frame - } - + _timestamp = FlxG.game.ticks; - _checked = false; - - var len = inputs != null ? inputs.length : 0; - for (i in 0...len) + triggered = false; + + var i = inputs != null ? inputs.length : 0; + while (i-- > 0) // Iterate backwards, since we may remove items { - var j = len - i - 1; - var input = inputs[j]; - + final input = inputs[i]; + if (input.destroyed) { - inputs.splice(j, 1); + inputs.remove(input); continue; } - + input.update(); - + if (input.check(this)) - { - _checked = true; - } + triggered = true; } - - triggered = _checked; - return _checked; + + return triggered; } /** diff --git a/flixel/input/actions/FlxActionInput.hx b/flixel/input/actions/FlxActionInput.hx index 0d8f6cffb8..c74f52792d 100644 --- a/flixel/input/actions/FlxActionInput.hx +++ b/flixel/input/actions/FlxActionInput.hx @@ -110,22 +110,22 @@ enum FlxInputDevice * Just a bucket for some handy sentinel values. * @since 4.6.0 */ -class FlxInputDeviceID +enum abstract FlxInputDeviceID(Int) from Int to Int { /** * Means "every connected device of the given type" (ie all gamepads, all steam controllers, etc) */ - public static inline var ALL:Int = -1; + var ALL = -1; /** * Means "the first connected device that has an active input" (ie a pressed button or moved analog stick/trigger/etc) */ - public static inline var FIRST_ACTIVE:Int = -2; + var FIRST_ACTIVE = -2; /** * Means "no device" */ - public static inline var NONE:Int = -3; + var NONE = -3; } /** diff --git a/flixel/input/actions/FlxActionInputAnalog.hx b/flixel/input/actions/FlxActionInputAnalog.hx index 58264d1bfb..1dff292005 100644 --- a/flixel/input/actions/FlxActionInputAnalog.hx +++ b/flixel/input/actions/FlxActionInputAnalog.hx @@ -97,7 +97,7 @@ class FlxActionInputAnalogMouseMotion extends FlxActionInputAnalog deadZone = DeadZone; invertX = InvertX; invertY = InvertY; - super(FlxInputDevice.MOUSE, -1, cast Trigger, Axis); + super(FlxInputDevice.MOUSE, -1, Trigger, Axis); } override public function update():Void @@ -144,7 +144,7 @@ class FlxActionInputAnalogMousePosition extends FlxActionInputAnalog */ public function new(Trigger:FlxAnalogState, Axis:FlxAnalogAxis = EITHER) { - super(FlxInputDevice.MOUSE, -1, cast Trigger, Axis); + super(FlxInputDevice.MOUSE, -1, Trigger, Axis); } override public function update():Void @@ -193,7 +193,7 @@ class FlxActionInputAnalogGamepad extends FlxActionInputAnalog */ public function new(InputID:FlxGamepadInputID, Trigger:FlxAnalogState, Axis:FlxAnalogAxis = EITHER, GamepadID:Int = FlxInputDeviceID.FIRST_ACTIVE) { - super(FlxInputDevice.GAMEPAD, InputID, cast Trigger, Axis, GamepadID); + super(FlxInputDevice.GAMEPAD, InputID, Trigger, Axis, GamepadID); } override public function update():Void @@ -265,7 +265,7 @@ class FlxActionInputAnalogSteam extends FlxActionInputAnalog @:allow(flixel.input.actions.FlxActionSet) function new(ActionHandle:Int, Trigger:FlxAnalogState, Axis:FlxAnalogAxis = EITHER, DeviceID:Int = FlxInputDeviceID.ALL) { - super(FlxInputDevice.STEAM_CONTROLLER, ActionHandle, cast Trigger, Axis, DeviceID); + super(FlxInputDevice.STEAM_CONTROLLER, ActionHandle, Trigger, Axis, DeviceID); #if FLX_NO_STEAM FlxG.log.warn("steamwrap library not installed; steam inputs will be ignored."); #end @@ -310,9 +310,9 @@ class FlxActionInputAnalog extends FlxActionInput static inline var A_X = true; static inline var A_Y = false; - function new(Device:FlxInputDevice, InputID:Int, Trigger:FlxInputState, Axis:FlxAnalogAxis = EITHER, DeviceID:Int = FlxInputDeviceID.FIRST_ACTIVE) + function new(Device:FlxInputDevice, InputID:Int, Trigger:FlxAnalogState, Axis:FlxAnalogAxis = EITHER, DeviceID:Int = FlxInputDeviceID.FIRST_ACTIVE) { - super(FlxInputType.ANALOG, Device, InputID, Trigger, DeviceID); + super(FlxInputType.ANALOG, Device, InputID, cast Trigger, DeviceID); axis = Axis; xMoved = new FlxInput(0); yMoved = new FlxInput(1); diff --git a/flixel/input/gamepad/FlxGamepad.hx b/flixel/input/gamepad/FlxGamepad.hx index a6a0005265..a6dfdd2726 100644 --- a/flixel/input/gamepad/FlxGamepad.hx +++ b/flixel/input/gamepad/FlxGamepad.hx @@ -1,6 +1,7 @@ package flixel.input.gamepad; import flixel.input.FlxInput.FlxInputState; +import flixel.input.gamepad.FlxGamepadMappedInput; import flixel.input.gamepad.lists.FlxGamepadAnalogList; import flixel.input.gamepad.lists.FlxGamepadButtonList; import flixel.input.gamepad.lists.FlxGamepadMotionValueList; @@ -879,13 +880,25 @@ class FlxGamepad implements IFlxDestroyable return _deadZone = deadZone; } - /** + /** + * A string representing the label of the target input. For instance, on a PS4 gamepad + * `A` is "x", while Xbox is "a" and the Switch pro controller is "B" * @since 4.8.0 */ public inline function getInputLabel(id:FlxGamepadInputID) { return mapping.getInputLabel(id); } + + /** + * The value of the target gamepad input. For instance, on a PS4 gamepad `A` is `PS4(PS4ID.X)`, + * while Xbox is `X_INPUT(XInputID.A)` and the Switch pro controller is `SWITCH_PRO(SwitchProID.B)` + * @since 5.9.0 + */ + public function getMappedInput(id:FlxGamepadInputID):FlxGamepadMappedInput + { + return mapping.getMappedInput(id); + } public function toString():String { diff --git a/flixel/input/gamepad/FlxGamepadAnalogStick.hx b/flixel/input/gamepad/FlxGamepadAnalogStick.hx index e80481b27b..31aca85a6b 100644 --- a/flixel/input/gamepad/FlxGamepadAnalogStick.hx +++ b/flixel/input/gamepad/FlxGamepadAnalogStick.hx @@ -2,7 +2,9 @@ package flixel.input.gamepad; import flixel.util.FlxStringUtil; -class FlxGamepadAnalogStick +typedef FlxGamepadAnalogStick = FlxTypedGamepadAnalogStick; + +class FlxTypedGamepadAnalogStick { public var x(default, null):Int; public var y(default, null):Int; @@ -10,22 +12,22 @@ class FlxGamepadAnalogStick /** * a raw button input ID, for sending a digital event for "up" alongside the analog event */ - public var rawUp(default, null):Int = -1; + public var rawUp(default, null):TInputID = cast -1; /** * a raw button input ID, for sending a digital event for "down" alongside the analog event */ - public var rawDown(default, null):Int = -1; + public var rawDown(default, null):TInputID = cast -1; /** * a raw button input ID, for sending a digital event for "left" alongside the analog event */ - public var rawLeft(default, null):Int = -1; + public var rawLeft(default, null):TInputID = cast -1; /** * a raw button input ID, for sending a digital event for "right" alongside the analog event */ - public var rawRight(default, null):Int = -1; + public var rawRight(default, null):TInputID = cast -1; /** * the absolute value the dpad must be greater than before digital inputs are sent @@ -37,20 +39,31 @@ class FlxGamepadAnalogStick */ public var mode(default, null):FlxAnalogToDigitalMode = BOTH; - public function new(x:Int, y:Int, ?settings:FlxGamepadAnalogStickSettings) + public function new(x:Int, y:Int, ?settings:FlxGamepadAnalogStickSettings) { this.x = x; this.y = y; - if (settings == null) - return; - - mode = (settings.mode != null) ? settings.mode : BOTH; - rawUp = (settings.up != null) ? settings.up : -1; - rawDown = (settings.down != null) ? settings.down : -1; - rawLeft = (settings.left != null) ? settings.left : -1; - rawRight = (settings.right != null) ? settings.right : -1; - digitalThreshold = (settings.threshold != null) ? settings.threshold : 0.5; + if (settings != null) + { + if (settings.mode != null) + mode = settings.mode; + + if (settings.up != null) + rawUp = settings.up; + + if (settings.down != null) + rawDown = settings.down; + + if (settings.left != null) + rawLeft = settings.left; + + if (settings.right != null) + rawRight = settings.right; + + if (settings.threshold != null) + digitalThreshold = settings.threshold; + } } public function toString():String @@ -68,12 +81,12 @@ class FlxGamepadAnalogStick } } -typedef FlxGamepadAnalogStickSettings = +typedef FlxGamepadAnalogStickSettings = { - ?up:Int, - ?down:Int, - ?left:Int, - ?right:Int, + ?up:TInputID, + ?down:TInputID, + ?left:TInputID, + ?right:TInputID, ?threshold:Float, ?mode:FlxAnalogToDigitalMode } diff --git a/flixel/input/gamepad/FlxGamepadInputID.hx b/flixel/input/gamepad/FlxGamepadInputID.hx index 3d3e15fa7d..78f09a8649 100644 --- a/flixel/input/gamepad/FlxGamepadInputID.hx +++ b/flixel/input/gamepad/FlxGamepadInputID.hx @@ -35,7 +35,7 @@ enum abstract FlxGamepadInputID(Int) from Int to Int /**right digital "bumper"*/ var RIGHT_SHOULDER = 5; - /**also known as "select", the leftmost center button*/ + /**also known as "select", the left-most center button*/ var BACK = 6; /**the rightmost center button*/ @@ -127,7 +127,19 @@ enum abstract FlxGamepadInputID(Int) from Int to Int /**left analog stick as a dpad, pushed left**/ var RIGHT_STICK_DIGITAL_LEFT = 41; - + + /** + * Mapped to The bottom face button on most controllers, and the + * right face button on Nintendo Switch controllers + **/ + var ACCEPT = 42; + + /** + * Mapped to The bottom face button on most controllers, and the + * right face button on Nintendo Switch controllers + **/ + var CANCEL = 43; + @:from public static inline function fromString(s:String) { diff --git a/flixel/input/gamepad/FlxGamepadManager.hx b/flixel/input/gamepad/FlxGamepadManager.hx index 79d9b8d401..0477304e5c 100644 --- a/flixel/input/gamepad/FlxGamepadManager.hx +++ b/flixel/input/gamepad/FlxGamepadManager.hx @@ -50,7 +50,13 @@ class FlxGamepadManager implements IFlxInputManager * @since 4.6.0 */ public var deviceDisconnected(default, null):FlxTypedSignalVoid>; - + + /** + * Whether the bottom or right face button is ACCEPT + * @since 5.9.0 + */ + public var acceptMode:FlxGamepadAcceptMode = BOTTOM; + /** * Stores all gamepads - can have null entries, but index matches event.device */ @@ -595,3 +601,27 @@ class FlxGamepadManager implements IFlxInputManager return count; } } + +/** + * @since 5.9.0 + */ +enum FlxGamepadAcceptMode +{ + /** + * The bottom face button is `ACCEPT` and the right face button is `CANCEL`. + * This is common on western-style consoles, like XBox or American PS4/5 + */ + BOTTOM; + + /** + * The right face button is `ACCEPT` and the bottom face button is `CANCEL`. + * This is common in Japanese PS4/5 consoles, and Nintendo consoles + */ + RIGHT; + + /** + * Behaves like `BOTTOM` for nearly all gamepads, but `RIGHT` for specific mappings, + * namely Nintendo Switch gamepads + */ + USE_MAPPING; +} diff --git a/flixel/input/gamepad/FlxGamepadMappedInput.hx b/flixel/input/gamepad/FlxGamepadMappedInput.hx new file mode 100644 index 0000000000..d6005c444a --- /dev/null +++ b/flixel/input/gamepad/FlxGamepadMappedInput.hx @@ -0,0 +1,57 @@ +package flixel.input.gamepad; + +import flixel.input.gamepad.FlxGamepad; +import flixel.input.gamepad.id.LogitechID; +import flixel.input.gamepad.id.MayflashWiiRemoteID; +import flixel.input.gamepad.id.MFiID; +import flixel.input.gamepad.id.OUYAID; +import flixel.input.gamepad.id.PS4ID; +import flixel.input.gamepad.id.PSVitaID; +import flixel.input.gamepad.id.SwitchJoyconLeftID; +import flixel.input.gamepad.id.SwitchJoyconRightID; +import flixel.input.gamepad.id.SwitchProID; +import flixel.input.gamepad.id.WiiRemoteID; +import flixel.input.gamepad.id.XInputID; + +/** + * A list of every possible gamepad input from every known device + * @since 5.9.0 + */ +@:using(flixel.input.gamepad.FlxGamepadMappedInput.FlxGamepadMappedInputTools) +enum FlxGamepadMappedInput +{ + LOGITECH(id:LogitechID); + MAYFLASH_WII(id:MayflashWiiRemoteID); + MFI(id:MFiID); + OUYA(id:OUYAID); + PS4(id:PS4ID); + PS_VITA(id:PSVitaID); + SWITCH_JOYCON_LEFT(id:SwitchJoyconLeftID); + SWITCH_JOYCON_RIGHT(id:SwitchJoyconRightID); + SWITCH_PRO(id:SwitchProID); + WII(id:WiiRemoteID); + X_INPUT(id:XInputID); + UNKNOWN(id:FlxGamepadInputID); +} + +private class FlxGamepadMappedInputTools +{ + public static inline function toModel(input:FlxGamepadMappedInput):FlxGamepadModel + { + return switch input + { + case FlxGamepadMappedInput.OUYA(_): FlxGamepadModel.OUYA; + case FlxGamepadMappedInput.PS4(_): FlxGamepadModel.PS4; + case FlxGamepadMappedInput.PS_VITA(_): FlxGamepadModel.PSVITA; + case FlxGamepadMappedInput.LOGITECH(_): FlxGamepadModel.LOGITECH; + case FlxGamepadMappedInput.X_INPUT(_): FlxGamepadModel.XINPUT; + case FlxGamepadMappedInput.WII(_): FlxGamepadModel.WII_REMOTE; + case FlxGamepadMappedInput.MAYFLASH_WII(_): FlxGamepadModel.MAYFLASH_WII_REMOTE; + case FlxGamepadMappedInput.SWITCH_PRO(_): FlxGamepadModel.SWITCH_PRO; + case FlxGamepadMappedInput.SWITCH_JOYCON_LEFT(_): FlxGamepadModel.SWITCH_JOYCON_LEFT; + case FlxGamepadMappedInput.SWITCH_JOYCON_RIGHT(_): FlxGamepadModel.SWITCH_JOYCON_RIGHT; + case FlxGamepadMappedInput.MFI(_): FlxGamepadModel.MFI; + case FlxGamepadMappedInput.UNKNOWN(_): FlxGamepadModel.UNKNOWN; + } + } +} \ No newline at end of file diff --git a/flixel/input/gamepad/id/LogitechID.hx b/flixel/input/gamepad/id/LogitechID.hx index 6b33c0e5d8..3c0024e48c 100644 --- a/flixel/input/gamepad/id/LogitechID.hx +++ b/flixel/input/gamepad/id/LogitechID.hx @@ -5,63 +5,73 @@ import flixel.input.gamepad.FlxGamepadAnalogStick; /** * IDs for Logitech controllers (key codes based on Cordless Rumblepad 2) */ -class LogitechID +enum abstract LogitechID(Int) to Int { #if flash - public static inline var ONE:Int = 8; - public static inline var TWO:Int = 9; - public static inline var THREE:Int = 10; - public static inline var FOUR:Int = 11; - public static inline var FIVE:Int = 12; - public static inline var SIX:Int = 13; - public static inline var SEVEN:Int = 14; - public static inline var EIGHT:Int = 15; - public static inline var NINE:Int = 16; - public static inline var TEN:Int = 17; - public static inline var LEFT_STICK_CLICK:Int = 18; - public static inline var RIGHT_STICK_CLICK:Int = 19; + var ONE = 8; + var TWO = 9; + var THREE = 10; + var FOUR = 11; + var FIVE = 12; + var SIX = 13; + var SEVEN = 14; + var EIGHT = 15; + var NINE = 16; + var TEN = 17; + var LEFT_STICK_CLICK = 18; + var RIGHT_STICK_CLICK = 19; - public static inline var DPAD_UP:Int = 4; - public static inline var DPAD_DOWN:Int = 5; - public static inline var DPAD_LEFT:Int = 6; - public static inline var DPAD_RIGHT:Int = 7; + var DPAD_UP = 4; + var DPAD_DOWN = 5; + var DPAD_LEFT = 6; + var DPAD_RIGHT = 7; // TODO: Someone needs to look this up and define it! (NOTE: not all logitech controllers have this) - public static inline var LOGITECH:Int = -1; + var LOGITECH = -1; #else // native and html5 - public static inline var ONE:Int = 0; - public static inline var TWO:Int = 1; - public static inline var THREE:Int = 2; - public static inline var FOUR:Int = 3; - public static inline var FIVE:Int = 4; - public static inline var SIX:Int = 5; - public static inline var SEVEN:Int = 6; - public static inline var EIGHT:Int = 7; - public static inline var NINE:Int = 8; - public static inline var TEN:Int = 9; - public static inline var LEFT_STICK_CLICK:Int = 10; - public static inline var RIGHT_STICK_CLICK:Int = 11; + var ONE = 0; + var TWO = 1; + var THREE = 2; + var FOUR = 3; + var FIVE = 4; + var SIX = 5; + var SEVEN = 6; + var EIGHT = 7; + var NINE = 8; + var TEN = 9; + var LEFT_STICK_CLICK = 10; + var RIGHT_STICK_CLICK = 11; // "fake" IDs, we manually watch for hat axis changes and then send events using these otherwise unused joystick button codes - public static inline var DPAD_UP:Int = 16; - public static inline var DPAD_DOWN:Int = 17; - public static inline var DPAD_LEFT:Int = 18; - public static inline var DPAD_RIGHT:Int = 19; + var DPAD_UP = 16; + var DPAD_DOWN = 17; + var DPAD_LEFT = 18; + var DPAD_RIGHT = 19; // TODO: Someone needs to look this up and define it! (NOTE: not all logitech controllers have this) - public static inline var LOGITECH:Int = -5; + var LOGITECH = -5; #end - - public static var LEFT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(0, 1, { - up: 24, - down: 25, - left: 26, - right: 27 + + var LEFT_STICK_UP = 24; + var LEFT_STICK_DOWN = 25; + var LEFT_STICK_LEFT = 26; + var LEFT_STICK_RIGHT = 27; + + var RIGHT_STICK_UP = 28; + var RIGHT_STICK_DOWN = 29; + var RIGHT_STICK_LEFT = 30; + var RIGHT_STICK_RIGHT = 31; + + public static final LEFT_ANALOG_STICK = new FlxTypedGamepadAnalogStick(0, 1, { + up: LEFT_STICK_UP, + down: LEFT_STICK_DOWN, + left: LEFT_STICK_LEFT, + right: LEFT_STICK_RIGHT }); - public static var RIGHT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(2, 3, { - up: 28, - down: 29, - left: 30, - right: 31 + public static final RIGHT_ANALOG_STICK = new FlxTypedGamepadAnalogStick(2, 3, { + up: RIGHT_STICK_UP, + down: RIGHT_STICK_DOWN, + left: RIGHT_STICK_LEFT, + right: RIGHT_STICK_RIGHT }); } diff --git a/flixel/input/gamepad/id/MFiID.hx b/flixel/input/gamepad/id/MFiID.hx index 8b5e7be4f0..d144e07bcf 100644 --- a/flixel/input/gamepad/id/MFiID.hx +++ b/flixel/input/gamepad/id/MFiID.hx @@ -1,41 +1,52 @@ package flixel.input.gamepad.id; +import flixel.input.gamepad.FlxGamepadAnalogStick; + /** * IDs for MFi controllers */ -class MFiID +enum abstract MFiID(Int) to Int { - public static inline var A:Int = 6; - public static inline var B:Int = 7; - public static inline var X:Int = 8; - public static inline var Y:Int = 9; - public static inline var LB:Int = 15; - public static inline var RB:Int = 16; - public static inline var BACK:Int = 10; - public static inline var START:Int = 12; - public static inline var LEFT_STICK_CLICK:Int = 13; - public static inline var RIGHT_STICK_CLICK:Int = 14; - - public static inline var GUIDE:Int = 11; + var LEFT_TRIGGER = 4; + var RIGHT_TRIGGER = 5; + + var A = 6; + var B = 7; + var X = 8; + var Y = 9; + var LB = 15; + var RB = 16; + var BACK = 10; + var GUIDE = 11; + var START = 12; + var LEFT_STICK_CLICK = 13; + var RIGHT_STICK_CLICK = 14; + + var DPAD_UP = 17; + var DPAD_DOWN = 18; + var DPAD_LEFT = 19; + var DPAD_RIGHT = 20; - public static inline var DPAD_UP:Int = 17; - public static inline var DPAD_DOWN:Int = 18; - public static inline var DPAD_LEFT:Int = 19; - public static inline var DPAD_RIGHT:Int = 20; - - public static var LEFT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(0, 1, { - up: 21, - down: 22, - left: 23, - right: 24 + var LEFT_STICK_UP = 21; + var LEFT_STICK_DOWN = 22; + var LEFT_STICK_LEFT = 23; + var LEFT_STICK_RIGHT = 24; + + var RIGHT_STICK_UP = 25; + var RIGHT_STICK_DOWN = 26; + var RIGHT_STICK_LEFT = 27; + var RIGHT_STICK_RIGHT = 28; + + public static final LEFT_ANALOG_STICK = new FlxTypedGamepadAnalogStick(0, 1, { + up: LEFT_STICK_UP, + down: LEFT_STICK_DOWN, + left: LEFT_STICK_LEFT, + right: LEFT_STICK_RIGHT }); - public static var RIGHT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(2, 3, { - up: 25, - down: 26, - left: 27, - right: 28 + public static final RIGHT_ANALOG_STICK = new FlxTypedGamepadAnalogStick(2, 3, { + up: RIGHT_STICK_UP, + down: RIGHT_STICK_DOWN, + left: RIGHT_STICK_LEFT, + right: RIGHT_STICK_RIGHT }); - - public static inline var LEFT_TRIGGER:Int = 4; - public static inline var RIGHT_TRIGGER:Int = 5; } diff --git a/flixel/input/gamepad/id/MayflashWiiRemoteID.hx b/flixel/input/gamepad/id/MayflashWiiRemoteID.hx index 3e0bf57ca6..d36e5f067b 100644 --- a/flixel/input/gamepad/id/MayflashWiiRemoteID.hx +++ b/flixel/input/gamepad/id/MayflashWiiRemoteID.hx @@ -7,7 +7,7 @@ import flixel.input.gamepad.FlxGamepadAnalogStick; * * @author larsiusprime */ -class MayflashWiiRemoteID +enum abstract MayflashWiiRemoteID(Int) to Int { /** * Things to add: @@ -19,158 +19,141 @@ class MayflashWiiRemoteID */ #if FLX_JOYSTICK_API // Standard Wii Remote inputs: - public static inline var REMOTE_ONE:Int = 0; - public static inline var REMOTE_TWO:Int = 1; - public static inline var REMOTE_A:Int = 2; - public static inline var REMOTE_B:Int = 3; + var REMOTE_ONE = 0; + var REMOTE_TWO = 1; + var REMOTE_A = 2; + var REMOTE_B = 3; - public static inline var REMOTE_MINUS:Int = 4; - public static inline var REMOTE_PLUS:Int = 5; + var REMOTE_MINUS = 4; + var REMOTE_PLUS = 5; - public static inline var REMOTE_HOME:Int = 11; + var REMOTE_HOME = 11; // Nunchuk attachment: - public static inline var NUNCHUK_Z:Int = 6; - public static inline var NUNCHUK_C:Int = 7; + var NUNCHUK_Z = 6; + var NUNCHUK_C = 7; - public static inline var NUNCHUK_DPAD_DOWN:Int = 12; - public static inline var NUNCHUK_DPAD_UP:Int = 13; - public static inline var NUNCHUK_DPAD_LEFT:Int = 14; - public static inline var NUNCHUK_DPAD_RIGHT:Int = 15; + var NUNCHUK_DPAD_DOWN = 12; + var NUNCHUK_DPAD_UP = 13; + var NUNCHUK_DPAD_LEFT = 14; + var NUNCHUK_DPAD_RIGHT = 15; - public static inline var NUNCHUK_MINUS:Int = 4; - public static inline var NUNCHUK_PLUS:Int = 5; + var NUNCHUK_MINUS = 4; + var NUNCHUK_PLUS = 5; - public static inline var NUNCHUK_HOME:Int = 11; + var NUNCHUK_HOME = 11; - public static inline var NUNCHUK_ONE:Int = 0; - public static inline var NUNCHUK_TWO:Int = 1; - public static inline var NUNCHUK_A:Int = 2; - public static inline var NUNCHUK_B:Int = 3; + var NUNCHUK_ONE = 0; + var NUNCHUK_TWO = 1; + var NUNCHUK_A = 2; + var NUNCHUK_B = 3; // classic controller attachment: - public static inline var CLASSIC_Y:Int = 0; // Identical to WiiRemote 1 - public static inline var CLASSIC_X:Int = 1; // Identical to WiiRemote 2 - public static inline var CLASSIC_B:Int = 2; // Identical to WiiRemote A - public static inline var CLASSIC_A:Int = 3; // Identical to WiiRemote B + var CLASSIC_Y = 0; // Identical to WiiRemote 1 + var CLASSIC_X = 1; // Identical to WiiRemote 2 + var CLASSIC_B = 2; // Identical to WiiRemote A + var CLASSIC_A = 3; // Identical to WiiRemote B - public static inline var CLASSIC_L:Int = 4; // Identical to MINUS and PLUS - public static inline var CLASSIC_R:Int = 5; - public static inline var CLASSIC_ZL:Int = 6; // Identical to C and Z - public static inline var CLASSIC_ZR:Int = 7; + var CLASSIC_L = 4; // Identical to MINUS and PLUS + var CLASSIC_R = 5; + var CLASSIC_ZL = 6; // Identical to C and Z + var CLASSIC_ZR = 7; - public static inline var CLASSIC_SELECT:Int = 8; - public static inline var CLASSIC_START:Int = 9; + var CLASSIC_SELECT = 8; + var CLASSIC_START = 9; - public static inline var CLASSIC_HOME:Int = 11; + var CLASSIC_HOME = 11; - public static inline var CLASSIC_DPAD_DOWN:Int = 12; - public static inline var CLASSIC_DPAD_UP:Int = 13; - public static inline var CLASSIC_DPAD_LEFT:Int = 14; - public static inline var CLASSIC_DPAD_RIGHT:Int = 15; + var CLASSIC_DPAD_DOWN = 12; + var CLASSIC_DPAD_UP = 13; + var CLASSIC_DPAD_LEFT = 14; + var CLASSIC_DPAD_RIGHT = 15; - public static inline var CLASSIC_ONE:Int = -1; - public static inline var CLASSIC_TWO:Int = -1; - - // Axis indices - public static inline var NUNCHUK_POINTER_X:Int = 2; - public static inline var NUNCHUK_POINTER_Y:Int = 3; - - // Yes, the WiiRemote DPAD is treated as ANALOG for some reason...so we have to pass in some "fake" ID's to get simulated digital inputs - public static var REMOTE_DPAD(default, null) = new FlxGamepadAnalogStick(0, 1, { - up: REMOTE_DPAD_UP, - down: REMOTE_DPAD_DOWN, - left: REMOTE_DPAD_LEFT, - right: REMOTE_DPAD_RIGHT, - threshold: 0.5, - mode: ONLY_DIGITAL - }); - - public static var LEFT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(0, 1, { - up: 26, - down: 27, - left: 28, - right: 29 - }); // the nunchuk only has the "left" analog stick - public static var RIGHT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(2, 3, { - up: 30, - down: 31, - left: 32, - right: 33 - }); // the classic controller has both the "left" and "right" analog sticks - - // these aren't real axes, they're simulated when the right digital buttons are pushed - public static inline var LEFT_TRIGGER_FAKE:Int = 4; - public static inline var RIGHT_TRIGGER_FAKE:Int = 5; - - // "fake" IDs - public static inline var REMOTE_DPAD_UP:Int = 22; - public static inline var REMOTE_DPAD_DOWN:Int = 23; - public static inline var REMOTE_DPAD_LEFT:Int = 24; - public static inline var REMOTE_DPAD_RIGHT:Int = 25; + var CLASSIC_ONE = -1; + var CLASSIC_TWO = -1; #else // gamepad API // Standard Wii Remote inputs: - public static inline var REMOTE_ONE:Int = 8; - public static inline var REMOTE_TWO:Int = 9; - public static inline var REMOTE_A:Int = 10; - public static inline var REMOTE_B:Int = 11; + var REMOTE_ONE = 8; + var REMOTE_TWO = 9; + var REMOTE_A = 10; + var REMOTE_B = 11; - public static inline var REMOTE_MINUS:Int = 12; - public static inline var REMOTE_PLUS:Int = 13; + var REMOTE_MINUS = 12; + var REMOTE_PLUS = 13; - public static inline var REMOTE_HOME:Int = 19; + var REMOTE_HOME = 19; // Nunchuk attachment: - public static inline var NUNCHUK_Z:Int = 14; - public static inline var NUNCHUK_C:Int = 15; + var NUNCHUK_Z = 14; + var NUNCHUK_C = 15; - public static inline var NUNCHUK_DPAD_UP:Int = 4; - public static inline var NUNCHUK_DPAD_DOWN:Int = 5; - public static inline var NUNCHUK_DPAD_LEFT:Int = 6; - public static inline var NUNCHUK_DPAD_RIGHT:Int = 7; + var NUNCHUK_DPAD_UP = 4; + var NUNCHUK_DPAD_DOWN = 5; + var NUNCHUK_DPAD_LEFT = 6; + var NUNCHUK_DPAD_RIGHT = 7; - public static inline var NUNCHUK_MINUS:Int = 12; - public static inline var NUNCHUK_PLUS:Int = 13; + var NUNCHUK_MINUS = 12; + var NUNCHUK_PLUS = 13; - public static inline var NUNCHUK_HOME:Int = 19; + var NUNCHUK_HOME = 19; - public static inline var NUNCHUK_A:Int = 10; - public static inline var NUNCHUK_B:Int = 11; + var NUNCHUK_A = 10; + var NUNCHUK_B = 11; - public static inline var NUNCHUK_ONE:Int = 8; - public static inline var NUNCHUK_TWO:Int = 9; + var NUNCHUK_ONE = 8; + var NUNCHUK_TWO = 9; // classic controller attachment: - public static inline var CLASSIC_Y:Int = 8; - public static inline var CLASSIC_X:Int = 9; - public static inline var CLASSIC_B:Int = 10; - public static inline var CLASSIC_A:Int = 11; + var CLASSIC_Y = 8; + var CLASSIC_X = 9; + var CLASSIC_B = 10; + var CLASSIC_A = 11; - public static inline var CLASSIC_L:Int = 12; - public static inline var CLASSIC_R:Int = 13; - public static inline var CLASSIC_ZL:Int = 14; - public static inline var CLASSIC_ZR:Int = 15; + var CLASSIC_L = 12; + var CLASSIC_R = 13; + var CLASSIC_ZL = 14; + var CLASSIC_ZR = 15; - public static inline var CLASSIC_SELECT:Int = 16; - public static inline var CLASSIC_START:Int = 17; + var CLASSIC_SELECT = 16; + var CLASSIC_START = 17; - public static inline var CLASSIC_HOME:Int = 19; + var CLASSIC_HOME = 19; - public static inline var CLASSIC_ONE:Int = -1; - public static inline var CLASSIC_TWO:Int = -1; + var CLASSIC_ONE = -1; + var CLASSIC_TWO = -1; // (input "10" does not seem to be defined) - public static inline var CLASSIC_DPAD_UP:Int = 4; - public static inline var CLASSIC_DPAD_DOWN:Int = 5; - public static inline var CLASSIC_DPAD_LEFT:Int = 6; - public static inline var CLASSIC_DPAD_RIGHT:Int = 7; - + var CLASSIC_DPAD_UP = 4; + var CLASSIC_DPAD_DOWN = 5; + var CLASSIC_DPAD_LEFT = 6; + var CLASSIC_DPAD_RIGHT = 7; + #end // Axis indices - public static inline var NUNCHUK_POINTER_X:Int = 2; - public static inline var NUNCHUK_POINTER_Y:Int = 3; + var NUNCHUK_POINTER_X = 2; + var NUNCHUK_POINTER_Y = 3; + + var LEFT_STICK_UP = 26; + var LEFT_STICK_DOWN = 27; + var LEFT_STICK_LEFT = 28; + var LEFT_STICK_RIGHT = 29; + + var RIGHT_STICK_UP = 30; + var RIGHT_STICK_DOWN = 31; + var RIGHT_STICK_LEFT = 32; + var RIGHT_STICK_RIGHT = 33; + + // these aren't real axes, they're simulated when the right digital buttons are pushed + var LEFT_TRIGGER_FAKE = 4; + var RIGHT_TRIGGER_FAKE = 5; + // "fake" IDs + var REMOTE_DPAD_UP = 22; + var REMOTE_DPAD_DOWN = 23; + var REMOTE_DPAD_LEFT = 24; + var REMOTE_DPAD_RIGHT = 25; + // Yes, the WiiRemote DPAD is treated as ANALOG for some reason...so we have to pass in some "fake" ID's to get simulated digital inputs - public static var REMOTE_DPAD(default, null) = new FlxGamepadAnalogStick(0, 1, { + public static final REMOTE_DPAD = new FlxTypedGamepadAnalogStick(0, 1, { up: REMOTE_DPAD_UP, down: REMOTE_DPAD_DOWN, left: REMOTE_DPAD_LEFT, @@ -178,28 +161,18 @@ class MayflashWiiRemoteID threshold: 0.5, mode: ONLY_DIGITAL }); - - public static var LEFT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(0, 1, { - up: 26, - down: 27, - left: 28, - right: 29 + + public static final LEFT_ANALOG_STICK = new FlxTypedGamepadAnalogStick(0, 1, { + up: LEFT_STICK_UP, + down: LEFT_STICK_DOWN, + left: LEFT_STICK_LEFT, + right: LEFT_STICK_RIGHT }); // the nunchuk only has the "left" analog stick - public static var RIGHT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(2, 3, { - up: 26, - down: 27, - left: 28, - right: 29 + + public static final RIGHT_ANALOG_STICK = new FlxTypedGamepadAnalogStick(2, 3, { + up: RIGHT_STICK_UP, + down: RIGHT_STICK_DOWN, + left: RIGHT_STICK_LEFT, + right: RIGHT_STICK_RIGHT }); // the classic controller has both the "left" and "right" analog sticks - - // these aren't real axes, they're simulated when the right digital buttons are pushed - public static inline var LEFT_TRIGGER_FAKE:Int = 4; - public static inline var RIGHT_TRIGGER_FAKE:Int = 5; - - // "fake" IDs - public static inline var REMOTE_DPAD_UP:Int = 22; - public static inline var REMOTE_DPAD_DOWN:Int = 23; - public static inline var REMOTE_DPAD_LEFT:Int = 24; - public static inline var REMOTE_DPAD_RIGHT:Int = 25; - #end } diff --git a/flixel/input/gamepad/id/OUYAID.hx b/flixel/input/gamepad/id/OUYAID.hx index 9e21a462fa..50defda484 100644 --- a/flixel/input/gamepad/id/OUYAID.hx +++ b/flixel/input/gamepad/id/OUYAID.hx @@ -5,37 +5,47 @@ import flixel.input.gamepad.FlxGamepadAnalogStick; /** * IDs for OUYA controllers */ -class OUYAID +enum abstract OUYAID(Int) to Int { - public static inline var O:Int = 6; - public static inline var U:Int = 8; - public static inline var Y:Int = 9; - public static inline var A:Int = 7; - public static inline var LB:Int = 15; - public static inline var RB:Int = 16; - public static inline var LEFT_STICK_CLICK:Int = 13; - public static inline var RIGHT_STICK_CLICK:Int = 14; - public static inline var HOME:Int = 0x01000012; // Not sure if press HOME is taken in account on OUYA - public static inline var LEFT_TRIGGER:Int = 4; - public static inline var RIGHT_TRIGGER:Int = 5; + var O = 6; + var U = 8; + var Y = 9; + var A = 7; + var LB = 15; + var RB = 16; + var LEFT_STICK_CLICK = 13; + var RIGHT_STICK_CLICK = 14; + var HOME = 0x01000012; // Not sure if press HOME is taken in account on OUYA + var LEFT_TRIGGER = 4; + var RIGHT_TRIGGER = 5; // "fake" IDs, we manually watch for hat axis changes and then send events using these otherwise unused joystick button codes - public static inline var DPAD_LEFT:Int = 19; - public static inline var DPAD_RIGHT:Int = 20; - public static inline var DPAD_DOWN:Int = 18; - public static inline var DPAD_UP:Int = 17; - + var DPAD_LEFT = 19; + var DPAD_RIGHT = 20; + var DPAD_DOWN = 18; + var DPAD_UP = 17; + + var LEFT_STICK_UP = 23; + var LEFT_STICK_DOWN = 24; + var LEFT_STICK_LEFT = 25; + var LEFT_STICK_RIGHT = 26; + + var RIGHT_STICK_UP = 27; + var RIGHT_STICK_DOWN = 28; + var RIGHT_STICK_LEFT = 29; + var RIGHT_STICK_RIGHT = 30; + // If TRIGGER axis returns value > 0 then LT is being pressed, and if it's < 0 then RT is being pressed - public static var LEFT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(0, 1, { - up: 23, - down: 24, - left: 25, - right: 26 + public static final LEFT_ANALOG_STICK = new FlxTypedGamepadAnalogStick(0, 1, { + up: LEFT_STICK_UP, + down: LEFT_STICK_DOWN, + left: LEFT_STICK_LEFT, + right: LEFT_STICK_RIGHT }); - public static var RIGHT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(2, 3, { - up: 27, - down: 28, - left: 29, - right: 30 + public static final RIGHT_ANALOG_STICK = new FlxTypedGamepadAnalogStick(2, 3, { + up: RIGHT_STICK_UP, + down: RIGHT_STICK_DOWN, + left: RIGHT_STICK_LEFT, + right: RIGHT_STICK_RIGHT }); } diff --git a/flixel/input/gamepad/id/PS4ID.hx b/flixel/input/gamepad/id/PS4ID.hx index 1fd01e7505..ccbb77ec63 100644 --- a/flixel/input/gamepad/id/PS4ID.hx +++ b/flixel/input/gamepad/id/PS4ID.hx @@ -18,136 +18,156 @@ import flixel.input.gamepad.FlxGamepadAnalogStick; * MAC: the PS4 controller seemed to work perfectly without anything special installed, and was not detected in the 360Controller * control panel, so it might just work right out of the box! */ -class PS4ID +enum abstract PS4ID(Int) to Int { #if flash - public static inline var SQUARE:Int = 10; - public static inline var X:Int = 11; - public static inline var CIRCLE:Int = 12; - public static inline var TRIANGLE:Int = 13; - public static inline var L1:Int = 14; - public static inline var R1:Int = 15; - public static inline var L2:Int = 16; - public static inline var R2:Int = 17; - public static inline var SHARE:Int = 18; - public static inline var OPTIONS:Int = 19; - public static inline var LEFT_STICK_CLICK:Int = 20; - public static inline var RIGHT_STICK_CLICK:Int = 21; - public static inline var PS:Int = 22; - public static inline var TOUCHPAD_CLICK:Int = 23; - - public static var LEFT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(0, 1, { - up: 24, - down: 25, - left: 26, - right: 27 - }); - public static var RIGHT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(2, 5, { - up: 28, - down: 29, - left: 30, - right: 31 - }); - - public static inline var DPAD_UP:Int = 6; - public static inline var DPAD_DOWN:Int = 7; - public static inline var DPAD_LEFT:Int = 8; - public static inline var DPAD_RIGHT:Int = 9; + var SQUARE = 10; + var X = 11; + var CIRCLE = 12; + var TRIANGLE = 13; + var L1 = 14; + var R1 = 15; + var L2 = 16; + var R2 = 17; + var SHARE = 18; + var OPTIONS = 19; + var LEFT_STICK_CLICK = 20; + var RIGHT_STICK_CLICK = 21; + var PS = 22; + var TOUCHPAD_CLICK = 23; + + static inline final LEFT_X = 0; + static inline final LEFT_Y = 1; + static inline final RIGHT_X = 2; + static inline final RIGHT_Y = 5; + + var LEFT_STICK_UP = 24; + var LEFT_STICK_DOWN = 25; + var LEFT_STICK_LEFT = 26; + var LEFT_STICK_RIGHT = 27; + + var RIGHT_STICK_UP = 28; + var RIGHT_STICK_DOWN = 29; + var RIGHT_STICK_LEFT = 30; + var RIGHT_STICK_RIGHT = 31; + + var DPAD_UP = 6; + var DPAD_DOWN = 7; + var DPAD_LEFT = 8; + var DPAD_RIGHT = 9; #elseif FLX_GAMEINPUT_API // #if (html5 || windows || mac || linux) - public static inline var X:Int = 6; - public static inline var CIRCLE:Int = 7; - public static inline var SQUARE:Int = 8; - public static inline var TRIANGLE:Int = 9; - public static inline var PS:Int = 11; - public static inline var OPTIONS:Int = 12; - public static inline var LEFT_STICK_CLICK:Int = 13; - public static inline var RIGHT_STICK_CLICK:Int = 14; - public static inline var L1:Int = 15; - public static inline var R1:Int = 16; + var X = 6; + var CIRCLE = 7; + var SQUARE = 8; + var TRIANGLE = 9; + var PS = 11; + var OPTIONS = 12; + var LEFT_STICK_CLICK = 13; + var RIGHT_STICK_CLICK = 14; + var L1 = 15; + var R1 = 16; #if ps4 - public static inline var TOUCHPAD_CLICK:Int = 10; // On an actual PS4, share is reserved by the system, and the touchpad click can serve more or less as a replacement for the "back/select" button - - public static var LEFT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(0, 1, { - up: 32, - down: 33, - left: 34, - right: 35 - }); - public static var RIGHT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(2, 3, { - up: 36, - down: 37, - left: 38, - right: 39 - }); - - public static inline var SHARE:Int = 40; // Not accessible on an actual PS4, just setting it to a dummy value + var TOUCHPAD_CLICK = 10; // On an actual PS4, share is reserved by the system, and the touchpad click can serve more or less as a replacement for the "back/select" button + + static inline final LEFT_X = 0; + static inline final LEFT_Y = 1; + static inline final RIGHT_X = 2; + static inline final RIGHT_Y = 3; + + var LEFT_STICK_UP = 32; + var LEFT_STICK_DOWN = 33; + var LEFT_STICK_LEFT = 34; + var LEFT_STICK_RIGHT = 35; + + var RIGHT_STICK_UP = 36; + var RIGHT_STICK_DOWN = 37; + var RIGHT_STICK_LEFT = 38; + var RIGHT_STICK_RIGHT = 39; + + var SHARE = 40; // Not accessible on an actual PS4, just setting it to a dummy value #else - public static inline var SHARE:Int = 10; // This is only accessible when not using an actual Playstation 4, otherwise it's reserved by the system - - public static var LEFT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(0, 1, { - up: 22, - down: 23, - left: 24, - right: 25 - }); - public static var RIGHT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(2, 3, { - up: 26, - down: 27, - left: 28, - right: 29 - }); - - public static inline var TOUCHPAD_CLICK:Int = 30; // I don't believe this is normally accessible on PC, just setting it to a dummy value - + var SHARE = 10; // This is only accessible when not using an actual Playstation 4, otherwise it's reserved by the system + + static inline final LEFT_X = 0; + static inline final LEFT_Y = 1; + static inline final RIGHT_X = 2; + static inline final RIGHT_Y = 3; + + var LEFT_STICK_UP = 22; + var LEFT_STICK_DOWN = 23; + var LEFT_STICK_LEFT = 24; + var LEFT_STICK_RIGHT = 25; + + var RIGHT_STICK_UP = 26; + var RIGHT_STICK_DOWN = 27; + var RIGHT_STICK_LEFT = 28; + var RIGHT_STICK_RIGHT = 29; + + var TOUCHPAD_CLICK = 30; // I don't believe this is normally accessible on PC, just setting it to a dummy value #end - public static inline var L2:Int = 4; - public static inline var R2:Int = 5; + var L2 = 4; + var R2 = 5; - public static inline var DPAD_UP:Int = 17; - public static inline var DPAD_DOWN:Int = 18; - public static inline var DPAD_LEFT:Int = 19; - public static inline var DPAD_RIGHT:Int = 20; + var DPAD_UP = 17; + var DPAD_DOWN = 18; + var DPAD_LEFT = 19; + var DPAD_RIGHT = 20; // On linux the drivers we're testing with just make the PS4 controller look like an XInput device, // So strictly speaking these ID's will probably not be used, but the compiler needs something or // else it will not compile on Linux #else // "legacy" - public static inline var SQUARE:Int = 0; - public static inline var X:Int = 1; - public static inline var CIRCLE:Int = 2; - public static inline var TRIANGLE:Int = 3; - public static inline var L1:Int = 4; - public static inline var R1:Int = 5; - - public static inline var SHARE:Int = 8; - public static inline var OPTIONS:Int = 9; - public static inline var LEFT_STICK_CLICK:Int = 10; - public static inline var RIGHT_STICK_CLICK:Int = 11; - public static inline var PS:Int = 12; - public static inline var TOUCHPAD_CLICK:Int = 13; - - public static inline var L2:Int = 3; - public static inline var R2:Int = 4; - - public static var LEFT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(0, 1, { - up: 27, - down: 28, - left: 29, - right: 30 - }); - public static var RIGHT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(2, 5, { - up: 31, - down: 32, - left: 33, - right: 34 - }); - + var SQUARE = 0; + var X = 1; + var CIRCLE = 2; + var TRIANGLE = 3; + var L1 = 4; + var R1 = 5; + + var SHARE = 8; + var OPTIONS = 9; + var LEFT_STICK_CLICK = 10; + var RIGHT_STICK_CLICK = 11; + var PS = 12; + var TOUCHPAD_CLICK = 13; + + var L2 = 3; + var R2 = 4; + + static inline final LEFT_X = 0; + static inline final LEFT_Y = 1; + static inline final RIGHT_X = 2; + static inline final RIGHT_Y = 5; + + var LEFT_STICK_UP = 27; + var LEFT_STICK_DOWN = 28; + var LEFT_STICK_LEFT = 29; + var LEFT_STICK_RIGHT = 30; + + var RIGHT_STICK_UP = 31; + var RIGHT_STICK_DOWN = 32; + var RIGHT_STICK_LEFT = 33; + var RIGHT_STICK_RIGHT = 34; + // "fake" IDs, we manually watch for hat axis changes and then send events using these otherwise unused joystick button codes - public static inline var DPAD_LEFT:Int = 15; - public static inline var DPAD_RIGHT:Int = 16; - public static inline var DPAD_DOWN:Int = 17; - public static inline var DPAD_UP:Int = 18; + var DPAD_LEFT = 15; + var DPAD_RIGHT = 16; + var DPAD_DOWN = 17; + var DPAD_UP = 18; #end + + public static final LEFT_ANALOG_STICK = new FlxTypedGamepadAnalogStick(LEFT_X, LEFT_Y, { + up: LEFT_STICK_UP, + down: LEFT_STICK_DOWN, + left: LEFT_STICK_LEFT, + right: LEFT_STICK_RIGHT + }); + public static final RIGHT_ANALOG_STICK = new FlxTypedGamepadAnalogStick(RIGHT_X, RIGHT_Y, { + up: RIGHT_STICK_UP, + down: RIGHT_STICK_DOWN, + left: RIGHT_STICK_LEFT, + right: RIGHT_STICK_RIGHT + }); } diff --git a/flixel/input/gamepad/id/PSVitaID.hx b/flixel/input/gamepad/id/PSVitaID.hx index bdcdfbc8f0..8a28fb9f42 100644 --- a/flixel/input/gamepad/id/PSVitaID.hx +++ b/flixel/input/gamepad/id/PSVitaID.hx @@ -8,32 +8,42 @@ import flixel.input.gamepad.FlxGamepadAnalogStick; * * This will ONLY work with the gamepad API (available only in OpenFL "next", not "legacy") and will NOT work with the joystick API */ -class PSVitaID +enum abstract PSVitaID(Int) to Int { - public static inline var X:Int = 6; - public static inline var CIRCLE:Int = 7; - public static inline var SQUARE:Int = 8; - public static inline var TRIANGLE:Int = 9; - public static inline var SELECT:Int = 10; - public static inline var START:Int = 12; - public static inline var L:Int = 15; - public static inline var R:Int = 16; + var X = 6; + var CIRCLE = 7; + var SQUARE = 8; + var TRIANGLE = 9; + var SELECT = 10; + var START = 12; + var L = 15; + var R = 16; - public static inline var DPAD_UP:Int = 17; - public static inline var DPAD_DOWN:Int = 18; - public static inline var DPAD_LEFT:Int = 19; - public static inline var DPAD_RIGHT:Int = 20; - - public static var LEFT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(0, 1, { - up: 21, - down: 22, - left: 23, - right: 24 + var DPAD_UP = 17; + var DPAD_DOWN = 18; + var DPAD_LEFT = 19; + var DPAD_RIGHT = 20; + + var LEFT_STICK_UP = 21; + var LEFT_STICK_DOWN = 22; + var LEFT_STICK_LEFT = 23; + var LEFT_STICK_RIGHT = 24; + + var RIGHT_STICK_UP = 25; + var RIGHT_STICK_DOWN = 26; + var RIGHT_STICK_LEFT = 27; + var RIGHT_STICK_RIGHT = 28; + + public static final LEFT_ANALOG_STICK = new FlxTypedGamepadAnalogStick(0, 1, { + up: LEFT_STICK_UP, + down: LEFT_STICK_DOWN, + left: LEFT_STICK_LEFT, + right: LEFT_STICK_RIGHT }); - public static var RIGHT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(2, 3, { - up: 25, - down: 26, - left: 27, - right: 28 + public static final RIGHT_ANALOG_STICK = new FlxTypedGamepadAnalogStick(2, 3, { + up: RIGHT_STICK_UP, + down: RIGHT_STICK_DOWN, + left: RIGHT_STICK_LEFT, + right: RIGHT_STICK_RIGHT }); } diff --git a/flixel/input/gamepad/id/SwitchJoyconLeftID.hx b/flixel/input/gamepad/id/SwitchJoyconLeftID.hx index 9d35d7a461..99090a87e4 100644 --- a/flixel/input/gamepad/id/SwitchJoyconLeftID.hx +++ b/flixel/input/gamepad/id/SwitchJoyconLeftID.hx @@ -19,44 +19,48 @@ import flixel.input.gamepad.FlxGamepadAnalogStick; * * @since 4.8.0 */ -class SwitchJoyconLeftID +enum abstract SwitchJoyconLeftID(Int) to Int { #if flash - public static inline var UP:Int = 8; - public static inline var LEFT:Int = 9; - public static inline var DOWN:Int = 10; - public static inline var RIGHT:Int = 11; - public static inline var SL:Int = 12; - public static inline var SR:Int = 13; - public static inline var ZL:Int = 14; - public static inline var L:Int = 15; - public static inline var MINUS:Int = 17; - public static inline var CAPTURE:Int = 21; - public static inline var LEFT_STICK_CLICK:Int = 22; - public static var LEFT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(0, 1, { - up: 24, - down: 25, - left: 26, - right: 27 - }); + var UP = 8; + var LEFT = 9; + var DOWN = 10; + var RIGHT = 11; + var SL = 12; + var SR = 13; + var ZL = 14; + var L = 15; + var MINUS = 17; + var CAPTURE = 21; + var LEFT_STICK_CLICK = 22; + + var LEFT_STICK_UP = 24; + var LEFT_STICK_DOWN = 25; + var LEFT_STICK_LEFT = 26; + var LEFT_STICK_RIGHT = 27; #else - public static inline var ZL:Int = 4; - public static inline var DOWN:Int = 6; - public static inline var RIGHT:Int = 7; - public static inline var LEFT:Int = 8; - public static inline var UP:Int = 9; - public static inline var L:Int = 10; - public static inline var MINUS:Int = 12; - public static inline var LEFT_STICK_CLICK:Int = 13; - public static inline var SL:Int = 15; - public static inline var SR:Int = 16; - public static inline var CAPTURE:Int = 21; - public static var LEFT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(0, 1, { - up: 22, - down: 23, - left: 24, - right: 25 - }); + var ZL = 4; + var DOWN = 6; + var RIGHT = 7; + var LEFT = 8; + var UP = 9; + var L = 10; + var MINUS = 12; + var LEFT_STICK_CLICK = 13; + var SL = 15; + var SR = 16; + var CAPTURE = 21; + + var LEFT_STICK_UP = 22; + var LEFT_STICK_DOWN = 23; + var LEFT_STICK_LEFT = 24; + var LEFT_STICK_RIGHT = 25; #end + public static final LEFT_ANALOG_STICK = new FlxTypedGamepadAnalogStick(0, 1, { + up: LEFT_STICK_UP, + down: LEFT_STICK_DOWN, + left: LEFT_STICK_LEFT, + right: LEFT_STICK_RIGHT + }); } diff --git a/flixel/input/gamepad/id/SwitchJoyconRightID.hx b/flixel/input/gamepad/id/SwitchJoyconRightID.hx index b75d3df1c1..626e131d33 100644 --- a/flixel/input/gamepad/id/SwitchJoyconRightID.hx +++ b/flixel/input/gamepad/id/SwitchJoyconRightID.hx @@ -19,51 +19,49 @@ import flixel.input.gamepad.FlxGamepadAnalogStick; * * @since 4.8.0 */ -class SwitchJoyconRightID + +enum abstract SwitchJoyconRightID(Int) to Int { #if flash - public static inline var A:Int = 8; - public static inline var B:Int = 9; - public static inline var X:Int = 10; - public static inline var Y:Int = 11; - public static inline var SL:Int = 12; - public static inline var SR:Int = 13; - public static inline var ZR:Int = 15; - public static inline var R:Int = 16; - public static inline var PLUS:Int = 17; - public static inline var HOME:Int = 20; - public static inline var CAPTURE:Int = 21; - public static inline var LEFT_STICK_CLICK:Int = 22; - public static var LEFT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(0, 1, { - up: 24, - down: 25, - left: 26, - right: 27 - }); - public static var RIGHT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(2, 3, { - up: 28, - down: 29, - left: 30, - right: 31 - }); + var A = 8; + var B = 9; + var X = 10; + var Y = 11; + var SL = 12; + var SR = 13; + var ZR = 15; + var R = 16; + var PLUS = 17; + var HOME = 20; + var CAPTURE = 21; + var LEFT_STICK_CLICK = 22; + + var LEFT_STICK_UP = 24; + var LEFT_STICK_DOWN = 25; + var LEFT_STICK_LEFT = 26; + var LEFT_STICK_RIGHT = 27; #else - public static inline var ZR:Int = 5; - public static inline var A:Int = 6; - public static inline var X:Int = 7; - public static inline var B:Int = 8; - public static inline var Y:Int = 9; - public static inline var R:Int = 10; - public static inline var HOME:Int = 11; - public static inline var PLUS:Int = 12; - public static inline var LEFT_STICK_CLICK:Int = 13; - public static inline var SL:Int = 15; - public static inline var SR:Int = 16; - public static var LEFT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(0, 1, { - up: 22, - down: 23, - left: 24, - right: 25 - }); - #end + var ZR = 5; + var A = 6; + var X = 7; + var B = 8; + var Y = 9; + var R = 10; + var HOME = 11; + var PLUS = 12; + var LEFT_STICK_CLICK = 13; + var SL = 15; + var SR = 16; + var LEFT_STICK_UP = 22; + var LEFT_STICK_DOWN = 23; + var LEFT_STICK_LEFT = 24; + var LEFT_STICK_RIGHT = 25; + #end + public static final LEFT_ANALOG_STICK = new FlxTypedGamepadAnalogStick(0, 1, { + up: LEFT_STICK_UP, + down: LEFT_STICK_DOWN, + left: LEFT_STICK_LEFT, + right: LEFT_STICK_RIGHT + }); } diff --git a/flixel/input/gamepad/id/SwitchProID.hx b/flixel/input/gamepad/id/SwitchProID.hx index 845a0264e9..0d8d79a7fd 100644 --- a/flixel/input/gamepad/id/SwitchProID.hx +++ b/flixel/input/gamepad/id/SwitchProID.hx @@ -17,70 +17,80 @@ import flixel.input.gamepad.FlxGamepadAnalogStick; * * @since 4.8.0 */ -class SwitchProID +enum abstract SwitchProID(Int) to Int { #if flash - public static inline var DPAD_UP:Int = 4; - public static inline var DPAD_DOWN:Int = 5; - public static inline var DPAD_LEFT:Int = 6; - public static inline var DPAD_RIGHT:Int = 7; - public static inline var A:Int = 8; - public static inline var B:Int = 9; - public static inline var X:Int = 10; - public static inline var Y:Int = 11; - public static inline var L:Int = 12; - public static inline var R:Int = 13; - public static inline var ZL:Int = 14; - public static inline var ZR:Int = 15; - public static inline var MINUS:Int = 16; - public static inline var PLUS:Int = 17; - public static inline var HOME:Int = 20; - public static inline var CAPTURE:Int = 21; - public static inline var LEFT_STICK_CLICK:Int = 22; - public static inline var RIGHT_STICK_CLICK:Int = 23; - public static var LEFT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(0, 1, { - up: 24, - down: 25, - left: 26, - right: 27 - }); - public static var RIGHT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(2, 3, { - up: 28, - down: 29, - left: 30, - right: 31 - }); + var DPAD_UP = 4; + var DPAD_DOWN = 5; + var DPAD_LEFT = 6; + var DPAD_RIGHT = 7; + var A = 8; + var B = 9; + var X = 10; + var Y = 11; + var L = 12; + var R = 13; + var ZL = 14; + var ZR = 15; + var MINUS = 16; + var PLUS = 17; + var HOME = 20; + var CAPTURE = 21; + var LEFT_STICK_CLICK = 22; + var RIGHT_STICK_CLICK = 23; + + var LEFT_STICK_UP = 24; + var LEFT_STICK_DOWN = 25; + var LEFT_STICK_LEFT = 26; + var LEFT_STICK_RIGHT = 27; + + var RIGHT_STICK_UP = 28; + var RIGHT_STICK_DOWN = 29; + var RIGHT_STICK_LEFT = 30; + var RIGHT_STICK_RIGHT = 31; + #else - public static inline var ZL:Int = 4; - public static inline var ZR:Int = 5; - public static inline var B:Int = 6; - public static inline var A:Int = 7; - public static inline var Y:Int = 8; - public static inline var X:Int = 9; - public static inline var MINUS:Int = 10; - public static inline var HOME:Int = 11; - public static inline var PLUS:Int = 12; - public static inline var LEFT_STICK_CLICK:Int = 13; - public static inline var RIGHT_STICK_CLICK:Int = 14; - public static inline var L:Int = 15; - public static inline var R:Int = 16; - public static inline var DPAD_UP:Int = 17; - public static inline var DPAD_DOWN:Int = 18; - public static inline var DPAD_LEFT:Int = 19; - public static inline var DPAD_RIGHT:Int = 20; - public static inline var CAPTURE:Int = 21; - public static var LEFT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(0, 1, { - up: 22, - down: 23, - left: 24, - right: 25 + var ZL = 4; + var ZR = 5; + var B = 6; + var A = 7; + var Y = 8; + var X = 9; + var MINUS = 10; + var HOME = 11; + var PLUS = 12; + var LEFT_STICK_CLICK = 13; + var RIGHT_STICK_CLICK = 14; + var L = 15; + var R = 16; + var DPAD_UP = 17; + var DPAD_DOWN = 18; + var DPAD_LEFT = 19; + var DPAD_RIGHT = 20; + var CAPTURE = 21; + + var LEFT_STICK_UP = 22; + var LEFT_STICK_DOWN = 23; + var LEFT_STICK_LEFT = 24; + var LEFT_STICK_RIGHT = 25; + + var RIGHT_STICK_UP = 26; + var RIGHT_STICK_DOWN = 27; + var RIGHT_STICK_LEFT = 28; + var RIGHT_STICK_RIGHT = 29; + #end + + public static final LEFT_ANALOG_STICK = new FlxTypedGamepadAnalogStick(0, 1, { + up: LEFT_STICK_UP, + down: LEFT_STICK_DOWN, + left: LEFT_STICK_LEFT, + right: LEFT_STICK_RIGHT }); - public static var RIGHT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(2, 3, { - up: 26, - down: 27, - left: 28, - right: 29 + public static final RIGHT_ANALOG_STICK = new FlxTypedGamepadAnalogStick(2, 3, { + up: RIGHT_STICK_UP, + down: RIGHT_STICK_DOWN, + left: RIGHT_STICK_LEFT, + right: RIGHT_STICK_RIGHT }); - #end } diff --git a/flixel/input/gamepad/id/WiiRemoteID.hx b/flixel/input/gamepad/id/WiiRemoteID.hx index 50919516ab..1fc0421c78 100644 --- a/flixel/input/gamepad/id/WiiRemoteID.hx +++ b/flixel/input/gamepad/id/WiiRemoteID.hx @@ -11,7 +11,7 @@ import flixel.input.gamepad.FlxGamepadAnalogStick; * * @author larsiusprime */ -class WiiRemoteID +enum abstract WiiRemoteID(Int) to Int { /** * Things to add: @@ -23,154 +23,163 @@ class WiiRemoteID */ #if FLX_JOYSTICK_API // Standard Wii Remote inputs: - public static inline var REMOTE_ONE:Int = 0; - public static inline var REMOTE_TWO:Int = 1; - public static inline var REMOTE_A:Int = 2; - public static inline var REMOTE_B:Int = 3; - public static inline var REMOTE_PLUS:Int = 4; - public static inline var REMOTE_MINUS:Int = 5; - public static inline var REMOTE_HOME:Int = 6; + var REMOTE_ONE = 0; + var REMOTE_TWO = 1; + var REMOTE_A = 2; + var REMOTE_B = 3; + var REMOTE_PLUS = 4; + var REMOTE_MINUS = 5; + var REMOTE_HOME = 6; // Nunchuk attachment: - public static inline var NUNCHUK_A:Int = 0; - public static inline var NUNCHUK_B:Int = 1; - public static inline var NUNCHUK_C:Int = 2; - public static inline var NUNCHUK_Z:Int = 3; - public static inline var NUNCHUK_ONE:Int = 4; - public static inline var NUNCHUK_TWO:Int = 5; - public static inline var NUNCHUK_PLUS:Int = 6; - public static inline var NUNCHUK_MINUS:Int = 7; - public static inline var NUNCHUK_HOME:Int = 8; + var NUNCHUK_A = 0; + var NUNCHUK_B = 1; + var NUNCHUK_C = 2; + var NUNCHUK_Z = 3; + var NUNCHUK_ONE = 4; + var NUNCHUK_TWO = 5; + var NUNCHUK_PLUS = 6; + var NUNCHUK_MINUS = 7; + var NUNCHUK_HOME = 8; // classic controller attachment: - public static inline var CLASSIC_A:Int = 0; - public static inline var CLASSIC_B:Int = 1; - public static inline var CLASSIC_Y:Int = 2; - public static inline var CLASSIC_X:Int = 3; - public static inline var CLASSIC_L:Int = 4; - public static inline var CLASSIC_R:Int = 5; - public static inline var CLASSIC_ZL:Int = 6; - public static inline var CLASSIC_ZR:Int = 7; - public static inline var CLASSIC_START:Int = 8; - public static inline var CLASSIC_SELECT:Int = 9; - public static inline var CLASSIC_HOME:Int = 10; - public static inline var CLASSIC_ONE:Int = 11; - public static inline var CLASSIC_TWO:Int = 12; - - public static inline var REMOTE_TILT_PITCH:Int = 2; - public static inline var REMOTE_TILT_ROLL:Int = 3; - - public static inline var NUNCHUK_TILT_PITCH:Int = 3; - public static inline var NUNCHUK_TILT_ROLL:Int = 2; - - public static inline var REMOTE_NULL_AXIS:Int = 4; - public static inline var NUNCHUK_NULL_AXIS:Int = 4; - - // Yes, the WiiRemote DPAD is treated as ANALOG for some reason... - // so we have to pass in some "fake" ID's to get simulated digital inputs - public static var REMOTE_DPAD(default, null) = new FlxGamepadAnalogStick(0, 1, { - up: REMOTE_DPAD_UP, - down: REMOTE_DPAD_DOWN, - left: REMOTE_DPAD_LEFT, - right: REMOTE_DPAD_RIGHT, - threshold: 0.5, - mode: ONLY_DIGITAL - }); - - // the nunchuk only has the "left" analog stick - public static var LEFT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(0, 1, { - up: 32, - down: 33, - left: 34, - right: 35 - }); - // the classic controller has both the "left" and "right" analog sticks - public static var RIGHT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(2, 3, { - up: 36, - down: 37, - left: 38, - right: 39 - }); - + var CLASSIC_A = 0; + var CLASSIC_B = 1; + var CLASSIC_Y = 2; + var CLASSIC_X = 3; + var CLASSIC_L = 4; + var CLASSIC_R = 5; + var CLASSIC_ZL = 6; + var CLASSIC_ZR = 7; + var CLASSIC_START = 8; + var CLASSIC_SELECT = 9; + var CLASSIC_HOME = 10; + var CLASSIC_ONE = 11; + var CLASSIC_TWO = 12; + + var REMOTE_TILT_PITCH = 2; + var REMOTE_TILT_ROLL = 3; + + var NUNCHUK_TILT_PITCH = 3; + var NUNCHUK_TILT_ROLL = 2; + + var REMOTE_NULL_AXIS = 4; + var NUNCHUK_NULL_AXIS = 4; + + var LEFT_STICK_UP = 32; + var LEFT_STICK_DOWN = 33; + var LEFT_STICK_LEFT = 34; + var LEFT_STICK_RIGHT = 35; + + var RIGHT_STICK_UP = 36; + var RIGHT_STICK_DOWN = 37; + var RIGHT_STICK_LEFT = 38; + var RIGHT_STICK_RIGHT = 39; + // these aren't real axes, they're simulated when the right digital buttons are pushed - public static inline var LEFT_TRIGGER_FAKE:Int = 4; - public static inline var RIGHT_TRIGGER_FAKE:Int = 5; + var LEFT_TRIGGER_FAKE = 4; + var RIGHT_TRIGGER_FAKE = 5; // "fake" ID's - public static inline var REMOTE_DPAD_UP:Int = 14; - public static inline var REMOTE_DPAD_DOWN:Int = 15; - public static inline var REMOTE_DPAD_LEFT:Int = 16; - public static inline var REMOTE_DPAD_RIGHT:Int = 17; - - public static inline var REMOTE_DPAD_X:Int = 18; - public static inline var REMOTE_DPAD_Y:Int = 19; - - public static inline var CLASSIC_DPAD_DOWN:Int = 24; - public static inline var CLASSIC_DPAD_UP:Int = 25; - public static inline var CLASSIC_DPAD_LEFT:Int = 26; - public static inline var CLASSIC_DPAD_RIGHT:Int = 27; - - public static inline var NUNCHUK_DPAD_DOWN:Int = 28; - public static inline var NUNCHUK_DPAD_UP:Int = 29; - public static inline var NUNCHUK_DPAD_LEFT:Int = 30; - public static inline var NUNCHUK_DPAD_RIGHT:Int = 31; + var REMOTE_DPAD_UP = 14; + var REMOTE_DPAD_DOWN = 15; + var REMOTE_DPAD_LEFT = 16; + var REMOTE_DPAD_RIGHT = 17; + + var REMOTE_DPAD_X = 18; + var REMOTE_DPAD_Y = 19; + + var CLASSIC_DPAD_DOWN = 24; + var CLASSIC_DPAD_UP = 25; + var CLASSIC_DPAD_LEFT = 26; + var CLASSIC_DPAD_RIGHT = 27; + + var NUNCHUK_DPAD_DOWN = 28; + var NUNCHUK_DPAD_UP = 29; + var NUNCHUK_DPAD_LEFT = 30; + var NUNCHUK_DPAD_RIGHT = 31; #else // gamepad API // Standard Wii Remote inputs: - public static inline var REMOTE_ONE:Int = 9; - public static inline var REMOTE_TWO:Int = 10; - public static inline var REMOTE_A:Int = 11; - public static inline var REMOTE_B:Int = 12; - public static inline var REMOTE_PLUS:Int = 13; - public static inline var REMOTE_MINUS:Int = 14; - public static inline var REMOTE_HOME:Int = 15; + var REMOTE_ONE = 9; + var REMOTE_TWO = 10; + var REMOTE_A = 11; + var REMOTE_B = 12; + var REMOTE_PLUS = 13; + var REMOTE_MINUS = 14; + var REMOTE_HOME = 15; // Nunchuk attachment: - public static inline var NUNCHUK_A:Int = 9; - public static inline var NUNCHUK_B:Int = 10; - public static inline var NUNCHUK_C:Int = 11; - public static inline var NUNCHUK_Z:Int = 12; - public static inline var NUNCHUK_ONE:Int = 13; - public static inline var NUNCHUK_TWO:Int = 14; - public static inline var NUNCHUK_PLUS:Int = 15; - public static inline var NUNCHUK_MINUS:Int = 16; - public static inline var NUNCHUK_HOME:Int = 17; - - public static inline var NUNCHUK_DPAD_UP:Int = 5; - public static inline var NUNCHUK_DPAD_DOWN:Int = 6; - public static inline var NUNCHUK_DPAD_LEFT:Int = 7; - public static inline var NUNCHUK_DPAD_RIGHT:Int = 8; + var NUNCHUK_A = 9; + var NUNCHUK_B = 10; + var NUNCHUK_C = 11; + var NUNCHUK_Z = 12; + var NUNCHUK_ONE = 13; + var NUNCHUK_TWO = 14; + var NUNCHUK_PLUS = 15; + var NUNCHUK_MINUS = 16; + var NUNCHUK_HOME = 17; + + var NUNCHUK_DPAD_UP = 5; + var NUNCHUK_DPAD_DOWN = 6; + var NUNCHUK_DPAD_LEFT = 7; + var NUNCHUK_DPAD_RIGHT = 8; // classic controller attachment: - public static inline var CLASSIC_A:Int = 9; - public static inline var CLASSIC_B:Int = 10; - public static inline var CLASSIC_Y:Int = 11; - public static inline var CLASSIC_X:Int = 12; - public static inline var CLASSIC_L:Int = 13; - public static inline var CLASSIC_R:Int = 14; - public static inline var CLASSIC_ZL:Int = 15; - public static inline var CLASSIC_ZR:Int = 16; - public static inline var CLASSIC_START:Int = 17; - public static inline var CLASSIC_SELECT:Int = 18; - public static inline var CLASSIC_HOME:Int = 19; - public static inline var CLASSIC_ONE:Int = 20; - public static inline var CLASSIC_TWO:Int = 21; - - public static inline var CLASSIC_DPAD_UP:Int = 5; - public static inline var CLASSIC_DPAD_DOWN:Int = 6; - public static inline var CLASSIC_DPAD_LEFT:Int = 7; - public static inline var CLASSIC_DPAD_RIGHT:Int = 8; - - public static inline var REMOTE_TILT_PITCH:Int = 2; - public static inline var REMOTE_TILT_ROLL:Int = 3; - - public static inline var NUNCHUK_TILT_PITCH:Int = 3; - public static inline var NUNCHUK_TILT_ROLL:Int = 2; - - public static inline var REMOTE_NULL_AXIS:Int = 4; - public static inline var NUNCHUK_NULL_AXIS:Int = 4; - - // Yes, the WiiRemote DPAD is treated as ANALOG for some reason...so we have to pass in some "fake" ID's to get simulated digital inputs - public static var REMOTE_DPAD(default, null) = new FlxGamepadAnalogStick(0, 1, { + var CLASSIC_A = 9; + var CLASSIC_B = 10; + var CLASSIC_Y = 11; + var CLASSIC_X = 12; + var CLASSIC_L = 13; + var CLASSIC_R = 14; + var CLASSIC_ZL = 15; + var CLASSIC_ZR = 16; + var CLASSIC_START = 17; + var CLASSIC_SELECT = 18; + var CLASSIC_HOME = 19; + var CLASSIC_ONE = 20; + var CLASSIC_TWO = 21; + + var CLASSIC_DPAD_UP = 5; + var CLASSIC_DPAD_DOWN = 6; + var CLASSIC_DPAD_LEFT = 7; + var CLASSIC_DPAD_RIGHT = 8; + + var REMOTE_TILT_PITCH = 2; + var REMOTE_TILT_ROLL = 3; + + var NUNCHUK_TILT_PITCH = 3; + var NUNCHUK_TILT_ROLL = 2; + + var REMOTE_NULL_AXIS = 4; + var NUNCHUK_NULL_AXIS = 4; + + var LEFT_STICK_UP = 28; + var LEFT_STICK_DOWN = 29; + var LEFT_STICK_LEFT = 30; + var LEFT_STICK_RIGHT = 31; + + var RIGHT_STICK_UP = 32; + var RIGHT_STICK_DOWN = 33; + var RIGHT_STICK_LEFT = 34; + var RIGHT_STICK_RIGHT = 35; + + // these aren't real axes, they're simulated when the right digital buttons are pushed + var LEFT_TRIGGER_FAKE = 4; + var RIGHT_TRIGGER_FAKE = 5; + + // "fake" ID's + var REMOTE_DPAD_UP = 22; + var REMOTE_DPAD_DOWN = 23; + var REMOTE_DPAD_LEFT = 24; + var REMOTE_DPAD_RIGHT = 25; + + var REMOTE_DPAD_X = 26; + var REMOTE_DPAD_Y = 27; + #end + + // Yes, the WiiRemote DPAD is treated as ANALOG for some reason... + // so we have to pass in some "fake" ID's to get simulated digital inputs + public static final REMOTE_DPAD = new FlxTypedGamepadAnalogStick(0, 1, { up: REMOTE_DPAD_UP, down: REMOTE_DPAD_DOWN, left: REMOTE_DPAD_LEFT, @@ -178,38 +187,25 @@ class WiiRemoteID threshold: 0.5, mode: ONLY_DIGITAL }); - + /** * the nunchuk only has the "left" analog stick */ - public static var LEFT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(0, 1, { - up: 28, - down: 29, - left: 30, - right: 31 + public static final LEFT_ANALOG_STICK = new FlxTypedGamepadAnalogStick(0, 1, { + up: LEFT_STICK_UP, + down: LEFT_STICK_DOWN, + left: LEFT_STICK_LEFT, + right: LEFT_STICK_RIGHT }); /** * the classic controller has both the "left" and "right" analog sticks */ - public static var RIGHT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(2, 3, { - up: 32, - down: 33, - left: 34, - right: 35 + public static final RIGHT_ANALOG_STICK = new FlxTypedGamepadAnalogStick(2, 3, { + up: RIGHT_STICK_UP, + down: RIGHT_STICK_DOWN, + left: RIGHT_STICK_LEFT, + right: RIGHT_STICK_RIGHT }); - // these aren't real axes, they're simulated when the right digital buttons are pushed - public static inline var LEFT_TRIGGER_FAKE:Int = 4; - public static inline var RIGHT_TRIGGER_FAKE:Int = 5; - - // "fake" ID's - public static inline var REMOTE_DPAD_UP:Int = 22; - public static inline var REMOTE_DPAD_DOWN:Int = 23; - public static inline var REMOTE_DPAD_LEFT:Int = 24; - public static inline var REMOTE_DPAD_RIGHT:Int = 25; - - public static inline var REMOTE_DPAD_X:Int = 26; - public static inline var REMOTE_DPAD_Y:Int = 27; - #end } diff --git a/flixel/input/gamepad/id/XInputID.hx b/flixel/input/gamepad/id/XInputID.hx index c25e217aa4..17ad775258 100644 --- a/flixel/input/gamepad/id/XInputID.hx +++ b/flixel/input/gamepad/id/XInputID.hx @@ -20,161 +20,184 @@ import flixel.input.gamepad.FlxGamepadAnalogStick; * MAC: we assume the user is using the 360 Controller driver, specifically this one: * https://github.com/360Controller/360Controller/releases */ -class XInputID +enum abstract XInputID(Int) to Int { #if flash - public static inline var A:Int = 4; - public static inline var B:Int = 5; - public static inline var X:Int = 6; - public static inline var Y:Int = 7; - public static inline var LB:Int = 8; - public static inline var RB:Int = 9; - - public static inline var BACK:Int = 12; - public static inline var GUIDE:Int = -1; - public static inline var START:Int = 13; - - public static inline var LEFT_STICK_CLICK:Int = 14; - public static inline var RIGHT_STICK_CLICK:Int = 15; - - public static inline var DPAD_UP:Int = 16; - public static inline var DPAD_DOWN:Int = 17; - public static inline var DPAD_LEFT:Int = 18; - public static inline var DPAD_RIGHT:Int = 19; - - public static inline var LEFT_TRIGGER:Int = 10; - public static inline var RIGHT_TRIGGER:Int = 11; - - public static var LEFT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(0, 1, { - up: 20, - down: 21, - left: 22, - right: 23 - }); - public static var RIGHT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(2, 3, { - up: 24, - down: 25, - left: 26, - right: 27 - }); + var A = 4; + var B = 5; + var X = 6; + var Y = 7; + var LB = 8; + var RB = 9; + + var BACK = 12; + var GUIDE = -1; + var START = 13; + + var LEFT_STICK_CLICK = 14; + var RIGHT_STICK_CLICK = 15; + + var DPAD_UP = 16; + var DPAD_DOWN = 17; + var DPAD_LEFT = 18; + var DPAD_RIGHT = 19; + + var LEFT_TRIGGER = 10; + var RIGHT_TRIGGER = 11; + + + static final LEFT_X = 0; + static final LEFT_Y = 1; + static final RIGHT_X = 2; + static final RIGHT_Y = 3; + + var LEFT_STICK_UP = 20; + var LEFT_STICK_DOWN = 21; + var LEFT_STICK_LEFT = 22; + var LEFT_STICK_RIGHT = 23; + + var RIGHT_STICK_UP = 24; + var RIGHT_STICK_DOWN = 25; + var RIGHT_STICK_LEFT = 26; + var RIGHT_STICK_RIGHT = 27; #elseif FLX_GAMEINPUT_API - public static inline var A:Int = 6; - public static inline var B:Int = 7; - public static inline var X:Int = 8; - public static inline var Y:Int = 9; - - public static inline var BACK:Int = 10; - public static inline var GUIDE:Int = #if mac 11 #else - 1 #end; - public static inline var START:Int = 12; - - public static inline var LEFT_STICK_CLICK:Int = 13; - public static inline var RIGHT_STICK_CLICK:Int = 14; - - public static inline var LB:Int = 15; - public static inline var RB:Int = 16; - - public static inline var DPAD_UP:Int = 17; - public static inline var DPAD_DOWN:Int = 18; - public static inline var DPAD_LEFT:Int = 19; - public static inline var DPAD_RIGHT:Int = 20; - - public static var LEFT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(0, 1, { - up: 21, - down: 22, - left: 23, - right: 24 - }); - public static var RIGHT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(2, 3, { - up: 25, - down: 26, - left: 27, - right: 28 - }); - - public static inline var LEFT_TRIGGER:Int = 4; - public static inline var RIGHT_TRIGGER:Int = 5; + var A = 6; + var B = 7; + var X = 8; + var Y = 9; + + var BACK = 10; + var GUIDE = #if mac 11 #else - 1 #end; + var START = 12; + + var LEFT_STICK_CLICK = 13; + var RIGHT_STICK_CLICK = 14; + + var LB = 15; + var RB = 16; + + var DPAD_UP = 17; + var DPAD_DOWN = 18; + var DPAD_LEFT = 19; + var DPAD_RIGHT = 20; + + static inline final LEFT_X = 0; + static inline final LEFT_Y = 1; + static inline final RIGHT_X = 2; + static inline final RIGHT_Y = 3; + + var LEFT_STICK_UP = 21; + var LEFT_STICK_DOWN = 22; + var LEFT_STICK_LEFT = 23; + var LEFT_STICK_RIGHT = 24; + + var RIGHT_STICK_UP = 25; + var RIGHT_STICK_DOWN = 26; + var RIGHT_STICK_LEFT = 27; + var RIGHT_STICK_RIGHT = 28; + + var LEFT_TRIGGER = 4; + var RIGHT_TRIGGER = 5; #elseif FLX_JOYSTICK_API #if (windows || linux) - public static inline var A:Int = 0; - public static inline var B:Int = 1; - public static inline var X:Int = 2; - public static inline var Y:Int = 3; + var A = 0; + var B = 1; + var X = 2; + var Y = 3; - public static inline var LB:Int = 4; - public static inline var RB:Int = 5; + var LB = 4; + var RB = 5; - public static inline var BACK:Int = 6; - public static inline var START:Int = 7; + var BACK = 6; + var START = 7; #if linux - public static inline var LEFT_STICK_CLICK:Int = 9; - public static inline var RIGHT_STICK_CLICK:Int = 10; - public static inline var GUIDE:Int = 8; + var LEFT_STICK_CLICK = 9; + var RIGHT_STICK_CLICK = 10; + var GUIDE = 8; #elseif windows - public static inline var LEFT_STICK_CLICK:Int = 8; - public static inline var RIGHT_STICK_CLICK:Int = 9; - public static inline var GUIDE:Int = 10; + var LEFT_STICK_CLICK = 8; + var RIGHT_STICK_CLICK = 9; + var GUIDE = 10; #end // "fake" IDs, we manually watch for hat axis changes and then send events using // these otherwise unused joystick button codes - public static inline var DPAD_UP:Int = 11; - public static inline var DPAD_DOWN:Int = 12; - public static inline var DPAD_LEFT:Int = 13; - public static inline var DPAD_RIGHT:Int = 14; - - public static inline var LEFT_TRIGGER:Int = 2; - public static inline var RIGHT_TRIGGER:Int = 5; - - public static var LEFT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(0, 1, { - up: 21, - down: 22, - left: 23, - right: 24 - }); - public static var RIGHT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(3, 4, { - up: 25, - down: 26, - left: 27, - right: 28 - }); + var DPAD_UP = 11; + var DPAD_DOWN = 12; + var DPAD_LEFT = 13; + var DPAD_RIGHT = 14; + + var LEFT_TRIGGER = 2; + var RIGHT_TRIGGER = 5; + + static inline final LEFT_X = 0; + static inline final LEFT_Y = 1; + static inline final RIGHT_X = 3; + static inline final RIGHT_Y = 4; + + var LEFT_STICK_UP = 21; + var LEFT_STICK_DOWN = 22; + var LEFT_STICK_LEFT = 23; + var LEFT_STICK_RIGHT = 24; + + var RIGHT_STICK_UP = 25; + var RIGHT_STICK_DOWN = 26; + var RIGHT_STICK_LEFT = 27; + var RIGHT_STICK_RIGHT = 28; #else // mac - public static inline var A:Int = 0; - public static inline var B:Int = 1; - public static inline var X:Int = 2; - public static inline var Y:Int = 3; - - public static inline var LB:Int = 4; - public static inline var RB:Int = 5; - - public static inline var LEFT_STICK_CLICK:Int = 6; - public static inline var RIGHT_STICK_CLICK:Int = 7; - - public static inline var BACK:Int = 9; - public static inline var START:Int = 8; - - public static inline var GUIDE:Int = 10; - - public static inline var DPAD_UP:Int = 11; - public static inline var DPAD_DOWN:Int = 12; - public static inline var DPAD_LEFT:Int = 13; - public static inline var DPAD_RIGHT:Int = 14; - - public static inline var LEFT_TRIGGER:Int = 2; - public static inline var RIGHT_TRIGGER:Int = 5; - - public static var LEFT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(0, 1, { - up: 21, - down: 22, - left: 23, - right: 24 - }); - public static var RIGHT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(3, 4, { - up: 25, - down: 26, - left: 27, - right: 28 - }); + var A = 0; + var B = 1; + var X = 2; + var Y = 3; + + var LB = 4; + var RB = 5; + + var LEFT_STICK_CLICK = 6; + var RIGHT_STICK_CLICK = 7; + + var BACK = 9; + var START = 8; + + var GUIDE = 10; + + var DPAD_UP = 11; + var DPAD_DOWN = 12; + var DPAD_LEFT = 13; + var DPAD_RIGHT = 14; + + var LEFT_TRIGGER = 2; + var RIGHT_TRIGGER = 5; + + static inline final LEFT_X = 0; + static inline final LEFT_Y = 1; + static inline final RIGHT_X = 3; + static inline final RIGHT_Y = 4; + + var LEFT_STICK_UP = 21; + var LEFT_STICK_DOWN = 22; + var LEFT_STICK_LEFT = 23; + var LEFT_STICK_RIGHT = 24; + + var RIGHT_STICK_UP = 25; + var RIGHT_STICK_DOWN = 26; + var RIGHT_STICK_LEFT = 27; + var RIGHT_STICK_RIGHT = 28; #end #end + + public static final LEFT_ANALOG_STICK = new FlxTypedGamepadAnalogStick(LEFT_X, LEFT_Y, { + up: LEFT_STICK_UP, + down: LEFT_STICK_DOWN, + left: LEFT_STICK_LEFT, + right: LEFT_STICK_RIGHT + }); + + public static var RIGHT_ANALOG_STICK = new FlxTypedGamepadAnalogStick(RIGHT_X, RIGHT_Y, { + up: RIGHT_STICK_UP, + down: RIGHT_STICK_DOWN, + left: RIGHT_STICK_LEFT, + right: RIGHT_STICK_RIGHT + }); } diff --git a/flixel/input/gamepad/lists/FlxGamepadButtonList.hx b/flixel/input/gamepad/lists/FlxGamepadButtonList.hx index ca741f1a41..f681041569 100644 --- a/flixel/input/gamepad/lists/FlxGamepadButtonList.hx +++ b/flixel/input/gamepad/lists/FlxGamepadButtonList.hx @@ -39,6 +39,10 @@ class FlxGamepadButtonList extends FlxBaseGamepadList inline function get_RIGHT_SHOULDER() return check(FlxGamepadInputID.RIGHT_SHOULDER); + /** + * Also known as "select", the left-most center button. + * Not to be confused with `CANCEL`, which is a face button (usually B) + */ public var BACK(get, never):Bool; inline function get_BACK() @@ -210,6 +214,25 @@ class FlxGamepadButtonList extends FlxBaseGamepadList inline function get_RIGHT_STICK_DIGITAL_LEFT() return check(FlxGamepadInputID.RIGHT_STICK_DIGITAL_LEFT); + + /** + * Mapped to The bottom face button on most controllers, and the + * right face button on Nintendo Switch controllers + **/ + public var ACCEPT(get, never):Bool; + + inline function get_ACCEPT() + return check(FlxGamepadInputID.ACCEPT); + + /** + * Mapped to The right face button on most controllers, and the + * bottom face button on Nintendo Switch controllers. + * Not to be confused with `BACK` which is the XInput "select" button + **/ + public var CANCEL(get, never):Bool; + + inline function get_CANCEL() + return check(FlxGamepadInputID.CANCEL); public function new(status:FlxInputState, gamepad:FlxGamepad) { diff --git a/flixel/input/gamepad/mappings/FlxGamepadMapping.hx b/flixel/input/gamepad/mappings/FlxGamepadMapping.hx index 86fa919a77..f33d69a98c 100644 --- a/flixel/input/gamepad/mappings/FlxGamepadMapping.hx +++ b/flixel/input/gamepad/mappings/FlxGamepadMapping.hx @@ -7,18 +7,26 @@ import flixel.input.gamepad.FlxGamepadInputID; import openfl.system.Capabilities; #end -class FlxGamepadMapping +typedef FlxGamepadMapping = FlxTypedGamepadMapping; + +class FlxTypedGamepadMapping { public var supportsMotion:Bool = false; public var supportsPointer:Bool = false; - public var leftStick:FlxGamepadAnalogStick; - public var rightStick:FlxGamepadAnalogStick; + public var leftStick:FlxTypedGamepadAnalogStick; + public var rightStick:FlxTypedGamepadAnalogStick; @:allow(flixel.input.gamepad.FlxGamepad) var attachment(default, set):FlxGamepadAttachment = NONE; var manufacturer:Manufacturer; + + /** + * Whether to treat `A` or `B` as `ACCEPT` or `CANCEL`, when `FlxG.gamepads.acceptMode` is `ADAPTIVE` + * @since 5.9.0 + */ + var bottomIsAccept:Bool = true; public function new(?attachment:FlxGamepadAttachment) { @@ -39,7 +47,7 @@ class FlxGamepadMapping function initValues():Void {} - public function getAnalogStick(ID:FlxGamepadInputID):FlxGamepadAnalogStick + public function getAnalogStick(ID:FlxGamepadInputID):FlxTypedGamepadAnalogStick { return switch (ID) { @@ -55,7 +63,7 @@ class FlxGamepadMapping /** * Given a raw hardware code, return the "universal" ID */ - public function getID(rawID:Int):FlxGamepadInputID + public function getID(rawID:TInputID):FlxGamepadInputID { return FlxGamepadInputID.NONE; } @@ -63,20 +71,44 @@ class FlxGamepadMapping /** * Given an ID, return the raw hardware code */ - public function getRawID(ID:FlxGamepadInputID):Int + public function getRawID(ID:FlxGamepadInputID):TInputID { - return -1; + return switch ID + { + case ACCEPT if (getGlobalBottomIsAccept()): getRawID(A); + case CANCEL if (getGlobalBottomIsAccept()): getRawID(B); + case ACCEPT: getRawID(B); + case CANCEL: getRawID(A); + default: cast -1;// TODO: Throw error + } + } + + function getGlobalBottomIsAccept() + { + #if FLX_GAMEPAD + if (FlxG.gamepads != null) + { + return switch FlxG.gamepads.acceptMode + { + case BOTTOM: true; + case RIGHT: false; + case USE_MAPPING: bottomIsAccept; + } + } + #end + + return bottomIsAccept; } /** * Whether this axis needs to be flipped */ - public function isAxisFlipped(axisID:Int):Bool + public function isAxisFlipped(axisID:TInputID):Bool { return false; } - public function isAxisForMotion(ID:FlxGamepadInputID):Bool + public function isAxisForMotion(ID:TInputID):Bool { return false; } @@ -86,7 +118,7 @@ class FlxGamepadMapping * Given an axis index value like 0-6, figures out which input that * corresponds to and returns a "fake" ButtonID for that input */ - public function axisIndexToRawID(axisID:Int):Int + public function axisIndexToRawID(axisID:TInputID):Int { return -1; } @@ -102,6 +134,11 @@ class FlxGamepadMapping return this.attachment = attachment; } + public function getMappedInput(id:FlxGamepadInputID) + { + return FlxGamepadMappedInput.UNKNOWN(id); + } + public function getInputLabel(id:FlxGamepadInputID):Null { if (getRawID(id) == -1) @@ -139,6 +176,10 @@ class FlxGamepadMapping case RIGHT_STICK_DIGITAL_DOWN: "rs-down"; case RIGHT_STICK_DIGITAL_LEFT: "rs-left"; case RIGHT_STICK_DIGITAL_RIGHT: "rs-right"; + case ACCEPT if (getGlobalBottomIsAccept()): getInputLabel(A); + case CANCEL if (getGlobalBottomIsAccept()): getInputLabel(B); + case ACCEPT: getInputLabel(B); + case CANCEL: getInputLabel(A); #if FLX_JOYSTICK_API case LEFT_TRIGGER_FAKE: "l2"; case RIGHT_TRIGGER_FAKE: "r2"; diff --git a/flixel/input/gamepad/mappings/LogitechMapping.hx b/flixel/input/gamepad/mappings/LogitechMapping.hx index 921ccdec2d..b7c309e52f 100644 --- a/flixel/input/gamepad/mappings/LogitechMapping.hx +++ b/flixel/input/gamepad/mappings/LogitechMapping.hx @@ -2,15 +2,16 @@ package flixel.input.gamepad.mappings; import flixel.input.gamepad.FlxGamepadInputID; import flixel.input.gamepad.id.LogitechID; +import flixel.input.gamepad.mappings.FlxGamepadMapping; -class LogitechMapping extends FlxGamepadMapping +class LogitechMapping extends FlxTypedGamepadMapping { #if FLX_JOYSTICK_API - static inline var LEFT_ANALOG_STICK_FAKE_X:Int = 20; - static inline var LEFT_ANALOG_STICK_FAKE_Y:Int = 21; + static inline var LEFT_ANALOG_STICK_FAKE_X = 20; + static inline var LEFT_ANALOG_STICK_FAKE_Y = 21; - static inline var RIGHT_ANALOG_STICK_FAKE_X:Int = 22; - static inline var RIGHT_ANALOG_STICK_FAKE_Y:Int = 23; + static inline var RIGHT_ANALOG_STICK_FAKE_X = 22; + static inline var RIGHT_ANALOG_STICK_FAKE_Y = 23; #end override function initValues():Void @@ -19,7 +20,7 @@ class LogitechMapping extends FlxGamepadMapping rightStick = LogitechID.RIGHT_ANALOG_STICK; } - override public function getID(rawID:Int):FlxGamepadInputID + override function getID(rawID:LogitechID):FlxGamepadInputID { return switch (rawID) { @@ -52,7 +53,7 @@ class LogitechMapping extends FlxGamepadMapping } } - override public function getRawID(ID:FlxGamepadInputID):Int + override function getRawID(ID:FlxGamepadInputID):LogitechID { return switch (ID) { @@ -85,10 +86,15 @@ class LogitechMapping extends FlxGamepadMapping case LEFT_TRIGGER_FAKE: LogitechID.SEVEN; case RIGHT_TRIGGER_FAKE: LogitechID.EIGHT; #end - default: -1; + default: super.getRawID(ID); } } + override function getMappedInput(id:FlxGamepadInputID) + { + return FlxGamepadMappedInput.LOGITECH(getRawID(id)); + } + override function getInputLabel(id:FlxGamepadInputID) { return switch (id) @@ -113,7 +119,7 @@ class LogitechMapping extends FlxGamepadMapping } #if FLX_JOYSTICK_API - override public function axisIndexToRawID(axisID:Int):Int + override function axisIndexToRawID(axisID:LogitechID):Int { return if (axisID == leftStick.x) LEFT_ANALOG_STICK_FAKE_X; else if (axisID == leftStick.y) LEFT_ANALOG_STICK_FAKE_Y; else if (axisID == rightStick.x) RIGHT_ANALOG_STICK_FAKE_X; diff --git a/flixel/input/gamepad/mappings/MFiMapping.hx b/flixel/input/gamepad/mappings/MFiMapping.hx index 5498338f57..5f8afb5f09 100644 --- a/flixel/input/gamepad/mappings/MFiMapping.hx +++ b/flixel/input/gamepad/mappings/MFiMapping.hx @@ -2,8 +2,9 @@ package flixel.input.gamepad.mappings; import flixel.input.gamepad.FlxGamepadInputID; import flixel.input.gamepad.id.MFiID; +import flixel.input.gamepad.mappings.FlxGamepadMapping; -class MFiMapping extends FlxGamepadMapping +class MFiMapping extends FlxTypedGamepadMapping { override function initValues():Void { @@ -11,7 +12,7 @@ class MFiMapping extends FlxGamepadMapping rightStick = MFiID.RIGHT_ANALOG_STICK; } - override public function getID(rawID:Int):FlxGamepadInputID + override function getID(rawID:MFiID):FlxGamepadInputID { return switch (rawID) { @@ -42,7 +43,7 @@ class MFiMapping extends FlxGamepadMapping } } - override public function getRawID(ID:FlxGamepadInputID):Int + override function getRawID(ID:FlxGamepadInputID):MFiID { return switch (ID) { @@ -75,12 +76,17 @@ class MFiMapping extends FlxGamepadMapping case LEFT_TRIGGER_FAKE: MFiID.LEFT_TRIGGER; case RIGHT_TRIGGER_FAKE: MFiID.RIGHT_TRIGGER; #end - default: -1; + default: super.getRawID(ID); } } + override function getMappedInput(id:FlxGamepadInputID) + { + return FlxGamepadMappedInput.MFI(getRawID(id)); + } + #if FLX_JOYSTICK_API - override public function axisIndexToRawID(axisID:Int):Int + override function axisIndexToRawID(axisID:MFiID):Int { // the axis index values for this don't overlap with anything so we can just return the original values! return axisID; diff --git a/flixel/input/gamepad/mappings/MayflashWiiRemoteMapping.hx b/flixel/input/gamepad/mappings/MayflashWiiRemoteMapping.hx index ac7dc77cdd..bbe3b1f194 100644 --- a/flixel/input/gamepad/mappings/MayflashWiiRemoteMapping.hx +++ b/flixel/input/gamepad/mappings/MayflashWiiRemoteMapping.hx @@ -3,8 +3,9 @@ package flixel.input.gamepad.mappings; import flixel.input.gamepad.FlxGamepad.FlxGamepadAttachment; import flixel.input.gamepad.FlxGamepadInputID; import flixel.input.gamepad.id.MayflashWiiRemoteID; +import flixel.input.gamepad.mappings.FlxGamepadMapping; -class MayflashWiiRemoteMapping extends FlxGamepadMapping +class MayflashWiiRemoteMapping extends FlxTypedGamepadMapping { #if FLX_JOYSTICK_API static inline var REMOTE_DPAD_X:Int = 16; @@ -22,7 +23,7 @@ class MayflashWiiRemoteMapping extends FlxGamepadMapping supportsPointer = true; } - override public function getID(rawID:Int):FlxGamepadInputID + override function getID(rawID:MayflashWiiRemoteID):FlxGamepadInputID { return switch (attachment) { @@ -32,7 +33,7 @@ class MayflashWiiRemoteMapping extends FlxGamepadMapping } } - function getIDClassicController(rawID:Int):FlxGamepadInputID + function getIDClassicController(rawID:MayflashWiiRemoteID):FlxGamepadInputID { return switch (rawID) { @@ -63,7 +64,7 @@ class MayflashWiiRemoteMapping extends FlxGamepadMapping } } - function getIDNunchuk(rawID:Int):FlxGamepadInputID + function getIDNunchuk(rawID:MayflashWiiRemoteID):FlxGamepadInputID { return switch (rawID) { @@ -80,16 +81,15 @@ class MayflashWiiRemoteMapping extends FlxGamepadMapping case MayflashWiiRemoteID.NUNCHUK_DPAD_DOWN: DPAD_DOWN; case MayflashWiiRemoteID.NUNCHUK_DPAD_LEFT: DPAD_LEFT; case MayflashWiiRemoteID.NUNCHUK_DPAD_RIGHT: DPAD_RIGHT; - default: - if (rawID == MayflashWiiRemoteID.LEFT_ANALOG_STICK.rawUp) LEFT_STICK_DIGITAL_UP; - if (rawID == MayflashWiiRemoteID.LEFT_ANALOG_STICK.rawDown) LEFT_STICK_DIGITAL_DOWN; - if (rawID == MayflashWiiRemoteID.LEFT_ANALOG_STICK.rawLeft) LEFT_STICK_DIGITAL_LEFT; - if (rawID == MayflashWiiRemoteID.LEFT_ANALOG_STICK.rawRight) LEFT_STICK_DIGITAL_RIGHT; - NONE; + case id if (id == MayflashWiiRemoteID.LEFT_ANALOG_STICK.rawUp): LEFT_STICK_DIGITAL_UP; + case id if (id == MayflashWiiRemoteID.LEFT_ANALOG_STICK.rawDown): LEFT_STICK_DIGITAL_DOWN; + case id if (id == MayflashWiiRemoteID.LEFT_ANALOG_STICK.rawLeft): LEFT_STICK_DIGITAL_LEFT; + case id if (id == MayflashWiiRemoteID.LEFT_ANALOG_STICK.rawRight): LEFT_STICK_DIGITAL_RIGHT; + default: NONE; } } - function getIDDefault(rawID:Int):FlxGamepadInputID + function getIDDefault(rawID:MayflashWiiRemoteID):FlxGamepadInputID { return switch (rawID) { @@ -108,7 +108,7 @@ class MayflashWiiRemoteMapping extends FlxGamepadMapping } } - override public function getRawID(ID:FlxGamepadInputID):Int + override function getRawID(ID:FlxGamepadInputID):MayflashWiiRemoteID { return switch (attachment) { @@ -118,7 +118,7 @@ class MayflashWiiRemoteMapping extends FlxGamepadMapping } } - function getRawClassicController(ID:FlxGamepadInputID):Int + function getRawClassicController(ID:FlxGamepadInputID):MayflashWiiRemoteID { return switch (ID) { @@ -151,7 +151,7 @@ class MayflashWiiRemoteMapping extends FlxGamepadMapping } } - function getRawNunchuk(ID:FlxGamepadInputID):Int + function getRawNunchuk(ID:FlxGamepadInputID):MayflashWiiRemoteID { return switch (ID) { @@ -174,11 +174,11 @@ class MayflashWiiRemoteMapping extends FlxGamepadMapping case LEFT_STICK_DIGITAL_DOWN: MayflashWiiRemoteID.LEFT_ANALOG_STICK.rawDown; case LEFT_STICK_DIGITAL_LEFT: MayflashWiiRemoteID.LEFT_ANALOG_STICK.rawLeft; case LEFT_STICK_DIGITAL_RIGHT: MayflashWiiRemoteID.LEFT_ANALOG_STICK.rawRight; - default: -1; + default: super.getRawID(ID); } } - function getRawDefault(ID:FlxGamepadInputID):Int + function getRawDefault(ID:FlxGamepadInputID):MayflashWiiRemoteID { return switch (ID) { @@ -193,12 +193,12 @@ class MayflashWiiRemoteMapping extends FlxGamepadMapping case BACK: MayflashWiiRemoteID.REMOTE_MINUS; case GUIDE: MayflashWiiRemoteID.REMOTE_HOME; case START: MayflashWiiRemoteID.REMOTE_PLUS; - default: -1; + default: super.getRawID(ID); } } #if FLX_JOYSTICK_API - override public function axisIndexToRawID(axisID:Int):Int + override function axisIndexToRawID(axisID:MayflashWiiRemoteID):Int { if (attachment == WII_NUNCHUCK || attachment == WII_CLASSIC_CONTROLLER) { @@ -223,7 +223,7 @@ class MayflashWiiRemoteMapping extends FlxGamepadMapping return axisID; } - override public function checkForFakeAxis(ID:FlxGamepadInputID):Int + override function checkForFakeAxis(ID:FlxGamepadInputID):Int { if (attachment == WII_NUNCHUCK) { @@ -258,6 +258,11 @@ class MayflashWiiRemoteMapping extends FlxGamepadMapping return super.set_attachment(attachment); } + override function getMappedInput(id:FlxGamepadInputID) + { + return FlxGamepadMappedInput.MAYFLASH_WII(getRawID(id)); + } + override function getInputLabel(id:FlxGamepadInputID) { var label = WiiRemoteMapping.getWiiInputLabel(id, attachment); diff --git a/flixel/input/gamepad/mappings/OUYAMapping.hx b/flixel/input/gamepad/mappings/OUYAMapping.hx index 372ba6a3f4..8af15095e3 100644 --- a/flixel/input/gamepad/mappings/OUYAMapping.hx +++ b/flixel/input/gamepad/mappings/OUYAMapping.hx @@ -2,8 +2,9 @@ package flixel.input.gamepad.mappings; import flixel.input.gamepad.FlxGamepadInputID; import flixel.input.gamepad.id.OUYAID; +import flixel.input.gamepad.mappings.FlxGamepadMapping; -class OUYAMapping extends FlxGamepadMapping +class OUYAMapping extends FlxTypedGamepadMapping { #if FLX_JOYSTICK_API static inline var LEFT_ANALOG_STICK_FAKE_X:Int = 19; @@ -19,7 +20,7 @@ class OUYAMapping extends FlxGamepadMapping rightStick = OUYAID.RIGHT_ANALOG_STICK; } - override public function getID(rawID:Int):FlxGamepadInputID + override function getID(rawID:OUYAID):FlxGamepadInputID { return switch (rawID) { @@ -50,7 +51,7 @@ class OUYAMapping extends FlxGamepadMapping } } - override public function getRawID(ID:FlxGamepadInputID):Int + override function getRawID(ID:FlxGamepadInputID):OUYAID { return switch (ID) { @@ -77,7 +78,7 @@ class OUYAMapping extends FlxGamepadMapping case RIGHT_STICK_DIGITAL_DOWN: OUYAID.RIGHT_ANALOG_STICK.rawDown; case RIGHT_STICK_DIGITAL_LEFT: OUYAID.RIGHT_ANALOG_STICK.rawLeft; case RIGHT_STICK_DIGITAL_RIGHT: OUYAID.RIGHT_ANALOG_STICK.rawRight; - default: -1; + default: super.getRawID(ID); } } @@ -93,9 +94,14 @@ class OUYAMapping extends FlxGamepadMapping case _: super.getInputLabel(id); } } - + + override function getMappedInput(id:FlxGamepadInputID) + { + return FlxGamepadMappedInput.OUYA(getRawID(id)); + } + #if FLX_JOYSTICK_API - override public function axisIndexToRawID(axisID:Int):Int + override function axisIndexToRawID(axisID:OUYAID):Int { return if (axisID == leftStick.x) LEFT_ANALOG_STICK_FAKE_X; else if (axisID == leftStick.y) LEFT_ANALOG_STICK_FAKE_Y; else if (axisID == rightStick.x) RIGHT_ANALOG_STICK_FAKE_X; diff --git a/flixel/input/gamepad/mappings/PS4Mapping.hx b/flixel/input/gamepad/mappings/PS4Mapping.hx index f636298f73..6d62b24d29 100644 --- a/flixel/input/gamepad/mappings/PS4Mapping.hx +++ b/flixel/input/gamepad/mappings/PS4Mapping.hx @@ -2,8 +2,9 @@ package flixel.input.gamepad.mappings; import flixel.input.gamepad.FlxGamepadInputID; import flixel.input.gamepad.id.PS4ID; +import flixel.input.gamepad.mappings.FlxGamepadMapping; -class PS4Mapping extends FlxGamepadMapping +class PS4Mapping extends FlxTypedGamepadMapping { #if FLX_JOYSTICK_API static inline var LEFT_ANALOG_STICK_FAKE_X:Int = 21; @@ -24,7 +25,7 @@ class PS4Mapping extends FlxGamepadMapping supportsPointer = true; } - override public function getID(rawID:Int):FlxGamepadInputID + override function getID(rawID:PS4ID):FlxGamepadInputID { return switch (rawID) { @@ -59,7 +60,7 @@ class PS4Mapping extends FlxGamepadMapping } } - override public function getRawID(ID:FlxGamepadInputID):Int + override function getRawID(ID:FlxGamepadInputID):PS4ID { return switch (ID) { @@ -96,7 +97,7 @@ class PS4Mapping extends FlxGamepadMapping case LEFT_TRIGGER_FAKE: LEFT_TRIGGER_FAKE; case RIGHT_TRIGGER_FAKE: RIGHT_TRIGGER_FAKE; #end - default: -1; + default: super.getRawID(ID); } } @@ -119,8 +120,13 @@ class PS4Mapping extends FlxGamepadMapping } } + override function getMappedInput(id:FlxGamepadInputID) + { + return FlxGamepadMappedInput.PS4(getRawID(id)); + } + #if FLX_JOYSTICK_API - override public function axisIndexToRawID(axisID:Int):Int + override function axisIndexToRawID(axisID:PS4ID):Int { // Analog stick and trigger values overlap with regular buttons so we remap to "fake" button ID's return if (axisID == leftStick.x) LEFT_ANALOG_STICK_FAKE_X; else if (axisID == leftStick.y) LEFT_ANALOG_STICK_FAKE_Y; else if (axisID == rightStick.x) diff --git a/flixel/input/gamepad/mappings/PSVitaMapping.hx b/flixel/input/gamepad/mappings/PSVitaMapping.hx index 8c19c80124..9099d9e01b 100644 --- a/flixel/input/gamepad/mappings/PSVitaMapping.hx +++ b/flixel/input/gamepad/mappings/PSVitaMapping.hx @@ -2,8 +2,9 @@ package flixel.input.gamepad.mappings; import flixel.input.gamepad.FlxGamepadInputID; import flixel.input.gamepad.id.PSVitaID; +import flixel.input.gamepad.mappings.FlxGamepadMapping; -class PSVitaMapping extends FlxGamepadMapping +class PSVitaMapping extends FlxTypedGamepadMapping { override function initValues():Void { @@ -11,7 +12,7 @@ class PSVitaMapping extends FlxGamepadMapping rightStick = PSVitaID.RIGHT_ANALOG_STICK; } - override public function getID(rawID:Int):FlxGamepadInputID + override function getID(rawID:PSVitaID):FlxGamepadInputID { return switch (rawID) { @@ -39,7 +40,7 @@ class PSVitaMapping extends FlxGamepadMapping } } - override public function getRawID(ID:FlxGamepadInputID):Int + override function getRawID(ID:FlxGamepadInputID):PSVitaID { return switch (ID) { @@ -63,7 +64,7 @@ class PSVitaMapping extends FlxGamepadMapping case RIGHT_STICK_DIGITAL_DOWN: PSVitaID.RIGHT_ANALOG_STICK.rawDown; case RIGHT_STICK_DIGITAL_LEFT: PSVitaID.RIGHT_ANALOG_STICK.rawLeft; case RIGHT_STICK_DIGITAL_RIGHT: PSVitaID.RIGHT_ANALOG_STICK.rawRight; - default: -1; + default: super.getRawID(ID); } } @@ -83,8 +84,13 @@ class PSVitaMapping extends FlxGamepadMapping case _: super.getInputLabel(id); } } - - override public function isAxisFlipped(axisID:Int):Bool + + override function getMappedInput(id:FlxGamepadInputID) + { + return FlxGamepadMappedInput.PS_VITA(getRawID(id)); + } + + override function isAxisFlipped(axisID:Int):Bool { return axisID == PSVitaID.LEFT_ANALOG_STICK.y || axisID == PSVitaID.RIGHT_ANALOG_STICK.y; } diff --git a/flixel/input/gamepad/mappings/SwitchJoyconLeftMapping.hx b/flixel/input/gamepad/mappings/SwitchJoyconLeftMapping.hx index 07c16e52e3..ac18224acf 100644 --- a/flixel/input/gamepad/mappings/SwitchJoyconLeftMapping.hx +++ b/flixel/input/gamepad/mappings/SwitchJoyconLeftMapping.hx @@ -2,11 +2,12 @@ package flixel.input.gamepad.mappings; import flixel.input.gamepad.FlxGamepadInputID; import flixel.input.gamepad.id.SwitchJoyconLeftID; +import flixel.input.gamepad.mappings.FlxGamepadMapping; /** * @since 4.8.0 */ -class SwitchJoyconLeftMapping extends FlxGamepadMapping +class SwitchJoyconLeftMapping extends FlxTypedGamepadMapping { #if FLX_JOYSTICK_API static inline var LEFT_ANALOG_STICK_FAKE_X:Int = 32; @@ -24,9 +25,10 @@ class SwitchJoyconLeftMapping extends FlxGamepadMapping leftStick = SwitchJoyconLeftID.LEFT_ANALOG_STICK; supportsMotion = true; supportsPointer = false; + bottomIsAccept = false; } - override public function getID(rawID:Int):FlxGamepadInputID + override function getID(rawID:SwitchJoyconLeftID):FlxGamepadInputID { return switch (rawID) { @@ -48,7 +50,7 @@ class SwitchJoyconLeftMapping extends FlxGamepadMapping } } - override public function getRawID(id:FlxGamepadInputID):Int + override function getRawID(id:FlxGamepadInputID):SwitchJoyconLeftID { return switch (id) { @@ -70,7 +72,7 @@ class SwitchJoyconLeftMapping extends FlxGamepadMapping case LEFT_TRIGGER_FAKE: LEFT_TRIGGER_FAKE; case RIGHT_TRIGGER_FAKE: RIGHT_TRIGGER_FAKE; #end - default: -1; + default: super.getRawID(id); } } @@ -91,8 +93,13 @@ class SwitchJoyconLeftMapping extends FlxGamepadMapping } } + override function getMappedInput(id:FlxGamepadInputID) + { + return FlxGamepadMappedInput.SWITCH_JOYCON_LEFT(getRawID(id)); + } + #if FLX_JOYSTICK_API - override public function axisIndexToRawID(axisID:Int):Int + override function axisIndexToRawID(axisID:SwitchJoyconLeftID):Int { // Analog stick and trigger values overlap with regular buttons so we remap to "fake" button ID's return if (axisID == leftStick.x) diff --git a/flixel/input/gamepad/mappings/SwitchJoyconRightMapping.hx b/flixel/input/gamepad/mappings/SwitchJoyconRightMapping.hx index 6a7bdc51a6..983b0df955 100644 --- a/flixel/input/gamepad/mappings/SwitchJoyconRightMapping.hx +++ b/flixel/input/gamepad/mappings/SwitchJoyconRightMapping.hx @@ -2,11 +2,12 @@ package flixel.input.gamepad.mappings; import flixel.input.gamepad.FlxGamepadInputID; import flixel.input.gamepad.id.SwitchJoyconRightID; +import flixel.input.gamepad.mappings.FlxGamepadMapping; /** * @since 4.8.0 */ -class SwitchJoyconRightMapping extends FlxGamepadMapping +class SwitchJoyconRightMapping extends FlxTypedGamepadMapping { #if FLX_JOYSTICK_API static inline var LEFT_ANALOG_STICK_FAKE_X:Int = 32; @@ -24,9 +25,10 @@ class SwitchJoyconRightMapping extends FlxGamepadMapping leftStick = SwitchJoyconRightID.LEFT_ANALOG_STICK; supportsMotion = true; supportsPointer = false; + bottomIsAccept = false; } - override public function getID(rawID:Int):FlxGamepadInputID + override function getID(rawID:SwitchJoyconRightID):FlxGamepadInputID { return switch (rawID) { @@ -49,7 +51,7 @@ class SwitchJoyconRightMapping extends FlxGamepadMapping } } - override public function getRawID(ID:FlxGamepadInputID):Int + override function getRawID(ID:FlxGamepadInputID):SwitchJoyconRightID { return switch (ID) { @@ -72,7 +74,7 @@ class SwitchJoyconRightMapping extends FlxGamepadMapping case LEFT_TRIGGER_FAKE: LEFT_TRIGGER_FAKE; case RIGHT_TRIGGER_FAKE: RIGHT_TRIGGER_FAKE; #end - default: -1; + default: super.getRawID(ID); } } @@ -94,8 +96,13 @@ class SwitchJoyconRightMapping extends FlxGamepadMapping } } + override function getMappedInput(id:FlxGamepadInputID) + { + return FlxGamepadMappedInput.SWITCH_JOYCON_RIGHT(getRawID(id)); + } + #if FLX_JOYSTICK_API - override public function axisIndexToRawID(axisID:Int):Int + override function axisIndexToRawID(axisID:SwitchJoyconRightID):Int { // Analog stick and trigger values overlap with regular buttons so we remap to "fake" button ID's return if (axisID == leftStick.x) diff --git a/flixel/input/gamepad/mappings/SwitchProMapping.hx b/flixel/input/gamepad/mappings/SwitchProMapping.hx index 190e879090..3b948887c8 100644 --- a/flixel/input/gamepad/mappings/SwitchProMapping.hx +++ b/flixel/input/gamepad/mappings/SwitchProMapping.hx @@ -2,11 +2,12 @@ package flixel.input.gamepad.mappings; import flixel.input.gamepad.FlxGamepadInputID; import flixel.input.gamepad.id.SwitchProID; +import flixel.input.gamepad.mappings.FlxGamepadMapping; /** * @since 4.8.0 */ -class SwitchProMapping extends FlxGamepadMapping +class SwitchProMapping extends FlxTypedGamepadMapping { #if FLX_JOYSTICK_API static inline var LEFT_ANALOG_STICK_FAKE_X:Int = 32; @@ -25,9 +26,10 @@ class SwitchProMapping extends FlxGamepadMapping rightStick = SwitchProID.RIGHT_ANALOG_STICK; supportsMotion = true; supportsPointer = false; + bottomIsAccept = false; } - override public function getID(rawID:Int):FlxGamepadInputID + override function getID(rawID:SwitchProID):FlxGamepadInputID { return switch (rawID) { @@ -61,7 +63,7 @@ class SwitchProMapping extends FlxGamepadMapping } } - override public function getRawID(ID:FlxGamepadInputID):Int + override function getRawID(ID:FlxGamepadInputID):SwitchProID { return switch (ID) { @@ -95,7 +97,7 @@ class SwitchProMapping extends FlxGamepadMapping case LEFT_TRIGGER_FAKE: LEFT_TRIGGER_FAKE; case RIGHT_TRIGGER_FAKE: RIGHT_TRIGGER_FAKE; #end - default: -1; + default: super.getRawID(ID); } } @@ -119,8 +121,13 @@ class SwitchProMapping extends FlxGamepadMapping } } + override function getMappedInput(id:FlxGamepadInputID) + { + return FlxGamepadMappedInput.SWITCH_PRO(getRawID(id)); + } + #if FLX_JOYSTICK_API - override public function axisIndexToRawID(axisID:Int):Int + override function axisIndexToRawID(axisID:SwitchProID):Int { // Analog stick and trigger values overlap with regular buttons so we remap to "fake" button ID's return if (axisID == leftStick.x) diff --git a/flixel/input/gamepad/mappings/WiiRemoteMapping.hx b/flixel/input/gamepad/mappings/WiiRemoteMapping.hx index 4b7c2f04e5..72ddb896c8 100644 --- a/flixel/input/gamepad/mappings/WiiRemoteMapping.hx +++ b/flixel/input/gamepad/mappings/WiiRemoteMapping.hx @@ -3,8 +3,9 @@ package flixel.input.gamepad.mappings; import flixel.input.gamepad.FlxGamepad.FlxGamepadAttachment; import flixel.input.gamepad.FlxGamepadInputID; import flixel.input.gamepad.id.WiiRemoteID; +import flixel.input.gamepad.mappings.FlxGamepadMapping; -class WiiRemoteMapping extends FlxGamepadMapping +class WiiRemoteMapping extends FlxTypedGamepadMapping { #if FLX_JOYSTICK_API static inline var LEFT_ANALOG_STICK_FAKE_X:Int = 20; @@ -20,7 +21,7 @@ class WiiRemoteMapping extends FlxGamepadMapping supportsPointer = false; } - override public function getID(rawID:Int):FlxGamepadInputID + override function getID(rawID:WiiRemoteID):FlxGamepadInputID { return switch (attachment) { @@ -30,7 +31,7 @@ class WiiRemoteMapping extends FlxGamepadMapping } } - function getIDClassicController(rawID:Int):FlxGamepadInputID + function getIDClassicController(rawID:WiiRemoteID):FlxGamepadInputID { return switch (rawID) { @@ -63,7 +64,7 @@ class WiiRemoteMapping extends FlxGamepadMapping } } - function getIDNunchuk(rawID:Int):FlxGamepadInputID + function getIDNunchuk(rawID:WiiRemoteID):FlxGamepadInputID { return switch (rawID) { @@ -80,16 +81,15 @@ class WiiRemoteMapping extends FlxGamepadMapping case WiiRemoteID.NUNCHUK_DPAD_DOWN: DPAD_DOWN; case WiiRemoteID.NUNCHUK_DPAD_LEFT: DPAD_LEFT; case WiiRemoteID.NUNCHUK_DPAD_RIGHT: DPAD_RIGHT; - default: - if (rawID == WiiRemoteID.LEFT_ANALOG_STICK.rawUp) LEFT_STICK_DIGITAL_UP; - if (rawID == WiiRemoteID.LEFT_ANALOG_STICK.rawDown) LEFT_STICK_DIGITAL_DOWN; - if (rawID == WiiRemoteID.LEFT_ANALOG_STICK.rawLeft) LEFT_STICK_DIGITAL_LEFT; - if (rawID == WiiRemoteID.LEFT_ANALOG_STICK.rawRight) LEFT_STICK_DIGITAL_RIGHT; - NONE; + case id if (id == WiiRemoteID.LEFT_ANALOG_STICK.rawUp): LEFT_STICK_DIGITAL_UP; + case id if (id == WiiRemoteID.LEFT_ANALOG_STICK.rawDown): LEFT_STICK_DIGITAL_DOWN; + case id if (id == WiiRemoteID.LEFT_ANALOG_STICK.rawLeft): LEFT_STICK_DIGITAL_LEFT; + case id if (id == WiiRemoteID.LEFT_ANALOG_STICK.rawRight): LEFT_STICK_DIGITAL_RIGHT; + default: super.getID(rawID); } } - function getIDDefault(rawID:Int):FlxGamepadInputID + function getIDDefault(rawID:WiiRemoteID):FlxGamepadInputID { return switch (rawID) { @@ -108,7 +108,7 @@ class WiiRemoteMapping extends FlxGamepadMapping } } - override public function getRawID(ID:FlxGamepadInputID):Int + override function getRawID(ID:FlxGamepadInputID):WiiRemoteID { return switch (attachment) { @@ -118,7 +118,7 @@ class WiiRemoteMapping extends FlxGamepadMapping } } - function getRawClassicController(ID:FlxGamepadInputID):Int + function getRawClassicController(ID:FlxGamepadInputID):WiiRemoteID { return switch (ID) { @@ -147,11 +147,11 @@ class WiiRemoteMapping extends FlxGamepadMapping case RIGHT_STICK_DIGITAL_DOWN: WiiRemoteID.RIGHT_ANALOG_STICK.rawDown; case RIGHT_STICK_DIGITAL_LEFT: WiiRemoteID.RIGHT_ANALOG_STICK.rawLeft; case RIGHT_STICK_DIGITAL_RIGHT: WiiRemoteID.RIGHT_ANALOG_STICK.rawRight; - default: -1; + default: super.getRawID(ID); } } - function getRawNunchuk(ID:FlxGamepadInputID):Int + function getRawNunchuk(ID:FlxGamepadInputID):WiiRemoteID { return switch (ID) { @@ -174,11 +174,11 @@ class WiiRemoteMapping extends FlxGamepadMapping case LEFT_STICK_DIGITAL_DOWN: WiiRemoteID.LEFT_ANALOG_STICK.rawDown; case LEFT_STICK_DIGITAL_LEFT: WiiRemoteID.LEFT_ANALOG_STICK.rawLeft; case LEFT_STICK_DIGITAL_RIGHT: WiiRemoteID.LEFT_ANALOG_STICK.rawRight; - default: -1; + default: super.getRawID(ID); } } - function getRawDefault(ID:FlxGamepadInputID):Int + function getRawDefault(ID:FlxGamepadInputID):WiiRemoteID { return switch (ID) { @@ -195,11 +195,11 @@ class WiiRemoteMapping extends FlxGamepadMapping case START: WiiRemoteID.REMOTE_PLUS; case TILT_PITCH: WiiRemoteID.REMOTE_TILT_PITCH; case TILT_ROLL: WiiRemoteID.REMOTE_TILT_ROLL; - default: -1; + default: super.getRawID(ID); } } - override public function isAxisForMotion(ID:FlxGamepadInputID):Bool + override function isAxisForMotion(ID:WiiRemoteID):Bool { if (attachment == NONE) { @@ -214,14 +214,14 @@ class WiiRemoteMapping extends FlxGamepadMapping return false; } - override public function isAxisFlipped(axisID:Int):Bool + override function isAxisFlipped(axisID:WiiRemoteID):Bool { return axisID == WiiRemoteID.LEFT_TRIGGER_FAKE; } #if FLX_JOYSTICK_API // Analog stick and trigger values overlap with regular buttons so we remap to "fake" button ID's - override public function axisIndexToRawID(axisID:Int):Int + override function axisIndexToRawID(axisID:WiiRemoteID):Int { // return null for this unused access so it doesn't overlap a button input if (attachment == NONE && axisID == WiiRemoteID.REMOTE_NULL_AXIS) @@ -253,7 +253,7 @@ class WiiRemoteMapping extends FlxGamepadMapping return axisID; } - override public function checkForFakeAxis(ID:FlxGamepadInputID):Int + override function checkForFakeAxis(ID:FlxGamepadInputID):WiiRemoteID { if (attachment == WII_NUNCHUCK && ID == FlxGamepadInputID.LEFT_TRIGGER) return WiiRemoteID.NUNCHUK_Z; @@ -348,4 +348,9 @@ class WiiRemoteMapping extends FlxGamepadMapping default: null; } } + + override function getMappedInput(id:FlxGamepadInputID) + { + return FlxGamepadMappedInput.WII(getRawID(id)); + } } diff --git a/flixel/input/gamepad/mappings/XInputMapping.hx b/flixel/input/gamepad/mappings/XInputMapping.hx index 4073dbe79b..bfbd560c5c 100644 --- a/flixel/input/gamepad/mappings/XInputMapping.hx +++ b/flixel/input/gamepad/mappings/XInputMapping.hx @@ -2,8 +2,9 @@ package flixel.input.gamepad.mappings; import flixel.input.gamepad.FlxGamepadInputID; import flixel.input.gamepad.id.XInputID; +import flixel.input.gamepad.mappings.FlxGamepadMapping; -class XInputMapping extends FlxGamepadMapping +class XInputMapping extends FlxTypedGamepadMapping { #if FLX_JOYSTICK_API static inline var LEFT_ANALOG_STICK_FAKE_X:Int = 15; @@ -22,7 +23,7 @@ class XInputMapping extends FlxGamepadMapping rightStick = XInputID.RIGHT_ANALOG_STICK; } - override public function getID(rawID:Int):FlxGamepadInputID + override function getID(rawID:XInputID):FlxGamepadInputID { return switch (rawID) { @@ -60,7 +61,7 @@ class XInputMapping extends FlxGamepadMapping } } - override public function getRawID(ID:FlxGamepadInputID):Int + override function getRawID(ID:FlxGamepadInputID):XInputID { return switch (ID) { @@ -93,12 +94,12 @@ class XInputMapping extends FlxGamepadMapping case RIGHT_STICK_DIGITAL_DOWN: XInputID.RIGHT_ANALOG_STICK.rawDown; case RIGHT_STICK_DIGITAL_LEFT: XInputID.RIGHT_ANALOG_STICK.rawLeft; case RIGHT_STICK_DIGITAL_RIGHT: XInputID.RIGHT_ANALOG_STICK.rawRight; - default: -1; + default: super.getRawID(ID); } } #if flash - override public function isAxisFlipped(axisID:Int):Bool + override function isAxisFlipped(axisID:XInputID):Bool { if (manufacturer == GooglePepper) return false; @@ -108,14 +109,19 @@ class XInputMapping extends FlxGamepadMapping #end #if xbox1 - override public function isAxisFlipped(axisID:Int):Bool + override function isAxisFlipped(axisID:XInputID):Bool { return axisID == XInputID.LEFT_ANALOG_STICK.y || axisID == XInputID.RIGHT_ANALOG_STICK.y; } #end + override function getMappedInput(id:FlxGamepadInputID) + { + return FlxGamepadMappedInput.X_INPUT(getRawID(id)); + } + #if FLX_JOYSTICK_API - override public function axisIndexToRawID(axisID:Int):Int + override function axisIndexToRawID(axisID:XInputID):Int { // Analog stick and trigger values overlap with regular buttons so we remap to "fake" button ID's return if (axisID == leftStick.x) LEFT_ANALOG_STICK_FAKE_X; else if (axisID == leftStick.y) LEFT_ANALOG_STICK_FAKE_Y; else if (axisID == rightStick.x) diff --git a/flixel/input/mouse/FlxMouse.hx b/flixel/input/mouse/FlxMouse.hx index 65f1c984b4..9b191291fb 100644 --- a/flixel/input/mouse/FlxMouse.hx +++ b/flixel/input/mouse/FlxMouse.hx @@ -285,7 +285,7 @@ class FlxMouse extends FlxPointer implements IFlxInputManager } else if ((Graphic is String)) { - cursor = new Bitmap(FlxAssets.getBitmapData(Graphic)); + cursor = new Bitmap(FlxG.assets.getBitmapData(Graphic, false)); } else { diff --git a/flixel/sound/FlxSound.hx b/flixel/sound/FlxSound.hx index 950c389e88..e087968790 100644 --- a/flixel/sound/FlxSound.hx +++ b/flixel/sound/FlxSound.hx @@ -7,7 +7,6 @@ import flixel.math.FlxPoint; import flixel.system.FlxAssets.FlxSoundAsset; import flixel.tweens.FlxTween; import flixel.util.FlxStringUtil; -import openfl.Assets; import openfl.events.Event; import openfl.events.IEventDispatcher; import openfl.media.Sound; @@ -17,9 +16,6 @@ import openfl.net.URLRequest; #if flash11 import openfl.utils.ByteArray; #end -#if (openfl >= "8.0.0") -import openfl.utils.AssetType; -#end /** * This is the universal flixel sound object, used for streaming, music, and sound effects. @@ -365,8 +361,8 @@ class FlxSound extends FlxBasic } else if ((EmbeddedSound is String)) { - if (Assets.exists(EmbeddedSound, AssetType.SOUND) || Assets.exists(EmbeddedSound, AssetType.MUSIC)) - _sound = Assets.getSound(EmbeddedSound); + if (FlxG.assets.exists(EmbeddedSound, SOUND)) + _sound = FlxG.assets.getSoundUnsafe(EmbeddedSound); else FlxG.log.error('Could not find a Sound asset with an ID of \'$EmbeddedSound\'.'); } diff --git a/flixel/system/FlxAssets.hx b/flixel/system/FlxAssets.hx index 7b3e75f341..c6915bc94f 100644 --- a/flixel/system/FlxAssets.hx +++ b/flixel/system/FlxAssets.hx @@ -2,9 +2,6 @@ package flixel.system; import haxe.macro.Expr; #if !macro -import openfl.display.BitmapData; -import openfl.display.Graphics; -import openfl.media.Sound; import flixel.FlxG; import flixel.graphics.FlxGraphic; import flixel.graphics.atlas.AseAtlas; @@ -12,6 +9,7 @@ import flixel.graphics.atlas.TexturePackerAtlas; import flixel.graphics.frames.FlxAtlasFrames; import flixel.graphics.frames.FlxFrame; import flixel.graphics.frames.FlxFramesCollection; +import flixel.system.frontEnds.AssetFrontEnd; import flixel.graphics.frames.bmfont.BMFont; import flixel.util.typeLimit.OneOfFour; import flixel.util.typeLimit.OneOfThree; @@ -19,7 +17,9 @@ import flixel.util.typeLimit.OneOfTwo; import haxe.io.Bytes; import haxe.Json; import haxe.xml.Access; -import openfl.Assets; +import openfl.display.BitmapData; +import openfl.display.Graphics; +import openfl.media.Sound; import openfl.utils.ByteArray; using StringTools; @@ -60,7 +60,7 @@ abstract FlxXmlAsset(OneOfTwo) from Xml from String if ((this is String)) { final str:String = cast this; - if (Assets.exists(str)) + if (FlxG.assets.exists(str)) return fromPath(str); return fromXmlString(str); @@ -71,12 +71,12 @@ abstract FlxXmlAsset(OneOfTwo) from Xml from String static inline function fromPath(path:String):Xml { - return fromXmlString(Assets.getText(path)); + return FlxG.assets.getXmlUnsafe(path); } static inline function fromXmlString(data:String):Xml { - return Xml.parse(data); + return FlxG.assets.parseXml(data); } } @@ -87,7 +87,7 @@ abstract FlxJsonAsset(OneOfTwo) from T from String if ((this is String)) { final str:String = cast this; - if (Assets.exists(str)) + if (FlxG.assets.exists(str)) return fromPath(str); return fromDataString(str); @@ -98,12 +98,12 @@ abstract FlxJsonAsset(OneOfTwo) from T from String static inline function fromPath(path:String):T { - return fromDataString(Assets.getText(path)); + return cast FlxG.assets.getJsonUnsafe(path); } static inline function fromDataString(data:String):T { - return cast Json.parse(data); + return cast FlxG.assets.parseJson(data); } } @@ -266,20 +266,22 @@ class FlxAssets graph.lineTo(100, 100); graph.endFill(); } - + + /** + * Gets an instance of a bitmap, logs when the asset is not found. + * @param id The ID or asset path for the bitmap + * @return A new BitmapData object + **/ public static inline function getBitmapData(id:String):BitmapData { - if (Assets.exists(id)) - return Assets.getBitmapData(id, true); - FlxG.log.error('Could not find a BitmapData asset with ID \'$id\'.'); - return null; + return FlxG.assets.getBitmapData(id); } /** * Generates BitmapData from specified class. Less typing. * - * @param source BitmapData class to generate BitmapData object from. - * @return Newly instantiated BitmapData object. + * @param source BitmapData class to generate BitmapData object from. + * @return Newly instantiated BitmapData object. */ public static inline function getBitmapFromClass(source:Class):BitmapData { @@ -293,22 +295,22 @@ class FlxAssets * 3) if the input is String, then it will get BitmapData from openfl.Assets; * 4) it will return null in any other case. * - * @param Graphic input data to get BitmapData object for. - * @return BitmapData for specified Dynamic object. + * @param graphic input data to get BitmapData object for. + * @return BitmapData for specified Dynamic object. */ - public static function resolveBitmapData(Graphic:FlxGraphicSource):BitmapData + public static function resolveBitmapData(graphic:FlxGraphicSource):BitmapData { - if ((Graphic is BitmapData)) + if ((graphic is BitmapData)) { - return cast Graphic; + return cast graphic; } - else if ((Graphic is Class)) + else if ((graphic is Class)) { - return FlxAssets.getBitmapFromClass(cast Graphic); + return getBitmapFromClass(cast graphic); } - else if ((Graphic is String)) + else if ((graphic is String)) { - return FlxAssets.getBitmapData(Graphic); + return FlxG.assets.getBitmapData(graphic); } return null; @@ -321,30 +323,28 @@ class FlxAssets * 3) if the input is String, then it will return it; * 4) it will return null in any other case. * - * @param Graphic input data to get string key for. - * @param Key optional key string. - * @return Key String for specified Graphic object. + * @param graphic input data to get string key for. + * @param key optional key string. + * @return Key String for specified Graphic object. */ - public static function resolveKey(Graphic:FlxGraphicSource, ?Key:String):String + public static function resolveKey(graphic:FlxGraphicSource, ?key:String):String { - if (Key != null) - { - return Key; - } - - if ((Graphic is BitmapData)) + if (key != null) + return key; + + if ((graphic is BitmapData)) { - return Key; + return key; } - else if ((Graphic is Class)) + else if ((graphic is Class)) { - return FlxG.bitmap.getKeyForClass(cast Graphic); + return FlxG.bitmap.getKeyForClass(cast graphic); } - else if ((Graphic is String)) + else if ((graphic is String)) { - return Graphic; + return graphic; } - + return null; } @@ -355,12 +355,27 @@ class FlxAssets * @param id The asset id of the local sound file. * @return The sound file. */ - public static function getSound(id:String):Sound + @:deprecated("FlxAssets.getSound is deprecated, use getSoundAddExtension, instead") + public static inline function getSound(id:String):Sound + { + return getSoundAddExtension(id); + } + + /** + * Loads an OpenFL sound asset from the given asset id. If an extension not provided the + * `defaultSoundExtension` is used (defaults to "ogg" on non-flash targets). + * + * @param id The asset id of the local sound file. + * @return The sound file. + * + * @since 5.9.0 + */ + public static function getSoundAddExtension(id:String, useCache = true):Sound { if (!id.endsWith(".mp3") && !id.endsWith(".ogg") && !id.endsWith(".wav")) id += "." + defaultSoundExtension; - return Assets.getSound(id); + return FlxG.assets.getSoundUnsafe(id, useCache); } public static function getVirtualInputFrames():FlxAtlasFrames diff --git a/flixel/system/FlxSplash.hx b/flixel/system/FlxSplash.hx index 3becdcc3fb..10092194a4 100644 --- a/flixel/system/FlxSplash.hx +++ b/flixel/system/FlxSplash.hx @@ -87,7 +87,7 @@ class FlxSplash extends FlxState #if FLX_SOUND_SYSTEM if (!muted) { - FlxG.sound.load(FlxAssets.getSound("flixel/sounds/flixel")).play(); + FlxG.sound.load(FlxAssets.getSoundAddExtension("flixel/sounds/flixel")).play(); } #end } diff --git a/flixel/system/debug/console/Console.hx b/flixel/system/debug/console/Console.hx index 638e543b84..f179566d5d 100644 --- a/flixel/system/debug/console/Console.hx +++ b/flixel/system/debug/console/Console.hx @@ -218,6 +218,24 @@ class Console extends Window if (!history.isEmpty) setText(history.getPreviousCommand()); + #if (html5 && FLX_KEYBOARD) + // FlxKeyboard.preventDefaultKeys adds "preventDefault" on HTML5 + // so it ends up not fully propegating our inputs to the stage/event listeners + // we do this small work around so we don't need to mess around with lime/openfl events + // todo: support the modifier keys + case Keyboard.RIGHT: + if (FlxG.keys.preventDefaultKeys.contains(Keyboard.RIGHT)) + { + @:privateAccess + input.window_onKeyDown(RIGHT, 0); + } + case Keyboard.LEFT: + if (FlxG.keys.preventDefaultKeys.contains(Keyboard.LEFT)) + { + @:privateAccess + input.window_onKeyDown(LEFT, 0); + } + #end case Keyboard.DOWN: if (!history.isEmpty) setText(history.getNextCommand()); diff --git a/flixel/system/debug/console/ConsoleUtil.hx b/flixel/system/debug/console/ConsoleUtil.hx index d52d5241ad..ae78b304ff 100644 --- a/flixel/system/debug/console/ConsoleUtil.hx +++ b/flixel/system/debug/console/ConsoleUtil.hx @@ -120,7 +120,7 @@ class ConsoleUtil else if (Reflect.isObject(Object)) // get instance fields fields = Type.getInstanceFields(Type.getClass(Object)); - // on Flash, enums are classes, so Std.is(_, Enum) fails + // on Flash, enums are classes, so Std.isOfType(_, Enum) fails fields.remove("__constructs__"); var filteredFields = []; diff --git a/flixel/system/debug/stats/Stats.hx b/flixel/system/debug/stats/Stats.hx index 02f971be20..a60de0f0bc 100644 --- a/flixel/system/debug/stats/Stats.hx +++ b/flixel/system/debug/stats/Stats.hx @@ -333,7 +333,7 @@ class Stats extends Window */ public inline function currentMem():Float { - return (System.totalMemory / 1024) / 1000; + return (#if (openfl >= "9.4.0") System.totalMemoryNumber #else System.totalMemory #end / 1024) / 1000; } /** diff --git a/flixel/system/debug/watch/Watch.hx b/flixel/system/debug/watch/Watch.hx index ff50592790..a2a0811095 100644 --- a/flixel/system/debug/watch/Watch.hx +++ b/flixel/system/debug/watch/Watch.hx @@ -30,7 +30,7 @@ class Watch extends Window entriesContainer.y = entriesContainerOffset.y; addChild(entriesContainer); - FlxG.signals.preStateSwitch.add(removeAll); + FlxG.signals.preStateSwitch.add(clear); } public function add(displayName:String, data:WatchEntryData):Void @@ -87,7 +87,7 @@ class Watch extends Window var entry = new WatchEntry(displayName, data, removeEntry); entries.push(entry); entriesContainer.addChild(entry); - resetEntries(); + updateSize(); } public function remove(displayName:String, data:WatchEntryData):Void @@ -102,19 +102,27 @@ class Watch extends Window entries.fastSplice(entry); entriesContainer.removeChild(entry); entry.destroy(); - resetEntries(); + updateSize(); } - public function removeAll():Void + /** + * internal method to remove all without calling updateSize + */ + function clear():Void { - for (i in 0...entries.length) + for (entry in entries) { - var entry = entries[i]; entriesContainer.removeChild(entry); entry.destroy(); } - entries.splice(0, entries.length); - resetEntries(); + + entries.resize(0); + } + + public function removeAll():Void + { + clear(); + updateSize(); } override public function update():Void @@ -125,9 +133,10 @@ class Watch extends Window override function updateSize():Void { + resetEntries(); minSize.setTo(getMaxMinWidth() + entriesContainerOffset.x, entriesContainer.height + entriesContainerOffset.y); super.updateSize(); - resetEntries(); + reposition(x, y); } function resetEntries():Void diff --git a/flixel/system/frontEnds/AssetFrontEnd.hx b/flixel/system/frontEnds/AssetFrontEnd.hx new file mode 100644 index 0000000000..382d27762a --- /dev/null +++ b/flixel/system/frontEnds/AssetFrontEnd.hx @@ -0,0 +1,640 @@ +package flixel.system.frontEnds; + +import flixel.FlxG; +import flixel.system.FlxAssets; +import flixel.system.debug.log.LogStyle; +import haxe.io.Bytes; +import haxe.io.Path; +import haxe.Json; +import haxe.xml.Access; +import openfl.display.BitmapData; +import openfl.media.Sound; +import openfl.utils.Assets; +import openfl.utils.AssetType; +import openfl.utils.AssetCache; +import openfl.utils.Future; +import openfl.text.Font; + +using StringTools; + +/** + * Accessed via `FlxG.assets`. The main interface for the asset system. By default, OpenFl's + * Asset system is used, which uses relative path strings to retrive assets, though you can completely + * avoid Openfl's asset system by setting custom methods to the following dynamic fields: `getAssetUnsafe`, + * `loadAsset`, `exists`, `isLocal` and `list`. + * + * ## Common Uses + * The initial reason for making customizable asset system + * was to allow for "hot-reloading", or testing new assets in your game without recompiling, with + * each change. Say, if you would like a debug feature where you load assets from source assets, + * rather than the assets copied over to your export folder, you could overwrite this system to do + * just that. + * + * Other potential uses for this are modding, bypassing the manifest and loading resources from + * a remote location. + * + * ### Quick Setup for "Hot-Reloading" + * To simplify the process mentioned above, the `FLX_CUSTOM_ASSETS_DIRECTORY` flag was created. + * By adding `-DFLX_CUSTOM_ASSETS_DIRECTORY="../../../assets"` to your lime build command + * it will automatically grab assets from your project root's assets folder rather than, the + * default "export/hl/bin/assets". This will only work with a single asset root folder with one + * asset library and will use the openfl asset system if the asset id starts with "flixel/" or + * tries to references a specific library using the format: "libName:asset/path/file.ext". + * + * @since 5.9.0 + */ +class AssetFrontEnd +{ + #if FLX_CUSTOM_ASSETS_DIRECTORY + /** + * The target directory + */ + final directory:String; + + /** + * The parent of the target directory, is prepended to any `id` passed in + */ + final parentDirectory:String; + + public function new () + { + final rawPath = '${haxe.macro.Compiler.getDefine("FLX_CUSTOM_ASSETS_DIRECTORY")}'; + // Remove final slash and accepts backslashes and removes redundancies + directory = Path.normalize(rawPath); + // Verify valid directory + if (sys.FileSystem.exists(directory) == false) + throw 'Invalid value:"$directory" of FLX_CUSTOM_ASSETS_DIRECTORY, expecting relative or absolute path'; + // remove final "/assets" since the id typically contains it + final split = sys.FileSystem.absolutePath(directory).split("/"); + split.pop(); + parentDirectory = split.join("/"); + } + + function getPath(id:String) + { + return Path.normalize('$parentDirectory/$id'); + } + + /** + * True for assets packaged with all HaxeFlixel build, and any non-default libraries + */ + function useOpenflAssets(id:String) + { + return id.startsWith("flixel/") || id.contains(':'); + } + #else + public function new () {} + #end + + /** + * Used by methods like `getAsset`, `getBitmapData`, `getText`, their "unsafe" counterparts and + * the like to get assets synchronously. Can be set to a custom function to avoid the existing + * asset system. Unlike its "safe" counterpart, there is no log on missing assets + * + * @param id The id of the asset, usually a path + * @param type The type of asset to look for, determines the type + * @param useCache Whether to allow use of the asset cache (if one exists) + * @return The asset, if found, otherwise `null` is returned + */ + public dynamic function getAssetUnsafe(id:String, type:FlxAssetType, useCache = true):Null + { + #if FLX_STANDARD_ASSETS_DIRECTORY + return getOpenflAssetUnsafe(id, type, useCache); + #else + + if (useOpenflAssets(id)) + return getOpenflAssetUnsafe(id, type, useCache); + // load from custom assets directory + final canUseCache = useCache && Assets.cache.enabled; + + final asset:Any = switch type + { + // No caching + case TEXT: + sys.io.File.getContent(getPath(id)); + case BINARY: + sys.io.File.getBytes(getPath(id)); + + // Check cache + case IMAGE if (canUseCache && Assets.cache.hasBitmapData(id)): + Assets.cache.getBitmapData(id); + case SOUND if (canUseCache && Assets.cache.hasSound(id)): + Assets.cache.getSound(id); + case FONT if (canUseCache && Assets.cache.hasFont(id)): + Assets.cache.getFont(id); + + // Get asset and set cache + case IMAGE: + final bitmap = BitmapData.fromFile(getPath(id)); + if (canUseCache) + Assets.cache.setBitmapData(id, bitmap); + bitmap; + case SOUND: + final sound = Sound.fromFile(getPath(id)); + if (canUseCache) + Assets.cache.setSound(id, sound); + sound; + case FONT: + final font = Font.fromFile(getPath(id)); + if (canUseCache) + Assets.cache.setFont(id, font); + font; + } + + return asset; + #end + } + + function getOpenflAssetUnsafe(id:String, type:FlxAssetType, useCache = true):Null + { + // Use openfl assets + return switch(type) + { + case TEXT: Assets.getText(id); + case BINARY: Assets.getBytes(id); + case IMAGE: Assets.getBitmapData(id, useCache); + case SOUND: Assets.getSound(id, useCache); + case FONT: Assets.getFont(id, useCache); + } + } + + /** + * Calls `getAssetUnsafe` if the asset exists, otherwise logs that the asset is missing, via `FlxG.log` + * + * @param id The id of the asset, usually a path + * @param type The type of asset to look for, determines the type + * @param useCache Whether to allow use of the asset cache (if one exists) + * @param logStyle How to log, if the asset is not found. Uses `LogStyle.ERROR` by default + */ + public function getAsset(id:String, type:FlxAssetType, useCache = true, ?logStyle:LogStyle):Null + { + inline function log(message:String) + { + if (logStyle == null) + logStyle = LogStyle.ERROR; + FlxG.log.advanced(message, logStyle); + } + + if (exists(id, type)) + { + if (isLocal(id, type)) + return getAssetUnsafe(id, type, useCache); + + log('$type asset "$id" exists, but only asynchronously'); + return null; + } + + log('Could not find a $type asset with ID \'$id\'.'); + return null; + } + + /** + * Used by methods like `loadBitmapData`, `loadText` and the like to get assets asynchronously. + * Can be set to a custom function to avoid the existing asset system. + * + * @param id The id of the asset, usually a path + * @param type The type of asset to look for, determines the type + * @param useCache Whether to allow use of the asset cache (if one exists) + */ + public dynamic function loadAsset(id:String, type:FlxAssetType, useCache = true):Future + { + #if FLX_STANDARD_ASSETS_DIRECTORY + return loadOpenflAsset(id, type, useCache); + #else + + if (useOpenflAssets(id)) + return loadOpenflAsset(id, type, useCache); + + // get the asset synchronously and wrap it in a future + return Future.withValue(getAsset(id, type, useCache)); + // TODO: html? + #end + } + + function loadOpenflAsset(id:String, type:FlxAssetType, useCache = true):Future + { + return switch(type) + { + case TEXT: Assets.loadText(id); + case BINARY: Assets.loadBytes(id); + case IMAGE: Assets.loadBitmapData(id, useCache); + case SOUND: Assets.loadSound(id, useCache); + case FONT: Assets.loadFont(id, useCache); + } + } + + /** + * Whether a specific asset ID and type exists. + * Can be set to a custom function to avoid the existing asset system. + * + * @param id The ID or asset path for the asset + * @param type The asset type to match, or null to match any type + */ + public dynamic function exists(id:String, ?type:FlxAssetType) + { + #if FLX_STANDARD_ASSETS_DIRECTORY + return Assets.exists(id, type.toOpenFlType()); + #else + if (useOpenflAssets(id)) + return Assets.exists(id, type.toOpenFlType()); + // Can't verify contents match expected type without + return sys.FileSystem.exists(getPath(id)); + #end + } + + /** + * Returns whether an asset is "local", and therefore can be loaded synchronously, or with the + * `getAsset` method, otherwise the `loadAsset` method should be used. + * Can be set to a custom function to avoid the existing asset system. + * + * @param id The ID or asset path for the asset + * @param type The asset type to match, or null to match any type + * @param useCache Whether to allow use of the asset cache (if one exists) + * @return Whether the asset is local + */ + public dynamic function isLocal(id:String, ?type:FlxAssetType, useCache = true) + { + #if FLX_STANDARD_ASSETS_DIRECTORY + return Assets.isLocal(id, type.toOpenFlType(), useCache); + #else + + if (useOpenflAssets(id)) + Assets.isLocal(id, type.toOpenFlType(), useCache); + + return true; + #end + } + + /** + * Returns a list of all assets (by type). + * Can be set to a custom function to avoid the existing asset system. + * + * @param type The asset type to match, or null to match any type + * @return An array of asset ID values + */ + public dynamic function list(?type:FlxAssetType) + { + #if FLX_STANDARD_ASSETS_DIRECTORY + return Assets.list(type.toOpenFlType()); + #else + // list all files in the directory, recursively + final list = []; + function addFiles(directory:String, prefix = "") + { + for (path in sys.FileSystem.readDirectory(directory)) + { + if (sys.FileSystem.isDirectory('$directory/$path')) + addFiles('$directory/$path',path + '/'); + else + list.push(prefix + path); + } + } + final prefix = Path.withoutDirectory(directory) + "/"; + addFiles(directory, prefix); + return list; + #end + } + + /** + * Gets an instance of a bitmap. Unlike its "safe" counterpart, there is no log on missing assets + * + * @param id The ID or asset path for the bitmap + * @param useCache Whether to allow use of the asset cache (if one exists) + * @return A new BitmapData object + */ + public inline function getBitmapDataUnsafe(id:String, useCache = false):BitmapData + { + return cast getAssetUnsafe(id, IMAGE, useCache); + } + + /** + * Gets an instance of a bitmap, logs when the asset is not found + * + * @param id The ID or asset path for the bitmap + * @param useCache Whether to allow use of the asset cache (if one exists) + * @return A new BitmapData object + */ + public inline function getBitmapData(id:String, useCache = false, ?logStyle:LogStyle):BitmapData + { + return cast getAsset(id, IMAGE, useCache, logStyle); + } + + /** + * Gets an instance of a sound. Unlike its "safe" counterpart, there is no log on missing assets + * + * @param id The ID or asset path for the sound + * @param useCache Whether to allow use of the asset cache (if one exists) + * @return A new `Sound` object Note: Dos not return a `FlxSound` + */ + public inline function getSoundUnsafe(id:String, useCache = true):Sound + { + return cast getAssetUnsafe(id, SOUND, useCache); + } + + /** + * Gets an instance of a sound, logs when the asset is not found + * + * @param id The ID or asset path for the sound + * @param useCache Whether to allow use of the asset cache (if one exists) + * @param logStyle How to log, if the asset is not found. Uses `LogStyle.ERROR` by default + * @return A new `Sound` object Note: Dos not return a `FlxSound` + */ + public inline function getSound(id:String, useCache = true, ?logStyle:LogStyle):Sound + { + return cast getAsset(id, SOUND, useCache, logStyle); + } + + /** + * Gets the contents of a text-based asset. Unlike its "safe" counterpart, there is no log + * on missing assets + * + * **Note:** The default asset system does not cache text assets + * + * @param id The ID or asset path for the asset + * @param useCache Whether to allow use of the asset cache (if one exists) + */ + public inline function getTextUnsafe(id:String, useCache = true):String + { + return cast getAssetUnsafe(id, TEXT, useCache); + } + + /** + * Gets the contents of a text-based asset, logs when the asset is not found + * + * **Note:** The default asset system does not cache text assets + * + * @param id The ID or asset path for the asset + * @param useCache Whether to allow use of the asset cache (if one exists) + * @param logStyle How to log, if the asset is not found. Uses `LogStyle.ERROR` by default + */ + public inline function getText(id:String, useCache = true, ?logStyle:LogStyle):String + { + return cast getAsset(id, TEXT, useCache, logStyle); + } + + /** + * Parses the contents of an xml-based asset into an `Xml` object. + * Unlike its "safe" counterpart, there is no log on missing assets + * + * **Note:** The default asset system does not cache xml assets + * + * @param id The ID or asset path for the asset + * @param useCache Whether to allow use of the asset cache (if one exists) + */ + public inline function getXmlUnsafe(id:String, useCache = true) + { + final text = getTextUnsafe(id, useCache); + return text != null ? parseXml(text) : null; + } + + /** + * Parses the contents of an xml-based asset into an `Xml` object, logs when the asset is not found + * + * **Note:** The default asset system does not cache xml assets + * + * @param id The ID or asset path for the asset + * @param useCache Whether to allow use of the asset cache (if one exists) + * @param logStyle How to log, if the asset is not found. Uses `LogStyle.ERROR` by default + */ + public inline function getXml(id:String, useCache = true, ?logStyle:LogStyle) + { + final text = getText(id, useCache, logStyle); + return text != null ? parseXml(text) : null; + } + + /** + * Gets the contents of a json-based asset. + * Unlike its "safe" counterpart, there is no log on missing assets + * + * **Note:** The default asset system does not cache json assets + * + * @param id The ID or asset path for the asset + * @param useCache Whether to allow use of the asset cache (if one exists) + */ + public inline function getJsonUnsafe(id:String, useCache = true) + { + final text = getTextUnsafe(id, useCache); + return text != null ? parseJson(text) : null; + } + + /** + * Gets the contents of a json-based asset, logs when the asset is not found + * + * **Note:** The default asset system does not cache json assets + * + * @param id The ID or asset path for the asset + * @param useCache Whether to allow use of the asset cache (if one exists) + * @param logStyle How to log, if the asset is not found. Uses `LogStyle.ERROR` by default + */ + public inline function getJson(id:String, useCache = true, ?logStyle:LogStyle) + { + final text = getText(id, useCache, logStyle); + return text != null ? parseJson(text) : null; + } + + /** + * Gets the contents of a binary asset. + * Unlike its "safe" counterpart, there is no log on missing assets + * + * **Note:** The default asset system does not cache binary assets + * + * @param id The ID or asset path for the asset + * @param useCache Whether to allow use of the asset cache (if one exists) + */ + public inline function getBytesUnsafe(id:String, useCache = true):Bytes + { + return cast getAssetUnsafe(id, BINARY, useCache); + } + + /** + * Gets the contents of a binary asset, logs when the asset is not found + * + * **Note:** The default asset system does not cache binary assets + * + * @param id The ID or asset path for the asset + * @param useCache Whether to allow use of the asset cache (if one exists) + * @param logStyle How to log, if the asset is not found. Uses `LogStyle.ERROR` by default + */ + public inline function getBytes(id:String, useCache = true, ?logStyle:LogStyle):Bytes + { + return cast getAsset(id, BINARY, useCache); + } + + /** + * Gets the contents of a font asset. + * Unlike its "safe" counterpart, there is no log on missing assets + * + * @param id The ID or asset path for the asset + * @param useCache Whether to allow use of the asset cache + */ + public inline function getFontUnsafe(id:String, useCache = true):Font + { + return cast getAssetUnsafe(id, FONT, useCache); + } + + /** + * Gets the contents of a font asset, logs when the asset is not found + * + * @param id The ID or asset path for the asset + * @param useCache Whether to allow use of the asset cache (if one exists) + * @param logStyle How to log, if the asset is not found. Uses `LogStyle.ERROR` by default + */ + public inline function getFont(id:String, useCache = true, ?logStyle:LogStyle):Font + { + return cast getAsset(id, FONT, useCache, logStyle); + } + + /** + * Loads a bitmap asset asynchronously + * + * @param id The ID or asset path for the asset + * @param useCache Whether to allow use of the asset cache (if one exists) + * @return Returns a `Future` which allows listeners to be added via methods like `onComplete` + */ + public inline function loadBitmapData(id:String, useCache = false):Future + { + return cast loadAsset(id, IMAGE, useCache); + } + + /** + * Loads a sound asset asynchronously + * + * @param id The ID or asset path for the asset + * @param useCache Whether to allow use of the asset cache (if one exists) + * @return Returns a `Future` which allows listeners to be added via methods like `onComplete` + */ + public inline function loadSound(id:String, useCache = true):Future + { + return cast loadAsset(id, SOUND, useCache); + } + + /** + * Loads a text asset asynchronously + * + * **Note:** The default asset system does not cache text assets + * + * @param id The ID or asset path for the asset + * @param useCache Whether to allow use of the asset cache (if one exists) + * @return Returns a `Future` which allows listeners to be added via methods like `onComplete` + */ + public inline function loadText(id:String, useCache = true):Future + { + return cast loadAsset(id, TEXT, useCache); + } + + /** + * Loads an xml asset asynchronously + * + * **Note:** The default asset system does not cache xml assets + * + * @param id The ID or asset path for the asset + * @param useCache Whether to allow use of the asset cache (if one exists) + * @return Returns a `Future` which allows listeners to be added via methods like `onComplete` + */ + public inline function loadXml(id:String, useCache = true):Future + { + return wrapFuture(loadText(id, useCache), parseXml); + } + + /** + * Loads a json asset asynchronously + * + * **Note:** The default asset system does not cache json assets + * + * @param id The ID or asset path for the asset + * @param useCache Whether to allow use of the asset cache (if one exists) + * @return Returns a `Future` which allows listeners to be added via methods like `onComplete` + */ + public inline function loadJson(id:String, useCache = true):Future + { + return wrapFuture(loadText(id, useCache), parseJson); + } + + /** + * Loads a binary asset asynchronously + * + * **Note:** The default asset system does not cache binary assets + * + * @param id The ID or asset path for the asset + * @param useCache Whether to allow use of the asset cache (if one exists) + * @return Returns a `Future` which allows listeners to be added via methods like `onComplete` + */ + public inline function loadBytes(id:String, useCache = true):Future + { + return cast loadAsset(id, BINARY, useCache); + } + + /** + * Loads a font asset asynchronously + * + * @param id The ID or asset path for the asset + * @param useCache Whether to allow use of the asset cache (if one exists) + * @return Returns a `Future` which allows listeners to be added via methods like `onComplete` + */ + public inline function loadFont(id:String, useCache = true):Future + { + return cast loadAsset(id, FONT, useCache); + } + + /** + * Parses a json string, creates and returns a struct + */ + public inline function parseJson(jsonText:String) + { + return Json.parse(jsonText); + } + + /** + * Parses an xml string, creates and returns an `Xml` object + */ + public inline function parseXml(xmlText:String) + { + return Xml.parse(xmlText); + } + + inline function wrapFuture(future:Future, converter:(T1)->T2):Future + { + final promise = new lime.app.Promise(); + + future.onComplete((data)->promise.complete(converter(data))); + future.onError((error)->promise.error(error)); + future.onProgress((progress, total)->promise.progress(progress, total)); + + return promise.future; + } +} + +/** + * The AssetType enum lists the core set of available + * asset types from the OpenFL command-line tools. + * @since 5.9.0 + */ +enum abstract FlxAssetType(String) +{ + /** Binary assets (data that is not readable as text) */ + var BINARY = "binary"; + + /** Font assets, such as *.ttf or *.otf files */ + var FONT = "font"; + + /** Image assets, such as *.png or *.jpg files */ + var IMAGE ="image"; + + /** Audio assets, such as *.ogg or *.wav files */ + var SOUND = "sound"; + + /** Text assets */ + var TEXT = "text"; + + public function toOpenFlType() + { + return switch((cast this:FlxAssetType)) + { + case BINARY: AssetType.BINARY; + case FONT: AssetType.FONT; + case IMAGE: AssetType.IMAGE; + case SOUND: AssetType.SOUND; + case TEXT: AssetType.TEXT; + } + } +} diff --git a/flixel/system/frontEnds/BitmapFrontEnd.hx b/flixel/system/frontEnds/BitmapFrontEnd.hx index a60557099e..4076756083 100644 --- a/flixel/system/frontEnds/BitmapFrontEnd.hx +++ b/flixel/system/frontEnds/BitmapFrontEnd.hx @@ -5,10 +5,10 @@ import flixel.graphics.FlxGraphic; import flixel.graphics.frames.FlxFrame; import flixel.math.FlxPoint; import flixel.math.FlxRect; -import flixel.system.FlxAssets.FlxGraphicAsset; +import flixel.system.FlxAssets; import flixel.util.FlxColor; import openfl.Assets; -#if !flash +#if FLX_OPENGL_AVAILABLE import lime.graphics.opengl.GL; #end @@ -19,9 +19,13 @@ import lime.graphics.opengl.GL; */ class BitmapFrontEnd { - #if !flash + #if FLX_OPENGL_AVAILABLE /** - * Gets max texture size for native targets + * Returns the maximum allowed width and height (in pixels) for a texture. + * This value is only available on hardware-accelerated targets that use OpenGL. + * On unsupported targets, the returned value will always be -1. + * + * @see https://opengl.gpuinfo.org/displaycapability.php?name=GL_MAX_TEXTURE_SIZE */ public var maxTextureSize(get, never):Int; #end @@ -212,7 +216,7 @@ class BitmapFrontEnd /** * Creates string key for further caching. * - * @param systemKey The first string key to use as a base for a new key. It's usually a key from openfl.Assets ("assets/image.png"). + * @param systemKey The first string key to use as a base for a new key. It's usually an asset key ("assets/image.png"). * @param userKey The second string key to use as a base for a new key. It's usually a key provided by the user * @param unique Whether generated key should be unique or not. * @return Created key. @@ -391,10 +395,13 @@ class BitmapFrontEnd } } - #if !flash + #if FLX_OPENGL_AVAILABLE function get_maxTextureSize():Int { - return cast GL.getParameter(GL.MAX_TEXTURE_SIZE); + if (FlxG.stage.window.context.attributes.hardware) + return cast GL.getParameter(GL.MAX_TEXTURE_SIZE); + + return -1; } #end diff --git a/flixel/system/frontEnds/CameraFrontEnd.hx b/flixel/system/frontEnds/CameraFrontEnd.hx index a343747f49..21b2c07831 100644 --- a/flixel/system/frontEnds/CameraFrontEnd.hx +++ b/flixel/system/frontEnds/CameraFrontEnd.hx @@ -74,6 +74,42 @@ class CameraFrontEnd cameraAdded.dispatch(NewCamera); return NewCamera; } + + /** + * Inserts a new camera object to the game. + * + * - If `position` is negative, `list.length + position` is used + * - If `position` exceeds `list.length`, the camera is added to the end. + * + * @param newCamera The camera you want to add. + * @param position The position in the list where you want to insert the camera + * @param defaultDrawTarget Whether to add the camera to the list of default draw targets. If false, + * `FlxBasics` will not render to it unless you add it to their `cameras` list. + * @return This FlxCamera instance. + */ + public function insert(newCamera:T, position:Int, defaultDrawTarget = true):T + { + // negative numbers are relative to the length (match Array.insert's behavior) + if (position < 0) + position += list.length; + + // invalid ranges are added (match Array.insert's behavior) + if (position >= list.length) + return add(newCamera); + + final childIndex = FlxG.game.getChildIndex(list[position].flashSprite); + FlxG.game.addChildAt(newCamera.flashSprite, childIndex); + + list.insert(position, newCamera); + if (defaultDrawTarget) + defaults.push(newCamera); + + for (i in position...list.length) + list[i].ID = i; + + cameraAdded.dispatch(newCamera); + return newCamera; + } /** * Remove a camera from the game. diff --git a/flixel/system/frontEnds/LogFrontEnd.hx b/flixel/system/frontEnds/LogFrontEnd.hx index b355c7ceb3..a93f27df74 100644 --- a/flixel/system/frontEnds/LogFrontEnd.hx +++ b/flixel/system/frontEnds/LogFrontEnd.hx @@ -64,7 +64,7 @@ class LogFrontEnd #if (FLX_SOUND_SYSTEM && !FLX_UNIT_TEST) if (style.errorSound != null) { - final sound = FlxAssets.getSound(style.errorSound); + final sound = FlxAssets.getSoundAddExtension(style.errorSound); if (sound != null) FlxG.sound.load(sound).play(); } diff --git a/flixel/system/frontEnds/SoundFrontEnd.hx b/flixel/system/frontEnds/SoundFrontEnd.hx index 9784d759bb..3a40e9ddc5 100644 --- a/flixel/system/frontEnds/SoundFrontEnd.hx +++ b/flixel/system/frontEnds/SoundFrontEnd.hx @@ -11,11 +11,7 @@ import flixel.system.FlxAssets; import flixel.system.ui.FlxSoundTray; import flixel.text.FlxInputText; import flixel.util.FlxSignal; -import openfl.Assets; import openfl.media.Sound; -#if (openfl >= "8.0.0") -import openfl.utils.AssetType; -#end /** * Accessed via `FlxG.sound`. @@ -213,8 +209,8 @@ class SoundFrontEnd public inline function cache(embeddedSound:String):Sound { // load the sound into the OpenFL assets cache - if (Assets.exists(embeddedSound, AssetType.SOUND) || Assets.exists(embeddedSound, AssetType.MUSIC)) - return Assets.getSound(embeddedSound, true); + if (FlxG.assets.exists(embeddedSound, SOUND)) + return FlxG.assets.getSoundUnsafe(embeddedSound, true); FlxG.log.error('Could not find a Sound asset with an ID of \'$embeddedSound\'.'); return null; } @@ -225,7 +221,7 @@ class SoundFrontEnd */ public function cacheAll():Void { - for (id in Assets.list(AssetType.SOUND)) + for (id in FlxG.assets.list(SOUND)) { cache(id); } diff --git a/flixel/system/macros/FlxDefines.hx b/flixel/system/macros/FlxDefines.hx index 8dd13e2fe4..882bb6aaf5 100644 --- a/flixel/system/macros/FlxDefines.hx +++ b/flixel/system/macros/FlxDefines.hx @@ -3,6 +3,7 @@ package flixel.system.macros; import haxe.macro.Compiler; import haxe.macro.Context; import haxe.macro.Expr.Position; +import haxe.io.Path; #if (flixel_addons >= "3.2.2") import flixel.addons.system.macros.FlxAddonDefines; #end @@ -43,6 +44,14 @@ private enum UserDefines FLX_TRACK_POOLS; /** Adds `creationInfo` to FlxGraphic instances, automatically defined with FLX_DEBUG */ FLX_TRACK_GRAPHICS; + /** + * Loads from the specified relative or absolute directory. Unlike other boolean flags, + * this flag should contain a string value. + * + * **Note:** When using assets entirely from outside the build directory, it is wise to disable + * any `` tags in your project.xml, to reduce your total memory + */ + FLX_CUSTOM_ASSETS_DIRECTORY; } /** @@ -86,6 +95,9 @@ private enum HelperDefines FLX_HEALTH; FLX_NO_TRACK_POOLS; FLX_NO_TRACK_GRAPHICS; + FLX_OPENGL_AVAILABLE; + /** Defined to `1`(or `true`) if `FLX_CUSTOM_ASSETS_DIRECTORY` is not defined */ + FLX_STANDARD_ASSETS_DIRECTORY; } class FlxDefines @@ -251,8 +263,36 @@ class FlxDefines if (defined(FLX_DEBUG)) define(FLX_TRACK_GRAPHICS); + + #if (lime_opengl || lime_opengles || lime_webgl) + // FlxG.stage.window.context.attributes.hardware is not always defined during unit tests + if (defined(FLX_NO_UNIT_TEST)) + define(FLX_OPENGL_AVAILABLE); + #end defineInversion(FLX_TRACK_GRAPHICS, FLX_NO_TRACK_GRAPHICS); + + if (defined(FLX_CUSTOM_ASSETS_DIRECTORY)) + { + if (!defined("sys")) + { + abort('FLX_CUSTOM_ASSETS_DIRECTORY is only available on sys targets', (macro null).pos); + } + else + { + // Todo: check sys targets + final rawDirectory = Path.normalize(definedValue(FLX_CUSTOM_ASSETS_DIRECTORY)); + final directory = Path.normalize(rawDirectory); + if (!sys.FileSystem.isDirectory(directory) || directory == "1") + { + final absPath = sys.FileSystem.absolutePath(directory); + abort('FLX_CUSTOM_ASSETS_DIRECTORY must be a path to a directory, got "$rawDirectory"' + + '\nabsolute path: $absPath', (macro null).pos); + } + } + } + else // define boolean inversion + define(FLX_STANDARD_ASSETS_DIRECTORY); } static function defineInversion(userDefine:UserDefines, invertedDefine:HelperDefines) @@ -280,6 +320,11 @@ class FlxDefines abort(errorMessage, (macro null).pos); } + static inline function definedValue(define:Dynamic):String + { + return Context.definedValue(Std.string(define)); + } + static inline function defined(define:Dynamic) { return Context.defined(Std.string(define)); diff --git a/flixel/system/ui/FlxSoundTray.hx b/flixel/system/ui/FlxSoundTray.hx index a5492bca4d..e04212ad84 100644 --- a/flixel/system/ui/FlxSoundTray.hx +++ b/flixel/system/ui/FlxSoundTray.hx @@ -148,7 +148,7 @@ class FlxSoundTray extends Sprite { if (!silent) { - var sound = FlxAssets.getSound(up ? volumeUpSound : volumeDownSound); + var sound = FlxAssets.getSoundAddExtension(up ? volumeUpSound : volumeDownSound); if (sound != null) FlxG.sound.load(sound).play(); } diff --git a/flixel/text/FlxInputText.hx b/flixel/text/FlxInputText.hx index cdea3319fc..0c24efe218 100644 --- a/flixel/text/FlxInputText.hx +++ b/flixel/text/FlxInputText.hx @@ -507,8 +507,8 @@ class FlxInputText extends FlxText implements IFlxInputText override function applyFormats(formatAdjusted:TextFormat, useBorderColor:Bool = false):Void { - // scroll variables will be reset when `textField.setTextFormat()` is called, - // cache the current ones first + // Scroll variables will be reset when `textField.setTextFormat()` is called, + // cache the current ones first. var cacheScrollH = scrollH; var cacheScrollV = scrollV; @@ -517,9 +517,15 @@ class FlxInputText extends FlxText implements IFlxInputText if (!useBorderColor && useSelectedTextFormat && selectionEndIndex > selectionBeginIndex) textField.setTextFormat(_selectionFormat, selectionBeginIndex, selectionEndIndex); - // set the scroll back to how it was - scrollH = cacheScrollH; - scrollV = cacheScrollV; + // Set the scroll back to how it was. + // This changes the internal text field's scroll instead to make sure that + // `__updateLayout()` gets called even if the scroll hasn't changed. + // If it doesn't get called here, it will be called when the text field + // is being drawn to this sprite's graphic, which will reset the scroll + // to the current selection, effectively making scrolling with the mouse + // wheel not work. + textField.scrollH = cacheScrollH; + textField.scrollV = cacheScrollV; } override function regenGraphic():Void @@ -609,7 +615,7 @@ class FlxInputText extends FlxText implements IFlxInputText * Clips the sprite inside the bounds of the text field, taking * `clipRect` into account. */ - function clipSprite(sprite:FlxSprite) + function clipSprite(sprite:FlxSprite, border:Bool = false) { if (sprite == null) return; @@ -619,7 +625,8 @@ class FlxInputText extends FlxText implements IFlxInputText rect = FlxRect.get(); rect.set(0, 0, sprite.width, sprite.height); - var bounds = FlxRect.get(0, 0, width, height); + var bounds = border ? FlxRect.get(-fieldBorderThickness, -fieldBorderThickness, width + (fieldBorderThickness * 2), + height + (fieldBorderThickness * 2)) : FlxRect.get(0, 0, width, height); if (clipRect != null) { bounds = bounds.clipTo(clipRect); @@ -1195,7 +1202,7 @@ class FlxInputText extends FlxText implements IFlxInputText _fieldBorderSprite.setPosition(x - fieldBorderThickness, y - fieldBorderThickness); _backgroundSprite.setPosition(x, y); - clipSprite(_fieldBorderSprite); + clipSprite(_fieldBorderSprite, true); clipSprite(_backgroundSprite); } @@ -1741,7 +1748,7 @@ class FlxInputText extends FlxText implements IFlxInputText super.set_clipRect(value); clipSprite(_backgroundSprite); - clipSprite(_fieldBorderSprite); + clipSprite(_fieldBorderSprite, true); clipSprite(_caret); for (box in _selectionBoxes) clipSprite(box); diff --git a/flixel/text/FlxText.hx b/flixel/text/FlxText.hx index 3378887100..f7228b9ce1 100644 --- a/flixel/text/FlxText.hx +++ b/flixel/text/FlxText.hx @@ -26,9 +26,6 @@ using flixel.util.FlxStringUtil; #if flash import openfl.geom.Rectangle; #end -#if (openfl >= "8.0.0") -import openfl.utils.AssetType; -#end // TODO: think about filters and text @@ -693,9 +690,9 @@ class FlxText extends FlxSprite if (Font != null) { var newFontName:String = Font; - if (Assets.exists(Font, AssetType.FONT)) + if (FlxG.assets.exists(Font, FONT)) { - newFontName = Assets.getFont(Font).fontName; + newFontName = FlxG.assets.getFontUnsafe(Font).fontName; } _defaultFormat.font = newFontName; diff --git a/flixel/tile/FlxBaseTilemap.hx b/flixel/tile/FlxBaseTilemap.hx index 178d5c0060..ce637a0e5c 100644 --- a/flixel/tile/FlxBaseTilemap.hx +++ b/flixel/tile/FlxBaseTilemap.hx @@ -11,7 +11,6 @@ import flixel.util.FlxCollision; import flixel.util.FlxColor; import flixel.util.FlxDirectionFlags; import flixel.util.FlxStringUtil; -import openfl.Assets; import openfl.display.BitmapData; using StringTools; @@ -390,9 +389,9 @@ class FlxBaseTilemap extends FlxObject startingIndex = 0, drawIndex = 1, collideIndex = 1) { // path to map data file? - if (Assets.exists(mapData)) + if (FlxG.assets.exists(mapData)) { - mapData = Assets.getText(mapData); + mapData = FlxG.assets.getTextUnsafe(mapData); } // Figure out the map dimensions based on the data string diff --git a/flixel/tweens/motion/Motion.hx b/flixel/tweens/motion/Motion.hx index 76f95cd8b6..744c069aa7 100644 --- a/flixel/tweens/motion/Motion.hx +++ b/flixel/tweens/motion/Motion.hx @@ -55,7 +55,8 @@ class Motion extends FlxTween } } - override function isTweenOf(object:Dynamic, ?field:String):Bool { + override function isTweenOf(object:Dynamic, ?field:String):Bool + { return _object == object && (field == null || field == "x" || field == "y"); } diff --git a/flixel/ui/FlxBar.hx b/flixel/ui/FlxBar.hx index 04b5a99a61..11997a8c72 100644 --- a/flixel/ui/FlxBar.hx +++ b/flixel/ui/FlxBar.hx @@ -158,7 +158,7 @@ class FlxBar extends FlxSprite * @param variable The variable of the object that is used to determine the bar position. For example if the parent was an FlxSprite this could be "health" to track the health value * @param min The minimum value. I.e. for a progress bar this would be zero (nothing loaded yet) * @param max The maximum value the bar can reach. I.e. for a progress bar this would typically be 100. - * @param showBorder Include a 1px border around the bar? (if true it adds +2 to width and height to accommodate it) + * @param showBorder Should the bar be outlined with a solid border? */ public function new(x:Float = 0, y:Float = 0, ?direction:FlxBarFillDirection, width:Int = 100, height:Int = 10, ?parentRef:Dynamic, variable:String = "", min:Float = 0, max:Float = 100, showBorder:Bool = false) @@ -324,37 +324,39 @@ class FlxBar extends FlxSprite } /** - * Creates a solid-colour filled health bar in the given colours, with optional 1px thick border. + * Creates a solid-colour filled health bar in the given colours, with optional border. * All colour values are in 0xAARRGGBB format, so if you want a slightly transparent health bar give it lower AA values. * * @param empty The color of the bar when empty in 0xAARRGGBB format (the background colour) * @param fill The color of the bar when full in 0xAARRGGBB format (the foreground colour) - * @param showBorder Should the bar be outlined with a 1px solid border? + * @param showBorder Should the bar be outlined with a solid border? * @param border The border colour in 0xAARRGGBB format + * @param borderSize The size of the border, in pixels. * @return This FlxBar object with generated images for front and background. */ - public function createFilledBar(empty:FlxColor, fill:FlxColor, showBorder:Bool = false, border:FlxColor = FlxColor.WHITE):FlxBar + public function createFilledBar(empty:FlxColor, fill:FlxColor, showBorder:Bool = false, border:FlxColor = FlxColor.WHITE, borderSize:Int = 1):FlxBar { - createColoredEmptyBar(empty, showBorder, border); - createColoredFilledBar(fill, showBorder, border); + createColoredEmptyBar(empty, showBorder, border, borderSize); + createColoredFilledBar(fill, showBorder, border, borderSize); return this; } /** - * Creates a solid-colour filled background for health bar in the given colour, with optional 1px thick border. + * Creates a solid-colour filled background for health bar in the given colour, with optional border. * * @param empty The color of the bar when empty in 0xAARRGGBB format (the background colour) - * @param showBorder Should the bar be outlined with a 1px solid border? + * @param showBorder Should the bar be outlined with a solid border? * @param border The border colour in 0xAARRGGBB format + * @param borderSize The size of the border, in pixels. * @return This FlxBar object with generated image for rendering health bar background. */ - public function createColoredEmptyBar(empty:FlxColor, showBorder:Bool = false, border:FlxColor = FlxColor.WHITE):FlxBar + public function createColoredEmptyBar(empty:FlxColor, showBorder:Bool = false, border:FlxColor = FlxColor.WHITE, borderSize:Int = 1):FlxBar { if (FlxG.renderTile) { var emptyKey:String = "empty: " + barWidth + "x" + barHeight + ":" + empty.toHexString(); if (showBorder) - emptyKey += ",border: " + border.toHexString(); + emptyKey += ",border: " + border.toHexString() + "borderSize: " + borderSize; if (!FlxG.bitmap.checkCache(emptyKey)) { @@ -363,7 +365,7 @@ class FlxBar extends FlxSprite if (showBorder) { emptyBar = new BitmapData(barWidth, barHeight, true, border); - emptyBar.fillRect(new Rectangle(1, 1, barWidth - 2, barHeight - 2), empty); + emptyBar.fillRect(new Rectangle(borderSize, borderSize, barWidth - borderSize * 2, barHeight - borderSize * 2), empty); } else { @@ -380,7 +382,7 @@ class FlxBar extends FlxSprite if (showBorder) { _emptyBar = new BitmapData(barWidth, barHeight, true, border); - _emptyBar.fillRect(new Rectangle(1, 1, barWidth - 2, barHeight - 2), empty); + _emptyBar.fillRect(new Rectangle(borderSize, borderSize, barWidth - borderSize * 2, barHeight - borderSize * 2), empty); } else { @@ -395,19 +397,20 @@ class FlxBar extends FlxSprite } /** - * Creates a solid-colour filled foreground for health bar in the given colour, with optional 1px thick border. + * Creates a solid-colour filled foreground for health bar in the given colour, with optional border. * @param fill The color of the bar when full in 0xAARRGGBB format (the foreground colour) - * @param showBorder Should the bar be outlined with a 1px solid border? + * @param showBorder Should the bar be outlined with a solid border? * @param border The border colour in 0xAARRGGBB format + * @param borderSize The size of the border, in pixels. * @return This FlxBar object with generated image for rendering actual values. */ - public function createColoredFilledBar(fill:FlxColor, showBorder:Bool = false, border:FlxColor = FlxColor.WHITE):FlxBar + public function createColoredFilledBar(fill:FlxColor, showBorder:Bool = false, border:FlxColor = FlxColor.WHITE, borderSize:Int = 1):FlxBar { if (FlxG.renderTile) { var filledKey:String = "filled: " + barWidth + "x" + barHeight + ":" + fill.toHexString(); if (showBorder) - filledKey += ",border: " + border.toHexString(); + filledKey += ",border: " + border.toHexString() + "borderSize: " + borderSize; if (!FlxG.bitmap.checkCache(filledKey)) { @@ -416,7 +419,7 @@ class FlxBar extends FlxSprite if (showBorder) { filledBar = new BitmapData(barWidth, barHeight, true, border); - filledBar.fillRect(new Rectangle(1, 1, barWidth - 2, barHeight - 2), fill); + filledBar.fillRect(new Rectangle(borderSize, borderSize, barWidth - borderSize * 2, barHeight - borderSize * 2), fill); } else { @@ -433,7 +436,7 @@ class FlxBar extends FlxSprite if (showBorder) { _filledBar = new BitmapData(barWidth, barHeight, true, border); - _filledBar.fillRect(new Rectangle(1, 1, barWidth - 2, barHeight - 2), fill); + _filledBar.fillRect(new Rectangle(borderSize, borderSize, barWidth - borderSize * 2, barHeight - borderSize * 2), fill); } else { @@ -447,37 +450,39 @@ class FlxBar extends FlxSprite } /** - * Creates a gradient filled health bar using the given colour ranges, with optional 1px thick border. + * Creates a gradient filled health bar using the given colour ranges, with optional border. * All colour values are in 0xAARRGGBB format, so if you want a slightly transparent health bar give it lower AA values. * * @param empty Array of colour values used to create the gradient of the health bar when empty, each colour must be in 0xAARRGGBB format (the background colour) * @param fill Array of colour values used to create the gradient of the health bar when full, each colour must be in 0xAARRGGBB format (the foreground colour) * @param chunkSize If you want a more old-skool looking chunky gradient, increase this value! * @param rotation Angle of the gradient in degrees. 90 = top to bottom, 180 = left to right. Any angle is valid - * @param showBorder Should the bar be outlined with a 1px solid border? + * @param showBorder Should the bar be outlined with a solid border? * @param border The border colour in 0xAARRGGBB format + * @param borderSize The size of the border, in pixels. * @return This FlxBar object with generated images for front and background. */ public function createGradientBar(empty:Array, fill:Array, chunkSize:Int = 1, rotation:Int = 180, showBorder:Bool = false, - border:FlxColor = FlxColor.WHITE):FlxBar + border:FlxColor = FlxColor.WHITE, borderSize:Int = 1):FlxBar { - createGradientEmptyBar(empty, chunkSize, rotation, showBorder, border); - createGradientFilledBar(fill, chunkSize, rotation, showBorder, border); + createGradientEmptyBar(empty, chunkSize, rotation, showBorder, border, borderSize); + createGradientFilledBar(fill, chunkSize, rotation, showBorder, border, borderSize); return this; } /** - * Creates a gradient filled background for health bar using the given colour range, with optional 1px thick border. + * Creates a gradient filled background for health bar using the given colour range, with optional border. * * @param empty Array of colour values used to create the gradient of the health bar when empty, each colour must be in 0xAARRGGBB format (the background colour) * @param chunkSize If you want a more old-skool looking chunky gradient, increase this value! * @param rotation Angle of the gradient in degrees. 90 = top to bottom, 180 = left to right. Any angle is valid - * @param showBorder Should the bar be outlined with a 1px solid border? + * @param showBorder Should the bar be outlined with a solid border? * @param border The border colour in 0xAARRGGBB format + * @param borderSize The size of the border, in pixels. * @return This FlxBar object with generated image for background rendering. */ public function createGradientEmptyBar(empty:Array, chunkSize:Int = 1, rotation:Int = 180, showBorder:Bool = false, - border:FlxColor = FlxColor.WHITE):FlxBar + border:FlxColor = FlxColor.WHITE, borderSize:Int = 1):FlxBar { if (FlxG.renderTile) { @@ -490,7 +495,7 @@ class FlxBar extends FlxSprite if (showBorder) { - emptyKey += ",border: " + border.toHexString(); + emptyKey += ",border: " + border.toHexString() + "borderSize: " + borderSize; } if (!FlxG.bitmap.checkCache(emptyKey)) @@ -500,7 +505,8 @@ class FlxBar extends FlxSprite if (showBorder) { emptyBar = new BitmapData(barWidth, barHeight, true, border); - FlxGradient.overlayGradientOnBitmapData(emptyBar, barWidth - 2, barHeight - 2, empty, 1, 1, chunkSize, rotation); + FlxGradient.overlayGradientOnBitmapData(emptyBar, barWidth - borderSize * 2, barHeight - borderSize * 2, empty, borderSize, borderSize, + chunkSize, rotation); } else { @@ -517,7 +523,8 @@ class FlxBar extends FlxSprite if (showBorder) { _emptyBar = new BitmapData(barWidth, barHeight, true, border); - FlxGradient.overlayGradientOnBitmapData(_emptyBar, barWidth - 2, barHeight - 2, empty, 1, 1, chunkSize, rotation); + FlxGradient.overlayGradientOnBitmapData(_emptyBar, barWidth - borderSize * 2, barHeight - borderSize * 2, empty, borderSize, borderSize, + chunkSize, rotation); } else { @@ -532,17 +539,18 @@ class FlxBar extends FlxSprite } /** - * Creates a gradient filled foreground for health bar using the given colour range, with optional 1px thick border. + * Creates a gradient filled foreground for health bar using the given colour range, with optional border. * * @param fill Array of colour values used to create the gradient of the health bar when full, each colour must be in 0xAARRGGBB format (the foreground colour) * @param chunkSize If you want a more old-skool looking chunky gradient, increase this value! * @param rotation Angle of the gradient in degrees. 90 = top to bottom, 180 = left to right. Any angle is valid - * @param showBorder Should the bar be outlined with a 1px solid border? + * @param showBorder Should the bar be outlined with a solid border? * @param border The border colour in 0xAARRGGBB format + * @param borderSize The size of the border, in pixels. * @return This FlxBar object with generated image for rendering actual values. */ public function createGradientFilledBar(fill:Array, chunkSize:Int = 1, rotation:Int = 180, showBorder:Bool = false, - border:FlxColor = FlxColor.WHITE):FlxBar + border:FlxColor = FlxColor.WHITE, borderSize:Int = 1):FlxBar { if (FlxG.renderTile) { @@ -555,7 +563,7 @@ class FlxBar extends FlxSprite if (showBorder) { - filledKey += ",border: " + border.toHexString(); + filledKey += ",border: " + border.toHexString() + "borderSize: " + borderSize; } if (!FlxG.bitmap.checkCache(filledKey)) @@ -565,7 +573,8 @@ class FlxBar extends FlxSprite if (showBorder) { filledBar = new BitmapData(barWidth, barHeight, true, border); - FlxGradient.overlayGradientOnBitmapData(filledBar, barWidth - 2, barHeight - 2, fill, 1, 1, chunkSize, rotation); + FlxGradient.overlayGradientOnBitmapData(filledBar, barWidth - borderSize * 2, barHeight - borderSize * 2, fill, borderSize, borderSize, + chunkSize, rotation); } else { @@ -582,7 +591,8 @@ class FlxBar extends FlxSprite if (showBorder) { _filledBar = new BitmapData(barWidth, barHeight, true, border); - FlxGradient.overlayGradientOnBitmapData(_filledBar, barWidth - 2, barHeight - 2, fill, 1, 1, chunkSize, rotation); + FlxGradient.overlayGradientOnBitmapData(_filledBar, barWidth - borderSize * 2, barHeight - borderSize * 2, fill, borderSize, borderSize, + chunkSize, rotation); } else { diff --git a/flixel/util/FlxAxes.hx b/flixel/util/FlxAxes.hx index 356d12ef8b..f05c2d2ae6 100644 --- a/flixel/util/FlxAxes.hx +++ b/flixel/util/FlxAxes.hx @@ -8,12 +8,12 @@ enum abstract FlxAxes(Int) var NONE = 0x00; /** - * Whether the horizontal axis is anebled + * Whether the horizontal axis is enabled */ public var x(get, never):Bool; /** - * Whether the vertical axis is anebled + * Whether the vertical axis is enabled */ public var y(get, never):Bool; diff --git a/flixel/util/FlxDirectionFlags.hx b/flixel/util/FlxDirectionFlags.hx index e3f6b546f5..dab579d34b 100644 --- a/flixel/util/FlxDirectionFlags.hx +++ b/flixel/util/FlxDirectionFlags.hx @@ -41,7 +41,8 @@ enum abstract FlxDirectionFlags(Int) from Int from FlxDirection to Int public var degrees(get, never):Float; function get_degrees():Float { - return switch (this) { + return switch (this) + { case RIGHT: 0; case DOWN: 90; case UP: -90; diff --git a/flixel/util/FlxSave.hx b/flixel/util/FlxSave.hx index f2164833ac..629e9f3e2e 100644 --- a/flixel/util/FlxSave.hx +++ b/flixel/util/FlxSave.hx @@ -1,6 +1,7 @@ package flixel.util; import flixel.util.FlxDestroyUtil.IFlxDestroyable; +import haxe.Exception; import openfl.errors.Error; import openfl.net.SharedObject; import openfl.net.SharedObjectFlushStatus; @@ -98,6 +99,19 @@ class FlxSave implements IFlxDestroyable return newStr; } + /** + * The default class resolver of a FlxSave, handles certain Flixel and Openfl classes + */ + public static inline function resolveFlixelClasses(name:String) + { + #if flash + return Type.resolveClass(name); + #else + @:privateAccess + return SharedObject.__resolveClass(name); + #end + } + /** * Allows you to directly access the data container in the local shared object. */ @@ -146,15 +160,18 @@ class FlxSave implements IFlxDestroyable /** * Automatically creates or reconnects to locally saved data. * - * @param name The name of the save (should be the same each time to access old data). - * May not contain spaces or any of the following characters: - * `~ % & \ ; : " ' , < > ? #` - * @param path The full or partial path to the file that created the shared object. - * Mainly used to differentiate from other FlxSaves. If you do not specify - * this parameter, the company name specified in your Project.xml is used. + * @param name The name of the save (should be the same each time to access old data). + * May not contain spaces or any of the following characters: + * `~ % & \ ; : " ' , < > ? #` + * @param path The full or partial path to the file that created the shared object. + * Mainly used to differentiate from other FlxSaves. If you do not specify + * this parameter, the company name specified in your Project.xml is used. + * @param backupParser If there is an error parsing the raw save data, this will be called as + * a backup. if null is returned, the save will stay in an error state. + * **Note:** This arg is never used when targeting flash * @return Whether or not you successfully connected to the save data. */ - public function bind(name:String, ?path:String):Bool + public function bind(name:String, ?path:String, ?backupParser:(String, Exception)->Null):Bool { destroy(); @@ -164,8 +181,35 @@ class FlxSave implements IFlxDestroyable try { - _sharedObject = FlxSharedObject.getLocal(name, path); - status = BOUND(name, path); + switch FlxSharedObject.getLocal(name, path) + { + case SUCCESS(sharedObject): + _sharedObject = sharedObject; + data = _sharedObject.data; + status = BOUND(name, path); + return true; + #if !flash + case FAILURE(PARSING(rawData, exception), sharedObject) if (backupParser != null): + // Use the provided backup parser + final parsedData = backupParser(rawData, exception); + if (parsedData == null) + { + status = LOAD_ERROR(PARSING(rawData, exception)); + return false; + } + + _sharedObject = sharedObject; + data = parsedData; + @:privateAccess + sharedObject.data = parsedData; + status = BOUND(name, path); + return true; + #end + case FAILURE(type, sharedObject): + _sharedObject = sharedObject; + status = LOAD_ERROR(type); + return false; + } } catch (e:Error) { @@ -173,8 +217,6 @@ class FlxSave implements IFlxDestroyable destroy(); return false; } - data = _sharedObject.data; - return true; } /** @@ -275,12 +317,12 @@ class FlxSave implements IFlxDestroyable { status = ERROR("There was an problem flushing the save data."); } - + checkStatus(); - + return isBound; } - + /** * Erases everything stored in the local shared object. * Data is immediately erased and the object is saved that way, @@ -292,7 +334,7 @@ class FlxSave implements IFlxDestroyable { if (!checkStatus()) return false; - + _sharedObject.clear(); data = {}; return true; @@ -307,12 +349,22 @@ class FlxSave implements IFlxDestroyable { switch (status) { + case BOUND(name, path): + return true; case EMPTY: - FlxG.log.warn("You must call FlxSave.bind() before you can read or write data."); + FlxG.log.warn("You must call save.bind() before you can read or write data."); case ERROR(msg): FlxG.log.error(msg); - default: - return true; + case LOAD_ERROR(IO(e)): + FlxG.log.error('IO ERROR: ${e.message}'); + case LOAD_ERROR(INVALID_NAME(name, reason)): + FlxG.log.error('Invalid name:"$name", ${reason == null ? "" : reason}.'); + case LOAD_ERROR(INVALID_PATH(path, reason)): + FlxG.log.error('Invalid path:"$path", ${reason == null ? "" : reason}.'); + case LOAD_ERROR(PARSING(rawData, e)): + FlxG.log.error('Error parsing "$rawData", ${e.message}.'); + case found: + throw 'Unexpected status: $found'; } return false; } @@ -376,9 +428,18 @@ private class FlxSharedObject extends SharedObject { #if (flash || android || ios) /** Use SharedObject as usual */ - public static inline function getLocal(name:String, ?localPath:String):SharedObject + public static inline function getLocal(name:String, ?localPath:String):LoadResult { - return SharedObject.getLocal(name, localPath); + try + { + final obj = SharedObject.getLocal(name, localPath); + return SUCCESS(obj); + } + catch (e) + { + // We can't detect parsing or naming errors in flash, just use IO for everything + return FAILURE(IO(e)); + } } public static inline function exists(name:String, ?path:String) @@ -421,10 +482,10 @@ private class FlxSharedObject extends SharedObject return path; } - public static function getLocal(name:String, ?localPath:String):SharedObject + public static function getLocal(name:String, ?localPath:String):LoadResult { if (name == null || name == "") - throw new Error('Error: Invalid name:"$name".'); + return FAILURE(INVALID_NAME(name)); if (localPath == null) localPath = ""; @@ -437,14 +498,17 @@ private class FlxSharedObject extends SharedObject { var encodedData = null; + if (~/(?:^|\/)\.\.\//.match(localPath)) + return FAILURE(INVALID_PATH(localPath, "../ not allowed in localPath")); + try { - if (~/(?:^|\/)\.\.\//.match(localPath)) - throw new Error("../ not allowed in localPath"); - encodedData = getData(name, localPath); } - catch (e:Dynamic) {} + catch (e) + { + return FAILURE(IO(e)); + } if (localPath == "") localPath = getDefaultLocalPath(); @@ -459,17 +523,21 @@ private class FlxSharedObject extends SharedObject try { final unserializer = new haxe.Unserializer(encodedData); - final resolver = { resolveEnum: Type.resolveEnum, resolveClass: SharedObject.__resolveClass }; + final resolver = { resolveEnum: Type.resolveEnum, resolveClass: FlxSave.resolveFlixelClasses }; unserializer.setResolver(cast resolver); sharedObject.data = unserializer.unserialize(); } - catch (e:Dynamic) {} + catch (e) + { + all.set(id, sharedObject); + return FAILURE(PARSING(encodedData, e), sharedObject); + } } all.set(id, sharedObject); } - return all.get(id); + return SUCCESS(all.get(id)); } #if (js && html5) @@ -652,20 +720,46 @@ private class FlxSharedObject extends SharedObject #end } +enum LoadResult +{ + SUCCESS(obj:SharedObject); + FAILURE(type:LoadFailureType, ?obj:SharedObject); +} + +enum LoadFailureType +{ + /** Malformed name string */ + INVALID_NAME(name:String, ?message:String); + + /** Malformed path string */ + INVALID_PATH(path:String, ?message:String); + + /** An error while retrieving the data */ + IO(exception:Exception); + + /** An error while parsing the data */ + PARSING(rawData:String, exception:Exception); +} + enum FlxSaveStatus { /** * The initial state, call bind() in order to use. */ EMPTY; - + /** * The save is set up correctly. */ BOUND(name:String, ?path:String); - + /** - * There was an issue. + * There was an issue during `flush` */ ERROR(msg:String); + + /** + * There was an issue while loading + */ + LOAD_ERROR(type:LoadFailureType); } diff --git a/flixel/util/FlxStringUtil.hx b/flixel/util/FlxStringUtil.hx index 13ef02ecf7..92bef9c222 100644 --- a/flixel/util/FlxStringUtil.hx +++ b/flixel/util/FlxStringUtil.hx @@ -568,7 +568,7 @@ class FlxStringUtil if ((ImageFile is String)) { - tempBitmapData = FlxAssets.getBitmapData(ImageFile); + tempBitmapData = FlxG.assets.getBitmapData(ImageFile); } else { diff --git a/flixel/util/typeLimit/OneOfFour.hx b/flixel/util/typeLimit/OneOfFour.hx index bac25d240b..ad92714037 100644 --- a/flixel/util/typeLimit/OneOfFour.hx +++ b/flixel/util/typeLimit/OneOfFour.hx @@ -3,7 +3,7 @@ package flixel.util.typeLimit; /** * Useful to limit a Dynamic function argument's type to the specified * type parameters. This does NOT make the use of Dynamic type-safe in - * any way (the underlying type is still Dynamic and Std.is() checks + + * any way (the underlying type is still Dynamic and Std.isOfType() checks + * casts are necessary). */ abstract OneOfFour(Dynamic) from T1 from T2 from T3 from T4 to T1 to T2 to T3 to T4 {} diff --git a/flixel/util/typeLimit/OneOfThree.hx b/flixel/util/typeLimit/OneOfThree.hx index e51307f062..a055a3bfda 100644 --- a/flixel/util/typeLimit/OneOfThree.hx +++ b/flixel/util/typeLimit/OneOfThree.hx @@ -3,7 +3,7 @@ package flixel.util.typeLimit; /** * Useful to limit a Dynamic function argument's type to the specified * type parameters. This does NOT make the use of Dynamic type-safe in - * any way (the underlying type is still Dynamic and Std.is() checks + + * any way (the underlying type is still Dynamic and Std.isOfType() checks + * casts are necessary). */ abstract OneOfThree(Dynamic) from T1 from T2 from T3 to T1 to T2 to T3 {} diff --git a/flixel/util/typeLimit/OneOfTwo.hx b/flixel/util/typeLimit/OneOfTwo.hx index 5eff2d3f27..0ffebc9bd4 100644 --- a/flixel/util/typeLimit/OneOfTwo.hx +++ b/flixel/util/typeLimit/OneOfTwo.hx @@ -3,7 +3,7 @@ package flixel.util.typeLimit; /** * Useful to limit a Dynamic function argument's type to the specified * type parameters. This does NOT make the use of Dynamic type-safe in - * any way (the underlying type is still Dynamic and Std.is() checks + + * any way (the underlying type is still Dynamic and Std.isOfType() checks + * casts are necessary). */ abstract OneOfTwo(Dynamic) from T1 from T2 to T1 to T2 {} diff --git a/haxelib.json b/haxelib.json index a5ddb35510..a3d45e9f22 100644 --- a/haxelib.json +++ b/haxelib.json @@ -7,5 +7,8 @@ "version": "5.9.0", "releasenote": "TBD", "contributors": ["haxeflixel", "Gama11", "GeoKureli"], - "dependencies": {} + "dependencies": { + "lime": "", + "openfl": "" + } } diff --git a/images/platforms.png b/images/platforms.png index b9be014dcb..52ff1713b7 100644 Binary files a/images/platforms.png and b/images/platforms.png differ diff --git a/images/showcase.png b/images/showcase.png index b0ff5e5dc3..8f2bc6360f 100644 Binary files a/images/showcase.png and b/images/showcase.png differ diff --git a/include.xml b/include.xml index d0c2a32b00..e1cb529dbf 100644 --- a/include.xml +++ b/include.xml @@ -47,9 +47,9 @@ -
+
- +
diff --git a/tests/coverage/Project.xml b/tests/coverage/Project.xml index 8a7d118958..e53cc93d2e 100644 --- a/tests/coverage/Project.xml +++ b/tests/coverage/Project.xml @@ -59,4 +59,23 @@
+
+ + + + + + + + + + + + + + + + + +
diff --git a/tests/coverage/test.bat b/tests/coverage/test.bat index bfb2f0b581..1ad805c04c 100644 --- a/tests/coverage/test.bat +++ b/tests/coverage/test.bat @@ -1,8 +1,11 @@ haxelib run lime build flash -Dcoverage1 haxelib run lime build flash -Dcoverage2 +haxelib run lime build flash -Dcoverage3 haxelib run lime build html5 -Dcoverage1 haxelib run lime build html5 -Dcoverage2 +haxelib run lime build html5 -Dcoverage3 haxelib run lime build neko -Dcoverage1 -haxelib run lime build neko -Dcoverage2 \ No newline at end of file +haxelib run lime build neko -Dcoverage2 +haxelib run lime build neko -Dcoverage3 \ No newline at end of file diff --git a/tests/unit/src/flixel/graphics/frames/bmfont/BMFontTest.hx b/tests/unit/src/flixel/graphics/frames/bmfont/BMFontTest.hx index a027f2b9ea..6d1f8dea4e 100644 --- a/tests/unit/src/flixel/graphics/frames/bmfont/BMFontTest.hx +++ b/tests/unit/src/flixel/graphics/frames/bmfont/BMFontTest.hx @@ -64,7 +64,7 @@ class BMFontTest extends FlxTest } // This assumes the incoming font has a specific configuration we are checking for - private function assertFont(font:BMFont) + function assertFont(font:BMFont) { // INFO Assert.areEqual("Arial Black", font.info.face); @@ -127,7 +127,7 @@ class BMFontTest extends FlxTest } } - private function assertCharMatches(expected:BMFontChar, actual:BMFontChar) + function assertCharMatches(expected:BMFontChar, actual:BMFontChar) { Assert.areEqual(expected.id, actual.id); Assert.areEqual(expected.x, actual.x); @@ -143,7 +143,7 @@ class BMFontTest extends FlxTest // Assert.areEqual(expected.letter, actual.letter); } - private function assertKerningMatches(expected:BMFontKerning, actual:BMFontKerning) + function assertKerningMatches(expected:BMFontKerning, actual:BMFontKerning) { Assert.areEqual(expected.first, actual.first); Assert.areEqual(expected.second, actual.second); diff --git a/tests/unit/src/flixel/math/FlxPointTest.hx b/tests/unit/src/flixel/math/FlxPointTest.hx index 984525fbac..b7dd865926 100644 --- a/tests/unit/src/flixel/math/FlxPointTest.hx +++ b/tests/unit/src/flixel/math/FlxPointTest.hx @@ -160,7 +160,8 @@ class FlxPointTest extends FlxTest } @Test - function testPivotDegrees() { + function testPivotDegrees() + { // Pivot around point in same quadrant point1.set(10, 10); point2.set(5, 5); @@ -183,10 +184,10 @@ class FlxPointTest extends FlxTest } function assertPointNearlyEquals(p:FlxPoint, x:Float, y:Float, tolerance:Float = .01, ?msg:String, ?info:PosInfos) - { - if (msg == null) - msg = 'Expected (x: $x | y: $y) but was $p'; + { + if (msg == null) + msg = 'Expected (x: $x | y: $y) but was $p'; - Assert.isTrue(Math.abs(x - p.x) <= tolerance && Math.abs(y -p.y) <= tolerance, msg, info); - } + Assert.isTrue(Math.abs(x - p.x) <= tolerance && Math.abs(y -p.y) <= tolerance, msg, info); + } } diff --git a/tests/unit/src/flixel/tile/FlxTilemapTest.hx b/tests/unit/src/flixel/tile/FlxTilemapTest.hx index 8642932480..c721c1554e 100644 --- a/tests/unit/src/flixel/tile/FlxTilemapTest.hx +++ b/tests/unit/src/flixel/tile/FlxTilemapTest.hx @@ -444,8 +444,8 @@ class FlxTilemapTest extends FlxTest tilemap.y += 20; tilemap.scale.set(2, 2); - final SIZE = 16; - final HALF = 8; + final size = 16; + final half = 8; Assert.areEqual(tilemap.getTileIndex(4), tilemap.getTileIndex(1, 1)); Assert.areEqual(1, tilemap.getTileIndex(4)); @@ -454,12 +454,12 @@ class FlxTilemapTest extends FlxTest Assert.areEqual(-1, tilemap.getMapIndex(1000, 1)); Assert.areEqual(-1, tilemap.getTileIndex(1000, 1)); - Assert.areEqual(8, tilemap.getMapIndexAt(10 + 2 * SIZE + HALF, 20 + 2 * SIZE + HALF)); - Assert.areEqual(0, tilemap.getTileIndexAt(10 + 2 * SIZE + HALF, 20 + 2 * SIZE + HALF)); - Assert.areEqual(-1, tilemap.getTileIndexAt(10 + 1000 * SIZE + HALF, 20 + 2 * SIZE + HALF)); + Assert.areEqual(8, tilemap.getMapIndexAt(10 + 2 * size + half, 20 + 2 * size + half)); + Assert.areEqual(0, tilemap.getTileIndexAt(10 + 2 * size + half, 20 + 2 * size + half)); + Assert.areEqual(-1, tilemap.getTileIndexAt(10 + 1000 * size + half, 20 + 2 * size + half)); Assert.areEqual(tilemap.getTileData(4), tilemap.getTileData(1, 1)); - Assert.areEqual(tilemap.getTileData(1, 1), tilemap.getTileDataAt(10 + 1 * SIZE + HALF, 20 + 1 * SIZE + HALF)); + Assert.areEqual(tilemap.getTileData(1, 1), tilemap.getTileDataAt(10 + 1 * size + half, 20 + 1 * size + half)); } function testGetColumnRowAt() @@ -494,25 +494,25 @@ class FlxTilemapTest extends FlxTest tilemap.y = 20; tilemap.scale.set(2, 2); - final SIZE = 16; - final HALF = 8; + final size = 16; + final half = 8; Assert.areEqual(0, tilemap.getColumnAt(tilemap.getColumnPos(0))); Assert.areEqual(1, tilemap.getColumnAt(tilemap.getColumnPos(1))); Assert.areEqual(2, tilemap.getColumnAt(tilemap.getColumnPos(2))); Assert.areEqual(3, tilemap.getColumnAt(tilemap.getColumnPos(3))); Assert.areEqual(1000, tilemap.getColumnAt(tilemap.getColumnPos(1000))); - Assert.areEqual(10 + 3 * SIZE, tilemap.getColumnPos(3)); - Assert.areEqual(10 + 3 * SIZE + HALF, tilemap.getColumnPos(3, true)); - Assert.areEqual(10 + 1000 * SIZE, tilemap.getColumnPos(1000)); + Assert.areEqual(10 + 3 * size, tilemap.getColumnPos(3)); + Assert.areEqual(10 + 3 * size + half, tilemap.getColumnPos(3, true)); + Assert.areEqual(10 + 1000 * size, tilemap.getColumnPos(1000)); Assert.areEqual(0, tilemap.getRowAt(tilemap.getRowPos(0))); Assert.areEqual(1, tilemap.getRowAt(tilemap.getRowPos(1))); Assert.areEqual(2, tilemap.getRowAt(tilemap.getRowPos(2))); Assert.areEqual(1000, tilemap.getRowAt(tilemap.getRowPos(1000))); - Assert.areEqual(20 + 2 * SIZE, tilemap.getRowPos(2)); - Assert.areEqual(20 + 2 * SIZE + HALF, tilemap.getRowPos(2, true)); - Assert.areEqual(20 + 1000 * SIZE, tilemap.getRowPos(1000)); + Assert.areEqual(20 + 2 * size, tilemap.getRowPos(2)); + Assert.areEqual(20 + 2 * size + half, tilemap.getRowPos(2, true)); + Assert.areEqual(20 + 1000 * size, tilemap.getRowPos(1000)); Assert.areEqual(null, tilemap.getTilePos(1000)); Assert.areEqual(null, tilemap.getTilePos(-1)); @@ -524,10 +524,10 @@ class FlxTilemapTest extends FlxTest Assert.areEqual(expectedY, actual.y, 'Point y [${actual.y}] was not equal to expected value [$expectedY]', infos); } - assertPosEqual(10 + -SIZE, 20 + -SIZE, tilemap.getTilePos(-1, -1)); - assertPosEqual(10 + SIZE, 20 + SIZE, tilemap.getTilePos(1, 1)); - assertPosEqual(10 + 1000 * SIZE, 20 + 1000 * SIZE, tilemap.getTilePos(1000, 1000)); - assertPosEqual(10 + 1000 * SIZE, 20 + 1000 * SIZE, tilemap.getTilePosAt(10 + 1000 * SIZE, 20 + 1000 * SIZE)); + assertPosEqual(10 + -size, 20 + -size, tilemap.getTilePos(-1, -1)); + assertPosEqual(10 + size, 20 + size, tilemap.getTilePos(1, 1)); + assertPosEqual(10 + 1000 * size, 20 + 1000 * size, tilemap.getTilePos(1000, 1000)); + assertPosEqual(10 + 1000 * size, 20 + 1000 * size, tilemap.getTilePosAt(10 + 1000 * size, 20 + 1000 * size)); } @Test @@ -543,7 +543,7 @@ class FlxTilemapTest extends FlxTest tilemap.y = 20; tilemap.scale.set(2, 2); - final SIZE = 16; + final size = 16; Assert.isTrue(tilemap.tileExists(4)); Assert.isTrue(tilemap.tileExists(1, 1)); @@ -552,10 +552,10 @@ class FlxTilemapTest extends FlxTest Assert.isFalse(tilemap.tileExists(1, 3)); Assert.isFalse(tilemap.tileExists(5, 5)); - Assert.isTrue(tilemap.tileExistsAt(10 + 1 * SIZE, 20 + 1 * SIZE)); - Assert.isFalse(tilemap.tileExistsAt(10 + 3 * SIZE, 20 + 1 * SIZE)); - Assert.isFalse(tilemap.tileExistsAt(10 + 1 * SIZE, 20 + 3 * SIZE)); - Assert.isFalse(tilemap.tileExistsAt(10 + 5 * SIZE, 20 + 5 * SIZE)); + Assert.isTrue(tilemap.tileExistsAt(10 + 1 * size, 20 + 1 * size)); + Assert.isFalse(tilemap.tileExistsAt(10 + 3 * size, 20 + 1 * size)); + Assert.isFalse(tilemap.tileExistsAt(10 + 1 * size, 20 + 3 * size)); + Assert.isFalse(tilemap.tileExistsAt(10 + 5 * size, 20 + 5 * size)); } @Test @@ -571,41 +571,41 @@ class FlxTilemapTest extends FlxTest tilemap.y = 20; tilemap.scale.set(2, 2); - final SIZE = 16; + final size = 16; Assert.isFalse(tilemap.columnExists(5)); Assert.isFalse(tilemap.rowExists(5)); Assert.isFalse(tilemap.tileExists(5, 5)); - Assert.isFalse(tilemap.columnExistsAt(10 + 5 * SIZE)); - Assert.isFalse(tilemap.rowExistsAt(20 + 5 * SIZE)); - Assert.isFalse(tilemap.tileExistsAt(10 + 5 * SIZE, 20 + 5 * SIZE)); + Assert.isFalse(tilemap.columnExistsAt(10 + 5 * size)); + Assert.isFalse(tilemap.rowExistsAt(20 + 5 * size)); + Assert.isFalse(tilemap.tileExistsAt(10 + 5 * size, 20 + 5 * size)); Assert.isFalse(tilemap.columnExists(4)); Assert.isFalse(tilemap.rowExists(4)); Assert.isFalse(tilemap.tileExists(4, 4)); - Assert.isFalse(tilemap.columnExistsAt(10 + 4 * SIZE)); - Assert.isFalse(tilemap.rowExistsAt(20 + 4 * SIZE)); + Assert.isFalse(tilemap.columnExistsAt(10 + 4 * size)); + Assert.isFalse(tilemap.rowExistsAt(20 + 4 * size)); Assert.isTrue(tilemap.columnExists(3)); Assert.isFalse(tilemap.rowExists(3)); Assert.isFalse(tilemap.tileExists(3, 3)); - Assert.isTrue(tilemap.columnExistsAt(10 + 3 * SIZE)); - Assert.isFalse(tilemap.rowExistsAt(20 + 3 * SIZE)); - Assert.isFalse(tilemap.tileExistsAt(10 + 3 * SIZE, 20 + 3 * SIZE)); + Assert.isTrue(tilemap.columnExistsAt(10 + 3 * size)); + Assert.isFalse(tilemap.rowExistsAt(20 + 3 * size)); + Assert.isFalse(tilemap.tileExistsAt(10 + 3 * size, 20 + 3 * size)); Assert.isTrue(tilemap.columnExists(2)); Assert.isTrue(tilemap.rowExists(2)); Assert.isTrue(tilemap.tileExists(2, 2)); - Assert.isTrue(tilemap.columnExistsAt(10 + 2 * SIZE)); - Assert.isTrue(tilemap.rowExistsAt(20 + 2 * SIZE)); - Assert.isTrue(tilemap.tileExistsAt(10 + 2 * SIZE, 20 + 2 * SIZE)); + Assert.isTrue(tilemap.columnExistsAt(10 + 2 * size)); + Assert.isTrue(tilemap.rowExistsAt(20 + 2 * size)); + Assert.isTrue(tilemap.tileExistsAt(10 + 2 * size, 20 + 2 * size)); Assert.isTrue(tilemap.columnExists(1)); Assert.isTrue(tilemap.rowExists(1)); Assert.isTrue(tilemap.tileExists(1, 1)); - Assert.isTrue(tilemap.columnExistsAt(10 + 1 * SIZE)); - Assert.isTrue(tilemap.rowExistsAt(20 + 1 * SIZE)); - Assert.isTrue(tilemap.tileExistsAt(10 + 1 * SIZE, 20 + 1 * SIZE)); + Assert.isTrue(tilemap.columnExistsAt(10 + 1 * size)); + Assert.isTrue(tilemap.rowExistsAt(20 + 1 * size)); + Assert.isTrue(tilemap.tileExistsAt(10 + 1 * size, 20 + 1 * size)); Assert.isTrue(tilemap.columnExists(0)); Assert.isTrue(tilemap.rowExists(0)); diff --git a/tests/unit/src/flixel/util/FlxSignalTest.hx b/tests/unit/src/flixel/util/FlxSignalTest.hx index 8205deba89..83c7aa9971 100644 --- a/tests/unit/src/flixel/util/FlxSignalTest.hx +++ b/tests/unit/src/flixel/util/FlxSignalTest.hx @@ -29,7 +29,7 @@ class FlxSignalTest extends FlxTest function callbackIncrementCounter() counter++; - function callbackIncrementCounter_Int(v:Int):Void + function callbackIncrementCounterInt(v:Int):Void counter++; function addAllEmptyCallbacks():Void @@ -162,11 +162,11 @@ class FlxSignalTest extends FlxTest } @Test - function testDispatchOnce_signal1():Void + function testDispatchOnceSignal1():Void { // see https://github.com/HaxeFoundation/hashlink/issues/578 - signal1.addOnce(callbackIncrementCounter_Int); + signal1.addOnce(callbackIncrementCounterInt); signal1.dispatch(42); signal1.dispatch(42);