Moved ConVar related files to engine
This commit is contained in:
@@ -7,7 +7,7 @@ import openfl.display.Sprite;
|
||||
import openfl.events.Event;
|
||||
import assets.Scanner;
|
||||
import assets.HTex;
|
||||
import game.ui.ConVar;
|
||||
import engine.ConVar;
|
||||
import game.ui.console.Console;
|
||||
|
||||
class Game
|
||||
@@ -41,20 +41,9 @@ class Game
|
||||
uiLayer = new Sprite();
|
||||
stage.addChild(gameLayer);
|
||||
stage.addChild(uiLayer);
|
||||
//player.graphics.lineStyle(2,0xFF0000);
|
||||
//player.graphics.drawRect(0,0,16,16);
|
||||
// var bitmapData:BitmapData = Assets.getBitmapData("textures/sprites/character.png");
|
||||
//player = new Player();
|
||||
//gameLayer.addChild(player.sprite);
|
||||
uiLayer.addChild(console);
|
||||
var cvar_cl_kankerlow:CVar = ConVar.registerCVar("cl_kankerlow", CInt, 10, FCVAR_ARCHIVE, "is de speler een kankerlow?",null,false,false,0,0,false);
|
||||
//var sheet:SpriteSheet = new SpriteSheet(sheetData);
|
||||
//var playerBitmap:Bitmap = new Bitmap(Tileset.tilesetMap["testsheet"].tileMap["testTile5"]);
|
||||
//var someotherbitmap:Bitmap = new Bitmap(Tileset.tilesetMap["testsheet"].tileMap["testTile3"]);
|
||||
//playerBitmap.scaleX = playerBitmap.scaleY = 10;
|
||||
//player.addChild(playerBitmap);
|
||||
//TextureData.parseConfig();
|
||||
//Sys.
|
||||
//var cvar_cl_kankerlow:CVar = ConVar.registerCVar("cl_kankerlow", CInt, 10, FCVAR_ARCHIVE, "is de speler een kankerlow?",null,false,false,0,0,false);
|
||||
|
||||
}
|
||||
public function onEnterFrame(e:Event):Void
|
||||
{
|
||||
|
||||
@@ -8,9 +8,9 @@ import game.video.Mode;
|
||||
import openfl.events.KeyboardEvent;
|
||||
import openfl.ui.Keyboard in Kb;
|
||||
import openfl.Lib;
|
||||
import game.ui.CVarType;
|
||||
import game.ui.CVar;
|
||||
import game.ui.ConVar;
|
||||
import engine.enums.CVarType;
|
||||
import engine.typedefs.CVar;
|
||||
import engine.ConVar;
|
||||
|
||||
class Input{
|
||||
public static var keys:Map<Int,Bool> = [];
|
||||
@@ -58,8 +58,10 @@ class Input{
|
||||
|
||||
}
|
||||
public static function onKeyIsUp(e:KeyboardEvent){
|
||||
if(bindMap[keyNameMap[e.keyCode]].indexOf("+") == 0){
|
||||
Console.consoleInstance.parseCmd(StringTools.replace(bindMap[keyNameMap[e.keyCode]],"+","-"));
|
||||
if(!Std.isOfType(Lib.current.stage.focus,TextField)){
|
||||
if(bindMap[keyNameMap[e.keyCode]].indexOf("+") == 0){
|
||||
Console.consoleInstance.parseCmd(StringTools.replace(bindMap[keyNameMap[e.keyCode]],"+","-"));
|
||||
}
|
||||
}
|
||||
keys[e.keyCode] = false;
|
||||
}
|
||||
@@ -112,6 +114,12 @@ class Input{
|
||||
if (keys[Kb.DOWN] && !keysLast[Kb.DOWN]){
|
||||
Console.histNext();
|
||||
}
|
||||
|
||||
}
|
||||
if(Console.consoleInstance.visible){
|
||||
if (keys[Kb.ESCAPE]){
|
||||
Console.toggle();
|
||||
}
|
||||
}
|
||||
keysLast = keys.copy();
|
||||
}
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
package game.ui;
|
||||
|
||||
|
||||
typedef CVar = {
|
||||
var name:String;
|
||||
var type:CVarType;
|
||||
var value:Dynamic;
|
||||
@:optional var callback:Void -> Void;
|
||||
};
|
||||
@@ -1,9 +0,0 @@
|
||||
package game.ui;
|
||||
|
||||
enum CVarType {
|
||||
CInt;
|
||||
CFloat;
|
||||
CString;
|
||||
CBool;
|
||||
CCmd;
|
||||
}
|
||||
@@ -1,135 +0,0 @@
|
||||
package game.ui;
|
||||
|
||||
import haxe.Constraints.Function;
|
||||
import engine.typedefs.CVar;
|
||||
import engine.typedefs.CCmd;
|
||||
import engine.enums.CVarType;
|
||||
import engine.enums.CVarFlag;
|
||||
import game.ui.console.Console;
|
||||
|
||||
|
||||
class ConVar{
|
||||
static var CVarMap:Map<String, CVar> = [];
|
||||
public static inline function registerCVar(_name:String, _type:CVarType, _value, _callback:Void->Void,_callOnSet:Bool=false)
|
||||
{
|
||||
if(CVarMap[_name]!=null){
|
||||
|
||||
return;
|
||||
}
|
||||
CVarMap[_name] = {
|
||||
name : _name,
|
||||
type : _type,
|
||||
value : _value,
|
||||
callback : _callback == null ? ()->{} : _callback
|
||||
}
|
||||
}
|
||||
public static inline function setCVar(_name:String, _value:Dynamic)
|
||||
{
|
||||
if(CVarMap[_name]!=null || CCmdMap[_name]!=null){
|
||||
Console.devMsg("Tried setting already defined command: " + _name + ", returning null instead");
|
||||
return null;
|
||||
}
|
||||
var cmd:CCmd = CCmdMap[_name] = {
|
||||
name : _name,
|
||||
callback : _callback
|
||||
}
|
||||
return cmd;
|
||||
}
|
||||
public static inline function setCVar(_name:String, _value:Dynamic):Void
|
||||
{
|
||||
var cv = getCVar(_name);
|
||||
if(cv != null){
|
||||
switch(cv.type){
|
||||
case CInt,CFloat:
|
||||
if(cv.bMax && _value > cv.fMax) _value = cv.fMax;
|
||||
if(cv.bMin && _value < cv.fMin) _value = cv.fMin;
|
||||
case CBool:
|
||||
if(Std.isOfType(_value, String)){
|
||||
var v:String = _value;
|
||||
_value = v.toLowerCase();
|
||||
if(_value == "true" || _value == "1"){
|
||||
_value = true;
|
||||
}
|
||||
else{
|
||||
_value = false;
|
||||
}
|
||||
}
|
||||
else if(Std.isOfType(_value, Int) || Std.isOfType(_value, Float)){
|
||||
if(_value %2 == 0){
|
||||
_value = false;
|
||||
}
|
||||
else{
|
||||
_value = true;
|
||||
}
|
||||
}
|
||||
else if(Std.isOfType(_value, Bool)){
|
||||
//do nothing
|
||||
}
|
||||
else{
|
||||
_value = cv.value;
|
||||
}
|
||||
case CString:
|
||||
_value = Std.string(_value);
|
||||
|
||||
}
|
||||
cv.value = _value;
|
||||
cv.callback();
|
||||
|
||||
}
|
||||
else{
|
||||
Console.consoleIndex.devMsg("trying to set null convar '"+_name+"'");
|
||||
}
|
||||
|
||||
}
|
||||
public static inline function isCVar(_name:String){
|
||||
return (CVarMap[_name] != null);
|
||||
|
||||
}
|
||||
public static inline function isCmd(_name:String){
|
||||
return (CCmdMap[_name] != null);
|
||||
}
|
||||
public static inline function runCmd(_name:String, _args:Array<String>){
|
||||
if(CCmdMap[_name] != null){
|
||||
CCmdMap[_name].callback(_args);
|
||||
}
|
||||
}
|
||||
public static inline function getCVarNames():Array<String>
|
||||
{
|
||||
var keys:Array<String> = [
|
||||
for(iterator in [CCmdMap.keys(),CVarMap.keys()]){
|
||||
for(key in iterator){
|
||||
key;
|
||||
}
|
||||
}
|
||||
];
|
||||
keys.sort(function(a:String, b:String):Int {
|
||||
a = a.toUpperCase();
|
||||
b = b.toUpperCase();
|
||||
if (a < b) {
|
||||
return -1;
|
||||
}
|
||||
else if (a > b) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
return keys;
|
||||
}
|
||||
public static var cmdList:CCmd = ConVar.registerCCmd("list", (cArgs:Array<String>)->{
|
||||
var keys:Array<String> = getCVarNames();
|
||||
for(key in keys){
|
||||
if(CVarMap[key] != null){
|
||||
Console.devMsg(key+" "+CVarMap[key].value);
|
||||
}
|
||||
else{
|
||||
Console.devMsg(key);
|
||||
}
|
||||
}
|
||||
});
|
||||
public static inline function getCVar(_name:String):CVar
|
||||
{
|
||||
return CVarMap[_name];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,7 +12,7 @@ import openfl.Assets;
|
||||
import openfl.text.TextFormat;
|
||||
import openfl.text.TextFieldType;
|
||||
import engine.typedefs.CVar;
|
||||
import game.ui.ConVar;
|
||||
import engine.ConVar;
|
||||
import engine.typedefs.CCmd;
|
||||
import game.ui.console.elements.ConsoleInput;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package game.video;
|
||||
|
||||
import engine.ConVar;
|
||||
import openfl.Lib;
|
||||
import openfl.display.StageDisplayState;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user