public ScriptContext(IRenderer2D renderer, Vector2D inmappos, bool insnaptogrid, bool insnaptonearest) { errorText = ""; context = this; snaptogrid = insnaptogrid; snaptonearest = insnaptonearest; mousemappos = inmappos; ui_parameters = new LuaUIParameters(16); if (float.IsNaN(mousemappos.x) || float.IsInfinity(mousemappos.x)) { mousemappos.x = 0f; } if (float.IsNaN(mousemappos.y) || float.IsInfinity(mousemappos.y)) { mousemappos.y = 0f; } rendererscale = renderer.Scale; scriptlog_sb = new StringBuilder(); debuglog_sb = new StringBuilder(); UserData.RegisterAssembly(); script = new Script(CoreModules.Preset_SoftSandbox); script.Options.DebugPrint = s => { LuaUI.DebugLogLine(s); }; script.Globals["Line2D"] = typeof(LuaLine2D); script.Globals["Vector2D"] = typeof(LuaVector2D); script.Globals["Vector3D"] = typeof(LuaVector3D); script.Globals["Map"] = typeof(LuaMap); script.Globals["Pen"] = typeof(Pen); script.Globals["UI"] = typeof(LuaUI); script.Globals["Data"] = typeof(LuaDataManager); script.Globals["MapFormat"] = typeof(LuaMapFormat); script.Globals["dofile"] = (Func <string, DynValue>)DoFile; script.Globals["dostring"] = (Func <string, DynValue>)DoString; script.Globals["require"] = (Func <string, DynValue>)Require; script.Options.DebugPrint = DebugLogLine; bInitializedRequireSandbox = false; // hacky workaround for .NET 3.5 bug, see RandomSeed for more info { object math = script.Globals["math"]; if (math is Table) { Table math_table = (Table)math; math_table["randomseed"] = (Func <DynValue, DynValue>)RandomSeed; } } }
public ScriptContext(IRenderer2D renderer, Vector2D inmappos, bool insnaptogrid, bool insnaptonearest) { errorText = ""; context = this; snaptogrid = insnaptogrid; snaptonearest = insnaptonearest; mousemappos = inmappos; ui_parameters = new LuaUIParameters(16); if (float.IsNaN(mousemappos.x) || float.IsInfinity(mousemappos.x)) { mousemappos.x = 0f; } if (float.IsNaN(mousemappos.y) || float.IsInfinity(mousemappos.y)) { mousemappos.y = 0f; } rendererscale = renderer.Scale; scriptlog_sb = new StringBuilder(); debuglog_sb = new StringBuilder(); UserData.RegisterAssembly(); script = new Script(CoreModules.Preset_SoftSandbox); script.Options.DebugPrint = s => { LuaUI.DebugLogLine(s); }; script.Globals["Line2D"] = typeof(LuaLine2D); script.Globals["Vector2D"] = typeof(LuaVector2D); script.Globals["Vector3D"] = typeof(LuaVector3D); script.Globals["Map"] = typeof(LuaMap); script.Globals["Pen"] = typeof(Pen); script.Globals["UI"] = typeof(LuaUI); script.Globals["Data"] = typeof(LuaDataManager); script.Globals["MapFormat"] = typeof(LuaMapFormat); script.Globals["dofile"] = (Func <string, DynValue>)DoFile; }
public static Pen FromClick(bool snaptogrid, bool snaptonearest) { return(new Pen(LuaUI.GetMouseMapPosition(snaptogrid, snaptonearest))); }