コード例 #1
0
ファイル: ToolWindow.cs プロジェクト: lofcz/SimplexRpgEngine
        void rec(DarkTreeNode dtn)
        {
            foreach (DarkTreeNode d in dtn.Nodes)
            {
                if (!d.IsFolder)
                {
                    SimplexProjectItem spi = new SimplexProjectItem();
                    spi.path      = d.FullPath;
                    spi.name      = d.Text;
                    spi.nameColor = d.Color;
                    spi.tag       = d.SuffixText;
                    spi.tagColor  = d.SuffixColor;

                    spi.path = spi.path.Replace("\\", "/");
                    spi.path = spi.path.Substring(0, spi.path.LastIndexOf("/"));
                    objects.Add(spi);
                }
                else
                {
                    rec(d);
                }
            }
        }
コード例 #2
0
ファイル: ToolWindow.cs プロジェクト: lofcz/SimplexRpgEngine
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            if (dtv.SelectedNodes.Count > 0)
            {
                string editorPath    = dtv.SelectedNodes[0].FullPath;
                string currentFolder = Directory.GetParent(Environment.CurrentDirectory).Parent.Parent.FullName +
                                       @"\SimplexCore\Prefabs\PrefabObject.cs";

                // get prefab class
                string[] prefabText = File.ReadAllLines(currentFolder);

                string className = Sgml.get_string("", "Object name");

                // generate actual class
                currentFolder = Directory.GetParent(Environment.CurrentDirectory).Parent.Parent.FullName +
                                @"\SimplexResources\Objects\" + className + ".cs";

                using (StreamWriter sw = new StreamWriter(currentFolder))
                {
                    foreach (string line in prefabText)
                    {
                        string ll = line;
                        ll = ll.Replace("{editorPath}", editorPath.Replace("\\", "/"));
                        ll = ll.Replace("PrefabObject", className);
                        ll = ll.Replace("SimplexCore.Prefabs", "SimplexResources.Objects");
                        sw.WriteLine(ll);
                    }

                    sw.Close();
                }

                // add new object
                // 1) locate projitems
                currentFolder = Directory.GetParent(Environment.CurrentDirectory).Parent.Parent.FullName +
                                @"\SimplexResources\SimplexResources.projitems";

                XDocument doc  = XDocument.Load(currentFolder);
                XElement  root = new XElement("Compile");
                root.Add(new XAttribute("Include", @"$(MSBuildThisFileDirectory)Objects\" + className + ".cs"));

                var v = doc.Root.Nodes().ToList();

                foreach (XElement xx in v)
                {
                    if (xx.Name.LocalName == "ItemGroup")
                    {
                        // good boi we can write here
                        xx.Add(root);
                        break; // prevent from adding to each root
                    }
                }

                doc.Save(currentFolder);

                // add new object to the sproject
                SimplexProjectItem spi = new SimplexProjectItem();
                spi.name = className;
                spi.path = editorPath;

                form1.currentProject.Objects.Add(spi);

                // finally save sproject
                string json = JsonConvert.SerializeObject(form1.currentProject, Formatting.Indented);
                File.WriteAllText(form1.currentProject.ProjectPath, json);

                DarkMessageBox.Show("Object was created, please restart the engine for changes to take effect.", "New object wizard");
            }
        }