ChompQuestVerifier/DumpCleaner/LocationParser.cs

70 lines
2.1 KiB
C#
Raw Normal View History

using DumpCleaner;
2024-08-09 19:26:24 +01:00
using DumpCleaner.Models;
using QuestValidator.Common;
using QuestValidator.Common.Helpers;
using System.Text.Json;
using System.Text.Json.Nodes;
public class LocationData
{
2024-08-09 19:26:24 +01:00
public LocationData(Location location, object rawLocation)
{
Location = location;
RawLocation = rawLocation;
}
public Location Location { get; set; }
2024-08-09 19:26:24 +01:00
public object RawLocation { get; set; }
}
public class LocationParser
{
private readonly Dictionary<string, LocationData> locations = new Dictionary<string, LocationData>();
private readonly string outputPath;
public LocationParser(string outputPath)
{
this.outputPath = outputPath;
}
internal void AddLocalLootDump(Dump dumpFile, string rawJson)
{
2024-08-09 19:26:24 +01:00
var localStart = JsonSerializer.Deserialize<LocalStart>(dumpFile.data.ToString());
var locationData = JsonSerializer.Deserialize<Location>(localStart.locationLoot.ToString());
var locationName = locationData.Id;
// already parsed, skip
if (locations.ContainsKey(locationName))
{
return;
}
// remove loot as not needed for base.json
locationData.Loot?.Clear();
// remove loot from raw file
JsonNode? parsedJson = JsonNode.Parse(rawJson);
var data = parsedJson["data"];
2024-08-09 19:26:24 +01:00
var locationLoot = data["locationLoot"];
locationLoot["Loot"] = new JsonArray();
2024-08-09 19:26:24 +01:00
var lootFreeJson = locationLoot.ToString();
2024-08-09 19:26:24 +01:00
locations.Add(locationName, new LocationData(locationData, JsonSerializer.Deserialize<object>(locationLoot)));
}
internal void CreateLocationFile()
{
foreach (var location in locations)
{
if (string.Equals(location.Value.Location.Id, "lighthouse2", StringComparison.CurrentCultureIgnoreCase))
{
continue;
}
2024-08-09 19:26:24 +01:00
JsonWriter.WriteJson(location.Value.RawLocation, $"{outputPath}/{location.Value.Location.Id.ToLower()}", Directory.GetCurrentDirectory(), "base");
LoggingHelpers.LogToConsole($"Found map file: {location.Value.Location.Id} wrote file to output folder");
}
}
}