Compare commits
3 Commits
34a691fa68
...
ac5787e2fb
| Author | SHA1 | Date | |
|---|---|---|---|
| ac5787e2fb | |||
| 2383b5f026 | |||
| 99dc07cd64 |
@ -17,7 +17,7 @@
|
|||||||
<source path="src" />
|
<source path="src" />
|
||||||
|
|
||||||
<!-- Macro configuration -->
|
<!-- Macro configuration -->
|
||||||
<haxeflag name="--macro" value="addGlobalMetadata('', '@:build(engine.macros.CCmdDecorator.build())')" />
|
<haxeflag name="--macro" value="addGlobalMetadata('', '@:build(engine.macros.ConVarDecorators.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" />
|
||||||
|
|||||||
@ -67,6 +67,10 @@ class ConVar{
|
|||||||
}
|
}
|
||||||
public static inline function setCVar(_name:String, _value:Dynamic):Void
|
public static inline function setCVar(_name:String, _value:Dynamic):Void
|
||||||
{
|
{
|
||||||
|
if(CVarMap == null){
|
||||||
|
Console.devMsg("CVarMap is null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
var cv = getCVar(_name);
|
var cv = getCVar(_name);
|
||||||
if(cv != null){
|
if(cv != null){
|
||||||
switch(cv.type){
|
switch(cv.type){
|
||||||
|
|||||||
@ -6,14 +6,14 @@ import engine.typedefs.console.CVar;
|
|||||||
import engine.typedefs.console.CCmd;
|
import engine.typedefs.console.CCmd;
|
||||||
import engine.enums.console.CVarType;
|
import engine.enums.console.CVarType;
|
||||||
import engine.enums.console.CVarFlag;
|
import engine.enums.console.CVarFlag;
|
||||||
import engine.macros.CCmdDecorator;
|
import engine.macros.ConVarDecorators;
|
||||||
import game.ui.console.Console;
|
import game.ui.console.Console;
|
||||||
|
|
||||||
@:keep
|
@:keep
|
||||||
// @:build(engine.macros.CCmdDecorator.build()) // No longer needed because we added the build macro to the project.xml
|
// @:build(engine.macros.CCmdDecorator.build()) // No longer needed because we added the build macro to the project.xml
|
||||||
class ConVars_Engine {
|
class ConVars_Engine {
|
||||||
|
|
||||||
@:command("list")
|
@:concmd("list")
|
||||||
public static function listCommands(args:Array<String>) {
|
public static function listCommands(args:Array<String>) {
|
||||||
var CVarMap:Map<String, CVar> = ConVar.getCVarMap();
|
var CVarMap:Map<String, CVar> = ConVar.getCVarMap();
|
||||||
var keys:Array<String> = ConVar.getCVarNames();
|
var keys:Array<String> = ConVar.getCVarNames();
|
||||||
@ -27,7 +27,7 @@ class ConVars_Engine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@:command("test")
|
@:concmd("test")
|
||||||
public static function testCommand() {
|
public static function testCommand() {
|
||||||
// Command implementation
|
// Command implementation
|
||||||
trace("Test Output");
|
trace("Test Output");
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package engine.enums.console;
|
package engine.enums.console;
|
||||||
|
|
||||||
enum CVarFlag{
|
enum CVarFlag{
|
||||||
|
FCVAR_NONE;
|
||||||
FCVAR_ARCHIVE;
|
FCVAR_ARCHIVE;
|
||||||
FCVAR_CHEAT;
|
FCVAR_CHEAT;
|
||||||
FVCAR_REPLICATED;
|
FVCAR_REPLICATED;
|
||||||
|
|||||||
@ -1,46 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
136
hGameTest/src/engine/macros/ConVarDecorators.hx
Normal file
136
hGameTest/src/engine/macros/ConVarDecorators.hx
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
package engine.macros;
|
||||||
|
|
||||||
|
import haxe.macro.Expr;
|
||||||
|
import haxe.macro.Context;
|
||||||
|
import haxe.macro.Expr.Field;
|
||||||
|
|
||||||
|
private typedef CVarMetadata = {
|
||||||
|
name: Expr,
|
||||||
|
type: String,
|
||||||
|
value: Expr,
|
||||||
|
flags: Expr,
|
||||||
|
help: Expr,
|
||||||
|
?callback: Expr
|
||||||
|
}
|
||||||
|
|
||||||
|
class ConVarDecorators {
|
||||||
|
static function extractCVarMetadata(params:Array<Expr>):CVarMetadata {
|
||||||
|
var metadata:CVarMetadata = null;
|
||||||
|
|
||||||
|
switch (params[0].expr) {
|
||||||
|
case EObjectDecl(fields):
|
||||||
|
metadata = {
|
||||||
|
name: macro "",
|
||||||
|
type: "CString",
|
||||||
|
value: macro 0,
|
||||||
|
flags: macro "FCVAR_NONE",
|
||||||
|
help: macro "",
|
||||||
|
callback: macro null
|
||||||
|
};
|
||||||
|
|
||||||
|
for (field in fields) {
|
||||||
|
switch (field.field) {
|
||||||
|
case "name": metadata.name = field.expr;
|
||||||
|
case "type": metadata.type = switch(field.expr.expr) {
|
||||||
|
case EConst(CString(s)): s;
|
||||||
|
case _: "CString";
|
||||||
|
}
|
||||||
|
case "value": metadata.value = field.expr;
|
||||||
|
case "flags": metadata.flags = field.expr;
|
||||||
|
case "help": metadata.help = field.expr;
|
||||||
|
case "callback": metadata.callback = field.expr;
|
||||||
|
case _:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case _:
|
||||||
|
}
|
||||||
|
return metadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static macro function build():Array<Field> {
|
||||||
|
var fields = Context.getBuildFields();
|
||||||
|
var pos = Context.currentPos();
|
||||||
|
|
||||||
|
for (field in fields) {
|
||||||
|
var cmdMeta = field.meta != null ? Lambda.find(field.meta, function(m) return m.name == ":concmd") : null;
|
||||||
|
var cvarMeta = field.meta != null ? Lambda.find(field.meta, function(m) return m.name == ":convar") : null;
|
||||||
|
|
||||||
|
if (cmdMeta != null) {
|
||||||
|
switch field.kind {
|
||||||
|
case FFun(f):
|
||||||
|
var name = cmdMeta.params.length > 0 ? switch (cmdMeta.params[0].expr) {
|
||||||
|
case EConst(CString(s)): s;
|
||||||
|
case _: field.name;
|
||||||
|
} : field.name;
|
||||||
|
|
||||||
|
var fnExpr = macro function(args:Array<String>) ${f.expr};
|
||||||
|
|
||||||
|
var initExpr = macro {
|
||||||
|
var cmd = engine.ConVar.registerCCmd($v{name}, $fnExpr);
|
||||||
|
cmd; // Return the command reference
|
||||||
|
};
|
||||||
|
|
||||||
|
// Generate a safe initialization field name
|
||||||
|
var initName = "__init__" + name;
|
||||||
|
|
||||||
|
fields.push({
|
||||||
|
name: initName,
|
||||||
|
access: [AStatic],
|
||||||
|
kind: FVar(null, initExpr),
|
||||||
|
pos: pos,
|
||||||
|
doc: null,
|
||||||
|
meta: [{
|
||||||
|
name: ":keep",
|
||||||
|
params: [],
|
||||||
|
pos: pos
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
case _:
|
||||||
|
}
|
||||||
|
} else if (cvarMeta != null && cvarMeta.params.length > 0) {
|
||||||
|
switch (field.kind) {
|
||||||
|
case FVar(t, e):
|
||||||
|
var meta = extractCVarMetadata(cvarMeta.params);
|
||||||
|
if (meta == null) continue;
|
||||||
|
|
||||||
|
// Extract name from metadata expression
|
||||||
|
var cvarName = switch(meta.name.expr) {
|
||||||
|
case EConst(CString(s)): s;
|
||||||
|
case _: field.name;
|
||||||
|
};
|
||||||
|
|
||||||
|
var initExpr = macro {
|
||||||
|
var cvar = $i{field.name} = engine.ConVar.registerCVar(
|
||||||
|
${meta.name},
|
||||||
|
${Context.parse('engine.enums.console.CVarType.' + meta.type, pos)},
|
||||||
|
${meta.value},
|
||||||
|
${Context.parse('engine.enums.console.CVarFlag.' + switch(meta.flags.expr) {
|
||||||
|
case EConst(CString(s)): s;
|
||||||
|
case _: "FCVAR_NONE";
|
||||||
|
}, pos)},
|
||||||
|
${meta.help},
|
||||||
|
${meta.callback ?? macro null}
|
||||||
|
);
|
||||||
|
trace($v{"Registered CVar: "} + $e{meta.name});
|
||||||
|
cvar; // Return the CVar reference
|
||||||
|
};
|
||||||
|
|
||||||
|
fields.push({
|
||||||
|
name: "__init__" + cvarName,
|
||||||
|
access: [AStatic],
|
||||||
|
kind: FVar(null, initExpr),
|
||||||
|
pos: pos,
|
||||||
|
doc: null,
|
||||||
|
meta: [{
|
||||||
|
name: ":keep",
|
||||||
|
params: [],
|
||||||
|
pos: pos
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
case _:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fields;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -18,7 +18,19 @@ class Input{
|
|||||||
public static var keys:Map<Int,Bool> = [];
|
public static var keys:Map<Int,Bool> = [];
|
||||||
public static var keysLast:Map<Int,Bool> = [];
|
public static var keysLast:Map<Int,Bool> = [];
|
||||||
public static var bindMap:Map<String, String> = ["~" => "toggleconsole", "\\" => "toggleconsole", "1" => "echo kak", "2" => "+attack"];
|
public static var bindMap:Map<String, String> = ["~" => "toggleconsole", "\\" => "toggleconsole", "1" => "echo kak", "2" => "+attack"];
|
||||||
public static var cv_debugKeys = ConVar.registerCVar("cl_debuginput", CInt, 0, null, "print debug messages related to input to console", null, false, true, 0, 0, false);
|
@:convar({
|
||||||
|
name: "cl_debuginput",
|
||||||
|
type: CVarType.CInt,
|
||||||
|
value: 0,
|
||||||
|
flags: CVarFlag.None,
|
||||||
|
help: "print debug messages related to input to console",
|
||||||
|
callback: function() {
|
||||||
|
trace("Debug input changed");
|
||||||
|
}
|
||||||
|
})
|
||||||
|
public static var cv_debugKeys:CVar;
|
||||||
|
|
||||||
|
// public static var cv_debugKeys = ConVar.registerCVar("cl_debuginput", CInt, 0, null, "print debug messages related to input to console", null, false, true, 0, 0, false);
|
||||||
public static var keyNameMap:Map<Int, String> = [
|
public static var keyNameMap:Map<Int, String> = [
|
||||||
Kb.HOME => "HOME", Kb.END => "END", Kb.INSERT => "INSERT", Kb.DELETE => "DELETE", Kb.PAGE_UP => "PGUP", Kb.PAGE_DOWN => "PGDN",
|
Kb.HOME => "HOME", Kb.END => "END", Kb.INSERT => "INSERT", Kb.DELETE => "DELETE", Kb.PAGE_UP => "PGUP", Kb.PAGE_DOWN => "PGDN",
|
||||||
Kb.ESCAPE => "ESC", Kb.F1 => "F1", Kb.F2 => "F2", Kb.F3 => "F3", Kb.F4 => "F4", Kb.F5 => "F5",
|
Kb.ESCAPE => "ESC", Kb.F1 => "F1", Kb.F2 => "F2", Kb.F3 => "F3", Kb.F4 => "F4", Kb.F5 => "F5",
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package game.ui.console;
|
|||||||
import game.ui.text.TextFormats;
|
import game.ui.text.TextFormats;
|
||||||
import assets.Fonts;
|
import assets.Fonts;
|
||||||
import openfl.Lib;
|
import openfl.Lib;
|
||||||
|
import engine.ui.UIPane.PaneLayout;
|
||||||
import openfl.events.Event;
|
import openfl.events.Event;
|
||||||
import openfl.text.TextFieldAutoSize;
|
import openfl.text.TextFieldAutoSize;
|
||||||
import openfl.text.TextField;
|
import openfl.text.TextField;
|
||||||
@ -17,377 +18,380 @@ import engine.typedefs.console.CCmd;
|
|||||||
import game.ui.console.elements.ConsoleInput;
|
import game.ui.console.elements.ConsoleInput;
|
||||||
import engine.ui.UIPane;
|
import engine.ui.UIPane;
|
||||||
|
|
||||||
|
class Console extends Sprite {
|
||||||
|
public var textFormat:TextFormat;
|
||||||
|
public var cOut:TextField;
|
||||||
|
public var cIn:TextField;
|
||||||
|
public var cInput:ConsoleInput;
|
||||||
|
public var cAutoComp:TextField;
|
||||||
|
|
||||||
class Console extends Sprite{
|
public static var consoleInstance:Console;
|
||||||
public var textFormat:TextFormat;
|
@:convar({
|
||||||
public var cOut:TextField;
|
name: "mat_consolebg",
|
||||||
public var cIn:TextField;
|
type: "CString",
|
||||||
public var cInput:ConsoleInput;
|
value: "0x222222",
|
||||||
public var cAutoComp:TextField;
|
help: "console background color",
|
||||||
public static var consoleInstance:Console;
|
callback: () -> {
|
||||||
|
if (Console.consoleInstance != null){
|
||||||
|
Console.consoleInstance.cOut.backgroundColor = Std.parseInt(Console.consoleInstance.cvar_mat_consolebg.value);
|
||||||
|
Console.consoleInstance.cIn.backgroundColor = Std.parseInt(Console.consoleInstance.cvar_mat_consolebg.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
public static var scvar_mat_consolebg:CVar;
|
||||||
|
|
||||||
public var cvar_mat_consolebg:CVar;
|
public var cvar_mat_consolebg:CVar;
|
||||||
public var ccmd_visible:CCmd = ConVar.registerCCmd("toggleconsole",(cArgs:Array<String>)->{
|
|
||||||
toggle();
|
|
||||||
});
|
|
||||||
public function new(){
|
|
||||||
super();
|
|
||||||
|
|
||||||
consoleInstance = this;
|
|
||||||
|
|
||||||
|
|
||||||
var consolePane:UIPane = new UIPane("yeeto",{width:800, height:600});
|
public var ccmd_visible:CCmd = ConVar.registerCCmd("toggleconsole", (cArgs:Array<String>) -> {
|
||||||
|
toggle();
|
||||||
|
});
|
||||||
|
|
||||||
this.addChild(consolePane.sprite);
|
public function new() {
|
||||||
consolePane.layout = VERTICAL;
|
super();
|
||||||
|
|
||||||
|
cvar_mat_consolebg = scvar_mat_consolebg;
|
||||||
|
consoleInstance = this;
|
||||||
|
|
||||||
//graphics.beginFill(0x555555);
|
var consolePane = new UIPane("yeeto", {width: 800, height: 600, minWidth: 400, minHeight: 300, maxWidth: 1200, maxHeight: 800});
|
||||||
//graphics.drawRect(0,0,800,600);
|
|
||||||
|
consolePane.layout = VERTICAL;
|
||||||
cInput = new ConsoleInput();
|
consolePane.layout = VERTICAL;
|
||||||
cIn = cInput.tf;
|
|
||||||
|
// graphics.beginFill(0x555555);
|
||||||
//cIn.setTextFormat(textFormat);
|
// graphics.drawRect(0,0,800,600);
|
||||||
cInput.y = 600-cInput.height-12;
|
|
||||||
cInput.x = 12;
|
cInput = new ConsoleInput();
|
||||||
|
cIn = cInput.tf;
|
||||||
cvar_mat_consolebg = ConVar.registerCVar("mat_consolebg",CString,"0x222222",null,"console background color", ()->{
|
|
||||||
cOut.backgroundColor = Std.parseInt(cvar_mat_consolebg.value);
|
// cIn.setTextFormat(textFormat);
|
||||||
cIn.backgroundColor = Std.parseInt(cvar_mat_consolebg.value);
|
cInput.y = 600 - cInput.height - 12;
|
||||||
},false,false,0,0,false);
|
cInput.x = 12;
|
||||||
|
|
||||||
cOut = new TextField();
|
|
||||||
cAutoComp = new TextField();
|
|
||||||
|
|
||||||
drawFields(cOut, cAutoComp);
|
|
||||||
|
|
||||||
|
|
||||||
cOut.addEventListener(Event.CHANGE, onOutputTextChange);
|
|
||||||
cIn.addEventListener(Event.CHANGE, onInputTextChange);
|
|
||||||
this.addChild(cOut);
|
|
||||||
this.addChild(cInput);
|
|
||||||
this.addChild(cAutoComp);
|
|
||||||
ConVar.registerCCmd("echo", (args:Array<String>) -> { Console.devMsg(args.join(" ").split('"').join(""));});
|
|
||||||
ConVar.registerCCmd("quit", (args:Array<String>) -> { Lib.application.window.close();});
|
|
||||||
}
|
|
||||||
public function drawFields(cOut:TextField, cAutoComp:TextField){
|
|
||||||
|
|
||||||
cOut.text = "hConsole Initialized\n";
|
|
||||||
cOut.defaultTextFormat = TextFormats.getFormats().cOutputFmt;
|
|
||||||
cOut.wordWrap = true;
|
|
||||||
//cOut.autoSize = TextFieldAutoSize.LEFT;
|
|
||||||
cOut.multiline = true;
|
|
||||||
cOut.background = true;
|
|
||||||
cOut.backgroundColor = Std.parseInt(cvar_mat_consolebg.value);
|
|
||||||
cOut.width = 800 - 24;
|
|
||||||
cOut.height = 600 - cIn.height - 38;
|
|
||||||
cOut.y = 12;
|
|
||||||
cOut.x = 12;
|
|
||||||
|
|
||||||
cAutoComp.text = "";
|
|
||||||
cAutoComp.defaultTextFormat = TextFormats.getFormats().cInputFmt;
|
|
||||||
cAutoComp.wordWrap = false;
|
|
||||||
cAutoComp.multiline = true;
|
|
||||||
cAutoComp.background = true;
|
|
||||||
cAutoComp.backgroundColor = 0x11111100;
|
|
||||||
cAutoComp.border = true;
|
|
||||||
cAutoComp.borderColor = 0x55555500;
|
|
||||||
cAutoComp.selectable = false;
|
|
||||||
cAutoComp.width = 400;
|
|
||||||
cAutoComp.height = 32*5;
|
|
||||||
cAutoComp.visible = false;
|
|
||||||
cAutoComp.x = 0;
|
|
||||||
cAutoComp.y = 600;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function parseCmd(cmd:String, bNoHist:Bool = false){
|
cOut = new TextField();
|
||||||
if(!bNoHist)
|
cAutoComp = new TextField();
|
||||||
history.push(cmd);
|
|
||||||
|
|
||||||
cmd = cmd.split(";").join(" ; ");
|
|
||||||
var subStrings = [];
|
|
||||||
var startQuoteIndex:Int = cmd.indexOf('"');
|
|
||||||
var endQuoteIndex:Int;
|
|
||||||
if(startQuoteIndex != -1){
|
|
||||||
while((startQuoteIndex = cmd.indexOf('"')) > -1){
|
|
||||||
//push start of the cmd up until the quotes start
|
|
||||||
subStrings.push(cmd.substring(0,startQuoteIndex));
|
|
||||||
//find next quote
|
|
||||||
endQuoteIndex = cmd.indexOf('"',startQuoteIndex+1)+1;
|
|
||||||
if(endQuoteIndex == 0){
|
|
||||||
cmd+='"';
|
|
||||||
endQuoteIndex = cmd.length;
|
|
||||||
|
|
||||||
}
|
|
||||||
//push quote content
|
|
||||||
subStrings.push(cmd.substring(startQuoteIndex,endQuoteIndex));
|
|
||||||
cmd = cmd.substr(endQuoteIndex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
subStrings.push(cmd);
|
|
||||||
//Split args
|
|
||||||
var newSubStrings = [];
|
|
||||||
for(subString in subStrings){
|
|
||||||
if(subString.indexOf('"') == -1){
|
|
||||||
// split spaced args
|
|
||||||
for(str in subString.split(" ")){
|
|
||||||
//we want to discard empty strings
|
|
||||||
if(str != "")
|
|
||||||
newSubStrings.push(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
newSubStrings.push(subString);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var commands = [];
|
|
||||||
//split off additional commands
|
|
||||||
while(newSubStrings.length > 0){
|
|
||||||
for(i in 0...newSubStrings.length){
|
|
||||||
if(newSubStrings[i] == ";"){
|
|
||||||
commands.push(newSubStrings.splice(0,i));
|
|
||||||
newSubStrings.shift();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(newSubStrings.length-1 == i){
|
|
||||||
commands.push(newSubStrings);
|
|
||||||
newSubStrings = [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
trace(commands);
|
|
||||||
execCommands(commands);
|
|
||||||
}
|
|
||||||
public function execCommands(commands:Array<Array<String>>){
|
|
||||||
for(command in commands){
|
|
||||||
// Store command name, value and args
|
|
||||||
var cName:String = command[0];
|
|
||||||
var cValue:String = command[1];
|
|
||||||
var cArgs:Array<String> = command.slice(1);
|
|
||||||
//Check if convar with that name actually exists
|
|
||||||
if(ConVar.isCVar(cName)){
|
|
||||||
//Get reference to convar object
|
|
||||||
var cv:CVar = ConVar.getCVar(command[0]);
|
|
||||||
//Check number of params
|
|
||||||
if(command.length == 1){
|
|
||||||
//No params after the cmd, print help string
|
|
||||||
devMsg(cv.name+" - "+cv.helpString);
|
|
||||||
devMsg(cv.name+" = "+cv.value);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
//Check for convar type and set value accordingly
|
|
||||||
switch(cv.type){
|
|
||||||
case CInt:
|
|
||||||
ConVar.setCVar(cName,Std.parseInt(cValue));
|
|
||||||
trace(cValue);
|
|
||||||
break;
|
|
||||||
case CFloat:
|
|
||||||
ConVar.setCVar(cName,Std.parseFloat(cValue));
|
|
||||||
break;
|
|
||||||
case CBool:
|
|
||||||
cValue = cValue.toLowerCase();
|
|
||||||
if(cValue == "1" || cValue == "true"){
|
|
||||||
ConVar.setCVar(cName,true);
|
|
||||||
}
|
|
||||||
else if(cValue == "0" || cValue == "false"){
|
|
||||||
ConVar.setCVar(cName,false);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case CString:
|
|
||||||
ConVar.setCVar(cName,cValue);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
//convar is actually a command, run it.
|
|
||||||
else if(ConVar.isCmd(cName)){
|
|
||||||
ConVar.runCmd(cName,cArgs);
|
|
||||||
}
|
|
||||||
//convar doesn't exist
|
|
||||||
else{
|
|
||||||
devMsg("unkown command: "+command[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public function submitInput(){
|
|
||||||
cOut.appendText(">"+cInput.getText()+"\n");
|
|
||||||
parseCmd(cInput.getText());
|
|
||||||
cInput.setText("");
|
|
||||||
cAutoComp.visible = false;
|
|
||||||
cOut.scrollV = cOut.maxScrollV;
|
|
||||||
histSelect = -1;
|
|
||||||
}
|
|
||||||
public function onOutputTextChange(e:Event){
|
|
||||||
cOut.scrollV = cOut.maxScrollV;
|
|
||||||
}
|
|
||||||
public function onInputTextChange(e:Event){
|
|
||||||
if(cInput.getText() != ""){
|
|
||||||
cAutoComp.text = "";
|
|
||||||
for(string in (autocompleteList = getCompList())){
|
|
||||||
cAutoComp.text += string+"\n";
|
|
||||||
trace(string);
|
|
||||||
}
|
|
||||||
cAutoComp.visible = true;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
cAutoComp.visible = false;
|
|
||||||
autocompleteList = history;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public static function toggle():Void
|
|
||||||
{
|
|
||||||
consoleInstance.visible = !consoleInstance.visible;
|
|
||||||
if(!consoleInstance.visible){
|
|
||||||
if(Lib.current.stage.focus == consoleInstance.cIn){
|
|
||||||
Lib.current.stage.focus = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
Lib.current.stage.focus = consoleInstance.cIn;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public static function devMsg(msg:String):Void
|
|
||||||
{
|
|
||||||
consoleInstance.cOut.appendText(msg+"\n");
|
|
||||||
consoleInstance.cOut.scrollV = consoleInstance.cOut.maxScrollV;
|
|
||||||
}
|
|
||||||
public static var history:Array<String> = [];
|
|
||||||
public static var histSelect:Int = -1;
|
|
||||||
public static var tmpInput:String = "";
|
|
||||||
public static var autocompleteList:Array<String> = [];
|
|
||||||
public static var compSelect:Int = -1;
|
|
||||||
public static function getCompList():Array<String>
|
|
||||||
{
|
|
||||||
// Split words
|
|
||||||
var inp:Array<String> = consoleInstance.cInput.getText().split(" ");
|
|
||||||
var inpStripped:Array<String> = [
|
|
||||||
for(word in inp){
|
|
||||||
if(word != "" && word != " "){
|
|
||||||
word;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
];
|
|
||||||
// Stop if input is empty
|
|
||||||
if(inp.length == 0) return [];
|
|
||||||
|
|
||||||
var cVars:Array<String> = ConVar.getCVarNames();
|
drawFields(cOut, cAutoComp);
|
||||||
var cVarFiltered:Array<String> = [];
|
|
||||||
// Loop through convars
|
cOut.addEventListener(Event.CHANGE, onOutputTextChange);
|
||||||
for(cVar in cVars){
|
cIn.addEventListener(Event.CHANGE, onInputTextChange);
|
||||||
//if there's one word just check if the convar starts with the input string
|
this.addChild(cOut);
|
||||||
if(inp.length == 1)
|
this.addChild(cInput);
|
||||||
{
|
this.addChild(cAutoComp);
|
||||||
// Check if the cvar starts with the input
|
ConVar.registerCCmd("echo", (args:Array<String>) -> {
|
||||||
if(cVar.indexOf(inp[0]) == 0){
|
Console.devMsg(args.join(" ").split('"').join(""));
|
||||||
cVarFiltered.push(cVar);
|
});
|
||||||
}
|
ConVar.registerCCmd("quit", (args:Array<String>) -> {
|
||||||
}
|
Lib.application.window.close();
|
||||||
// User pressed space at least once but entered no other words. Check if first word occurs at any position
|
});
|
||||||
else if(inpStripped.length == 1 && inp.length > 1){
|
}
|
||||||
if(cVar.indexOf(inp[0]) > -1){
|
|
||||||
cVarFiltered.push(cVar);
|
public function drawFields(cOut:TextField, cAutoComp:TextField) {
|
||||||
}
|
cOut.text = "hConsole Initialized\n";
|
||||||
}
|
cOut.defaultTextFormat = TextFormats.getFormats().cOutputFmt;
|
||||||
// Multiple words, check for cvars that contain all of them
|
cOut.wordWrap = true;
|
||||||
else if(inpStripped.length > 1)
|
// cOut.autoSize = TextFieldAutoSize.LEFT;
|
||||||
{
|
cOut.multiline = true;
|
||||||
var bWordNotPresent:Bool = false;
|
cOut.background = true;
|
||||||
for(word in inpStripped){
|
trace(cvar_mat_consolebg);
|
||||||
if(cVar.indexOf(word) == -1){
|
cOut.backgroundColor = Std.parseInt(cvar_mat_consolebg.value);
|
||||||
bWordNotPresent = true;
|
cOut.width = 800 - 24;
|
||||||
}
|
cOut.height = 600 - cIn.height - 38;
|
||||||
}
|
cOut.y = 12;
|
||||||
if(!bWordNotPresent)
|
cOut.x = 12;
|
||||||
cVarFiltered.push(cVar);
|
|
||||||
}
|
cAutoComp.text = "";
|
||||||
}
|
cAutoComp.defaultTextFormat = TextFormats.getFormats().cInputFmt;
|
||||||
return cVarFiltered;
|
cAutoComp.wordWrap = false;
|
||||||
}
|
cAutoComp.multiline = true;
|
||||||
public static function histPrev():Void
|
cAutoComp.background = true;
|
||||||
{
|
cAutoComp.backgroundColor = 0x11111100;
|
||||||
// Only complete if input field is empty or scrolling through hist
|
cAutoComp.border = true;
|
||||||
if(consoleInstance.cInput.getText() == "" || histSelect != -1){
|
cAutoComp.borderColor = 0x55555500;
|
||||||
// Store current input in tmpInput
|
cAutoComp.selectable = false;
|
||||||
if(histSelect == -1) tmpInput = consoleInstance.cInput.getText();
|
cAutoComp.width = 400;
|
||||||
// Only go through history if history is not empty
|
cAutoComp.height = 32 * 5;
|
||||||
if(history.length != 0){
|
cAutoComp.visible = false;
|
||||||
// Check if currently selecting a history entry
|
cAutoComp.x = 0;
|
||||||
if(histSelect >= 0){
|
cAutoComp.y = 600;
|
||||||
histSelect--;
|
}
|
||||||
}
|
|
||||||
// Not currently selecting a history entry
|
public function parseCmd(cmd:String, bNoHist:Bool = false) {
|
||||||
else{
|
if (!bNoHist)
|
||||||
// Put selector to the newest
|
history.push(cmd);
|
||||||
histSelect = history.length -1;
|
|
||||||
}
|
cmd = cmd.split(";").join(" ; ");
|
||||||
if(histSelect != -1){
|
var subStrings = [];
|
||||||
// Put correct history entry in the input field
|
var startQuoteIndex:Int = cmd.indexOf('"');
|
||||||
consoleInstance.cInput.setText(history[histSelect]);
|
var endQuoteIndex:Int;
|
||||||
}
|
if (startQuoteIndex != -1) {
|
||||||
else{
|
while ((startQuoteIndex = cmd.indexOf('"')) > -1) {
|
||||||
// Restore tmp input
|
// push start of the cmd up until the quotes start
|
||||||
consoleInstance.cInput.setText(tmpInput);
|
subStrings.push(cmd.substring(0, startQuoteIndex));
|
||||||
}
|
// find next quote
|
||||||
}
|
endQuoteIndex = cmd.indexOf('"', startQuoteIndex + 1) + 1;
|
||||||
// History is empty
|
if (endQuoteIndex == 0) {
|
||||||
else{
|
cmd += '"';
|
||||||
// Do nothing
|
endQuoteIndex = cmd.length;
|
||||||
return;
|
}
|
||||||
}
|
// push quote content
|
||||||
}
|
subStrings.push(cmd.substring(startQuoteIndex, endQuoteIndex));
|
||||||
// Now we need to descend through the autocomplete list
|
cmd = cmd.substr(endQuoteIndex);
|
||||||
else{
|
}
|
||||||
if(autocompleteList.length == 0){
|
}
|
||||||
return;
|
subStrings.push(cmd);
|
||||||
}
|
// Split args
|
||||||
else{
|
var newSubStrings = [];
|
||||||
// Check if currently selecting an autocomplete entry
|
for (subString in subStrings) {
|
||||||
if(compSelect > -1){
|
if (subString.indexOf('"') == -1) {
|
||||||
|
// split spaced args
|
||||||
}
|
for (str in subString.split(" ")) {
|
||||||
// Not currently selecting an autocomplete entry
|
// we want to discard empty strings
|
||||||
else{
|
if (str != "")
|
||||||
|
newSubStrings.push(str);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
newSubStrings.push(subString);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
var commands = [];
|
||||||
public static function histNext():Void
|
// split off additional commands
|
||||||
{
|
while (newSubStrings.length > 0) {
|
||||||
// Only complete if input field is empty or scrolling through hist
|
for (i in 0...newSubStrings.length) {
|
||||||
if(consoleInstance.cIn.text == "" || histSelect != -1){
|
if (newSubStrings[i] == ";") {
|
||||||
// Store current input in tmpInput
|
commands.push(newSubStrings.splice(0, i));
|
||||||
if(histSelect == -1) tmpInput = consoleInstance.cIn.text;
|
newSubStrings.shift();
|
||||||
// Only go through history if history is not empty
|
break;
|
||||||
if(history.length != 0){
|
}
|
||||||
// Check if currently selecting a history entry
|
if (newSubStrings.length - 1 == i) {
|
||||||
if(histSelect < history.length -1){
|
commands.push(newSubStrings);
|
||||||
histSelect++;
|
newSubStrings = [];
|
||||||
}
|
}
|
||||||
// Otherwise wrap around
|
}
|
||||||
else{
|
}
|
||||||
// Put selector to no selection
|
trace(commands);
|
||||||
histSelect = -1;
|
execCommands(commands);
|
||||||
}
|
}
|
||||||
if(histSelect != -1){
|
|
||||||
// Put correct history entry in the input field
|
public function execCommands(commands:Array<Array<String>>) {
|
||||||
consoleInstance.cIn.text = history[histSelect];
|
for (command in commands) {
|
||||||
}
|
// Store command name, value and args
|
||||||
else{
|
var cName:String = command[0];
|
||||||
// Restore tmp input
|
var cValue:String = command[1];
|
||||||
consoleInstance.cIn.text = tmpInput;
|
var cArgs:Array<String> = command.slice(1);
|
||||||
}
|
// Check if convar with that name actually exists
|
||||||
}
|
if (ConVar.isCVar(cName)) {
|
||||||
// History is empty
|
// Get reference to convar object
|
||||||
else{
|
var cv:CVar = ConVar.getCVar(command[0]);
|
||||||
// Do nothing
|
// Check number of params
|
||||||
return;
|
if (command.length == 1) {
|
||||||
}
|
// No params after the cmd, print help string
|
||||||
}
|
devMsg(cv.name + " - " + cv.helpString);
|
||||||
}
|
devMsg(cv.name + " = " + cv.value);
|
||||||
}
|
} else {
|
||||||
|
// Check for convar type and set value accordingly
|
||||||
|
switch (cv.type) {
|
||||||
|
case CInt:
|
||||||
|
ConVar.setCVar(cName, Std.parseInt(cValue));
|
||||||
|
trace(cValue);
|
||||||
|
break;
|
||||||
|
case CFloat:
|
||||||
|
ConVar.setCVar(cName, Std.parseFloat(cValue));
|
||||||
|
break;
|
||||||
|
case CBool:
|
||||||
|
cValue = cValue.toLowerCase();
|
||||||
|
if (cValue == "1" || cValue == "true") {
|
||||||
|
ConVar.setCVar(cName, true);
|
||||||
|
} else if (cValue == "0" || cValue == "false") {
|
||||||
|
ConVar.setCVar(cName, false);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case CString:
|
||||||
|
ConVar.setCVar(cName, cValue);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// convar is actually a command, run it.
|
||||||
|
else if (ConVar.isCmd(cName)) {
|
||||||
|
ConVar.runCmd(cName, cArgs);
|
||||||
|
}
|
||||||
|
// convar doesn't exist
|
||||||
|
else {
|
||||||
|
devMsg("unkown command: " + command[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function submitInput() {
|
||||||
|
cOut.appendText(">" + cInput.getText() + "\n");
|
||||||
|
parseCmd(cInput.getText());
|
||||||
|
cInput.setText("");
|
||||||
|
cAutoComp.visible = false;
|
||||||
|
cOut.scrollV = cOut.maxScrollV;
|
||||||
|
histSelect = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onOutputTextChange(e:Event) {
|
||||||
|
cOut.scrollV = cOut.maxScrollV;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onInputTextChange(e:Event) {
|
||||||
|
if (cInput.getText() != "") {
|
||||||
|
cAutoComp.text = "";
|
||||||
|
for (string in (autocompleteList = getCompList())) {
|
||||||
|
cAutoComp.text += string + "\n";
|
||||||
|
trace(string);
|
||||||
|
}
|
||||||
|
cAutoComp.visible = true;
|
||||||
|
} else {
|
||||||
|
cAutoComp.visible = false;
|
||||||
|
autocompleteList = history;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function toggle():Void {
|
||||||
|
consoleInstance.visible = !consoleInstance.visible;
|
||||||
|
if (!consoleInstance.visible) {
|
||||||
|
if (Lib.current.stage.focus == consoleInstance.cIn) {
|
||||||
|
Lib.current.stage.focus = null;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Lib.current.stage.focus = consoleInstance.cIn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function devMsg(msg:String):Void {
|
||||||
|
consoleInstance.cOut.appendText(msg + "\n");
|
||||||
|
consoleInstance.cOut.scrollV = consoleInstance.cOut.maxScrollV;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static var history:Array<String> = [];
|
||||||
|
public static var histSelect:Int = -1;
|
||||||
|
public static var tmpInput:String = "";
|
||||||
|
public static var autocompleteList:Array<String> = [];
|
||||||
|
public static var compSelect:Int = -1;
|
||||||
|
|
||||||
|
public static function getCompList():Array<String> {
|
||||||
|
// Split words
|
||||||
|
var inp:Array<String> = consoleInstance.cInput.getText().split(" ");
|
||||||
|
var inpStripped:Array<String> = [
|
||||||
|
for (word in inp) {
|
||||||
|
if (word != "" && word != " ") {
|
||||||
|
word;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
// Stop if input is empty
|
||||||
|
if (inp.length == 0)
|
||||||
|
return [];
|
||||||
|
|
||||||
|
var cVars:Array<String> = ConVar.getCVarNames();
|
||||||
|
var cVarFiltered:Array<String> = [];
|
||||||
|
// Loop through convars
|
||||||
|
for (cVar in cVars) {
|
||||||
|
// if there's one word just check if the convar starts with the input string
|
||||||
|
if (inp.length == 1) {
|
||||||
|
// Check if the cvar starts with the input
|
||||||
|
if (cVar.indexOf(inp[0]) == 0) {
|
||||||
|
cVarFiltered.push(cVar);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// User pressed space at least once but entered no other words. Check if first word occurs at any position
|
||||||
|
else if (inpStripped.length == 1 && inp.length > 1) {
|
||||||
|
if (cVar.indexOf(inp[0]) > -1) {
|
||||||
|
cVarFiltered.push(cVar);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Multiple words, check for cvars that contain all of them
|
||||||
|
else if (inpStripped.length > 1) {
|
||||||
|
var bWordNotPresent:Bool = false;
|
||||||
|
for (word in inpStripped) {
|
||||||
|
if (cVar.indexOf(word) == -1) {
|
||||||
|
bWordNotPresent = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!bWordNotPresent)
|
||||||
|
cVarFiltered.push(cVar);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cVarFiltered;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function histPrev():Void {
|
||||||
|
// Only complete if input field is empty or scrolling through hist
|
||||||
|
if (consoleInstance.cInput.getText() == "" || histSelect != -1) {
|
||||||
|
// Store current input in tmpInput
|
||||||
|
if (histSelect == -1)
|
||||||
|
tmpInput = consoleInstance.cInput.getText();
|
||||||
|
// Only go through history if history is not empty
|
||||||
|
if (history.length != 0) {
|
||||||
|
// Check if currently selecting a history entry
|
||||||
|
if (histSelect >= 0) {
|
||||||
|
histSelect--;
|
||||||
|
}
|
||||||
|
// Not currently selecting a history entry
|
||||||
|
else {
|
||||||
|
// Put selector to the newest
|
||||||
|
histSelect = history.length - 1;
|
||||||
|
}
|
||||||
|
if (histSelect != -1) {
|
||||||
|
// Put correct history entry in the input field
|
||||||
|
consoleInstance.cInput.setText(history[histSelect]);
|
||||||
|
} else {
|
||||||
|
// Restore tmp input
|
||||||
|
consoleInstance.cInput.setText(tmpInput);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// History is empty
|
||||||
|
else {
|
||||||
|
// Do nothing
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Now we need to descend through the autocomplete list
|
||||||
|
else {
|
||||||
|
if (autocompleteList.length == 0) {
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
// Check if currently selecting an autocomplete entry
|
||||||
|
if (compSelect > -1) {}
|
||||||
|
// Not currently selecting an autocomplete entry
|
||||||
|
else {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function histNext():Void {
|
||||||
|
// Only complete if input field is empty or scrolling through hist
|
||||||
|
if (consoleInstance.cIn.text == "" || histSelect != -1) {
|
||||||
|
// Store current input in tmpInput
|
||||||
|
if (histSelect == -1)
|
||||||
|
tmpInput = consoleInstance.cIn.text;
|
||||||
|
// Only go through history if history is not empty
|
||||||
|
if (history.length != 0) {
|
||||||
|
// Check if currently selecting a history entry
|
||||||
|
if (histSelect < history.length - 1) {
|
||||||
|
histSelect++;
|
||||||
|
}
|
||||||
|
// Otherwise wrap around
|
||||||
|
else {
|
||||||
|
// Put selector to no selection
|
||||||
|
histSelect = -1;
|
||||||
|
}
|
||||||
|
if (histSelect != -1) {
|
||||||
|
// Put correct history entry in the input field
|
||||||
|
consoleInstance.cIn.text = history[histSelect];
|
||||||
|
} else {
|
||||||
|
// Restore tmp input
|
||||||
|
consoleInstance.cIn.text = tmpInput;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// History is empty
|
||||||
|
else {
|
||||||
|
// Do nothing
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -15,7 +15,7 @@ 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);
|
||||||
}
|
}
|
||||||
@:command("mat_setvideomode")
|
@:concmd("mat_setvideomode")
|
||||||
public static function cCmdMatSetVideoMode(args:Array<String>){
|
public static function cCmdMatSetVideoMode(args:Array<String>){
|
||||||
Mode.setVideoMode(Std.parseInt(args[0]), Std.parseInt(args[1]), Std.parseInt(args[2]));
|
Mode.setVideoMode(Std.parseInt(args[0]), Std.parseInt(args[1]), Std.parseInt(args[2]));
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user