Skip to content

Commit

Permalink
Add compatibility checks with flixel (#419)
Browse files Browse the repository at this point in the history
* check compatibility with flixel

* update formatting settings

* wrap in #if macro
  • Loading branch information
Geokureli authored Jan 4, 2024
1 parent 719fd7b commit b82db84
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"[haxe]": {
"editor.formatOnSave": true
"editor.formatOnSave": true,
"editor.formatOnSaveMode": "modifications"
}
}
6 changes: 6 additions & 0 deletions flixel/addons/effects/chainable/FlxEffectSprite.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package flixel.addons.effects.chainable;

// TODO: remove this check when min flixel version is 5.6.0,
// So that FlxAddonDefines will handle this
#if (flixel < "5.3.0")
#error "Flixel-Addons is not compatible with flixel versions older than 5.3.0";
#end

import flixel.FlxCamera;
import flixel.FlxSprite;
import flixel.graphics.FlxGraphic;
Expand Down
64 changes: 64 additions & 0 deletions flixel/addons/system/macros/FlxAddonDefines.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package flixel.addons.system.macros;

#if macro
import haxe.macro.Compiler;
import haxe.macro.Context;
import haxe.macro.Expr.Position;

// private enum UserAddonDefines {}
// private enum HelperAddonDefines {}

/**
* The purpose of these "defines" classes is mainly to properly communicate version compatibility
* among flixel libs, we shouldn't be overly concerned with backwards compatibility, but we do want
* to know when a change breaks compatibility between Flixel-Addons and Flixel.
*
* @since 3.2.2
*/
@:allow(flixel.system.macros.FlxDefines)
@:access(flixel.system.macros.FlxDefines)
class FlxAddonDefines
{
/**
* Called from `flixel.system.macros.FlxDefines` on versions 5.6.0 or later
*/
public static function run()
{
#if !display
checkCompatibility();
#end
}

static function checkCompatibility()
{
/** this function is only ran in flixel versions 5.6.0 or later, meaning this error will
* never happen. So we've added flixel version checks in the following modules:
* - `FlxEffectSprite`
* - `FlxTypeText`
* - `FlxTransitionableState`
* - `FlxWeapon`
*
* When the minimum version of flixel is changed to 5.6.0 or greater, remove the above
* checks and this comment.
*/
#if (flixel < "5.3.0")
FlxDefines.abortVersion("Flixel", "5.3.0 or newer", "flixel", (macro null).pos);
#end
}

static function isValidUserDefine(define:Any)
{
return false;
}

static function abortVersion(dependency:String, supported:String, found:String, pos:Position)
{
abort('Flixel-Addons: Unsupported $dependency version! Supported versions are $supported (found ${Context.definedValue(found)}).', pos);
}

static function abort(message:String, pos:Position)
{
Context.fatalError(message, pos);
}
}
#end
6 changes: 6 additions & 0 deletions flixel/addons/text/FlxTypeText.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package flixel.addons.text;

// TODO: remove this check when min flixel version is 5.6.0,
// So that FlxAddonDefines will handle this
#if (flixel < "5.3.0")
#error "Flixel-Addons is not compatible with flixel versions older than 5.3.0";
#end

import flixel.FlxG;
import flixel.input.keyboard.FlxKey;
import flixel.math.FlxMath;
Expand Down
6 changes: 6 additions & 0 deletions flixel/addons/transition/FlxTransitionableState.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package flixel.addons.transition;

// TODO: remove this check when min flixel version is 5.6.0,
// So that FlxAddonDefines will handle this
#if (flixel < "5.3.0")
#error "Flixel-Addons is not compatible with flixel versions older than 5.3.0";
#end

import flixel.FlxState;

/**
Expand Down
6 changes: 6 additions & 0 deletions flixel/addons/weapon/FlxWeapon.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package flixel.addons.weapon;

// TODO: remove this check when min flixel version is 5.6.0,
// So that FlxAddonDefines will handle this
#if (flixel < "5.3.0")
#error "Flixel-Addons is not compatible with flixel versions older than 5.3.0";
#end

import flixel.FlxBasic;
import flixel.FlxG;
import flixel.FlxObject;
Expand Down

0 comments on commit b82db84

Please sign in to comment.