private void 添加ToolStripMenuItem_Click(object sender, EventArgs e) { if (treeViewRoot.SelectedNode.Level == 1) { scriptRoot[m_cur_index].addScene((ScriptScene)treeViewRoot.SelectedNode.Tag); } else if (treeViewRoot.SelectedNode.Level == 2) { ScriptScene scene = (ScriptScene)treeViewRoot.SelectedNode.Parent.Tag; scene.addSection((ScriptSection)treeViewRoot.SelectedNode.Tag); } else if (treeViewRoot.SelectedNode.Level == 3) { MessageBox.Show("不能在此处添加", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else if (treeViewRoot.SelectedNode.Level > 3) { FormAddCode addform = new FormAddCode(0, selectIndex); if (addform.ShowDialog() == DialogResult.OK) { selectIndex = addform.m_select + 1; if (addform.m_select < 4) { MessageBox.Show("code 0,1,2,3不能被手动添加", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } ScriptSection sec = (ScriptSection)getLeve2Nodes(treeViewRoot.SelectedNode).Tag; sec.addCode(addform.m_select, (ScriptCommand)treeViewRoot.SelectedNode.Parent.Tag); } } buildTreeView(scriptRoot[m_cur_index]); }
private void 添加子事件ToolStripMenuItem_Click(object sender, EventArgs e) { var node = treeViewRoot.SelectedNode; if (node.Level < 4) { MessageBox.Show("不能在这里添加子事件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } FormAddCode addform = new FormAddCode(); if (addform.ShowDialog() == DialogResult.OK) { if (addform.m_select < 4) { MessageBox.Show("code 0,1,2,3不能被手动添加", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } ScriptSection sec = (ScriptSection)getLeve2Nodes(node).Tag; ScriptCommand newCmd = (ScriptCommand)node.Parent.Tag; newCmd.extValue = 2; sec.addCode(0, newCmd); sec.addCode(addform.m_select, newCmd, true); sec.addCode(1, newCmd); buildTreeView(scriptRoot[m_cur_index]); } }
/// <summary> /// init /// </summary> public ScriptSettupInfo() { ScriptSection section = ConfigManager.Configger.GetFirstOrAddConfig <ScriptSection>(); //init runtime path. ScriptChangedDelay = section.ScriptChangedDelay; RuntimePath = section.RuntimePath; RuntimePrivateBinPath = section.RuntimePrivateBinPath; ScriptRelativePath = section.ScriptRelativePath; ScriptIsDebug = section.ScriptIsDebug; ModelScriptPath = section.ModelScriptPath; CSharpScriptPath = section.CSharpScriptPath; ScriptMainProgram = section.ScriptMainProgram; ScriptMainTypeName = section.ScriptMainTypeName; //Py setting DisablePython = section.DisablePython; PythonIsDebug = section.PythonIsDebug; PythonScriptPath = section.PythonScriptPath; PythonReferenceLibFile = section.PythonReferenceLibFile; //Lua setting DisableLua = section.DisableLua; LuaScriptPath = section.LuaScriptPath; ReferencedAssemblyNames = new List <string> { Path.Combine(RuntimePrivateBinPath, "NLog.dll"), Path.Combine(RuntimePrivateBinPath, "Newtonsoft.Json.dll"), Path.Combine(RuntimePrivateBinPath, "protobuf-net.dll"), Path.Combine(RuntimePrivateBinPath, "ServiceStack.Redis.dll"), Path.Combine(RuntimePrivateBinPath, "ZyGames.Framework.Common.dll"), Path.Combine(RuntimePrivateBinPath, "ZyGames.Framework.dll") }; }
// PUT api/Section/5 public IHttpActionResult PutScriptSection(decimal id, ScriptSection scriptsection) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != scriptsection.ScriptSectionID) { return(BadRequest()); } db.Entry(scriptsection).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ScriptSectionExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
/// <summary> /// Eval for multiple lines of code /// </summary> /// <param name="s"></param> /// <param name="parser"></param> /// <param name="section"></param> /// <param name="opType">Use null to check if rawCodes is not optimized</param> /// <param name="rawCodes"></param> /// <param name="check"></param> /// <param name="cmds"></param> /// <returns></returns> public static List <LogInfo> EvalOptLines(EngineState s, CodeParser parser, ScriptSection section, CodeType?opType, List <string> rawCodes, ErrorCheck check, out CodeCommand[] cmds) { // Parse CodeCommand List <LogInfo> errorLogs; (cmds, errorLogs) = parser.ParseStatements(rawCodes); if (errorLogs.Any(x => x.State == LogState.Error)) { Assert.AreEqual(ErrorCheck.ParserError, check); return(new List <LogInfo>()); } if (opType is CodeType type) { Assert.AreEqual(1, cmds.Length); Assert.AreEqual(type, cmds[0].Type); } else { Assert.IsTrue(1 < cmds.Length); } // Reset halt flags s.ResetFull(); // Run CodeCommands return(Engine.RunCommands(s, section, cmds, s.CurSectionInParams, s.CurSectionOutParams, false)); }
/// <summary> /// Eval for multiple lines of code /// </summary> /// <param name="s"></param> /// <param name="opType">Use null to check if rawCodes is not optimized</param> /// <param name="rawCodes"></param> /// <param name="check"></param> /// <param name="cmds"></param> /// <returns></returns> public static List <LogInfo> EvalOptLines(EngineState s, CodeType?opType, List <string> rawCodes, ErrorCheck check, out CodeCommand[] cmds) { ScriptSection section = DummySection(); CodeParser parser = new CodeParser(section, Global.Setting, Project.Compat); return(EvalOptLines(s, parser, section, opType, rawCodes, check, out cmds)); }
public static List<LogInfo> AddVariables(EngineState s, CodeCommand cmd) { CodeInfo_AddVariables info = cmd.Info.Cast<CodeInfo_AddVariables>(); string scriptFile = StringEscaper.Preprocess(s, info.ScriptFile); string sectionName = StringEscaper.Preprocess(s, info.SectionName); Script sc = Engine.GetScriptInstance(s, s.CurrentScript.RealPath, scriptFile, out _); // Does section exist? if (!sc.Sections.ContainsKey(sectionName)) return new List<LogInfo> {new LogInfo(LogState.Error, $"Script [{scriptFile}] does not have section [{sectionName}]")}; // Directly read from file List<string> lines = IniReadWriter.ParseRawSection(sc.RealPath, sectionName); if (lines == null) return new List<LogInfo> {new LogInfo(LogState.Error, $"Script [{scriptFile}] does not have section [{sectionName}]")}; // Add Variables Dictionary<string, string> varDict = IniReadWriter.ParseIniLinesVarStyle(lines); List<LogInfo> varLogs = s.Variables.AddVariables(info.Global ? VarsType.Global : VarsType.Local, varDict); // Add Macros ScriptSection localSection = sc.Sections[sectionName]; List<LogInfo> macroLogs = s.Macro.LoadMacroDict(info.Global ? MacroType.Global : MacroType.Local, localSection, lines, true); varLogs.AddRange(macroLogs); if (varLogs.Count == 0) // No variables varLogs.Add(new LogInfo(LogState.Info, $"Script [{scriptFile}]'s section [{sectionName}] does not have any variables")); return varLogs; }
/// <summary> /// Register a ScriptBlock on the HttpContext for a specific section /// </summary> /// <param name="block"></param> /// <param name="section"></param> public void RegisterScriptBlock(ScriptBlock block, ScriptSection section) { var key = ScriptKey + section; ScriptBlocks blocks = null; var context = _httpContextAccessor.HttpContext; if (context.Items.ContainsKey(key)) { blocks = context.Items[key] as ScriptBlocks; } if (blocks == null) { blocks = new ScriptBlocks(); context.Items.Add(key, blocks); } blocks.Add(block); if (_logger.IsEnabled(LogLevel.Information)) { _logger.LogInformation($"Added script blocks to context with key {key}"); } }
public static List <LogInfo> Visible(EngineState s, CodeCommand cmd) { List <LogInfo> logs = new List <LogInfo>(1); Debug.Assert(cmd.Info.GetType() == typeof(CodeInfo_Visible)); CodeInfo_Visible info = cmd.Info as CodeInfo_Visible; string visibilityStr = StringEscaper.Preprocess(s, info.Visibility); bool visibility = false; if (visibilityStr.Equals("True", StringComparison.OrdinalIgnoreCase)) { visibility = true; } else if (visibilityStr.Equals("False", StringComparison.OrdinalIgnoreCase) == false) { logs.Add(new LogInfo(LogState.Error, $"Invalid boolean value [{visibilityStr}]")); return(logs); } Script p = cmd.Addr.Script; ScriptSection iface = p.GetInterface(out string ifaceSecName); if (iface == null) { logs.Add(new LogInfo(LogState.Error, $"Script [{cmd.Addr.Script.ShortPath}] does not have section [{ifaceSecName}]")); return(logs); } List <UIControl> uiCtrls = iface.GetUICtrls(true); UIControl uiCtrl = uiCtrls.Find(x => x.Key.Equals(info.InterfaceKey, StringComparison.OrdinalIgnoreCase)); if (uiCtrl == null) { logs.Add(new LogInfo(LogState.Error, $"Cannot find interface control [{info.InterfaceKey}] in section [{ifaceSecName}]")); return(logs); } if (uiCtrl.Visibility != visibility) { uiCtrl.Visibility = visibility; uiCtrl.Update(); // Re-render Script Application.Current.Dispatcher.Invoke(() => { MainWindow w = (Application.Current.MainWindow as MainWindow); if (w.CurMainTree.Script == cmd.Addr.Script) { w.DrawScript(cmd.Addr.Script); } }); } logs.Add(new LogInfo(LogState.Success, $"Interface control [{info.InterfaceKey}]'s visibility set to [{visibility}]")); return(logs); }
private void 除ToolStripMenuItem_Click(object sender, EventArgs e) { ScriptSection sec = null; ScriptCommand n_cmd = null; var node = treeViewRoot.SelectedNode; DialogResult dr; if (node.Level <= 2) { if (node.PrevNode == null && node.NextNode == null) { MessageBox.Show("唯一的Scetion或Scene不能删除", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { dr = MessageBox.Show("确定要删除这条数据吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dr == DialogResult.OK) { if (node.Level == 1) { scriptRoot[m_cur_index].removeScene((ScriptScene)node.Tag); } else { ScriptScene scene = (ScriptScene)node.Parent.Tag; scene.removeSection((ScriptSection)node.Tag); } treeViewRoot.Nodes.Remove(node); } return; } } else if (node.Level == 3) { MessageBox.Show("不能被删除", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { sec = (ScriptSection)getLeve2Nodes(node).Tag; n_cmd = (ScriptCommand)node.Tag; } dr = MessageBox.Show("确定要删除这条数据吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dr == DialogResult.OK) { if (node.Nodes.Count < 1) { sec.removeCode(n_cmd); } else { RemoveCode(sec, node); } node.Remove(); } }
public IHttpActionResult RenderScriptSection(decimal id) { ScriptSection scriptsection = db.ScriptSections.Find(id); if (scriptsection == null) { return(NotFound()); } return(Ok(scriptsection)); }
protected void RemoveCode(ScriptSection sec, TreeNode nodes) { foreach (TreeNode node in nodes.Nodes) { if (node.Nodes.Count > 0) { RemoveCode(sec, node); } sec.removeCode((ScriptCommand)node.Tag); } sec.removeCode((ScriptCommand)nodes.Tag); }
public IHttpActionResult PostScriptSection(ScriptSection scriptsection) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.ScriptSections.Add(scriptsection); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = scriptsection.ScriptSectionID }, scriptsection)); }
public IHttpActionResult GetScriptSection(string SectionUniqueName) { ScriptSection scriptsection = db.ScriptSections.Where(b => b.SectionName.Equals(SectionUniqueName)).FirstOrDefault(); //ScriptSection scriptsection = db.ScriptSections.Where(b => b.SectionName.Equals(SectionUniqueName)).Include("ScriptSectionLayouts").Select(m => new ScriptSection { ScriptSectionID = m.ScriptSectionID, ClientID = m.ClientID, SectionName = m.SectionName, SectionDesc = m.SectionDesc, DateCreated = m.DateCreated, DateLastModified = m.DateLastModified, UserLastModified = m.UserLastModified, ScriptSectionLayouts = m.ScriptSectionLayouts.OrderBy(o => o.Sequence).ToList() }).FirstOrDefault(); if (scriptsection == null) { return(NotFound()); } return(Ok(scriptsection)); }
public IHttpActionResult DeleteScriptSection(decimal id) { ScriptSection scriptsection = db.ScriptSections.Find(id); if (scriptsection == null) { return(NotFound()); } db.ScriptSections.Remove(scriptsection); db.SaveChanges(); return(Ok(scriptsection)); }
private void 剪切ToolStripMenuItem_Click(object sender, EventArgs e) { ScriptSection sec = null; ScriptCommand n_cmd = null; var node = treeViewRoot.SelectedNode; if (node.Level <= 2) { if (node.PrevNode == null && node.NextNode == null) { MessageBox.Show("唯一的Scetion或Scene不能删除", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { if (node.Level == 1) { scriptRoot[m_cur_index].removeScene((ScriptScene)node.Tag); } else { ScriptScene scene = (ScriptScene)node.Parent.Tag; scene.removeSection((ScriptSection)node.Tag); } } } else if (node.Level == 3) { MessageBox.Show("不能被删除", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { sec = (ScriptSection)node.Parent.Parent.Tag; n_cmd = (ScriptCommand)node.Tag; sec.removeCode(n_cmd); } copyNode = new TreeNode(); copyNode.Text = node.Text; copyNode.Tag = node.Tag; copyNode = CopyTreeNode(copyNode, node); cutNodeParent = node.Parent; 粘帖ToolStripMenuItem.Enabled = true; node.Remove(); isCut = true; }
/// <summary> /// Gets all script blocks registered on the context for a given section. /// </summary> /// <param name="section"></param> /// <returns></returns> public ScriptBlocks GetScriptBlocks(ScriptSection section) { var key = ScriptKey + section; var context = _httpContextAccessor.HttpContext; if (!context.Items.ContainsKey(key)) { return(null); } if (_logger.IsEnabled(LogLevel.Information)) { _logger.LogInformation($"Found script blocks on context with key {key}"); } return(context.Items[key] as ScriptBlocks); }
public static List <LogInfo> EvalLines(EngineState s, List <string> rawCodes, ErrorCheck check, out CodeCommand[] cmds) { // Create CodeCommand List <LogInfo> errorLogs; ScriptSection dummySection = DummySection(); CodeParser parser = new CodeParser(dummySection, Global.Setting, Project.Compat); (cmds, errorLogs) = parser.ParseStatements(rawCodes); if (errorLogs.Any(x => x.State == LogState.Error)) { Assert.AreEqual(ErrorCheck.ParserError, check); return(new List <LogInfo>()); } // Reset halt flags s.ResetFull(); // Run CodeCommands return(Engine.RunCommands(s, dummySection, cmds, s.CurSectionInParams, s.CurSectionOutParams, false)); }
public void Visible() { string srcFile = Path.Combine(EngineTests.Project.ProjectDir, TestSuiteInterface, "ReadInterface.script"); string scriptFile = Path.GetTempFileName(); try { void SingleTemplate(string rawCode, string key, string compStr, ErrorCheck check = ErrorCheck.Success) { File.Copy(srcFile, scriptFile, true); EngineState s = EngineTests.CreateEngineState(); Script sc = s.Project.LoadScriptRuntime(scriptFile, new LoadScriptRuntimeOptions()); // ScriptSection ifaceSection = sc.GetInterfaceSection(out _); ScriptSection section = sc.Sections["Process"]; // Enable Visible command CodeParser.Options opts = CodeParser.Options.CreateOptions(Global.Setting, EngineTests.Project.Compat); opts.AllowLegacyInterfaceCommand = true; CodeParser parser = new CodeParser(section, opts); try { EngineTests.Eval(s, parser, rawCode, CodeType.Visible, check); if (check == ErrorCheck.Success) { string dest = IniReadWriter.ReadKey(scriptFile, "Interface", key); Assert.IsTrue(dest.Equals(compStr, StringComparison.Ordinal)); } } finally { if (File.Exists(scriptFile)) { File.Delete(scriptFile); } } } void OptTemplate(List <string> rawCodes, (string key, string value)[] compTuples, bool optSuccess, ErrorCheck check = ErrorCheck.Success)
public static void SetDelPermanent(EngineState s) { string scPath = s.Project.MainScript.RealPath; IniReadWriter.DeleteKey(scPath, "Variables", "%PermDest%"); try { // Set EngineTests.Eval(s, "Set,%PermDest%,PEBakery,PERMANENT", CodeType.Set, ErrorCheck.Success); string dest = s.Variables.GetValue(VarsType.Global, "PermDest"); Assert.IsTrue(dest.Equals("PEBakery", StringComparison.Ordinal)); // Check memory-cached script section ScriptSection varSect = s.Project.MainScript.Sections["Variables"]; int idx = Array.FindIndex(varSect.Lines, x => x.StartsWith("%PermDest%=")); Assert.AreNotEqual(-1, idx); // Check script file string permanent = IniReadWriter.ReadKey(scPath, "Variables", "%PermDest%"); Assert.IsTrue(dest.Equals(permanent, StringComparison.Ordinal)); // Delete EngineTests.Eval(s, "Set,%PermDest%,NIL,PERMANENT", CodeType.Set, ErrorCheck.Success); // Check memory-cached script section idx = Array.FindIndex(varSect.Lines, x => x.StartsWith("%PermDest%=")); Assert.AreEqual(-1, idx); // Check script file permanent = IniReadWriter.ReadKey(scPath, "Variables", "%PermDest%"); Assert.IsNull(permanent); } finally { IniReadWriter.DeleteKey(scPath, "Variables", "%PermDest%"); } }
void CopyNode(ScriptSection sec, TreeNode node, int level = 1) { ScriptCommand copy_cmd = new ScriptCommand(); foreach (TreeNode eachNode in node.Nodes) { if (eachNode.Index == 0) { copy_cmd = (ScriptCommand)eachNode.Parent.Tag; sec.addCode(copy_cmd.id, (ScriptCommand)eachNode.Parent.Tag, true); sec.addCode(0, copy_cmd); } else { copy_cmd = (ScriptCommand)eachNode.Tag; sec.addCode(copy_cmd.id, (ScriptCommand)eachNode.Parent.Tag); } if (eachNode.Nodes.Count > 0) { CopyNode(sec, eachNode); } } }
public static List <LogInfo> Eval(EngineState s, ScriptSection section, string rawCode, CodeType type, ErrorCheck check, out CodeCommand cmd) { CodeParser parser = new CodeParser(section, Global.Setting, Project.Compat); return(Eval(s, parser, rawCode, type, check, out cmd)); }
private void SyntaxCheckButton_Click(object sender, RoutedEventArgs e) { if (m.Syntax_InputCode.Equals(string.Empty, StringComparison.Ordinal)) { m.Syntax_Output = "No Code"; return; } Project project = m.CodeBox_CurrentProject; Script p = project.MainScript; ScriptSection section; if (project.MainScript.Sections.ContainsKey("Process")) { section = p.Sections["Process"]; } else { section = new ScriptSection(p, "Process", SectionType.Code, new List <string>(), 1); } SectionAddress addr = new SectionAddress(p, section); List <string> lines = m.Syntax_InputCode.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).ToList(); List <CodeCommand> cmds = CodeParser.ParseStatements(lines, addr, out List <LogInfo> errorLogs); // Check Macros Macro macro = new Macro(project, project.Variables, out List <LogInfo> macroLogs); if (macro.MacroEnabled) { foreach (CodeCommand cmd in cmds) { if (cmd.Type == CodeType.Macro) { Debug.Assert(cmd.Info.GetType() == typeof(CodeInfo_Macro)); CodeInfo_Macro info = cmd.Info as CodeInfo_Macro; if (!macro.MacroDict.ContainsKey(info.MacroType)) { errorLogs.Add(new LogInfo(LogState.Error, $"Invalid CodeType or Macro [{info.MacroType}]", cmd)); } } } } if (0 < errorLogs.Count) { StringBuilder b = new StringBuilder(); for (int i = 0; i < errorLogs.Count; i++) { LogInfo log = errorLogs[i]; b.AppendLine($"[{i + 1}/{errorLogs.Count}] {log.Message} ({log.Command})"); } m.Syntax_Output = b.ToString(); } else { m.Syntax_Output = "No Error"; } }
public static List <LogInfo> Set(EngineState s, CodeCommand cmd) { CodeInfo_Set info = cmd.Info.Cast <CodeInfo_Set>(); Variables.VarKeyType varType = Variables.DetectType(info.VarKey); if (varType == Variables.VarKeyType.None) { // Check Macro if (Regex.Match(info.VarKey, Macro.MacroNameRegex, RegexOptions.Compiled | RegexOptions.CultureInvariant).Success) // Macro Name Validation { string macroCommand = StringEscaper.Preprocess(s, info.VarValue); if (macroCommand.Equals("NIL", StringComparison.OrdinalIgnoreCase)) { macroCommand = null; } LogInfo log = s.Macro.SetMacro(info.VarKey, macroCommand, cmd.Section, info.Permanent, false); return(new List <LogInfo>(1) { log }); } } // [WB082 Behavior] -> Enabled if s.CompatAllowSetModifyInterface == true // If PERMANENT was used but the key exists in interface command, the value will not be written to script.project but in interface. // Need to investigate where the logs are saved in this case. switch (info.Permanent) { case true: { // Check if interface contains VarKey List <LogInfo> logs = new List <LogInfo>(); if (Variables.DetectType(info.VarKey) != Variables.VarKeyType.Variable) { goto case false; } #region Set interface control's value (Compat) if (s.CompatAllowSetModifyInterface) { string varKey = Variables.TrimPercentMark(info.VarKey); string finalValue = StringEscaper.Preprocess(s, info.VarValue); Script sc = cmd.Section.Script; ScriptSection iface = sc.GetInterfaceSection(out _); if (iface == null) { goto case false; } (List <UIControl> uiCtrls, _) = UIParser.ParseStatements(iface.Lines, iface); UIControl uiCtrl = uiCtrls.Find(x => x.Key.Equals(varKey, StringComparison.OrdinalIgnoreCase)); if (uiCtrl == null) { goto case false; } bool valid = uiCtrl.SetValue(finalValue, false, out List <LogInfo> varLogs); logs.AddRange(varLogs); if (valid) { uiCtrl.Update(); // Also update variables logs.AddRange(Variables.SetVariable(s, info.VarKey, info.VarValue, false, false)); return(logs); } } goto case false; #endregion } case false: default: return(Variables.SetVariable(s, info.VarKey, info.VarValue, info.Global, info.Permanent)); } }
/// <summary> /// Eval for multiple lines of code /// </summary> /// <param name="s"></param> /// <param name="parser"></param> /// <param name="section"></param> /// <param name="opType">Use null to check if rawCodes is not optimized</param> /// <param name="rawCodes"></param> /// <param name="check"></param> /// <returns></returns> public static List <LogInfo> EvalOptLines(EngineState s, CodeParser parser, ScriptSection section, CodeType?opType, List <string> rawCodes, ErrorCheck check) { return(EvalOptLines(s, parser, section, opType, rawCodes, check, out _)); }
private void 粘帖ToolStripMenuItem_Click(object sender, EventArgs e) { if (copyNode != null && treeViewRoot.SelectedNode != null) { if (copyNode.Level != treeViewRoot.SelectedNode.Level) { if (cutNodeParent != null && cutNodeParent.Level != treeViewRoot.SelectedNode.Parent.Level) { MessageBox.Show("粘贴目录不匹配", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } if (isCut) { cutNodeParent.Nodes.Add(copyNode); } if (treeViewRoot.SelectedNode.Level == 1) { ScriptScene scene = scriptRoot[m_cur_index].addScene((ScriptScene)copyNode.Tag); scene.SectionList = ((ScriptScene)copyNode.Tag).SectionList; } else if (treeViewRoot.SelectedNode.Level == 2) { ScriptScene scene = (ScriptScene)(copyNode.Parent != null ? copyNode.Parent.Tag : cutNodeParent.Tag); ScriptSection section = scene.addSection((ScriptSection)copyNode.Tag); section.CommandList = ((ScriptSection)copyNode.Tag).CommandList; } else if (treeViewRoot.SelectedNode.Level == 3) { MessageBox.Show("不能在此处复制", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else if (treeViewRoot.SelectedNode.Level > 3) { ScriptCommand copy_cmd = (ScriptCommand)copyNode.Tag; if (copy_cmd.id != 0) { ScriptSection sec = (ScriptSection)getLeve2Nodes(copyNode).Tag; if (copyNode.Nodes.Count > 0) { //sec.addCode(copy_cmd.id, (ScriptCommand)copyNode.Parent.Tag, true); CopyNode(sec, copyNode); } else { sec.addCode(copy_cmd.id, (ScriptCommand)copyNode.Tag); } //int copy_index = sec.FindCommand((ScriptCommand)copyNode.Parent.Tag); //int index = sec.addCode(copy_cmd.id, (ScriptCommand)copyNode.Parent.Tag, copy_cmd.isExtValueAvailable()); //sec.CommandList[index] = sec.CommandList[copy_index]; } else { MessageBox.Show("code 0,1,2,3不能被手动添加", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } buildTreeView(scriptRoot[m_cur_index]); } }
/// <summary> /// Eval for multiple lines of code /// </summary> /// <param name="s"></param> /// <param name="section"></param> /// <param name="opType">Use null to check if rawCodes is not optimized</param> /// <param name="rawCodes"></param> /// <param name="check"></param> /// <returns></returns> public static List <LogInfo> EvalOptLines(EngineState s, ScriptSection section, CodeType?opType, List <string> rawCodes, ErrorCheck check) { CodeParser parser = new CodeParser(section, Global.Setting, Project.Compat); return(EvalOptLines(s, parser, section, opType, rawCodes, check, out _)); }
public static List <LogInfo> Set(EngineState s, CodeCommand cmd) { Debug.Assert(cmd.Info.GetType() == typeof(CodeInfo_Set)); CodeInfo_Set info = cmd.Info as CodeInfo_Set; Variables.VarKeyType varType = Variables.DetermineType(info.VarKey); if (varType == Variables.VarKeyType.None) { // Check Macro if (Regex.Match(info.VarKey, Macro.MacroNameRegex, RegexOptions.Compiled | RegexOptions.CultureInvariant).Success) // Macro Name Validation { string macroCommand = StringEscaper.Preprocess(s, info.VarValue); if (macroCommand.Equals("NIL", StringComparison.OrdinalIgnoreCase)) { macroCommand = null; } LogInfo log = s.Macro.SetMacro(info.VarKey, macroCommand, cmd.Addr, info.Permanent, false); return(new List <LogInfo>(1) { log }); } } // [WB082 Behavior] // If PERMANENT was used but the key exists in interface command, the value will not be written to script.project but in interface. // Need to investigate where the logs are saved in this case. switch (info.Permanent) { case true: { // Check if interface contains VarKey List <LogInfo> logs = new List <LogInfo>(); if (Variables.DetermineType(info.VarKey) != Variables.VarKeyType.Variable) { goto case false; } string varKey = Variables.TrimPercentMark(info.VarKey); string finalValue = StringEscaper.Preprocess(s, info.VarValue); #region Set UI Script p = cmd.Addr.Script; ScriptSection iface = p.GetInterface(out string sectionName); if (iface == null) { goto case false; } List <UIControl> uiCmds = iface.GetUICtrls(true); UIControl uiCmd = uiCmds.Find(x => x.Key.Equals(varKey, StringComparison.OrdinalIgnoreCase)); if (uiCmd == null) { goto case false; } bool match = uiCmd.SetValue(finalValue, false, out List <LogInfo> varLogs); logs.AddRange(varLogs); if (match) { uiCmd.Update(); logs.AddRange(Variables.SetVariable(s, info.VarKey, info.VarValue, false, false)); return(logs); } else { goto case false; } #endregion } case false: default: return(Variables.SetVariable(s, info.VarKey, info.VarValue, info.Global, info.Permanent)); } }
public static List <LogInfo> WriteInterface(EngineState s, CodeCommand cmd) { // WriteInterface,<Element>,<ScriptFile>,<Section>,<Key>,<Value> List <LogInfo> logs = new List <LogInfo>(2); Debug.Assert(cmd.Info.GetType() == typeof(CodeInfo_WriteInterface)); CodeInfo_WriteInterface info = cmd.Info as CodeInfo_WriteInterface; string scriptFile = StringEscaper.Preprocess(s, info.ScriptFile); string section = StringEscaper.Preprocess(s, info.Section); string key = StringEscaper.Preprocess(s, info.Key); string finalValue = StringEscaper.Preprocess(s, info.Value); Script p = Engine.GetScriptInstance(s, cmd, s.CurrentScript.FullPath, scriptFile, out bool inCurrentScript); if (!p.Sections.ContainsKey(section)) { logs.Add(new LogInfo(LogState.Error, $"Script [{scriptFile}] does not have section [{section}]")); return(logs); } ScriptSection iface = p.Sections[section]; List <UIControl> uiCmds = iface.GetUICtrls(true); UIControl uiCmd = uiCmds.Find(x => x.Key.Equals(key, StringComparison.OrdinalIgnoreCase)); if (uiCmd == null) { logs.Add(new LogInfo(LogState.Error, $"Interface control [{key}] does not exist")); return(logs); } switch (info.Element) { case InterfaceElement.Text: uiCmd.Text = finalValue; break; case InterfaceElement.Visible: { bool visibility = false; if (finalValue.Equals("True", StringComparison.OrdinalIgnoreCase)) { visibility = true; } else if (!finalValue.Equals("False", StringComparison.OrdinalIgnoreCase)) { logs.Add(new LogInfo(LogState.Error, $"[{finalValue}] is not a valid boolean value")); return(logs); } uiCmd.Visibility = visibility; } break; case InterfaceElement.PosX: { if (!NumberHelper.ParseInt32(finalValue, out int x)) { logs.Add(new LogInfo(LogState.Error, $"[{finalValue}] is not a valid integer")); return(logs); } uiCmd.Rect.X = x; } break; case InterfaceElement.PosY: { if (!NumberHelper.ParseInt32(finalValue, out int y)) { logs.Add(new LogInfo(LogState.Error, $"[{finalValue}] is not a valid integer")); return(logs); } uiCmd.Rect.Y = y; } break; case InterfaceElement.Width: { if (!NumberHelper.ParseInt32(finalValue, out int width)) { logs.Add(new LogInfo(LogState.Error, $"[{finalValue}] is not a valid integer")); return(logs); } uiCmd.Rect.Width = width; } break; case InterfaceElement.Height: { if (!NumberHelper.ParseInt32(finalValue, out int height)) { logs.Add(new LogInfo(LogState.Error, $"[{finalValue}] is not a valid integer")); return(logs); } uiCmd.Rect.Height = height; } break; case InterfaceElement.Value: { bool success = uiCmd.SetValue(finalValue, false, out List <LogInfo> varLogs); logs.AddRange(varLogs); if (success == false && varLogs.Count == 0) { logs.Add(new LogInfo(LogState.Error, $"Writing [Value] to [{uiCmd.Type}] is not supported")); return(logs); } } break; default: throw new InternalException($"Internal Logic Error at WriteInterface"); } // Update uiCmd into file uiCmd.Update(); // Rerender Script Application.Current?.Dispatcher.Invoke(() => { // Application.Current is null in unit test MainWindow w = (Application.Current.MainWindow as MainWindow); if (w.CurMainTree.Script == cmd.Addr.Script) { w.DrawScript(cmd.Addr.Script); } }); return(logs); }
private async void SyntaxCheckCommand_Executed(object sender, ExecutedRoutedEventArgs e) { if (_m.SyntaxInputCode.Length == 0) { _m.SyntaxCheckResult = "Please input code."; return; } SyntaxCheckButton.Focus(); _m.CanExecuteCommand = false; try { _m.SyntaxCheckResult = "Checking..."; await Task.Run(() => { Project p = _m.CurrentProject; Script sc = p.MainScript; ScriptSection section; if (p.MainScript.Sections.ContainsKey(ScriptSection.Names.Process)) { section = sc.Sections[ScriptSection.Names.Process]; } else // Create dummy [Process] section instance { section = new ScriptSection(sc, ScriptSection.Names.Process, SectionType.Code, new string[0], 1); } // Split lines from SyntaxInputCode List <string> lines = new List <string>(); using (StringReader r = new StringReader(_m.SyntaxInputCode)) { string line; while ((line = r.ReadLine()) != null) { line = line.Trim(); lines.Add(line); } } // Run CodeParser to retrieve parsing errors CodeParser parser = new CodeParser(section, Global.Setting, sc.Project.Compat); (CodeCommand[] cmds, List <LogInfo> errorLogs) = parser.ParseStatements(lines); // Check macro commands Macro macro = new Macro(p, p.Variables, out _); if (macro.MacroEnabled) { foreach (CodeCommand cmd in cmds.Where(x => x.Type == CodeType.Macro)) { CodeInfo_Macro info = cmd.Info.Cast <CodeInfo_Macro>(); if (!macro.GlobalDict.ContainsKey(info.MacroType)) { errorLogs.Add(new LogInfo(LogState.Error, $"Invalid CodeType or Macro [{info.MacroType}]", cmd)); } } } // Print results if (0 < errorLogs.Count) { StringBuilder b = new StringBuilder(); for (int i = 0; i < errorLogs.Count; i++) { LogInfo log = errorLogs[i]; b.AppendLine($"[{i + 1}/{errorLogs.Count}] {log.Message} ({log.Command})"); } _m.SyntaxCheckResult = b.ToString(); } else { _m.SyntaxCheckResult = "Error not found."; } }); } finally { _m.CanExecuteCommand = true; CommandManager.InvalidateRequerySuggested(); SyntaxCheckResultTextBox.Focus(); } }