static public void StartInitFlow() { BubConsole.CSay("Looking for Init script!"); var mainfile = ""; foreach (string e in SBubble.ResFiles) { var ce = e.ToUpper(); if (ce == "INIT.LUA" || qstr.Suffixed(ce, "/INIT.LUA") || ce == "INIT.NIL" || qstr.Suffixed(ce, "/INIT.NIL")) { mainfile = e; } } if (mainfile == "") { Error.GoError("Startup error", "INIT.LUA or INIT.NIL required somewhere in any folder.", "None have been found"); } else { //mainfile = "Script/Viezelul.lua"; GoHardFlow(BubConsole.Flow); try { BubConsole.WriteLine($"Loading Init Script: {mainfile}"); SBubble.NewState("$INIT", mainfile); //SBubble.State("$INIT").state.DoString("local fc = ''\nfor k,v in pairs(_G) do\n fc=fc .. type(v) .. ' ' ..k..'\\n'\n end\n error(fc)"); // debug line SBubble.State("$INIT").state.DoString("assert(type(Bubble_Init)=='function','Function expected for Bubble_Init, got '..type(Bubble_Init))\nBubble_Init()"); } catch (Exception e) { Error.GoError("Init Error", e.Message, ""); } } }
private APIFlow(string state) { State = state; var s = SBubble.State(state).state; s["Bubble_Flow"] = this; SBubble.State(state).DoString(QuickStream.StringFromEmbed("Flow.lua"), "Flow Management"); }
public Bubble_Audio(string s) { var state = SBubble.State(s).state; var script = QuickStream.StringFromEmbed("Audio.nil"); state["Bubble_Audio"] = this; SBubble.DoNIL(s, script, "Audio init script"); }
public void DoStateLua(string s, string script, string chunk = "LUA:DOSTATE") { try { SBubble.State(s).DoString(script, chunk); } catch (Exception Uitzondering) { SBubble.MyError($"LuaDoString(\"{s}\",\"{script}\",\"{chunk}\"):", Uitzondering.Message, ""); } }
private Bubble_Input(string state) { var script = QuickStream.StringFromEmbed("Input.lua"); SBubble.State(state).state["Bubble_Input"] = this; SBubble.DoNIL(state, "#macro MouseLeft 1\n#macro MouseRight 2\n#macro MouseCenter 3", "Mouse Button macros"); SBubble.State(state).DoString(script, "Input API header"); }
public static void LetsGo() { #region Install Error Manager, and the global engine! NALACore.Core.Window.Title = SBubble.Title; #endregion #region The base MonoGame stuff SBubble.AddInit(delegate(string v) { SBubble.State(v).DoString($"function {FlowManager.NOTHING}() end", "Alright move along, nothing to see here!"); }); SBubble.AddInit(BubbleConsole.StateInit); SBubble.AddInit(BubbleGraphics.InitGraphics); SBubble.AddInit(Bubble_Audio.Init); SBubble.AddInit(APIFlow.Init); SBubble.AddInit(BubbleSuperGlobal.Init); SBubble.AddInit(Bubble_Input.Init); SBubble.AddInit(Bubble_Save.Init); SBubble.AddInit(Bubble_Conf.Init); SBubble.AddInit(Bubble_GameJolt.Init); SBubble.AddInit(BubbleTimer.Init); SBubble.AddInit(Bubble_Swap.Init); #endregion #region Extras to use in savegames Bubble_Save.SaveXtra["RPGPARTY"] = delegate(UseJCR6.TJCRCreate j, string dir) { RPG.RPGSave(j, $"XTRA/{dir}"); }; Bubble_Save.LoadXtra["RPGPARTY"] = delegate(UseJCR6.TJCRDIR j, string dir) { RPG.RPGLoad(j, $"XTRA/{dir}"); return(true); }; Bubble_Save.SaveXtra["SWAP"] = Bubble_Swap.SwapSave; Bubble_Save.LoadXtra["SWAP"] = Bubble_Swap.SwapLoad; #endregion #region The stuff needed for NALA in particular // Own APIs for NIL and Lua //SBubble.AddInit(MapScriptAPI.API_Init); SBubble.AddInit(RPG_API.Init); // Kthura Init Kthura.SetDefaultTextureJCR(SBubble.JCR); // Textures are all in the same project KthuraDraw.DrawDriver = new KthuraDrawMonoGame(); // Tell Kthura to use the MonoGame Driver to display the map KthuraDrawMonoGame.CrashOnNoTex = delegate(string msg) { SBubble.MyError("Kthura Texture Error", msg, ""); }; // SBubble Kthura API SBubble.AddInit(KthuraBubble.KthuraBubble.Init); SBubble.AddInit(KthuraBubble.KthBlockAPI.Init); SBubble.AddInit(KthuraBubble.KthuraAbyssGenerator.Init); // TODO: API for TeddyBear // TODO: API for Swap Data Manager // TODO: API for RPGStat RPG.JCRSTORAGE = "lzma"; #endregion // Start init script FlowManager.StartInitFlow(); }
static public void API_Init(string namestate) { var ret = new MapScriptAPI(); var state = SBubble.State(namestate).state; var script = QuickStream.StringFromEmbed("MapScriptAPI.nil"); state["NALAMSAPI"] = ret; SBubble.DoNIL(namestate, script, "MapScript init script"); }
static public void Init(string vm) { var nieuw = new BubbleTimer(); var state = SBubble.State(vm).state; nieuw.statename = vm; state["API_BUBBLE_TIMER"] = nieuw; state.DoString(Script, "Timer init script"); }
static public void Init(string state) { me = new RPG_API(); var script = QuickStream.StringFromEmbed("RPG_API.nil"); SBubble.State(state).state["NALA_RPG"] = me; SBubble.DoNIL(state, script, "Link code RPG API"); me.statename = state; }
public static void Init(string s) { var state = SBubble.State(s).state; var script = QuickStream.StringFromEmbed("Bubble_Conf.nil"); state["Bubble_Conf"] = new Bubble_Conf(); Debug.WriteLine($"Initiating state: {s}"); BubConsole.CSay($"State \"{s}\" being prepared for Bubble_Conf"); SBubble.DoNIL(s, script, "Message box init script"); }
public void LoadState(string s, string file) { s = s.ToUpper(); if (qstr.Prefixed(s, "FLOW_")) { throw new Exception("Non-Flow states may NOT be prefixed with FLOW_"); } SBubble.NewState(s, file); SBubble.State(s).state.DoString("if BUB_Load then BUB_Load() end"); }
private BubbleGraphics(Lua state, string id) { var bt = QuickStream.OpenEmbedded("Graphics.nil"); var script = bt.ReadString((int)bt.Size); vm = id; bt.Close(); state["BubbleGraphics"] = this; SBubble.DoNIL(id, script, "Graphics init script"); SBubble.State(id).DoString("Color = SetColor", "HACKING!"); // Prevent confusion since the console's not really accesible anyway }
public void LoadFlow(string flow, string file) { flow = flow.ToUpper(); if (!qstr.Prefixed(flow, "FLOW_")) { flow = $"FLOW_{flow}"; } SBubble.NewState(flow, file); BubConsole.WriteLine($"Created new flow: {flow}"); SBubble.State(flow).state.DoString("if BUB_Load then BUB_Load() end"); }
static public void Init(string astatename) { var Kth = new KthuraBubble(); var S = SBubble.State(astatename).state; S["BKTHURA"] = Kth; Kth.statename = astatename; var bt = QuickStream.OpenEmbedded("KthuraBubble.nil"); var l = bt.ReadString((int)bt.Size); bt.Close(); SBubble.DoNIL(astatename, l, "Kthura API Link Script"); }
public bool GetBoolLua(string state, string call, string chunk = "LUA.GETBOOL") { var O = SBubble.State(state).DoString($"return {call}", chunk); if (O.Length == 0) { SBubble.MyError("GetBoolLuaError", "Nothing has been properly returned!", ""); return(false); } else { return((bool)O[0]); } }
static public void Init(string statename) { var me = new Bubble_Swap(); try { var script = QuickStream.StringFromEmbed("Bubble_Swap.nil"); me.statename = statename; me.State = SBubble.State(statename); me.LuaState = me.State.state; me.LuaState["Bubble_Swap"] = me; SBubble.DoNIL(statename, script, "BUBBLE_Swap Init"); } catch (Exception DoffeEllende) { SBubble.MyError("Init BUBBLE_Swap Error", DoffeEllende.Message, $"{SBubble.TraceLua(statename)}\n\n{DoffeEllende.StackTrace}"); } }
static public void NewSoftFlow(string tag, string scriptfile) { //BubConsole.CSay($"Starting new state {tag} with script {scriptfile}"); tag = tag.ToUpper(); if (!qstr.Prefixed(tag, "FLOW_")) { tag = $"FLOW_{tag}"; } SBubble.NewState(tag, scriptfile); try { SBubble.State(tag).DoString($"(BUB_Load or {NOTHING})()", "LOAD"); } catch (Exception NotAnExceptionJustAnErrorBozos) { SBubble.MyError("Load Error", NotAnExceptionJustAnErrorBozos.Message, ""); } }
public string GetStringLua(string state, string call, string chunk = "LUA.GETSTRING") { try { var O = SBubble.State(state).DoString($"return {call}", chunk); if (O == null || O.Length == 0) { SBubble.MyError("GetStringLuaError", "Nothing has been properly returned!", ""); return(""); } else { return((string)O[0]); } } catch (Exception Kut) { SBubble.MyError($"LuaGetString(\"{state}\",\"{call}\",\"{chunk}\"):", Kut.Message, ""); return("Kilo Utrecht Tango"); } }
public void GoToFlow(string flow) { flow = flow.ToUpper(); if (!qstr.Prefixed(flow, "FLOW_")) { flow = $"FLOW_{flow}"; } if (!SBubble.HaveState(flow)) { SBubble.MyError("Flow Management Error", $"GoToFlow: Flow {flow} doesn't exist!", SBubble.TraceLua(State)); } else { FlowManager.CurrentFlow = flow; BubConsole.WriteLine($"Flow set to: {flow}"); SBubble.State(flow).DoString("if BUB_Arrive then assert(type(BUB_Arrive)=='function','BUB_Arrive must be a function but it is a '..type(BUB_Arrive)) BUB_Arrive() end"); } }
public int GetIntLua(string state, string call, string chunk = "LUA.GETINT") { try { var O = SBubble.State(state).DoString($"return {call}", chunk); if (O.Length == 0) { SBubble.MyError("GetIntLuaError", "Nothing has been properly returned!", ""); return(0); } else { return(Convert.ToInt32(O[0])); } } catch (Exception Klote) { SBubble.MyError($"LuaGetInt(\"{state}\",\"{call}\",\"{chunk}\"):", Klote.Message, ""); return(0); } }
static public void StateInit(string vm) { api = new BubbleConsole(); var s = SBubble.State(vm).state; s["Bubble_Console_Console"] = api; //* SBubble.DoNIL(vm, @" #accept Bubble_Console_Console global void CWriteLine(string msg,int r, int g, int b) assert(r>=0 and r<=255 and g>=0 and g<=255 and b>=0 and b<=255,'CWriteLine color setting invalid! ('..r..','..g..','..b..')') Bubble_Console_Console:WriteLine(msg,r,g,b) end global void CPrint(string msg,r,g,b) CWriteLine(msg,tonumber(r) or 255, tonumber(g) or 255, tonumber(b) or 255) end global void CSayColor(int r, int g, int b) assert(r>=0 and r<=255 and g>=0 and g<=255 and b>=0 and b<=255,'CWriteLine color setting invalid!') Bubble_Console_Console:SetCSayColor(r,g,b) end global void CSay(string msg) Bubble_Console_Console:CSay(msg) end global void GoConsole() Bubble_Console_Console:GoConsole() end // It's USELESS to use this in your script, as this will either be ignored or lead to conflicts // The Console Command manager needs this! global void ConsoleSuccess(bool succ) Bubble_Console_Console.CommandSuccess = succ end ", "Console initizer"); }
static void Main(string[] args) { JCR6_lzma.Init(); JCR6_zlib.Init(); JCR6_jxsrcca.Init(); SBubble.Init("CLI", ErrorHandler); var mainfile = ""; foreach (string e in SBubble.ResFiles) { var ce = e.ToUpper(); if (ce == "MAIN.LUA" || qstr.Suffixed(ce, "/MAIN.LUA")) { mainfile = e; } } if (mainfile == "") { ErrorHandler("Bubble", "No main script could be found", ""); } SBubble.NewState("MAIN", mainfile); object[] r = null; string cmd = ""; try { cmd = $"assert(main and type(main)==\"function\",\"No 'main' function found!\")\nreturn main({SBubble.StringArray2Lua(args)},\"{MKL.MyExe.Replace("\\", "/")}\")"; r = SBubble.State("MAIN").DoString(cmd); } catch (Exception e) { ErrorHandler("Main call", e.Message, cmd); } long exitcode = 0; try { if (r != null && r[0] != null) { exitcode = (long)(r[0]); } } catch (Exception e) { ErrorHandler("Main Function", "Main function must either return 'nil' or an integer value!", $"{e.Message}\n\n{r[0].GetType()}"); } Environment.Exit((int)exitcode); }
public static void Init(string vm) { var api = new KthBlockAPI(); var s = SBubble.State(vm).state; s["KTHURA_BLOCK"] = api; //* SBubble.DoNIL(vm, @" global void ShowBlockMap(map,string Layer,int x, int y) switch type(map) case 'int' KTHURA_BLOCK:ComeToMe(map,Layer,x,y) case 'table' KTHURA_BLOCK:ComeToMe(map.ID,Layer,x,y) default error('Blockmap request faulty!') end end ", "Console initizer"); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // TQMG TQMG.Init(graphics, GraphicsDevice, spriteBatch, SBubble.JCR); // Make sure all states consider at least these! SBubble.AddInit(delegate(string v) { SBubble.State(v).DoString($"function {FlowManager.NOTHING}() end", "Alright move along, nothing to see here!"); }); SBubble.AddInit(BubbleConsole.StateInit); SBubble.AddInit(BubbleGraphics.InitGraphics); SBubble.AddInit(Bubble_Audio.Init); SBubble.AddInit(APIFlow.Init); SBubble.AddInit(BubbleSuperGlobal.Init); SBubble.AddInit(Bubble_Input.Init); SBubble.AddInit(Bubble_Save.Init); // Start init script FlowManager.StartInitFlow(); // Error Test //Error.GoError("Test", "TestError", "Traceme"); }
static public void InitGraphics(string vm) { new BubbleGraphics(SBubble.State(vm).state, vm); }
void Exe(string rawcmd) { rawcmd = rawcmd.Trim(); if (rawcmd == "") { return; } string[] chopped; { var chop = new List <string>(); var str = false; var s = ""; for (int i = 0; i < rawcmd.Length; i++) { switch (rawcmd[i]) { case '"': str = !str; break; case ' ': if (str) { goto default; // diryt way to fallthrough, but it's the only thing C# supports! } chop.Add(s); s = ""; break; default: s += rawcmd[i]; break; } } chop.Add(s); chopped = chop.ToArray(); } string cmd = chopped[0].ToUpper(); string[] arg = new string[0]; if (chopped.Length > 1) { arg = chopped.Skip(1).Take(chopped.Length - 1).ToArray(); } switch (cmd) { case "F**K": case "PISS": case "SHIT": WriteLine("?Did you mother never tell you not to say such words?", 255, 0, 0); break; case "BYE": case "EXIT": case "QUIT": FlowManager.TimeToDie = true; break; case "SAY": foreach (string a in arg) { CSay(a); } break; default: try { // Need to group as some extra vars are needed! { var CFlow = FlowManager.CurrentFlow; var FFlow = $"FLOW_{CFlow}"; var SFlow = SBubble.State(CFlow); var JArgs = ""; BubConsScriptSuccess = false; foreach (string a in arg) { if (JArgs != "") { JArgs += ", "; } JArgs += $"\"{a}\""; } // Execute local if available SFlow.DoString($"if not ConsoleCommands then ConsoleSuccess(false) return end\nif not ConsoleCommands['.hasmember']('{cmd}') then ConsoleSuccess(false) return end\nConsoleSuccess(true)\nConsoleCommands.{cmd}({JArgs})"); if (BubConsScriptSuccess) { break; // If done, get outta here } // Load the global commands if needed if (!SBubble.HaveState("DEBUG_CONSOLE_COMMANDS")) { WriteLine("Since this is the first time the Debug Console Commands are neeed", 255, 180, 0); WriteLine("The commands need to be loaded now, just a moment", 255, 180, 0); SBubble.NewState("DEBUG_CONSOLE_COMMANDS", "Script/System/Console.nil"); WriteLine("Ok", 0, 255, 255); } // Execute gloal SBubble.State("DEBUG_CONSOLE_COMMANDS").DoString($"if not ConsoleCommands then CSay('Hey buddy! No ConsoleCommands group exists!') ConsoleSuccess(false) return end\nif not ConsoleCommands['.hasmember']('{cmd}') then ConsoleSuccess(false) return end\nConsoleSuccess(true)\nConsoleCommands.{cmd}({JArgs})"); if (BubConsScriptSuccess) { break; // If done, get outta here } } // Failure, or so it seems. WriteLine("?Not understood", 255, 0, 0); } catch (Exception NietGoed) { WriteLine("?.NET error", 255, 0, 0); WriteLine($" {NietGoed.Message}", 255, 255, 0); } break; } }