Use macro to register ccmds
This commit is contained in:
parent
9571e136b3
commit
34a691fa68
@ -15,6 +15,10 @@
|
|||||||
|
|
||||||
<!-- classpath, haxe libs -->
|
<!-- classpath, haxe libs -->
|
||||||
<source path="src" />
|
<source path="src" />
|
||||||
|
|
||||||
|
<!-- Macro configuration -->
|
||||||
|
<haxeflag name="--macro" value="addGlobalMetadata('', '@:build(engine.macros.CCmdDecorator.build())')" />
|
||||||
|
|
||||||
<assets path="./res/textures" rename="textures" />
|
<assets path="./res/textures" rename="textures" />
|
||||||
<assets path="./res/fonts" rename="fonts" />
|
<assets path="./res/fonts" rename="fonts" />
|
||||||
<assets path="./res/data" rename="data"/>
|
<assets path="./res/data" rename="data"/>
|
||||||
@ -24,6 +28,6 @@
|
|||||||
<!--<icon path="assets/openfl.svg" /> -->
|
<!--<icon path="assets/openfl.svg" /> -->
|
||||||
<!-- <assets path="assets/img" rename="img" /> -->
|
<!-- <assets path="assets/img" rename="img" /> -->
|
||||||
|
|
||||||
<!-- optimize output
|
<!-- optimize output -->
|
||||||
<haxeflag name="-dce full" /> -->
|
<haxeflag name="-dce full" />
|
||||||
</project>
|
</project>
|
||||||
36
hGameTest/src/engine/ConVars_Engine.hx
Normal file
36
hGameTest/src/engine/ConVars_Engine.hx
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package engine;
|
||||||
|
|
||||||
|
import game.video.Mode;
|
||||||
|
import haxe.macro.Expr.Field;
|
||||||
|
import engine.typedefs.console.CVar;
|
||||||
|
import engine.typedefs.console.CCmd;
|
||||||
|
import engine.enums.console.CVarType;
|
||||||
|
import engine.enums.console.CVarFlag;
|
||||||
|
import engine.macros.CCmdDecorator;
|
||||||
|
import game.ui.console.Console;
|
||||||
|
|
||||||
|
@:keep
|
||||||
|
// @:build(engine.macros.CCmdDecorator.build()) // No longer needed because we added the build macro to the project.xml
|
||||||
|
class ConVars_Engine {
|
||||||
|
|
||||||
|
@:command("list")
|
||||||
|
public static function listCommands(args:Array<String>) {
|
||||||
|
var CVarMap:Map<String, CVar> = ConVar.getCVarMap();
|
||||||
|
var keys:Array<String> = ConVar.getCVarNames();
|
||||||
|
for(key in keys){
|
||||||
|
if(CVarMap[key] != null){
|
||||||
|
Console.devMsg(key+" "+ CVarMap[key].value);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
Console.devMsg(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@:command("test")
|
||||||
|
public static function testCommand() {
|
||||||
|
// Command implementation
|
||||||
|
trace("Test Output");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
46
hGameTest/src/engine/macros/CCmdDecorator.hx
Normal file
46
hGameTest/src/engine/macros/CCmdDecorator.hx
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
package engine.macros;
|
||||||
|
|
||||||
|
import haxe.macro.Expr;
|
||||||
|
import haxe.macro.Context;
|
||||||
|
|
||||||
|
class CCmdDecorator {
|
||||||
|
public static macro function build():Array<Field> {
|
||||||
|
var fields = Context.getBuildFields();
|
||||||
|
var pos = Context.currentPos();
|
||||||
|
|
||||||
|
for (field in fields) {
|
||||||
|
var meta = field.meta != null ? Lambda.find(field.meta, function(m) return m.name == ":command") : null;
|
||||||
|
if (meta != null) {
|
||||||
|
trace(meta);
|
||||||
|
switch field.kind {
|
||||||
|
case FFun(f):
|
||||||
|
var name = meta.params.length > 0
|
||||||
|
? switch(meta.params[0].expr) {
|
||||||
|
case EConst(CString(s)): s;
|
||||||
|
case _: field.name;
|
||||||
|
}
|
||||||
|
: field.name;
|
||||||
|
|
||||||
|
// Create a static initializer field
|
||||||
|
var initField = {
|
||||||
|
name: "__init__" + name,
|
||||||
|
access: [AStatic, APrivate],
|
||||||
|
kind: FVar(null, macro {
|
||||||
|
engine.ConVar.registerCCmd($v{name}, function(args:Array<String>) {
|
||||||
|
${f.expr};
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
pos: pos,
|
||||||
|
doc: null,
|
||||||
|
meta: []
|
||||||
|
};
|
||||||
|
|
||||||
|
// Add the initializer field
|
||||||
|
fields.push(initField);
|
||||||
|
case _:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fields;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -15,9 +15,10 @@ class Mode
|
|||||||
public static function setVideoMode(width:Int, height:Int, fs:Int = null){
|
public static function setVideoMode(width:Int, height:Int, fs:Int = null){
|
||||||
getWindow().resize(width,height);
|
getWindow().resize(width,height);
|
||||||
}
|
}
|
||||||
public static var cvMatSetVideoMode:CCmd = ConVar.registerCCmd("mat_setvideomode",(args:Array<String>)->{
|
@:command("mat_setvideomode")
|
||||||
setVideoMode(Std.parseInt(args[0]), Std.parseInt(args[1]), Std.parseInt(args[2]));
|
public static function cCmdMatSetVideoMode(args:Array<String>){
|
||||||
});
|
Mode.setVideoMode(Std.parseInt(args[0]), Std.parseInt(args[1]), Std.parseInt(args[2]));
|
||||||
|
}
|
||||||
public static function switchFsMode(toState:Int = 0){
|
public static function switchFsMode(toState:Int = 0){
|
||||||
if(toState == 0){
|
if(toState == 0){
|
||||||
if(Lib.current.stage.displayState != StageDisplayState.FULL_SCREEN_INTERACTIVE){
|
if(Lib.current.stage.displayState != StageDisplayState.FULL_SCREEN_INTERACTIVE){
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user