constants macros: reset(), init() and @:lazy
Co-Authored-By: Ne_Eo <NeeEoo@users.noreply.github.com>
This commit is contained in:
@@ -6,10 +6,17 @@ import flixel.util.FlxColor;
|
||||
|
||||
using StringTools;
|
||||
|
||||
@:build(funkin.backend.system.macros.ConstantsMacro.build())
|
||||
class Constants {
|
||||
// these arent good since someone could easily change through meta.set() - Nex
|
||||
// @:lazy public static var WINDOW_TITLE:String = Application.current.meta.get('name');
|
||||
// @:lazy public static var BUILD_FILENAME:String = Application.current.meta.get('file');
|
||||
// @:lazy public static var VERSION:String = Application.current.meta.get('version');
|
||||
|
||||
public static var COMMIT_NUMBER = GitCommitMacro.commitNumber;
|
||||
public static var COMMIT_HASH = GitCommitMacro.commitHash;
|
||||
public static var COMMIT_MESSAGE = 'Commit $COMMIT_NUMBER ($COMMIT_HASH)';
|
||||
@:lazy public static var VERSION_MESSAGE:String = 'Codename Engine v${Application.current.meta.get('version')}';
|
||||
|
||||
public static var REPO_NAME = "CodenameEngine";
|
||||
public static var REPO_OWNER = "FNF-CNE-Devs";
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package funkin.editors.charter;
|
||||
|
||||
import haxe.macro.Expr.Constant;
|
||||
import flixel.text.FlxText.FlxTextFormat;
|
||||
import flixel.text.FlxText.FlxTextFormatMarkerPair;
|
||||
import funkin.backend.chart.ChartData;
|
||||
|
||||
@@ -429,9 +429,10 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset
|
||||
@:noCompletion private function get_danceInterval()
|
||||
return beatInterval;
|
||||
|
||||
|
||||
// these wont update when you change the constants!!! they just start from the constant for qol if we'll ever edit them in the future - Nex
|
||||
public static var FALLBACK_CHARACTER:String = Constants.DEFAULT_CHARACTER;
|
||||
public static var FALLBACK_DEAD_CHARACTER:String = Constants.DEFAULT_GAMEOVER_CHARACTER;
|
||||
|
||||
public static function getXMLFromCharName(character:OneOfTwo<String, Character>):Access {
|
||||
var char:Character = null;
|
||||
if (character is Character) {
|
||||
|
||||
@@ -86,7 +86,7 @@ class Note extends FlxSprite
|
||||
return PlayState.instance.getNoteType(noteTypeID);
|
||||
}
|
||||
|
||||
public static var swagWidth:Float = 160 * 0.7;
|
||||
public static var swagWidth:Float = 160 * 0.7; // TODO: remove this
|
||||
|
||||
private static var __customNoteTypeExists:Map<String, Bool> = [];
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ class VideoCutscene extends Cutscene {
|
||||
|
||||
// ZIP PATH: EXPORT
|
||||
// TODO: this but better and more ram friendly
|
||||
localPath = './.temp/video-${curVideo++}.${Constants.VIDEO_EXT}';
|
||||
localPath = './.temp/video-${curVideo++}.${Path.extension(path)}';
|
||||
Main.execAsync(function() {
|
||||
File.saveBytes(localPath, Assets.getBytes(path));
|
||||
videoReady = true;
|
||||
|
||||
@@ -72,7 +72,7 @@ class MainMenuState extends MusicBeatState
|
||||
|
||||
FlxG.camera.follow(camFollow, null, 0.06);
|
||||
|
||||
versionText = new FunkinText(5, FlxG.height - 2, 0, 'Codename Engine v${Application.current.meta.get('version')}\n${Constants.COMMIT_MESSAGE}\n[${controls.getKeyName(SWITCHMOD)}] Open Mods menu\n');
|
||||
versionText = new FunkinText(5, FlxG.height - 2, 0, '${Constants.VERSION_MESSAGE}\n${Constants.COMMIT_MESSAGE}\n[${controls.getKeyName(SWITCHMOD)}] Open Mods menu\n');
|
||||
versionText.y -= versionText.height;
|
||||
versionText.scrollFactor.set();
|
||||
add(versionText);
|
||||
|
||||
Reference in New Issue
Block a user