public void AnalyzeGlobals() { if (_orig.Globals.Count != _mod.Globals.Count) { _output.WriteLine($"GLOBALS COUNT MISMATCH! Original: {_orig.Globals.Count} Modified: {_mod.Globals.Count}"); return; } for (int i = 0; i < _orig.Globals.Count; i++) { ScriptGlobal orig_Glo = _orig.Globals[i]; ScriptGlobal mod_Glo = _mod.Globals[i]; _currentScriptObject = mod_Glo; if (!CompareGlobals(orig_Glo, mod_Glo)) { WriteScriptObject(); _output.WriteLine($"Global Index: {i} - Information Mismatch"); continue; } var orig_Exp = _orig.Expressions.FindExpression(orig_Glo.ExpressionIndex); var mod_Exp = _mod.Expressions.FindExpression(mod_Glo.ExpressionIndex); _output.Indent++; WalkExpressions(orig_Exp, mod_Exp); _output.Indent--; _corrupt = false; } }
/// <summary> /// Processes global declarations. Opens a datum. Creates the global node. Pushes the value type. /// </summary> /// <param name="context"></param> public override void EnterGlobalDeclaration(HS_Gen1Parser.GlobalDeclarationContext context) { if (_debug) { _logger.Global(context, CompilerContextAction.Enter); } // Create a new Global and add it to the table. string valueType = context.VALUETYPE().GetTextSanitized(); ScriptGlobal glo = new ScriptGlobal() { Name = context.ID().GetTextSanitized(), Type = (short)_opcodes.GetTypeInfo(valueType).Opcode, ExpressionIndex = _currentIndex, }; _globals.Add(glo); if (_debug) { _logger.Information($"A global declaration was detected by the parser. The index {_globalPushIndex} will be opened."); } OpenDatum(_globalPushIndex); _expectedTypes.PushType(valueType); }
public bool worldmap_coords_clicked(MouseEventArgs e, int x, int y) { int GameX = Display.PixelToGameCoords(x); int GameY = Display.PixelToGameCoords(y); if (Control.ModifierKeys == Keys.Control && e.Button == MouseButtons.Left) { ActionDone = true; if (Control.MouseButtons == MouseButtons.Right) { if (CurrentRoute == null) { MessageBox.Show("No route currently constructed."); return(false); } else { CurrentRoute.WayPoints = new List <TrainWaypoint>(); } } //MessageBox.Show("Left with ctrl."); if (CurrentRoute == null) { TrainRoute route = CreateRoute(); if (route == null) { return(false); } route.WayPoints = new List <TrainWaypoint>(); CurrentRoute = route; //Routes.Add(route); } TrainWaypoint wp = CreateWaypoint(GameX, GameY); if (wp == null || CurrentRoute == null) { return(false); } CurrentRoute.WayPoints.Add(wp); ScriptGlobal.RefreshWorldMap(); return(true); } if (Control.ModifierKeys == Keys.Control && e.Button == MouseButtons.Right) { TrainWaypoint wp = GetWaypoint(GameX, GameY); if (wp == null) { return(false); } DeleteWaypoint(wp); ScriptGlobal.RefreshWorldMap(); return(true); } return(false); }
private readonly ScriptInstruction[] m_scriptInstructions; //指令集 public ScriptContext(Script script, string breviary, ScriptFunctionData functionData, double[] constDouble, long[] constLong, string[] constString, ScriptContext[] constContexts, ScriptClassData[] constClasses) { m_script = script; m_global = script.Global; this.constDouble = constDouble; this.constLong = constLong; this.constString = constString; this.constContexts = constContexts; this.constClasses = constClasses; this.internalCount = functionData.internalCount; m_Breviary = breviary; m_FunctionData = functionData; m_scriptInstructions = functionData.scriptInstructions; }
public void main_form_loaded() { FormLoaded = true; ToolStripMenuItem SaveMenuItem = new ToolStripMenuItem("Save Train Routes"); SaveMenuItem.Click += SaveRoutes_Click; foreach (ToolStripMenuItem Item in MainForm.MainMenuStrip.Items) { if (Item.Name == "fileToolStripMenuItem") { Item.DropDownItems.Insert(2, SaveMenuItem); } } LoadRoutes(); ScriptGlobal.RefreshWorldMap(); GetControl("pnlWorldMap").Focus(); }
internal static void Init() { LoggerInternal = LogManager.GetLogger(nameof(ScriptService)); EnumTypes = typeof(Engine).Assembly.GetTypes().Where(x => x.IsEnum); CacheTypes(); Lua = new Lua(LuaIntegerType.Int32, LuaFloatType.Double); GlobalEnvironment = new ScriptGlobal(Lua); ExecutionQueue = new ConcurrentWorkQueue <Execution>(execution => { if (!execution.TryFulfill()) { ExecutionQueue.Enqueue(execution); // send to back of queue } else { execution.Set(); } }); }
void ScriptingDefinitionsToStream(Import import) { if (Head.ScriptFunctionsCount > 0) { var sfunc = new ScriptFunction(); foreach (Import.ScriptFunction sc in import.ScriptFunctions.Values) { sfunc.Reset(sc); sfunc.Write(MemoryStream); } } if (Head.ScriptGlobalsCount > 0) { var sglob = new ScriptGlobal(); foreach (Import.ScriptGlobal sc in import.ScriptGlobals.Values) { sglob.Reset(sc); sglob.Write(MemoryStream); } } }
/// <summary> /// Create the global context for the runtime. /// </summary> internal static async ValueTask <ScriptGlobal> CreateGlobalAsync( IContext e, IScriptValue say = null, IScriptValue storage = null) { var context = new ScriptGlobal { ["author"] = ScriptValue.FromObject(new ScriptUser(e.GetAuthor())), ["channel"] = ScriptValue.FromObject(new ScriptChannel(e.GetChannel())), ["message"] = ScriptValue.FromObject(new ScriptMessage(e.GetMessage())), ["args"] = await CreateArgumentsAsync(e), ["say"] = say ?? new ScriptSayFunction(), ["embed"] = new CreateEmbedFunction(), ["storage"] = storage ?? await CreateStorageAsync(e) }; if (e.GetGuild() != null) { context["guild"] = ScriptValue.FromObject(new ScriptGuild(e.GetGuild())); } return(context); }
void ProcessScriptGlobals(ProjectState state, IO.XmlStream s) { foreach (XmlNode n in s.Cursor.ChildNodes) { if (n.Name != "global") { continue; } s.SaveCursor(n); var sg = new ScriptGlobal(state, s); s.RestoreCursor(); string name_str = sg.ToString(); if (state.scriptingInterface.Globals.Contains(name_str)) { Debug.LogFile.WriteLine("Engine already contains a {0} named '{1}', ignoring...", "script global", name_str); continue; } try { ScriptGlobals.Add(name_str, sg); } catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "script global definition", name_str); } } }
void ProcessScriptGlobals(ProjectState state, IO.XmlStream s) { foreach (XmlNode n in s.Cursor.ChildNodes) { if (n.Name != "global") continue; s.SaveCursor(n); var sg = new ScriptGlobal(state, s); s.RestoreCursor(); string name_str = sg.ToString(); if (state.scriptingInterface.Globals.Contains(name_str)) { Debug.LogFile.WriteLine("Engine already contains a {0} named '{1}', ignoring...", "script global", name_str); continue; } try { ScriptGlobals.Add(name_str, sg); } catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "script global definition", name_str); } } }
public GlobalPairs(ScriptGlobal global, ScriptMap itorResult) { m_Enumerator = global.GetEnumerator(); m_ItorResult = itorResult; }
private bool CompareGlobals(ScriptGlobal orig, ScriptGlobal mod) { bool index = orig.ExpressionIndex.IsValid && mod.ExpressionIndex.IsValid; return(index && (orig.Name == mod.Name) && (orig.Type == mod.Type)); }
/// <summary> /// Process a XML file containing CheApe definitions /// </summary> /// <param name="state"></param> /// <param name="s"></param> private void ProcessFile(ProjectState state, BlamLib.IO.XmlStream s) { int complexity = 1 + PreprocessXmlNodeComplexity(); BlamVersion def_engine = BlamVersion.Unknown; s.ReadAttribute("game", ref def_engine); if (def_engine != state.Definition.Engine) { Debug.Assert.If(false, "CheApe definition '{0}' is for {1}. Expected a {2} definition.", s.FileName, def_engine, state.Definition.Engine); } else { string name_str; foreach (XmlNode n in s.Cursor.ChildNodes) { switch (n.Name) { #region Enums case "enums": s.SaveCursor(n); foreach (XmlNode n2 in s.Cursor.ChildNodes) { if (n2.Name != "Enum") continue; s.SaveCursor(n2); StringList list = new StringList(state, s); s.RestoreCursor(); name_str = list.ToString(); try { Enums.Add(name_str, list); } catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "enum definition", name_str); } } s.RestoreCursor(); break; #endregion #region Flags case "flags": s.SaveCursor(n); foreach (XmlNode n2 in s.Cursor.ChildNodes) { if (n2.Name != "Flag") continue; s.SaveCursor(n2); StringList list = new StringList(state, s); s.RestoreCursor(); name_str = list.ToString(); try { Flags.Add(name_str, list); } catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "flag definition", name_str); } } s.RestoreCursor(); break; #endregion #region Tag References case "references": s.SaveCursor(n); foreach (XmlNode n2 in s.Cursor.ChildNodes) { if (n2.Name != "Reference") continue; s.SaveCursor(n2); TagReference tagref = new TagReference(state, s); s.RestoreCursor(); name_str = tagref.ToString(); try { References.Add(name_str, tagref); } catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "tag reference definition", name_str); } } s.RestoreCursor(); break; #endregion #region Tag Data case "data": s.SaveCursor(n); foreach (XmlNode n2 in s.Cursor.ChildNodes) { if (n2.Name != "TagData") continue; s.SaveCursor(n2); TagData tagdata = new TagData(state, s); s.RestoreCursor(); name_str = tagdata.ToString(); try { Data.Add(name_str, tagdata); } catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "tag data definition", name_str); } } s.RestoreCursor(); break; #endregion #region Script Functions case "scriptFunctions": if (state.scriptingInterface == null) break; s.SaveCursor(n); foreach (XmlNode n2 in s.Cursor.ChildNodes) { if (n2.Name != "function") continue; s.SaveCursor(n2); ScriptFunction sc = new ScriptFunction(state, s); s.RestoreCursor(); name_str = sc.ToString(); if (state.scriptingInterface.Functions.Contains(name_str)) { Debug.LogFile.WriteLine("Engine already contains a {0} named '{1}', skipping...", "script function", name_str); continue; } try { ScriptFunctions.Add(name_str, sc); } catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "script function definition", name_str); } } s.RestoreCursor(); break; #endregion #region Script Globals case "scriptGlobals": if (state.scriptingInterface == null) break; s.SaveCursor(n); foreach (XmlNode n2 in s.Cursor.ChildNodes) { if (n2.Name != "global") continue; s.SaveCursor(n2); ScriptGlobal sc = new ScriptGlobal(state, s); s.RestoreCursor(); name_str = sc.ToString(); if (state.scriptingInterface.Globals.Contains(name_str)) { Debug.LogFile.WriteLine("Engine already contains a {0} named '{1}', ignoring...", "script global", name_str); continue; } try { ScriptGlobals.Add(name_str, sc); } catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "script global definition", name_str); } } s.RestoreCursor(); break; #endregion #region Fix-ups case "fixups": s.SaveCursor(n); foreach (XmlNode n2 in s.Cursor.ChildNodes) { if (n2.Name != "fixup") continue; s.SaveCursor(n2); Fixup fu = new Fixup(state, s); s.RestoreCursor(); name_str = fu.ToString(); try { Fixups.Add(name_str, fu); } catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "fix-up definition", name_str); } } s.RestoreCursor(); break; #endregion default: ProcessDefinition(n, state, s); break; } } } }
public void resources_loaded() { ScriptGlobal.RefreshWorldMap(); }
public abstract void CreateScope(ScriptGlobal scriptGlobals);
/// <summary> /// Process a XML file containing CheApe definitions /// </summary> /// <param name="state"></param> /// <param name="s"></param> private void ProcessFile(ProjectState state, BlamLib.IO.XmlStream s) { int complexity = 1 + PreprocessXmlNodeComplexity(); BlamVersion def_engine = BlamVersion.Unknown; s.ReadAttribute("game", ref def_engine); if (def_engine != state.Definition.Engine) { Debug.Assert.If(false, "CheApe definition '{0}' is for {1}. Expected a {2} definition.", s.FileName, def_engine, state.Definition.Engine); } else { string name_str; foreach (XmlNode n in s.Cursor.ChildNodes) { switch (n.Name) { #region Enums case "enums": s.SaveCursor(n); foreach (XmlNode n2 in s.Cursor.ChildNodes) { if (n2.Name != "Enum") { continue; } s.SaveCursor(n2); StringList list = new StringList(state, s); s.RestoreCursor(); name_str = list.ToString(); try { Enums.Add(name_str, list); } catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "enum definition", name_str); } } s.RestoreCursor(); break; #endregion #region Flags case "flags": s.SaveCursor(n); foreach (XmlNode n2 in s.Cursor.ChildNodes) { if (n2.Name != "Flag") { continue; } s.SaveCursor(n2); StringList list = new StringList(state, s); s.RestoreCursor(); name_str = list.ToString(); try { Flags.Add(name_str, list); } catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "flag definition", name_str); } } s.RestoreCursor(); break; #endregion #region Tag References case "references": s.SaveCursor(n); foreach (XmlNode n2 in s.Cursor.ChildNodes) { if (n2.Name != "Reference") { continue; } s.SaveCursor(n2); TagReference tagref = new TagReference(state, s); s.RestoreCursor(); name_str = tagref.ToString(); try { References.Add(name_str, tagref); } catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "tag reference definition", name_str); } } s.RestoreCursor(); break; #endregion #region Tag Data case "data": s.SaveCursor(n); foreach (XmlNode n2 in s.Cursor.ChildNodes) { if (n2.Name != "TagData") { continue; } s.SaveCursor(n2); TagData tagdata = new TagData(state, s); s.RestoreCursor(); name_str = tagdata.ToString(); try { Data.Add(name_str, tagdata); } catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "tag data definition", name_str); } } s.RestoreCursor(); break; #endregion #region Script Functions case "scriptFunctions": if (state.scriptingInterface == null) { break; } s.SaveCursor(n); foreach (XmlNode n2 in s.Cursor.ChildNodes) { if (n2.Name != "function") { continue; } s.SaveCursor(n2); ScriptFunction sc = new ScriptFunction(state, s); s.RestoreCursor(); name_str = sc.ToString(); if (state.scriptingInterface.Functions.Contains(name_str)) { Debug.LogFile.WriteLine("Engine already contains a {0} named '{1}', skipping...", "script function", name_str); continue; } try { ScriptFunctions.Add(name_str, sc); } catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "script function definition", name_str); } } s.RestoreCursor(); break; #endregion #region Script Globals case "scriptGlobals": if (state.scriptingInterface == null) { break; } s.SaveCursor(n); foreach (XmlNode n2 in s.Cursor.ChildNodes) { if (n2.Name != "global") { continue; } s.SaveCursor(n2); ScriptGlobal sc = new ScriptGlobal(state, s); s.RestoreCursor(); name_str = sc.ToString(); if (state.scriptingInterface.Globals.Contains(name_str)) { Debug.LogFile.WriteLine("Engine already contains a {0} named '{1}', ignoring...", "script global", name_str); continue; } try { ScriptGlobals.Add(name_str, sc); } catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "script global definition", name_str); } } s.RestoreCursor(); break; #endregion #region Fix-ups case "fixups": s.SaveCursor(n); foreach (XmlNode n2 in s.Cursor.ChildNodes) { if (n2.Name != "fixup") { continue; } s.SaveCursor(n2); Fixup fu = new Fixup(state, s); s.RestoreCursor(); name_str = fu.ToString(); try { Fixups.Add(name_str, fu); } catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "fix-up definition", name_str); } } s.RestoreCursor(); break; #endregion default: ProcessDefinition(n, state, s); break; } } } }