chore(extractor): add game data extractor

This commit is contained in:
Anna 2023-10-13 04:23:07 -04:00
parent a5b49f1b84
commit 96087e337f
Signed by: anna
GPG Key ID: D0943384CD9F87D1
6 changed files with 153 additions and 0 deletions

7
game-data-extractor/.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
bin/
obj/
/packages/
riderModule.iml
/_ReSharper.Caches/
/territories.json
/worlds.json

View File

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Lumina" Version="3.12.1" />
<PackageReference Include="Lumina.Excel" Version="6.5.0" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GameDataExtractor", "GameDataExtractor.csproj", "{A5787DDB-B0CE-4E36-A188-F3E2F431C716}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A5787DDB-B0CE-4E36-A188-F3E2F431C716}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A5787DDB-B0CE-4E36-A188-F3E2F431C716}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A5787DDB-B0CE-4E36-A188-F3E2F431C716}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A5787DDB-B0CE-4E36-A188-F3E2F431C716}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,71 @@
using Lumina;
using Lumina.Excel.GeneratedSheets;
namespace GameDataExtractor;
internal class Maps {
private GameData Data { get; }
internal Maps(GameData data) {
this.Data = data;
}
internal Dictionary<uint, TerritoryInfo> Extract() {
var dict = new Dictionary<uint, TerritoryInfo>();
var fromMaps = this.Data.GetExcelSheet<Map>()!
.Where(map => map.RowId != 0 && map.TerritoryType.Row != 0)
.Select(map => (Map: map, Territory: map.TerritoryType.Value!, Name: map.TerritoryType.Value?.PlaceName.Value?.Name.RawString))
.Where(tuple => !string.IsNullOrWhiteSpace(tuple.Name));
var fromTerris = this.Data.GetExcelSheet<TerritoryType>()!
.Where(terri => terri.RowId != 0 && terri.Map.Row != 0)
.Select(terri => (Map: terri.Map.Value!, Territory: terri, Name: terri.PlaceName.Value?.Name.RawString))
.Where(tuple => !string.IsNullOrWhiteSpace(tuple.Name));
foreach (var (map, territory, name) in fromMaps.Concat(fromTerris)) {
if (!dict.ContainsKey(territory.RowId)) {
dict[territory.RowId] = new TerritoryInfo {
Battle = territory.ContentFinderCondition.Row != 0,
Maps = new List<MapInfo>(),
};
}
var id = map.Id.RawString;
if (string.IsNullOrWhiteSpace(id) || string.IsNullOrWhiteSpace(name)) {
continue;
}
if (dict[territory.RowId].Maps.Any(info => info.Id == id)) {
continue;
}
dict[territory.RowId].Maps.Add(new MapInfo {
Id = id,
Name = name,
OffsetX = map.OffsetX,
OffsetY = map.OffsetY,
Scale = map.SizeFactor,
});
}
foreach (var info in dict.Values) {
info.Maps.Sort((a, b) => string.Compare(a.Id, b.Id, StringComparison.Ordinal));
}
return dict;
}
}
[Serializable]
public class TerritoryInfo {
public bool Battle { get; init; }
public List<MapInfo> Maps { get; init; }
}
[Serializable]
public class MapInfo {
public string Id { get; init; }
public string Name { get; init; }
public short OffsetX { get; init; }
public short OffsetY { get; init; }
public ushort Scale { get; init; }
}

View File

@ -0,0 +1,19 @@
using System.Text.Json;
using GameDataExtractor;
using Lumina;
var data = new GameData("/home/anna/.xlcore/ffxiv/game/sqpack");
var maps = new Maps(data).Extract();
var worlds = new Worlds(data).Extract();
await WriteToFile("territories.json", maps);
await WriteToFile("worlds.json", worlds);
Console.WriteLine("Done");
return;
async Task WriteToFile<T>(string path, T item) {
await using var file = File.Create(path);
await JsonSerializer.SerializeAsync(file, item);
}

View File

@ -0,0 +1,25 @@
using Lumina;
using Lumina.Excel.GeneratedSheets;
namespace GameDataExtractor;
internal class Worlds {
private GameData Data { get; }
internal Worlds(GameData data) {
this.Data = data;
}
internal Dictionary<uint, string> Extract() {
var worlds = new Dictionary<uint, string>();
foreach (var world in this.Data.GetExcelSheet<World>()!) {
if (!world.IsPublic) {
continue;
}
worlds[world.RowId] = world.Name.RawString;
}
return worlds;
}
}