megamappingway/game-data-extractor/Maps.cs

85 lines
2.8 KiB
C#

using Lumina;
using Lumina.Excel.GeneratedSheets;
namespace GameDataExtractor;
internal class Maps {
private GameData Data { get; }
internal Maps(GameData data) {
this.Data = data;
}
internal List<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));
var quests = this.Data.GetExcelSheet<Quest>()!;
foreach (var (map, territory, name) in fromMaps.Concat(fromTerris)) {
if (!dict.ContainsKey(territory.RowId)) {
var (subtitle, category) = territory.GetSubtitleAndCategory(quests);
dict[territory.RowId] = new TerritoryInfo {
Id = territory.RowId,
Name = name!,
Subtitle = subtitle,
Category = category,
Battle = territory.ContentFinderCondition.Row != 0,
Maps = new List<MapInfo>(),
};
}
var id = map.Id.RawString;
if (string.IsNullOrWhiteSpace(id)) {
continue;
}
if (dict[territory.RowId].Maps.Any(info => info.Id == id)) {
continue;
}
dict[territory.RowId].Maps.Add(new MapInfo {
Id = id,
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
.OrderBy(entry => entry.Value.Battle)
.ThenBy(entry => entry.Key)
.Select(entry => entry.Value)
.ToList();
}
}
[Serializable]
public class TerritoryInfo {
public uint Id { get; set; }
public string Name { get; set; }
public string? Subtitle { get; set; }
public string? Category { get; set; }
public bool Battle { get; init; }
public List<MapInfo> Maps { get; init; }
}
[Serializable]
public class MapInfo {
public string Id { get; init; }
public short OffsetX { get; init; }
public short OffsetY { get; init; }
public ushort Scale { get; init; }
}