Skip to content

Commit

Permalink
saving edited files experiments.
Browse files Browse the repository at this point in the history
  • Loading branch information
se5a committed Jun 3, 2024
1 parent bf1a38a commit 4e75311
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
31 changes: 27 additions & 4 deletions Pulsar4X/Pulsar4X.Client/ModFileEditing/BluePrintsUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Numerics;
using ImGuiNET;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Pulsar4X.Blueprints;
using Pulsar4X.DataStructures;
using Pulsar4X.Interfaces;
Expand Down Expand Up @@ -116,7 +117,7 @@ public void Display(string label)
{
if (FileDialog.Display(ref _fileDialogPath, ref _fileName, ref _showFileDialog))
{

Save();
}
}
}
Expand Down Expand Up @@ -186,14 +187,36 @@ protected override void Save()
{
using (StreamWriter outputFile = new StreamWriter(Path.Combine(_fileDialogPath, _fileName)))
{
foreach (TechCategoryBlueprint blueprint in _itemBlueprints)

var tcb = new Tcb() {};
tcb.Payload = new List<TechCategoryBlueprint>();
foreach (TechCategoryBlueprint bpt in _itemBlueprints)
{
tcb.Payload.Add(bpt);
}
var json = JsonConvert.SerializeObject(tcb, Formatting.Indented);
outputFile.WriteLine(json);


/*
Dictionary<ModInstruction.DataType, List<TechCategoryBlueprint>> dic = new Dictionary<ModInstruction.DataType, List<TechCategoryBlueprint>>();
dic.Add(ModInstruction.DataType.TechCategory, new List<TechCategoryBlueprint>());
foreach (TechCategoryBlueprint bpt in _itemBlueprints)
{
var json = JsonConvert.SerializeObject(blueprint, Formatting.Indented);
outputFile.WriteLine(json);
dic[ModInstruction.DataType.TechCategory].Add(bpt);
}
var json = JsonConvert.SerializeObject(dic, Formatting.Indented);
outputFile.WriteLine(json);
*/
}
}

class Tcb
{
[JsonConverter(typeof(StringEnumConverter))]
public ModInstruction.DataType Type = ModInstruction.DataType.TechCategory;
public List<TechCategoryBlueprint> Payload;
}

public override void DisplayEditorWindow(int selectedIndex)
{
Expand Down
7 changes: 7 additions & 0 deletions Pulsar4X/Pulsar4X.Client/ModFileEditing/FileDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
namespace Pulsar4X.SDL2UI.ModFileEditing;


/*TODO:
*Conformation Dialog if overwriting.
*Ability to filter by file extension
*Proper colomn sizing
*Filter by colomns
*/

public static class FileDialog
{
public enum SaveOrLoad
Expand Down

0 comments on commit 4e75311

Please sign in to comment.