constants macros: reset(), init() and @:lazy
Co-Authored-By: Ne_Eo <NeeEoo@users.noreply.github.com>
This commit is contained in:
@@ -17,9 +17,13 @@ class MainState extends FlxState {
|
||||
public static var betaWarningShown:Bool = false;
|
||||
public override function create() {
|
||||
super.create();
|
||||
if (!initiated)
|
||||
if (!initiated) {
|
||||
Main.loadGameSettings();
|
||||
Constants.init();
|
||||
}
|
||||
|
||||
initiated = true;
|
||||
Constants.reset();
|
||||
|
||||
#if sys
|
||||
CoolUtil.deleteFolder('./.temp/'); // delete temp folder
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package funkin.backend.system.macros;
|
||||
|
||||
#if macro
|
||||
import haxe.macro.Context;
|
||||
import haxe.macro.Expr;
|
||||
#end
|
||||
|
||||
class ConstantsMacro {
|
||||
#if macro
|
||||
static function build() {
|
||||
var fields = Context.getBuildFields();
|
||||
|
||||
var resetFields:Array<Expr> = [];
|
||||
var lazyFields:Array<Expr> = [];
|
||||
for(field in fields) {
|
||||
switch(field.kind) {
|
||||
case FVar(t, e):
|
||||
resetFields.push(macro $i{field.name} = ${e});
|
||||
|
||||
var hasLazy = false;
|
||||
for(meta in field.meta) {
|
||||
if(meta.name == ":lazy") {
|
||||
hasLazy = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(hasLazy) {
|
||||
lazyFields.push(macro $i{field.name} = ${e});
|
||||
field.kind = FVar(t, null);
|
||||
}
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
fields.push({
|
||||
name: "reset",
|
||||
pos: Context.currentPos(),
|
||||
access: [APublic, AStatic],
|
||||
kind: FFun({
|
||||
args: [],
|
||||
ret: null,
|
||||
expr: macro {
|
||||
$b{resetFields}
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
fields.push({
|
||||
name: "init",
|
||||
pos: Context.currentPos(),
|
||||
access: [APublic, AStatic],
|
||||
kind: FFun({
|
||||
args: [],
|
||||
ret: null,
|
||||
expr: macro {
|
||||
$b{lazyFields}
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
return fields;
|
||||
}
|
||||
#end
|
||||
}
|
||||
@@ -22,7 +22,7 @@ class UpdateUtil {
|
||||
}
|
||||
|
||||
public static function checkForUpdates():UpdateCheckCallback {
|
||||
var curTag = 'v${Constants.VERSION}';
|
||||
var curTag = 'v${Application.current.meta.get('version')}';
|
||||
trace(curTag);
|
||||
|
||||
var error = false;
|
||||
|
||||
Reference in New Issue
Block a user