mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Use JSON serialization settings
This commit is contained in:
parent
134ba469d3
commit
0e545850cc
@ -1,10 +1,12 @@
|
||||
using NewHorizons.External;
|
||||
using NewHorizons.External.Configs;
|
||||
using NewHorizons.External.Modules;
|
||||
using Newtonsoft.Json;
|
||||
using OWML.Common;
|
||||
using OWML.Common.Menus;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -47,6 +49,12 @@ namespace NewHorizons.Utility.DebugUtilities
|
||||
private bool saveButtonUnlocked = false;
|
||||
private Vector2 recentModListScrollPosition = Vector2.zero;
|
||||
|
||||
private static JsonSerializerSettings jsonSettings = new JsonSerializerSettings
|
||||
{
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
DefaultValueHandling = DefaultValueHandling.Ignore,
|
||||
Formatting = Formatting.Indented,
|
||||
};
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@ -54,6 +62,7 @@ namespace NewHorizons.Utility.DebugUtilities
|
||||
_drc = this.GetRequiredComponent<DebugRaycaster>();
|
||||
LoadFavoriteProps();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (!Main.Debug) return;
|
||||
@ -85,6 +94,7 @@ namespace NewHorizons.Utility.DebugUtilities
|
||||
pauseMenuButton = Main.Instance.ModHelper.Menus.PauseMenu.OptionsButton.Duplicate("Toggle Prop Placer Menu".ToUpper());
|
||||
InitMenu();
|
||||
}
|
||||
|
||||
private void RestoreMenuOpennessState() { menuOpen = openMenuOnPause; }
|
||||
private void ToggleMenu() { menuOpen = !menuOpen; openMenuOnPause = !openMenuOnPause; }
|
||||
|
||||
@ -237,22 +247,28 @@ namespace NewHorizons.Utility.DebugUtilities
|
||||
|
||||
var relativePath = filePath.Replace(loadedMod.ModHelper.Manifest.ModFolderPath, "");
|
||||
|
||||
var json = JsonConvert.SerializeObject(loadedConfigFiles[filePath], jsonSettings);
|
||||
// Add the schema line
|
||||
json = "{\n\t\"$schema\": \"https://raw.githubusercontent.com/xen-42/outer-wilds-new-horizons/main/NewHorizons/Schemas/body_schema.json\"," + json.Substring(1);
|
||||
|
||||
try
|
||||
{
|
||||
Logger.Log("Saving... " + relativePath + " to " + filePath);
|
||||
var directoryName = System.IO.Path.GetDirectoryName(loadedMod.ModHelper.Manifest.ModFolderPath + relativePath);
|
||||
System.IO.Directory.CreateDirectory(directoryName);
|
||||
var path = loadedMod.ModHelper.Manifest.ModFolderPath + relativePath;
|
||||
var directoryName = Path.GetDirectoryName(path);
|
||||
Directory.CreateDirectory(directoryName);
|
||||
|
||||
loadedMod.ModHelper.Storage.Save(loadedConfigFiles[filePath], relativePath);
|
||||
File.WriteAllText(path, json);
|
||||
}
|
||||
catch (Exception e) { Logger.LogError("Failed to save file " + backupFolderName + relativePath); Logger.LogError(e.Message + "\n" + e.StackTrace); }
|
||||
|
||||
try
|
||||
{
|
||||
var directoryName = System.IO.Path.GetDirectoryName(Main.Instance.ModHelper.Manifest.ModFolderPath + backupFolderName + relativePath);
|
||||
System.IO.Directory.CreateDirectory(directoryName);
|
||||
var path = Main.Instance.ModHelper.Manifest.ModFolderPath + backupFolderName + relativePath;
|
||||
var directoryName = Path.GetDirectoryName(path);
|
||||
Directory.CreateDirectory(directoryName);
|
||||
|
||||
Main.Instance.ModHelper.Storage.Save(loadedConfigFiles[filePath], backupFolderName+relativePath);
|
||||
File.WriteAllText(path, json);
|
||||
}
|
||||
catch (Exception e) { Logger.LogError("Failed to save backup file " + backupFolderName + relativePath); Logger.LogError(e.Message + "\n" + e.StackTrace); }
|
||||
}
|
||||
@ -312,7 +328,6 @@ namespace NewHorizons.Utility.DebugUtilities
|
||||
_dpp = this.GetRequiredComponent<DebugPropPlacer>();
|
||||
_drc = this.GetRequiredComponent<DebugRaycaster>();
|
||||
|
||||
|
||||
Texture2D bgTexture = ImageUtilities.MakeSolidColorTexture((int)EditorMenuSize.x, (int)EditorMenuSize.y, Color.black);
|
||||
|
||||
_editorMenuStyle = new GUIStyle
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user