From 12a3a77053c645b50a8845a382daf8366fa0c2c0 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Mon, 2 Sep 2019 21:53:47 +0300 Subject: [PATCH] add string cvars --- src/game/g_console.pas | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/game/g_console.pas b/src/game/g_console.pas index 5953403..4723978 100644 --- a/src/game/g_console.pas +++ b/src/game/g_console.pas @@ -64,6 +64,7 @@ procedure conwritefln (const s: AnsiString; args: array of const; show: Boolean= procedure conRegVar (const conname: AnsiString; pvar: PBoolean; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false; ahidden: Boolean=false); overload; procedure conRegVar (const conname: AnsiString; pvar: PSingle; amin, amax: Single; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false; ahidden: Boolean=false); overload; procedure conRegVar (const conname: AnsiString; pvar: PInteger; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false; ahidden: Boolean=false); overload; +procedure conRegVar (const conname: AnsiString; pvar: PAnsiString; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false; ahidden: Boolean=false); overload; // <0: no arg; 0/1: true/false function conGetBoolArg (p: SSArray; idx: Integer): Integer; @@ -282,6 +283,24 @@ begin end; +procedure strVarHandler (me: PCommand; p: SSArray); +var + old: AnsiString; +begin + if (Length(p) <> 2) then + begin + conwritefln('%s %s', [me.cmd, PAnsiString(me.ptr)^]); + end + else + begin + old := PAnsiString(me.ptr)^; + PAnsiString(me.ptr)^ := p[1]; + if PAnsiString(me.ptr)^ <> old then + g_Console_WriteGameConfig(); + end; +end; + + procedure conRegVar (const conname: AnsiString; pvar: PBoolean; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false; ahidden: Boolean=false); overload; var f: Integer; @@ -324,6 +343,26 @@ begin end; +procedure conRegVar (const conname: AnsiString; pvar: PAnsiString; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false; ahidden: Boolean=false); overload; +var + f: Integer; + cp: PCommand; +begin + f := Length(commands); + SetLength(commands, f+1); + cp := @commands[f]; + cp.cmd := LowerCase(conname); + cp.proc := nil; + cp.procEx := strVarHandler; + cp.help := ahelp; + cp.hidden := ahidden; + cp.ptr := pvar; + cp.msg := amsg; + cp.cheat := acheat; + cp.action := -1; + cp.player := -1; +end; + // ////////////////////////////////////////////////////////////////////////// // type PVarSingle = ^TVarSingle; -- 2.29.2