Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using Oculus.Newtonsoft.Json;
- using Oculus.Newtonsoft.Json.Linq;
- using UnityEngine;
- namespace SubnauticaBZRP
- {
- public class Json : MonoBehaviour
- {
- public class Root
- {
- public List<BiomeNames> BiomeNames { get; set; }
- }
- public class BiomeNames
- {
- public int BiomeId { get; set; }
- public string Biomename { get; set; }
- public string TimeDateFound { get; set; }
- public string Location { get; set; }
- }
- public static bool CheckIfBiomeExists(string bName)
- {
- bool found = false;
- var fileContent = File.ReadAllText(ConfigFile.lightStatePath);
- var accountsFromFile = JsonConvert.DeserializeObject<Root>(fileContent);
- foreach (var c in accountsFromFile.BiomeNames)
- {
- if (!c.Biomename.Equals(bName))
- {
- found = true;
- break;
- }
- }
- return found;
- }
- public static void CreateJson()
- {
- var setting = new JsonSerializerSettings();
- setting.Formatting = Formatting.Indented;
- setting.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
- setting.CheckAdditionalContent = true;
- var jsonString = "{" +
- "\"BiomeNames\": [" +
- "{\"BiomeId\": \"0\"," +
- "\"Biomename\": \"First\"" +
- ",\"TimeDateFound\": \"Now\"" +
- ",\"Location\": \"Here\"}," +
- "]}";
- var damn = JsonConvert.DeserializeObject(jsonString);
- var shit = JsonConvert.SerializeObject(damn, setting);
- File.AppendAllText(ConfigFile.lightStatePath, shit);
- }
- public static void AddNewBiome(string bName)
- {
- if(!File.Exists(ConfigFile.lightStatePath))
- {
- CreateJson();
- }
- else if (CheckIfBiomeExists(bName))
- {
- int biomeId = 0;
- var setting = new JsonSerializerSettings();
- setting.Formatting = Formatting.Indented;
- setting.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
- setting.CheckAdditionalContent = true;
- int locX = Mathf.FloorToInt(Player.main.rigidBody.velocity.x);
- int locY = Mathf.FloorToInt(Player.main.rigidBody.velocity.y);
- int locZ = Mathf.FloorToInt(Player.main.rigidBody.velocity.z);
- string locXYZ = $"{locX},{locY},{locZ}";
- // var fileContent = File.ReadAllText(ConfigFile.lightStatePath);
- //var accountsFromFile = JsonConvert.DeserializeObject<Root>(fileContent);
- JObject root = (JObject)JsonConvert.DeserializeObject(File.ReadAllText(ConfigFile.lightStatePath));
- JArray biomeNames = (Oculus.Newtonsoft.Json.Linq.JArray)root["BiomeNames"];
- JObject newItem = new JObject();
- newItem["BiomeId"] = biomeId;
- newItem["Biomename"] = bName;
- newItem["TimeDateFound"] = DateTime.Now.ToString();
- newItem["Location"] = locXYZ;
- // ...
- biomeNames.Add(newItem);
- biomeId++;
- var json = JsonConvert.SerializeObject(biomeNames, setting);
- File.AppendAllText(ConfigFile.lightStatePath, json);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement