mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Serializer that uses tabs
This commit is contained in:
parent
22f4063ca0
commit
c2483a3271
@ -225,9 +225,7 @@ namespace NewHorizons.Utility.DebugMenu
|
||||
|
||||
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);
|
||||
var json = loadedConfigFiles[filePath].ToSerializedJson();
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
@ -1,15 +1,48 @@
|
||||
using NewHorizons.External.Configs;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using UnityEngine;
|
||||
using NomaiCoordinates = NewHorizons.External.Configs.StarSystemConfig.NomaiCoordinates;
|
||||
|
||||
namespace NewHorizons.Utility
|
||||
{
|
||||
public static class NewHorizonsExtensions
|
||||
{
|
||||
private static JsonSerializer jsonSerializer = new JsonSerializer
|
||||
{
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
DefaultValueHandling = DefaultValueHandling.Ignore,
|
||||
Formatting = Formatting.Indented,
|
||||
};
|
||||
|
||||
private static StringBuilder stringBuilder = new StringBuilder();
|
||||
|
||||
public static string ToSerializedJson(this PlanetConfig planetConfig)
|
||||
{
|
||||
string json = "{}";
|
||||
using (StringWriter stringWriter = new StringWriter(stringBuilder))
|
||||
{
|
||||
using (JsonTextWriter jsonTextWriter = new JsonTextWriter(stringWriter)
|
||||
{
|
||||
Formatting = Formatting.Indented,
|
||||
IndentChar = '\t',
|
||||
Indentation = 1
|
||||
})
|
||||
{
|
||||
jsonSerializer.Serialize(jsonTextWriter, planetConfig);
|
||||
json = "{\n\t\"$schema\": \"https://raw.githubusercontent.com/xen-42/outer-wilds-new-horizons/main/NewHorizons/Schemas/body_schema.json\"," + stringBuilder.ToString().Substring(1);
|
||||
stringBuilder.Clear();
|
||||
}
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
public static MVector3 ToMVector3(this Vector3 vector3)
|
||||
{
|
||||
return new MVector3(vector3.x, vector3.y, vector3.z);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user