From b70402c50bbc0b0807129071cf36224cd0d07e3b Mon Sep 17 00:00:00 2001 From: sowgro Date: Sun, 18 May 2025 00:34:12 -0400 Subject: [PATCH 1/3] Add option to export to JSON --- .../Editor/GameRuleFileEditor.Designer.cs | 61 ++++++++++--------- PCK-Studio/Forms/Editor/GameRuleFileEditor.cs | 22 +++++++ .../Forms/Editor/GameRuleFileEditor.resx | 3 + Vendor/OMI-Lib | 2 +- 4 files changed, 57 insertions(+), 31 deletions(-) diff --git a/PCK-Studio/Forms/Editor/GameRuleFileEditor.Designer.cs b/PCK-Studio/Forms/Editor/GameRuleFileEditor.Designer.cs index d7e8c3de..1e5e4a97 100644 --- a/PCK-Studio/Forms/Editor/GameRuleFileEditor.Designer.cs +++ b/PCK-Studio/Forms/Editor/GameRuleFileEditor.Designer.cs @@ -44,6 +44,7 @@ private void InitializeComponent() this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.openToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.exportToJSONToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.compressionLvlToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.levelToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.noneToolStripMenuItem = new PckStudio.ToolboxItems.ToolStripRadioButtonMenuItem(); @@ -55,6 +56,7 @@ private void InitializeComponent() this.pS3ToolStripMenuItem = new PckStudio.ToolboxItems.ToolStripRadioButtonMenuItem(); this.xbox360ToolStripMenuItem = new PckStudio.ToolboxItems.ToolStripRadioButtonMenuItem(); this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); + this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog(); this.MessageContextMenu.SuspendLayout(); this.DetailContextMenu.SuspendLayout(); this.menuStrip1.SuspendLayout(); @@ -77,9 +79,7 @@ private void InitializeComponent() // // MessageContextMenu // - this.MessageContextMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.addGameRuleToolStripMenuItem, - this.removeGameRuleToolStripMenuItem}); + this.MessageContextMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.addGameRuleToolStripMenuItem, this.removeGameRuleToolStripMenuItem }); this.MessageContextMenu.Name = "MessageContextMenu"; this.MessageContextMenu.Size = new System.Drawing.Size(178, 48); // @@ -108,14 +108,13 @@ private void InitializeComponent() this.GrfParametersTreeView.Name = "GrfParametersTreeView"; this.GrfParametersTreeView.Size = new System.Drawing.Size(219, 312); this.GrfParametersTreeView.TabIndex = 1; + this.GrfParametersTreeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.GrfParametersTreeView_AfterSelect); this.GrfParametersTreeView.NodeMouseDoubleClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.GrfDetailsTreeView_NodeMouseDoubleClick); this.GrfParametersTreeView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.GrfDetailsTreeView_KeyDown); // // DetailContextMenu // - this.DetailContextMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.addToolStripMenuItem1, - this.removeToolStripMenuItem}); + this.DetailContextMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.addToolStripMenuItem1, this.removeToolStripMenuItem }); this.DetailContextMenu.Name = "DetailContextMenu"; this.DetailContextMenu.Size = new System.Drawing.Size(118, 48); // @@ -158,9 +157,7 @@ private void InitializeComponent() // menuStrip1 // this.menuStrip1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64))))); - this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.fileToolStripMenuItem, - this.compressionLvlToolStripMenuItem}); + this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.fileToolStripMenuItem, this.compressionLvlToolStripMenuItem }); this.menuStrip1.Location = new System.Drawing.Point(25, 60); this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Size = new System.Drawing.Size(450, 24); @@ -169,9 +166,7 @@ private void InitializeComponent() // // fileToolStripMenuItem // - this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.openToolStripMenuItem, - this.saveToolStripMenuItem}); + this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.openToolStripMenuItem, this.saveToolStripMenuItem, this.exportToJSONToolStripMenuItem }); this.fileToolStripMenuItem.ForeColor = System.Drawing.SystemColors.Menu; this.fileToolStripMenuItem.Name = "fileToolStripMenuItem"; this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20); @@ -180,7 +175,7 @@ private void InitializeComponent() // openToolStripMenuItem // this.openToolStripMenuItem.Name = "openToolStripMenuItem"; - this.openToolStripMenuItem.Size = new System.Drawing.Size(103, 22); + this.openToolStripMenuItem.Size = new System.Drawing.Size(154, 22); this.openToolStripMenuItem.Text = "Open"; this.openToolStripMenuItem.Click += new System.EventHandler(this.openToolStripMenuItem_Click); // @@ -188,15 +183,20 @@ private void InitializeComponent() // this.saveToolStripMenuItem.BackColor = System.Drawing.Color.Transparent; this.saveToolStripMenuItem.Name = "saveToolStripMenuItem"; - this.saveToolStripMenuItem.Size = new System.Drawing.Size(103, 22); + this.saveToolStripMenuItem.Size = new System.Drawing.Size(154, 22); this.saveToolStripMenuItem.Text = "Save"; this.saveToolStripMenuItem.Click += new System.EventHandler(this.saveToolStripMenuItem_Click); // + // exportToJSONToolStripMenuItem + // + this.exportToJSONToolStripMenuItem.Name = "exportToJSONToolStripMenuItem"; + this.exportToJSONToolStripMenuItem.Size = new System.Drawing.Size(154, 22); + this.exportToJSONToolStripMenuItem.Text = "Export To JSON"; + this.exportToJSONToolStripMenuItem.Click += new System.EventHandler(this.exportToJSONToolStripMenuItem_Click); + // // compressionLvlToolStripMenuItem // - this.compressionLvlToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.levelToolStripMenuItem, - this.typeToolStripMenuItem}); + this.compressionLvlToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.levelToolStripMenuItem, this.typeToolStripMenuItem }); this.compressionLvlToolStripMenuItem.ForeColor = System.Drawing.SystemColors.Menu; this.compressionLvlToolStripMenuItem.Name = "compressionLvlToolStripMenuItem"; this.compressionLvlToolStripMenuItem.Size = new System.Drawing.Size(89, 20); @@ -205,11 +205,7 @@ private void InitializeComponent() // levelToolStripMenuItem // this.levelToolStripMenuItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; - this.levelToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.noneToolStripMenuItem, - this.compressedToolStripMenuItem, - this.compressedRLEToolStripMenuItem, - this.compressedRLECRCToolStripMenuItem}); + this.levelToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.noneToolStripMenuItem, this.compressedToolStripMenuItem, this.compressedRLEToolStripMenuItem, this.compressedRLECRCToolStripMenuItem }); this.levelToolStripMenuItem.Name = "levelToolStripMenuItem"; this.levelToolStripMenuItem.Size = new System.Drawing.Size(101, 22); this.levelToolStripMenuItem.Text = "Level"; @@ -251,10 +247,7 @@ private void InitializeComponent() // typeToolStripMenuItem // this.typeToolStripMenuItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; - this.typeToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.wiiUPSVitaToolStripMenuItem, - this.pS3ToolStripMenuItem, - this.xbox360ToolStripMenuItem}); + this.typeToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.wiiUPSVitaToolStripMenuItem, this.pS3ToolStripMenuItem, this.xbox360ToolStripMenuItem }); this.typeToolStripMenuItem.Name = "typeToolStripMenuItem"; this.typeToolStripMenuItem.Size = new System.Drawing.Size(101, 22); this.typeToolStripMenuItem.Text = "Type"; @@ -293,9 +286,7 @@ private void InitializeComponent() // // tableLayoutPanel1 // - this.tableLayoutPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); + this.tableLayoutPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.tableLayoutPanel1.Controls.Add(this.metroLabel1, 0, 0); @@ -310,6 +301,13 @@ private void InitializeComponent() this.tableLayoutPanel1.Size = new System.Drawing.Size(450, 312); this.tableLayoutPanel1.TabIndex = 4; // + // saveFileDialog1 + // + this.saveFileDialog1.DefaultExt = "json"; + this.saveFileDialog1.Filter = "JSON File|*.json"; + this.saveFileDialog1.Title = "Export to JSON"; + this.saveFileDialog1.FileOk += new System.ComponentModel.CancelEventHandler(this.saveFileDialog1_FileOk); + // // GameRuleFileEditor // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -337,9 +335,12 @@ private void InitializeComponent() this.tableLayoutPanel1.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); - } + private System.Windows.Forms.SaveFileDialog saveFileDialog1; + + private System.Windows.Forms.ToolStripMenuItem exportToJSONToolStripMenuItem; + #endregion private System.Windows.Forms.TreeView GrfTreeView; diff --git a/PCK-Studio/Forms/Editor/GameRuleFileEditor.cs b/PCK-Studio/Forms/Editor/GameRuleFileEditor.cs index 0abbcf56..425b2247 100644 --- a/PCK-Studio/Forms/Editor/GameRuleFileEditor.cs +++ b/PCK-Studio/Forms/Editor/GameRuleFileEditor.cs @@ -17,8 +17,11 @@ **/ using System; using System.Collections.Generic; +using System.ComponentModel; +using System.IO; using System.Linq; using System.Windows.Forms; +using Newtonsoft.Json; using PckStudio.Forms.Additional_Popups.Grf; using PckStudio.Internal.Misc; using OMI.Formats.GameRule; @@ -268,5 +271,24 @@ private void GameRuleFileEditor_FormClosing(object sender, FormClosingEventArgs saveToolStripMenuItem_Click(sender, EventArgs.Empty); } } + + private void exportToJSONToolStripMenuItem_Click(object sender, EventArgs e) + { + saveFileDialog1.FileName = "gameRules.json"; + saveFileDialog1.ShowDialog(); + } + + private void saveFileDialog1_FileOk(object sender, CancelEventArgs e) + { + if (saveFileDialog1.FileName == "") + { + return; + } + + TextWriter writer = new StreamWriter(saveFileDialog1.FileName); + JsonSerializer serializer = new JsonSerializer(); + serializer.Formatting = Formatting.Indented; + serializer.Serialize(writer, _file.Root.ChildRules); + } } } diff --git a/PCK-Studio/Forms/Editor/GameRuleFileEditor.resx b/PCK-Studio/Forms/Editor/GameRuleFileEditor.resx index 90505333..be82ab78 100644 --- a/PCK-Studio/Forms/Editor/GameRuleFileEditor.resx +++ b/PCK-Studio/Forms/Editor/GameRuleFileEditor.resx @@ -126,6 +126,9 @@ 348, 17 + + 454, 18 + diff --git a/Vendor/OMI-Lib b/Vendor/OMI-Lib index cbb980c4..a8494d53 160000 --- a/Vendor/OMI-Lib +++ b/Vendor/OMI-Lib @@ -1 +1 @@ -Subproject commit cbb980c490e24535ea1b750bc921c702fde98345 +Subproject commit a8494d5300b9078bb35dbff999a3236d2fe33b75 From b737d931bb9020b315104dc1e8a6aae11a148d9d Mon Sep 17 00:00:00 2001 From: sowgro Date: Sun, 18 May 2025 00:37:57 -0400 Subject: [PATCH 2/3] Remove broken generated code --- PCK-Studio/Forms/Editor/GameRuleFileEditor.Designer.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/PCK-Studio/Forms/Editor/GameRuleFileEditor.Designer.cs b/PCK-Studio/Forms/Editor/GameRuleFileEditor.Designer.cs index 1e5e4a97..5148b8d5 100644 --- a/PCK-Studio/Forms/Editor/GameRuleFileEditor.Designer.cs +++ b/PCK-Studio/Forms/Editor/GameRuleFileEditor.Designer.cs @@ -108,7 +108,6 @@ private void InitializeComponent() this.GrfParametersTreeView.Name = "GrfParametersTreeView"; this.GrfParametersTreeView.Size = new System.Drawing.Size(219, 312); this.GrfParametersTreeView.TabIndex = 1; - this.GrfParametersTreeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.GrfParametersTreeView_AfterSelect); this.GrfParametersTreeView.NodeMouseDoubleClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.GrfDetailsTreeView_NodeMouseDoubleClick); this.GrfParametersTreeView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.GrfDetailsTreeView_KeyDown); // From 87639fb0270750de2feb81fb9234356fe6cb1d71 Mon Sep 17 00:00:00 2001 From: sowgro Date: Sun, 18 May 2025 00:55:34 -0400 Subject: [PATCH 3/3] Flush writer --- PCK-Studio/Forms/Editor/GameRuleFileEditor.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/PCK-Studio/Forms/Editor/GameRuleFileEditor.cs b/PCK-Studio/Forms/Editor/GameRuleFileEditor.cs index 425b2247..105e7633 100644 --- a/PCK-Studio/Forms/Editor/GameRuleFileEditor.cs +++ b/PCK-Studio/Forms/Editor/GameRuleFileEditor.cs @@ -289,6 +289,7 @@ private void saveFileDialog1_FileOk(object sender, CancelEventArgs e) JsonSerializer serializer = new JsonSerializer(); serializer.Formatting = Formatting.Indented; serializer.Serialize(writer, _file.Root.ChildRules); + writer.Flush(); } } }