private void btnLoad_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Title = "打开剧本文件"; ofd.Filter = "旧版本eex剧本文件(*.eex)|*.eex|新版本eex剧本文件(*.eex)|*.eex|eex new剧本文件(*.eex_new)|*.eex_new|eex json剧本文件(*.eexjs)|*.eexjs"; ofd.Multiselect = false; if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { try { int group = 0; if (ofd.FilterIndex == 2) { group = 1; } ScriptRoot sr = EexFile.loadFile(ofd.FileName, group); buildTreeView(sr); String readString = sr.toJsonObject().ToString(Newtonsoft.Json.Formatting.Indented); tbContent.Text = readString; scriptRoot = sr; } catch (EexReaderException exception) { MessageBox.Show(this, String.Format("文件{0},解析指令0x{1:x}出错,内部信息为:{2}", ofd.FileName, exception.CommandId, exception.Message)); } } }
public static String scriptRoot2JsonText(ScriptRoot sr) { JObject jo = sr.toJsonObject(); String text = jo.ToString(Newtonsoft.Json.Formatting.Indented); return(text); }
public static void saveJsonFile(ScriptRoot root, String path) { using (StreamWriter sw = new StreamWriter(path, false, Encoding.UTF8)) { String text = scriptRoot2JsonText(root); sw.Write(text); } }
public static ScriptRoot jsonText2ScriptRoot(String text) { JObject job = JObject.Parse(text); ScriptRoot root = new ScriptRoot(); root.loadJson(job); return(root); }
public static void saveEexNewFile(ScriptRoot root, String path) { EexBinaryWriter writer = new EexBinaryWriter(EexBinaryWriter.ENCODING_UTF8); root.saveNewWriter(writer); using (FileStream fs = new FileStream(path, FileMode.Create)) { fs.Write(writer.getContent(), 0, writer.getIndex()); } }
public static void saveEexFile(ScriptRoot root, String path, int group) { EexBinaryWriter writer = new EexBinaryWriter(); root.saveWriter(writer, group); using (FileStream fs = new FileStream(path, FileMode.Create)) { fs.Write(writer.getContent(), 0, writer.getIndex()); } }
public static void saveStringToExcel(ScriptRoot root, String path) { List <string> textList = new List <string>(); foreach (ScriptScene scene in root.SceneList) { foreach (ScriptSection section in scene.SectionList) { foreach (ScriptCommand cmd in section.CommandList) { if (cmd.ArrayValues.GetLength(0) > 0) { for (int j = 0; j < cmd.ArrayValues.GetLength(0); j++) { for (int i = 0; i < cmd.Keys.Length; i++) { int fieldId = cmd.Keys[i]; if (ScriptConfig.Instance.getEexType(fieldId) == EexType.EexString) { textList.Add(cmd.ArrayValues[j][i].ToString()); } } } } else { for (int i = 0; i < cmd.Keys.Length; i++) { int fieldId = cmd.Keys[i]; if (ScriptConfig.Instance.getEexType(fieldId) == EexType.EexString) { textList.Add(cmd.Values[i].ToString()); } } } } } } if (textList.Count > 0) { XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet sheet = (XSSFSheet)workbook.CreateSheet("Sheet1"); for (int i = 0; i < textList.Count; i++) { XSSFRow row = (XSSFRow)sheet.CreateRow(i); row.CreateCell(0).SetCellValue(textList[i]); } using (FileStream fs = new FileStream(path, FileMode.Create)) { workbook.Write(fs); } } }
public static ScriptRoot loadJsonFile(String path) { using (StreamReader sr = new StreamReader(path, Encoding.UTF8)) { using (JsonTextReader jr = new JsonTextReader(sr)) { JObject jo = JObject.Load(jr); ScriptRoot root = new ScriptRoot(path); root.loadJson(jo); return(root); } } }
public void WithLockedDevice(IStructureData structure, IBlockData block, Action action, Action lockFailed = null) { using (var locked = ConveyorHelpers.CreateDeviceLock(ScriptRoot, ScriptRoot.GetCurrentPlayfield(), structure.GetCurrent(), block.Position)) { if (locked.Success) { action(); } else { lockFailed?.Invoke(); } } }
private void 新建NToolStripMenuItem_Click(object sender, EventArgs e) { ScriptRoot sr = new ScriptRoot(null); sr.addScene(0); scriptRoot.Add(sr); buildTreeView(sr); TabPage Page = new TabPage(); Page.Name = "Page1"; Page.Text = sr.getNodeText(); tabControl1.Controls.Add(Page); tabControl1.SelectedIndex = tabControl1.Controls.Count - 1; }
private void 打开OToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Title = "打开剧本文件"; ofd.Filter = "eex new剧本文件(*.eex_new)|*.eex_new"; ofd.Multiselect = true; if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { ScriptRoot sr = null; for (int i = 0; i < ofd.FileNames.Length; i++) { bool isExist = false; for (int j = 0; j < scriptRoot.Count; j++) { if (scriptRoot[j].m_path == ofd.FileNames[i]) { isExist = true; sr = scriptRoot[j]; m_cur_index = j; tabControl1.SelectTab(m_cur_index); break; } } if (!isExist) { try { TabPage Page = new TabPage(); Page.Name = "Page1"; Page.Text = ofd.FileNames[i].Substring(ofd.FileNames[i].LastIndexOf("\\") + 1, ofd.FileNames[i].Length - 1 - ofd.FileNames[i].LastIndexOf("\\")); Page.BackColor = Color.White; tabControl1.Controls.Add(Page); sr = EexFile.loadFile(ofd.FileNames[i]); scriptRoot.Add(sr); tabControl1.SelectedIndex = tabControl1.Controls.Count - 1; } catch (EexReaderException exception) { MessageBox.Show(this, String.Format("文件{0},解析指令0x{1:x}出错,内部信息为:{2}", ofd.FileName[i], exception.CommandId, exception.Message)); } } } buildTreeView(sr); } }
public static ScriptRoot loadEexNewFile(String path) { using (FileStream fs = new FileStream(path, FileMode.Open)) { byte[] buffer = new byte[fs.Length]; int readLen = fs.Read(buffer, 0, buffer.Length); if (readLen != buffer.Length) { throw new EexReaderException( String.Format("读取字节数={0},总字节数={1}", readLen, buffer.Length)); } fs.Close(); ScriptRoot root = new ScriptRoot(path); root.loadNewReader(new EexBinaryReader(buffer, EexBinaryReader.ENCODING_UTF8)); return(root); } }
public override bool runCmd(CommandConfig cfg) { string destPath = Path.Combine(cfg.CheckPath, dir.Replace("%gamedir%", cfg.GameDir)); string[] files = Directory.GetFiles(destPath, file, SearchOption.AllDirectories); ScriptRoot root = new ScriptRoot(); foreach (string filePath in files) { bool eexFileOk = true; try { using (FileStream fs = new FileStream(filePath, FileMode.Open)) { byte[] buffer = new byte[fs.Length]; int readLen = fs.Read(buffer, 0, buffer.Length); fs.Close(); if (readLen == buffer.Length) { eexFileOk = root.loadReader(new EexBinaryReader(buffer, EexBinaryReader.ENCODING_UTF8)); } else { eexFileOk = false; } } } catch (Exception) { eexFileOk = false; } if (!eexFileOk) { logText("错误:" + filePath + " 格式不对!"); return(false); } } if (cfg.ShowAllLog) { logText(ToString() + " 完毕"); } return(true); }
private void 另存为AToolStripMenuItem_Click(object sender, EventArgs e) { ScriptRoot sr = scriptRoot[m_cur_index]; if (sr == null) { MessageBox.Show(this, "未加载,无法保存"); return; } SaveFileDialog sfd = new SaveFileDialog(); sfd.Title = "保存剧本文件"; sfd.Filter = "eex new剧本文件(*.eex_new)|*.eex_new"; if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { EexFile.saveFile(sr, sfd.FileName); } }
private void buildTreeView(ScriptRoot root) { treeViewRoot.BeginUpdate(); treeViewRoot.Nodes.Clear(); TreeNode tnRoot = new TreeNode(root.getNodeText()); tnRoot.Tag = root; foreach (ScriptScene item in root.SceneList) { TreeNode tnScene = new TreeNode(item.getNodeText()); tnScene.Tag = item; foreach (ScriptSection section in item.SectionList) { TreeNode tnSection = new TreeNode(section.getNodeText()); tnSection.Tag = section; addScriptCommand(tnSection, section.CommandList); tnSection.Expand(); tnScene.Nodes.Add(tnSection); } tnScene.Expand(); tnRoot.Nodes.Add(tnScene); } tnRoot.Expand(); treeViewRoot.Nodes.Add(tnRoot); treeViewRoot.EndUpdate(); treeViewRoot.ExpandAll(); foreach (TreeNode nodes in treeViewRoot.Nodes) { if (nodes.Nodes.Count > 0) { ChangeBgColor(nodes); } } }
public static void saveFile(ScriptRoot root, String path) { switch (getFileType(path)) { case EexFileType.TYPE_EEX: saveEexFile(root, path); break; case EexFileType.TYPE_EEX_NEW: saveEexNewFile(root, path); break; case EexFileType.TYPE_EEXJS: saveJsonFile(root, path); break; default: throw new EexReaderException( String.Format("{0} 扩展名不认识,无法保存", path)); } }
private void btnSave_Click(object sender, EventArgs e) { ScriptRoot sr = scriptRoot; if (sr == null) { MessageBox.Show(this, "json未加载,无法保存"); return; } /* * try * { * sr = EexFile.jsonText2ScriptRoot(tbContent.Text); * } * catch (Exception) * { * MessageBox.Show(this, "json格式错误,无法保存"); * return; * } * */ buildTreeView(sr); String readString = sr.toJsonObject().ToString(Newtonsoft.Json.Formatting.Indented); tbContent.Text = readString; SaveFileDialog sfd = new SaveFileDialog(); sfd.Title = "保存剧本文件"; sfd.Filter = "旧版本eex剧本文件(*.eex)|*.eex|新版本eex剧本文件(*.eex)|*.eex|eex new剧本文件(*.eex_new)|*.eex_new|eex json剧本文件(*.eexjs)|*.eexjs"; if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { int group = 0; if (sfd.FilterIndex <= 2) { group = sfd.FilterIndex - 1; } EexFile.saveFile(sr, sfd.FileName, group); } }
private void buildTreeView(ScriptRoot root) { treeContent.Clear(); treeViewRoot.BeginUpdate(); treeViewRoot.Nodes.Clear(); TreeNode tnRoot = new TreeNode(root.getNodeText()); tnRoot.Tag = root; treeContent[tnRoot] = root.toJsonObject().ToString(Newtonsoft.Json.Formatting.Indented); foreach (ScriptScene item in root.SceneList) { TreeNode tnScene = new TreeNode(item.getNodeText()); tnScene.Tag = item; treeContent[tnScene] = item.toJsonObject().ToString(Newtonsoft.Json.Formatting.Indented); foreach (ScriptSection section in item.SectionList) { TreeNode tnSection = new TreeNode(section.getNodeText()); tnSection.Tag = section; treeContent[tnSection] = section.toJsonObject().ToString(Newtonsoft.Json.Formatting.Indented); addScriptCommand(tnSection, section.CommandList); tnSection.Expand(); tnScene.Nodes.Add(tnSection); } tnScene.Expand(); tnRoot.Nodes.Add(tnScene); } tnRoot.Expand(); treeViewRoot.Nodes.Add(tnRoot); treeViewRoot.EndUpdate(); }
public IEnumerable <IEntityData> EntitiesById(string ids) => ScriptRoot.GetEntities().Where(E => new[] { E.Id.ToString() }.GetUniqueNames(ids).Any()).Select(E => new EntityData(ScriptRoot.GetCurrentPlayfield(), E));
public IEnumerable <IEntityData> EntitiesByName(string names) => ScriptRoot.GetEntities().Where(E => new[] { E.Name }.GetUniqueNames(names).Any()).Select(E => new EntityData(ScriptRoot.GetCurrentPlayfield(), E));
public bool IsLocked(IStructureData structure, IBlockData block) => ScriptRoot.GetCurrentPlayfield().IsStructureDeviceLocked(structure.GetCurrent().Id, block.Position);
private void btnOpen_Click(object sender, EventArgs e) { int commandId = -1; if (tbCommand.Enabled) { try { commandId = Convert.ToInt32(tbCommand.Text, 16); if (commandId < 0) { MessageBox.Show(this, "指令格式必须为16进制的数字"); tbCommand.Focus(); return; } } catch (Exception) { MessageBox.Show(this, "指令格式必须为16进制的数字"); tbCommand.Focus(); return; } } OpenFileDialog ofd = new OpenFileDialog(); ofd.Title = "打开剧本文件"; ofd.Multiselect = true; ofd.Filter = "旧版本eex剧本文件(*.eex)|*.eex|新版本eex剧本文件(*.eex)|*.eex|eex new剧本文件(*.eex_new)|*.eex_new|eex json剧本文件(*.eexjs)|*.eexjs"; ofd.Multiselect = true; if (ofd.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } string loadExcelPath = ""; if (cbLoadExcel.Checked) { FolderBrowserDialog fbdLoad = new FolderBrowserDialog(); fbdLoad.Description = "选择Excel翻译文件目录"; if (fbdLoad.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } loadExcelPath = fbdLoad.SelectedPath; } FolderBrowserDialog fbd = new FolderBrowserDialog(); fbd.Description = "选择输出文件目录"; if (fbd.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } int inGroup = 0; if (ofd.FilterIndex == 2) { inGroup = 1; } int outGroup = 0; if (rbNewEex.Checked) { outGroup = 1; } foreach (string inFilePath in ofd.FileNames) { try { ScriptRoot sr = EexFile.loadFile(inFilePath, inGroup); if (commandId >= 0 && !sr.containCommand(commandId)) { continue; } if (!String.IsNullOrEmpty(loadExcelPath)) { string excelPath = Path.Combine(loadExcelPath, Path.GetFileNameWithoutExtension(inFilePath) + ".xlsx"); if (File.Exists(excelPath)) { bool result = EexFile.loadStringFromExcel(sr, excelPath); if (!result) { MessageBox.Show(this, String.Format("加载文件{0}出错,行数太少", excelPath)); return; } } } if (rbXlsxText.Checked) { EexFile.saveStringToExcel(sr, Path.Combine(fbd.SelectedPath, getOutFileName(inFilePath))); } else { EexFile.saveFile(sr, Path.Combine(fbd.SelectedPath, getOutFileName(inFilePath)), outGroup); } } catch (EexReaderException exception) { MessageBox.Show(this, String.Format("文件{0},解析指令0x{1:x}出错,内部信息为:{2}", inFilePath, exception.CommandId, exception.Message)); return; } } MessageBox.Show(this, "转换完成"); }
public static bool loadStringFromExcel(ScriptRoot root, String path) { List <string> textList = new List <string>(); using (FileStream fs = new FileStream(path, FileMode.Open)) { XSSFWorkbook workbook = new XSSFWorkbook(fs); XSSFSheet sheet = (XSSFSheet)workbook.GetSheetAt(0); for (int i = sheet.FirstRowNum; i <= sheet.LastRowNum; i++) { XSSFRow row = (XSSFRow)sheet.GetRow(i); if (row == null || row.GetCell(0) == null) { textList.Add(""); continue; } textList.Add(row.GetCell(0).ToString()); } } int textIndex = 0; foreach (ScriptScene scene in root.SceneList) { foreach (ScriptSection section in scene.SectionList) { foreach (ScriptCommand cmd in section.CommandList) { if (cmd.ArrayValues.GetLength(0) > 0) { for (int j = 0; j < cmd.ArrayValues.GetLength(0); j++) { for (int i = 0; i < cmd.Keys.Length; i++) { int fieldId = cmd.Keys[i]; if (ScriptConfig.Instance.getEexType(fieldId) == EexType.EexString) { if (textIndex >= textList.Count) { //cmd.ArrayValues[j][i] = ""; } else { cmd.ArrayValues[j][i] = textList[textIndex]; } textIndex++; } } } } else { for (int i = 0; i < cmd.Keys.Length; i++) { int fieldId = cmd.Keys[i]; if (ScriptConfig.Instance.getEexType(fieldId) == EexType.EexString) { if (textIndex >= textList.Count) { //cmd.Values[i] = ""; } else { cmd.Values[i] = textList[textIndex]; } textIndex++; } } } } } } return(true); }