public string Execute(string Script, List<int> breakpoints = null) { System.Text.StringBuilder sb = new StringBuilder(); if (!string.IsNullOrEmpty(Script)) { Jint.JintEngine engine = new Jint.JintEngine(); engine.AllowClr = true; engine.SetDebugMode(true); engine.DisableSecurity(); if (breakpoints != null) { foreach (var line in breakpoints) { engine.BreakPoints.Add(new Jint.Debugger.BreakPoint(line + 1, 1)); } engine.Break += engine_Break; } try { var result = engine.Run(Script, true); if (result != null) sb.Append(result.ToString()); } catch (Exception exc) { sb.Append("An error has occured, details:\r\n"); sb.Append(exc.Message); } sb.Append("\r\nDone"); } else { sb.Append("No script found to execute."); } return sb.ToString(); }
private void parseScriptFile(string filename) { //Clear map script information mapName = "<name not set>"; eastMapFilename = null; westMapFilename = null; northMapFilename = null; southMapFilename = null; tmxMapFilename = null; scriptFilename = filename; //Empty NPE list NPEs = new List<NPE>(); var engine = new Jint.JintEngine(); engine.DisableSecurity(); //Needed so the scripts can call methods on NPE objects. engine.SetDebugMode(true); engine.SetFunction("name", new Action<string>(setMapName)); engine.SetFunction("east", new Action<string>(setEastMapfile)); engine.SetFunction("west", new Action<string>(setWestMapfile)); engine.SetFunction("north", new Action<string>(setNorthMapfile)); engine.SetFunction("south", new Action<string>(setSouthMapfile)); engine.SetFunction("mapfile", new Action<string>(setTmxMapfile)); engine.SetFunction("newNPE", new Func<NPE>(newNPE)); engine.SetFunction("addNPE", new Action<NPE>(addNPE)); engine.SetFunction("getFlag", new Func<string, bool>(getFlag)); engine.SetFunction("setFlag", new Action<string>(setFlag)); engine.SetFunction("dialogue", new Action<string>(dialogue)); engine.SetFunction("save", new Action<Player>(save)); engine.Run(File.ReadAllText(MAP_DIRECTORY + filename)); }
private void parseScriptFile(string filename) { //Clear neighboring room and mapfile strings eastMapFilename = null; westMapFilename = null; northMapFilename = null; southMapFilename = null; tmxMapFilename = null; //Empty NPE list NPEs = new List<NPE>(); var engine = new Jint.JintEngine(); engine.DisableSecurity(); engine.SetDebugMode(true); engine.SetFunction("name",new Action<string>(setMapName)); engine.SetFunction("east", new Action<string>(setEastMapfile)); engine.SetFunction("west", new Action<string>(setWestMapfile)); engine.SetFunction("north", new Action<string>(setNorthMapfile)); engine.SetFunction("south", new Action<string>(setSouthMapfile)); engine.SetFunction("mapfile", new Action<string>(setTmxMapfile)); engine.SetFunction("newNPE", new Func<NPE>(newNPE)); engine.SetFunction("addNPE", new Action<NPE>(addNPE)); engine.SetFunction("getFlag", new Func<string, bool>(getFlag)); engine.SetFunction("setFlag", new Action<string>(setFlag)); engine.SetFunction("dialogue", new Action<string>(dialogue)); engine.SetFunction("battleTexture", new Action<string>(setBattleTexture)); engine.SetFunction("newEnemy", new NewEnemyDelegate(js_newEnemy)); engine.SetFunction("addRandomEncounter", new Action<object>(addRandomEncounter)); engine.SetFunction("battle", new Action<object, object>(battle)); engine.SetFunction("reloadMap", new Action(reloadMap)); engine.SetFunction("store", new Action<object, object>(store)); engine.SetFunction("newItem", new NewItemDelegate(js_newItem)); engine.SetFunction("save", new Action<object>(save)); engine.Run(File.ReadAllText(mapDirectory + filename)); }
private void parseScriptFile(string filename) { //Clear map script information mapName = "<name not set>"; eastMapFilename = null; westMapFilename = null; northMapFilename = null; southMapFilename = null; tmxMapFilename = null; scriptFilename = filename; //Empty NPE and random encounter lists NPEs = new List<NPE>(); randomEncounters = new List<Enemy>(); //Clear battle and music attributes battleTexture = null; overworldMusic = null; randomBattleMusic = null; var engine = new Jint.JintEngine(); engine.DisableSecurity(); //Needed so the scripts can call methods on NPE objects. engine.SetDebugMode(true); engine.SetFunction("name", new Action<string>(js_setMapName)); engine.SetFunction("battleTexture", new Action<string>(js_setBattleTexture)); engine.SetFunction("east", new Action<string>(js_setEastMapfile)); engine.SetFunction("west", new Action<string>(js_setWestMapfile)); engine.SetFunction("north", new Action<string>(js_setNorthMapfile)); engine.SetFunction("south", new Action<string>(js_setSouthMapfile)); engine.SetFunction("mapfile", new Action<string>(js_setTmxMapfile)); engine.SetFunction("newNPE", new Func<NPE>(js_newNPE)); engine.SetFunction("addNPE", new Action<NPE>(js_addNPE)); engine.SetFunction("getFlag", new Func<string, bool>(js_getFlag)); engine.SetFunction("setFlag", new Action<string>(js_setFlag)); engine.SetFunction("dialogue", new Action<string>(js_dialogue)); engine.SetFunction("reloadMap", new Action(ReloadMap)); engine.SetFunction("save", new Action<Player>(js_save)); engine.SetFunction("newItem", new NewItemDelegate(js_newItem)); engine.SetFunction("addRandomEncounter", new Action<Enemy>(js_addRandomEncounter)); engine.SetFunction("newEnemy", new NewEnemyDelegate(js_newEnemy)); engine.SetFunction("battle", new Action<Player, Enemy, string>(js_battle)); engine.SetFunction("store", new Action<Player, ArrayList>(js_store)); engine.SetFunction("overworldMusic", new Action<string>(js_overworldMusic)); engine.SetFunction("randomBattleMusic", new Action<string>(js_randomBattleMusic)); engine.SetFunction("win", new Action(js_win)); engine.Run(File.ReadAllText(MAP_DIRECTORY + filename)); }