refactor: update for api 9
This commit is contained in:
parent
3ab9670da1
commit
89cfed4300
|
@ -6,68 +6,67 @@ using System.Linq;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Dalamud.Game;
|
|
||||||
using Dalamud.Game.Gui.PartyFinder.Types;
|
using Dalamud.Game.Gui.PartyFinder.Types;
|
||||||
using Dalamud.Logging;
|
using Dalamud.Plugin.Services;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace RemotePartyFinder {
|
namespace RemotePartyFinder;
|
||||||
internal class Gatherer : IDisposable {
|
|
||||||
#if DEBUG
|
internal class Gatherer : IDisposable {
|
||||||
|
#if DEBUG
|
||||||
private const string UploadUrl = "http://192.168.174.240:7878/contribute/multiple";
|
private const string UploadUrl = "http://192.168.174.240:7878/contribute/multiple";
|
||||||
#elif RELEASE
|
#elif RELEASE
|
||||||
private const string UploadUrl = "https://xivpf.com/contribute/multiple";
|
private const string UploadUrl = "https://xivpf.com/contribute/multiple";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private Plugin Plugin { get; }
|
private Plugin Plugin { get; }
|
||||||
|
|
||||||
private ConcurrentDictionary<int, List<PartyFinderListing>> Batches { get; } = new();
|
private ConcurrentDictionary<int, List<PartyFinderListing>> Batches { get; } = new();
|
||||||
private Stopwatch UploadTimer { get; } = new();
|
private Stopwatch UploadTimer { get; } = new();
|
||||||
private HttpClient Client { get; } = new();
|
private HttpClient Client { get; } = new();
|
||||||
|
|
||||||
internal Gatherer(Plugin plugin) {
|
internal Gatherer(Plugin plugin) {
|
||||||
this.Plugin = plugin;
|
this.Plugin = plugin;
|
||||||
|
|
||||||
this.UploadTimer.Start();
|
this.UploadTimer.Start();
|
||||||
|
|
||||||
this.Plugin.PartyFinderGui.ReceiveListing += this.OnListing;
|
this.Plugin.PartyFinderGui.ReceiveListing += this.OnListing;
|
||||||
this.Plugin.Framework.Update += this.OnUpdate;
|
this.Plugin.Framework.Update += this.OnUpdate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose() {
|
||||||
|
this.Plugin.Framework.Update -= this.OnUpdate;
|
||||||
|
this.Plugin.PartyFinderGui.ReceiveListing -= this.OnListing;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnListing(PartyFinderListing listing, PartyFinderListingEventArgs args) {
|
||||||
|
if (!this.Batches.ContainsKey(args.BatchNumber)) {
|
||||||
|
this.Batches[args.BatchNumber] = new List<PartyFinderListing>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose() {
|
this.Batches[args.BatchNumber].Add(listing);
|
||||||
this.Plugin.Framework.Update -= this.OnUpdate;
|
}
|
||||||
this.Plugin.PartyFinderGui.ReceiveListing -= this.OnListing;
|
|
||||||
|
private void OnUpdate(IFramework framework1) {
|
||||||
|
if (this.UploadTimer.Elapsed < TimeSpan.FromSeconds(10)) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnListing(PartyFinderListing listing, PartyFinderListingEventArgs args) {
|
this.UploadTimer.Restart();
|
||||||
if (!this.Batches.ContainsKey(args.BatchNumber)) {
|
|
||||||
this.Batches[args.BatchNumber] = new List<PartyFinderListing>();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Batches[args.BatchNumber].Add(listing);
|
foreach (var (batch, listings) in this.Batches.ToList()) {
|
||||||
}
|
this.Batches.Remove(batch, out _);
|
||||||
|
Task.Run(async () => {
|
||||||
private void OnUpdate(Framework framework) {
|
var uploadable = listings
|
||||||
if (this.UploadTimer.Elapsed < TimeSpan.FromSeconds(10)) {
|
.Select(listing => new UploadableListing(listing))
|
||||||
return;
|
.ToList();
|
||||||
}
|
var json = JsonConvert.SerializeObject(uploadable);
|
||||||
|
var resp = await this.Client.PostAsync(UploadUrl, new StringContent(json) {
|
||||||
this.UploadTimer.Restart();
|
Headers = { ContentType = MediaTypeHeaderValue.Parse("application/json") },
|
||||||
|
|
||||||
foreach (var (batch, listings) in this.Batches.ToList()) {
|
|
||||||
this.Batches.Remove(batch, out _);
|
|
||||||
Task.Run(async () => {
|
|
||||||
var uploadable = listings
|
|
||||||
.Select(listing => new UploadableListing(listing))
|
|
||||||
.ToList();
|
|
||||||
var json = JsonConvert.SerializeObject(uploadable);
|
|
||||||
var resp = await this.Client.PostAsync(UploadUrl, new StringContent(json) {
|
|
||||||
Headers = { ContentType = MediaTypeHeaderValue.Parse("application/json") },
|
|
||||||
});
|
|
||||||
var output = await resp.Content.ReadAsStringAsync();
|
|
||||||
PluginLog.Log(output);
|
|
||||||
});
|
});
|
||||||
}
|
var output = await resp.Content.ReadAsStringAsync();
|
||||||
|
Plugin.Log.Info(output);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,26 +1,26 @@
|
||||||
using Dalamud.Game;
|
using Dalamud.IoC;
|
||||||
using Dalamud.Game.Gui.PartyFinder;
|
|
||||||
using Dalamud.IoC;
|
|
||||||
using Dalamud.Plugin;
|
using Dalamud.Plugin;
|
||||||
|
using Dalamud.Plugin.Services;
|
||||||
|
|
||||||
namespace RemotePartyFinder {
|
namespace RemotePartyFinder;
|
||||||
public class Plugin : IDalamudPlugin {
|
|
||||||
public string Name => "Remote Party Finder";
|
|
||||||
|
|
||||||
[PluginService]
|
public class Plugin : IDalamudPlugin {
|
||||||
internal Framework Framework { get; private init; }
|
[PluginService]
|
||||||
|
internal static IPluginLog Log { get; private set; }
|
||||||
|
|
||||||
[PluginService]
|
[PluginService]
|
||||||
internal PartyFinderGui PartyFinderGui { get; private init; }
|
internal IFramework Framework { get; private init; }
|
||||||
|
|
||||||
private Gatherer Gatherer { get; }
|
[PluginService]
|
||||||
|
internal IPartyFinderGui PartyFinderGui { get; private init; }
|
||||||
|
|
||||||
public Plugin() {
|
private Gatherer Gatherer { get; }
|
||||||
this.Gatherer = new Gatherer(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose() {
|
public Plugin() {
|
||||||
this.Gatherer.Dispose();
|
this.Gatherer = new Gatherer(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Dispose() {
|
||||||
|
this.Gatherer.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,68 +5,68 @@ using Dalamud.Game.Gui.PartyFinder.Types;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Serialization;
|
using Newtonsoft.Json.Serialization;
|
||||||
|
|
||||||
namespace RemotePartyFinder {
|
namespace RemotePartyFinder;
|
||||||
[Serializable]
|
|
||||||
[JsonObject(NamingStrategyType = typeof(SnakeCaseNamingStrategy))]
|
|
||||||
internal class UploadableListing {
|
|
||||||
public uint Id { get; }
|
|
||||||
public uint ContentIdLower { get; }
|
|
||||||
public byte[] Name { get; }
|
|
||||||
public byte[] Description { get; }
|
|
||||||
public ushort CreatedWorld { get; }
|
|
||||||
public ushort HomeWorld { get; }
|
|
||||||
public ushort CurrentWorld { get; }
|
|
||||||
public DutyCategory Category { get; }
|
|
||||||
public ushort Duty { get; }
|
|
||||||
public DutyType DutyType { get; }
|
|
||||||
public bool BeginnersWelcome { get; }
|
|
||||||
public ushort SecondsRemaining { get; }
|
|
||||||
public ushort MinItemLevel { get; }
|
|
||||||
public byte NumParties { get; }
|
|
||||||
public byte SlotsAvailable { get; }
|
|
||||||
public uint LastServerRestart { get; }
|
|
||||||
public ObjectiveFlags Objective { get; }
|
|
||||||
public ConditionFlags Conditions { get; }
|
|
||||||
public DutyFinderSettingsFlags DutyFinderSettings { get; }
|
|
||||||
public LootRuleFlags LootRules { get; }
|
|
||||||
public SearchAreaFlags SearchArea { get; }
|
|
||||||
public List<UploadableSlot> Slots { get; }
|
|
||||||
public List<byte> JobsPresent { get; }
|
|
||||||
|
|
||||||
internal UploadableListing(PartyFinderListing listing) {
|
[Serializable]
|
||||||
this.Id = listing.Id;
|
[JsonObject(NamingStrategyType = typeof(SnakeCaseNamingStrategy))]
|
||||||
this.ContentIdLower = listing.ContentIdLower;
|
internal class UploadableListing {
|
||||||
this.Name = listing.Name.Encode();
|
public uint Id { get; }
|
||||||
this.Description = listing.Description.Encode();
|
public uint ContentIdLower { get; }
|
||||||
this.CreatedWorld = (ushort) listing.World.Value.RowId;
|
public byte[] Name { get; }
|
||||||
this.HomeWorld = (ushort) listing.HomeWorld.Value.RowId;
|
public byte[] Description { get; }
|
||||||
this.CurrentWorld = (ushort) listing.CurrentWorld.Value.RowId;
|
public ushort CreatedWorld { get; }
|
||||||
this.Category = listing.Category;
|
public ushort HomeWorld { get; }
|
||||||
this.Duty = listing.RawDuty;
|
public ushort CurrentWorld { get; }
|
||||||
this.DutyType = listing.DutyType;
|
public DutyCategory Category { get; }
|
||||||
this.BeginnersWelcome = listing.BeginnersWelcome;
|
public ushort Duty { get; }
|
||||||
this.SecondsRemaining = listing.SecondsRemaining;
|
public DutyType DutyType { get; }
|
||||||
this.MinItemLevel = listing.MinimumItemLevel;
|
public bool BeginnersWelcome { get; }
|
||||||
this.NumParties = listing.Parties;
|
public ushort SecondsRemaining { get; }
|
||||||
this.SlotsAvailable = listing.SlotsAvailable;
|
public ushort MinItemLevel { get; }
|
||||||
this.LastServerRestart = listing.LastPatchHotfixTimestamp;
|
public byte NumParties { get; }
|
||||||
this.Objective = listing.Objective;
|
public byte SlotsAvailable { get; }
|
||||||
this.Conditions = listing.Conditions;
|
public uint LastServerRestart { get; }
|
||||||
this.DutyFinderSettings = listing.DutyFinderSettings;
|
public ObjectiveFlags Objective { get; }
|
||||||
this.LootRules = listing.LootRules;
|
public ConditionFlags Conditions { get; }
|
||||||
this.SearchArea = listing.SearchArea;
|
public DutyFinderSettingsFlags DutyFinderSettings { get; }
|
||||||
this.Slots = listing.Slots.Select(slot => new UploadableSlot(slot)).ToList();
|
public LootRuleFlags LootRules { get; }
|
||||||
this.JobsPresent = listing.RawJobsPresent.ToList();
|
public SearchAreaFlags SearchArea { get; }
|
||||||
}
|
public List<UploadableSlot> Slots { get; }
|
||||||
}
|
public List<byte> JobsPresent { get; }
|
||||||
|
|
||||||
[Serializable]
|
internal UploadableListing(PartyFinderListing listing) {
|
||||||
[JsonObject(NamingStrategyType = typeof(SnakeCaseNamingStrategy))]
|
this.Id = listing.Id;
|
||||||
internal class UploadableSlot {
|
this.ContentIdLower = listing.ContentIdLower;
|
||||||
public JobFlags Accepting { get; }
|
this.Name = listing.Name.Encode();
|
||||||
|
this.Description = listing.Description.Encode();
|
||||||
internal UploadableSlot(PartyFinderSlot slot) {
|
this.CreatedWorld = (ushort) listing.World.Value.RowId;
|
||||||
this.Accepting = slot.Accepting.Aggregate((JobFlags) 0, (agg, flag) => agg | flag);
|
this.HomeWorld = (ushort) listing.HomeWorld.Value.RowId;
|
||||||
}
|
this.CurrentWorld = (ushort) listing.CurrentWorld.Value.RowId;
|
||||||
|
this.Category = listing.Category;
|
||||||
|
this.Duty = listing.RawDuty;
|
||||||
|
this.DutyType = listing.DutyType;
|
||||||
|
this.BeginnersWelcome = listing.BeginnersWelcome;
|
||||||
|
this.SecondsRemaining = listing.SecondsRemaining;
|
||||||
|
this.MinItemLevel = listing.MinimumItemLevel;
|
||||||
|
this.NumParties = listing.Parties;
|
||||||
|
this.SlotsAvailable = listing.SlotsAvailable;
|
||||||
|
this.LastServerRestart = listing.LastPatchHotfixTimestamp;
|
||||||
|
this.Objective = listing.Objective;
|
||||||
|
this.Conditions = listing.Conditions;
|
||||||
|
this.DutyFinderSettings = listing.DutyFinderSettings;
|
||||||
|
this.LootRules = listing.LootRules;
|
||||||
|
this.SearchArea = listing.SearchArea;
|
||||||
|
this.Slots = listing.Slots.Select(slot => new UploadableSlot(slot)).ToList();
|
||||||
|
this.JobsPresent = listing.RawJobsPresent.ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
[JsonObject(NamingStrategyType = typeof(SnakeCaseNamingStrategy))]
|
||||||
|
internal class UploadableSlot {
|
||||||
|
public JobFlags Accepting { get; }
|
||||||
|
|
||||||
|
internal UploadableSlot(PartyFinderSlot slot) {
|
||||||
|
this.Accepting = slot.Accepting.Aggregate((JobFlags) 0, (agg, flag) => agg | flag);
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,83 +3,83 @@ using Pidgin;
|
||||||
using static Pidgin.Parser;
|
using static Pidgin.Parser;
|
||||||
using static Pidgin.Parser<char>;
|
using static Pidgin.Parser<char>;
|
||||||
|
|
||||||
namespace SourceGenerator {
|
namespace SourceGenerator;
|
||||||
internal static class AutoTranslate {
|
|
||||||
internal static Parser<char, (string name, Maybe<IEnumerable<ISelectorPart>> selector)> Parser() {
|
|
||||||
var sheetName = Any
|
|
||||||
.AtLeastOnceUntil(Lookahead(Char('[').IgnoreResult().Or(End)))
|
|
||||||
.Select(string.Concat)
|
|
||||||
.Labelled("sheetName");
|
|
||||||
|
|
||||||
var numPair = Map(
|
internal static class AutoTranslate {
|
||||||
(first, second) => (ISelectorPart) new IndexRange(
|
internal static Parser<char, (string name, Maybe<IEnumerable<ISelectorPart>> selector)> Parser() {
|
||||||
uint.Parse(string.Concat(first)),
|
var sheetName = Any
|
||||||
uint.Parse(string.Concat(second))
|
.AtLeastOnceUntil(Lookahead(Char('[').IgnoreResult().Or(End)))
|
||||||
),
|
.Select(string.Concat)
|
||||||
Digit.AtLeastOnce().Before(Char('-')),
|
.Labelled("sheetName");
|
||||||
Digit.AtLeastOnce()
|
|
||||||
)
|
|
||||||
.Labelled("numPair");
|
|
||||||
var singleRow = Digit
|
|
||||||
.AtLeastOnce()
|
|
||||||
.Select(string.Concat)
|
|
||||||
.Select(num => (ISelectorPart) new SingleRow(uint.Parse(num)));
|
|
||||||
var column = String("col-")
|
|
||||||
.Then(Digit.AtLeastOnce())
|
|
||||||
.Select(string.Concat)
|
|
||||||
.Select(num => (ISelectorPart) new ColumnSpecifier(uint.Parse(num)));
|
|
||||||
var noun = String("noun")
|
|
||||||
.Select(_ => (ISelectorPart) new NounMarker());
|
|
||||||
|
|
||||||
var selectorItems = OneOf(
|
var numPair = Map(
|
||||||
Try(numPair),
|
(first, second) => (ISelectorPart) new IndexRange(
|
||||||
singleRow,
|
uint.Parse(string.Concat(first)),
|
||||||
column,
|
uint.Parse(string.Concat(second))
|
||||||
noun
|
),
|
||||||
)
|
Digit.AtLeastOnce().Before(Char('-')),
|
||||||
.Separated(Char(','))
|
Digit.AtLeastOnce()
|
||||||
.Labelled("selectorItems");
|
)
|
||||||
var selector = selectorItems
|
.Labelled("numPair");
|
||||||
.Between(Char('['), Char(']'))
|
var singleRow = Digit
|
||||||
.Labelled("selector");
|
.AtLeastOnce()
|
||||||
|
.Select(string.Concat)
|
||||||
|
.Select(num => (ISelectorPart) new SingleRow(uint.Parse(num)));
|
||||||
|
var column = String("col-")
|
||||||
|
.Then(Digit.AtLeastOnce())
|
||||||
|
.Select(string.Concat)
|
||||||
|
.Select(num => (ISelectorPart) new ColumnSpecifier(uint.Parse(num)));
|
||||||
|
var noun = String("noun")
|
||||||
|
.Select(_ => (ISelectorPart) new NounMarker());
|
||||||
|
|
||||||
return Map(
|
var selectorItems = OneOf(
|
||||||
(name, selector) => (name, selector),
|
Try(numPair),
|
||||||
sheetName,
|
singleRow,
|
||||||
selector.Optional()
|
column,
|
||||||
);
|
noun
|
||||||
}
|
)
|
||||||
}
|
.Separated(Char(','))
|
||||||
|
.Labelled("selectorItems");
|
||||||
|
var selector = selectorItems
|
||||||
|
.Between(Char('['), Char(']'))
|
||||||
|
.Labelled("selector");
|
||||||
|
|
||||||
internal interface ISelectorPart {
|
return Map(
|
||||||
}
|
(name, selector) => (name, selector),
|
||||||
|
sheetName,
|
||||||
internal class SingleRow : ISelectorPart {
|
selector.Optional()
|
||||||
public uint Row { get; }
|
);
|
||||||
|
|
||||||
public SingleRow(uint row) {
|
|
||||||
this.Row = row;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal class IndexRange : ISelectorPart {
|
|
||||||
public uint Start { get; }
|
|
||||||
public uint End { get; }
|
|
||||||
|
|
||||||
public IndexRange(uint start, uint end) {
|
|
||||||
this.Start = start;
|
|
||||||
this.End = end;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal class NounMarker : ISelectorPart {
|
|
||||||
}
|
|
||||||
|
|
||||||
internal class ColumnSpecifier : ISelectorPart {
|
|
||||||
public uint Column { get; }
|
|
||||||
|
|
||||||
public ColumnSpecifier(uint column) {
|
|
||||||
this.Column = column;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal interface ISelectorPart {
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class SingleRow : ISelectorPart {
|
||||||
|
public uint Row { get; }
|
||||||
|
|
||||||
|
public SingleRow(uint row) {
|
||||||
|
this.Row = row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class IndexRange : ISelectorPart {
|
||||||
|
public uint Start { get; }
|
||||||
|
public uint End { get; }
|
||||||
|
|
||||||
|
public IndexRange(uint start, uint end) {
|
||||||
|
this.Start = start;
|
||||||
|
this.End = end;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class NounMarker : ISelectorPart {
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class ColumnSpecifier : ISelectorPart {
|
||||||
|
public uint Column { get; }
|
||||||
|
|
||||||
|
public ColumnSpecifier(uint column) {
|
||||||
|
this.Column = column;
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,452 +10,452 @@ using Lumina.Excel.GeneratedSheets;
|
||||||
using Lumina.Text;
|
using Lumina.Text;
|
||||||
using Pidgin;
|
using Pidgin;
|
||||||
|
|
||||||
namespace SourceGenerator {
|
namespace SourceGenerator;
|
||||||
internal class Program {
|
|
||||||
private static void Main(string[] args) {
|
|
||||||
var data = new Dictionary<Language, GameData>(4);
|
|
||||||
foreach (var lang in Languages.Keys) {
|
|
||||||
data[lang] = new GameData(args[0], new LuminaOptions {
|
|
||||||
PanicOnSheetChecksumMismatch = false,
|
|
||||||
DefaultExcelLanguage = lang,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
var prog = new Program(data);
|
internal class Program {
|
||||||
|
private static void Main(string[] args) {
|
||||||
File.WriteAllText(Path.Join(args[1], "duties.rs"), prog.GenerateDuties());
|
var data = new Dictionary<Language, GameData>(4);
|
||||||
File.WriteAllText(Path.Join(args[1], "jobs.rs"), prog.GenerateJobs());
|
foreach (var lang in Languages.Keys) {
|
||||||
File.WriteAllText(Path.Join(args[1], "roulettes.rs"), prog.GenerateRoulettes());
|
data[lang] = new GameData(args[0], new LuminaOptions {
|
||||||
File.WriteAllText(Path.Join(args[1], "worlds.rs"), prog.GenerateWorlds());
|
PanicOnSheetChecksumMismatch = false,
|
||||||
File.WriteAllText(Path.Join(args[1], "territory_names.rs"), prog.GenerateTerritoryNames());
|
DefaultExcelLanguage = lang,
|
||||||
File.WriteAllText(Path.Join(args[1], "auto_translate.rs"), prog.GenerateAutoTranslate());
|
});
|
||||||
File.WriteAllText(Path.Join(args[1], "treasure_maps.rs"), prog.GenerateTreasureMaps());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Dictionary<Language, GameData> Data { get; }
|
var prog = new Program(data);
|
||||||
|
|
||||||
private Program(Dictionary<Language, GameData> data) {
|
File.WriteAllText(Path.Join(args[1], "duties.rs"), prog.GenerateDuties());
|
||||||
this.Data = data;
|
File.WriteAllText(Path.Join(args[1], "jobs.rs"), prog.GenerateJobs());
|
||||||
|
File.WriteAllText(Path.Join(args[1], "roulettes.rs"), prog.GenerateRoulettes());
|
||||||
|
File.WriteAllText(Path.Join(args[1], "worlds.rs"), prog.GenerateWorlds());
|
||||||
|
File.WriteAllText(Path.Join(args[1], "territory_names.rs"), prog.GenerateTerritoryNames());
|
||||||
|
File.WriteAllText(Path.Join(args[1], "auto_translate.rs"), prog.GenerateAutoTranslate());
|
||||||
|
File.WriteAllText(Path.Join(args[1], "treasure_maps.rs"), prog.GenerateTreasureMaps());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Dictionary<Language, GameData> Data { get; }
|
||||||
|
|
||||||
|
private Program(Dictionary<Language, GameData> data) {
|
||||||
|
this.Data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static StringBuilder DefaultHeader(bool localisedText = false) {
|
||||||
|
var sb = new StringBuilder("use std::collections::HashMap;\n");
|
||||||
|
|
||||||
|
if (localisedText) {
|
||||||
|
sb.Append("use super::LocalisedText;\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static StringBuilder DefaultHeader(bool localisedText = false) {
|
return sb;
|
||||||
var sb = new StringBuilder("use std::collections::HashMap;\n");
|
}
|
||||||
|
|
||||||
if (localisedText) {
|
private static readonly Dictionary<Language, string> Languages = new() {
|
||||||
sb.Append("use super::LocalisedText;\n");
|
[Language.English] = "en",
|
||||||
}
|
[Language.Japanese] = "ja",
|
||||||
|
[Language.German] = "de",
|
||||||
|
[Language.French] = "fr",
|
||||||
|
};
|
||||||
|
|
||||||
return sb;
|
private string? GetLocalisedStruct<T>(uint rowId, Func<T, SeString?> nameFunc, uint indent = 0, bool capitalise = false) where T : ExcelRow {
|
||||||
|
var def = this.Data[Language.English].GetExcelSheet<T>()!.GetRow(rowId)!;
|
||||||
|
var defName = nameFunc(def)?.TextValue();
|
||||||
|
if (string.IsNullOrEmpty(defName)) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static readonly Dictionary<Language, string> Languages = new() {
|
var sb = new StringBuilder();
|
||||||
[Language.English] = "en",
|
|
||||||
[Language.Japanese] = "ja",
|
|
||||||
[Language.German] = "de",
|
|
||||||
[Language.French] = "fr",
|
|
||||||
};
|
|
||||||
|
|
||||||
private string? GetLocalisedStruct<T>(uint rowId, Func<T, SeString?> nameFunc, uint indent = 0, bool capitalise = false) where T : ExcelRow {
|
sb.Append("LocalisedText {\n");
|
||||||
var def = this.Data[Language.English].GetExcelSheet<T>()!.GetRow(rowId)!;
|
|
||||||
var defName = nameFunc(def)?.TextValue();
|
foreach (var (language, key) in Languages) {
|
||||||
if (string.IsNullOrEmpty(defName)) {
|
var row = this.Data[language].GetExcelSheet<T>(language)?.GetRow(rowId);
|
||||||
return null;
|
var name = row == null
|
||||||
|
? defName
|
||||||
|
: nameFunc(row)?.TextValue().Replace("\"", "\\\"");
|
||||||
|
name ??= defName;
|
||||||
|
if (capitalise) {
|
||||||
|
name = name[..1].ToUpperInvariant() + name[1..];
|
||||||
}
|
}
|
||||||
|
|
||||||
var sb = new StringBuilder();
|
for (var i = 0; i < indent + 4; i++) {
|
||||||
|
|
||||||
sb.Append("LocalisedText {\n");
|
|
||||||
|
|
||||||
foreach (var (language, key) in Languages) {
|
|
||||||
var row = this.Data[language].GetExcelSheet<T>(language)?.GetRow(rowId);
|
|
||||||
var name = row == null
|
|
||||||
? defName
|
|
||||||
: nameFunc(row)?.TextValue().Replace("\"", "\\\"");
|
|
||||||
name ??= defName;
|
|
||||||
if (capitalise) {
|
|
||||||
name = name[..1].ToUpperInvariant() + name[1..];
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < indent + 4; i++) {
|
|
||||||
sb.Append(' ');
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.Append($"{key}: \"{name}\",\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < indent; i++) {
|
|
||||||
sb.Append(' ');
|
sb.Append(' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
sb.Append('}');
|
sb.Append($"{key}: \"{name}\",\n");
|
||||||
|
|
||||||
return sb.ToString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GenerateDuties() {
|
for (var i = 0; i < indent; i++) {
|
||||||
var sb = DefaultHeader(true);
|
sb.Append(' ');
|
||||||
sb.Append('\n');
|
|
||||||
|
|
||||||
sb.Append("#[derive(Debug)]\n");
|
|
||||||
sb.Append("pub struct DutyInfo {\n");
|
|
||||||
sb.Append(" pub name: LocalisedText,\n");
|
|
||||||
sb.Append(" pub high_end: bool,\n");
|
|
||||||
sb.Append(" pub content_kind: ContentKind,\n");
|
|
||||||
sb.Append("}\n\n");
|
|
||||||
|
|
||||||
sb.Append("#[derive(Debug, Clone, Copy)]\n");
|
|
||||||
sb.Append("#[allow(unused)]\n");
|
|
||||||
sb.Append("#[repr(u32)]\n");
|
|
||||||
sb.Append("pub enum ContentKind {\n");
|
|
||||||
foreach (var kind in this.Data[Language.English].GetExcelSheet<ContentType>()!) {
|
|
||||||
var name = kind.Name.TextValue().Replace(" ", "").Replace("&", "");
|
|
||||||
if (name.Length > 0) {
|
|
||||||
sb.Append($" {name} = {kind.RowId},\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.Append(" Other(u32),\n");
|
|
||||||
sb.Append("}\n\n");
|
|
||||||
|
|
||||||
sb.Append("impl ContentKind {\n");
|
|
||||||
|
|
||||||
sb.Append(" fn from_u32(kind: u32) -> Self {\n");
|
|
||||||
sb.Append(" match kind {\n");
|
|
||||||
foreach (var kind in this.Data[Language.English].GetExcelSheet<ContentType>()!) {
|
|
||||||
var name = kind.Name.TextValue().Replace(" ", "").Replace("&", "");
|
|
||||||
if (name.Length > 0) {
|
|
||||||
sb.Append($" {kind.RowId} => Self::{name},\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.Append(" x => Self::Other(x),\n");
|
|
||||||
sb.Append(" }\n");
|
|
||||||
sb.Append(" }\n\n");
|
|
||||||
|
|
||||||
sb.Append(" pub fn as_u32(self) -> u32 {\n");
|
|
||||||
sb.Append(" match self {\n");
|
|
||||||
foreach (var kind in this.Data[Language.English].GetExcelSheet<ContentType>()!) {
|
|
||||||
var name = kind.Name.TextValue().Replace(" ", "").Replace("&", "");
|
|
||||||
if (name.Length > 0) {
|
|
||||||
sb.Append($" Self::{name} => {kind.RowId},\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.Append(" Self::Other(x) => x,\n");
|
|
||||||
sb.Append(" }\n");
|
|
||||||
sb.Append(" }\n");
|
|
||||||
|
|
||||||
sb.Append("}\n\n");
|
|
||||||
|
|
||||||
sb.Append("lazy_static::lazy_static! {\n");
|
|
||||||
sb.Append(" pub static ref DUTIES: HashMap<u32, DutyInfo> = maplit::hashmap! {\n");
|
|
||||||
|
|
||||||
foreach (var cfc in this.Data[Language.English].GetExcelSheet<ContentFinderCondition>()!) {
|
|
||||||
if (cfc.RowId == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
var name = this.GetLocalisedStruct<ContentFinderCondition>(cfc.RowId, row => row.Name, 12, true);
|
|
||||||
if (name == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
var highEnd = cfc.HighEndDuty ? "true" : "false";
|
|
||||||
var contentType = cfc.ContentType.Value;
|
|
||||||
var contentKind = contentType?.Name?.TextValue().Replace(" ", "").Replace("&", "");
|
|
||||||
if (string.IsNullOrEmpty(contentKind)) {
|
|
||||||
contentKind = $"Other({contentType?.RowId ?? 0})";
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.Append($" {cfc.RowId} => DutyInfo {{\n");
|
|
||||||
sb.Append($" name: {name},\n");
|
|
||||||
sb.Append($" high_end: {highEnd},\n");
|
|
||||||
sb.Append($" content_kind: ContentKind::{contentKind},\n");
|
|
||||||
sb.Append(" },\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.Append(" };\n");
|
|
||||||
sb.Append("}\n");
|
|
||||||
|
|
||||||
return sb.ToString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GenerateJobs() {
|
sb.Append('}');
|
||||||
var sb = DefaultHeader();
|
|
||||||
sb.Append("use ffxiv_types::jobs::{ClassJob, Class, Job, NonCombatJob};\n\n");
|
|
||||||
sb.Append("lazy_static::lazy_static! {\n");
|
|
||||||
sb.Append(" pub static ref JOBS: HashMap<u32, ClassJob> = maplit::hashmap! {\n");
|
|
||||||
|
|
||||||
foreach (var cj in this.Data[Language.English].GetExcelSheet<ClassJob>()!) {
|
return sb.ToString();
|
||||||
if (cj.RowId == 0) {
|
}
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
var name = cj.NameEnglish.TextValue().Replace(" ", "");
|
private string GenerateDuties() {
|
||||||
if (name.Length <= 0) {
|
var sb = DefaultHeader(true);
|
||||||
continue;
|
sb.Append('\n');
|
||||||
}
|
|
||||||
|
|
||||||
var isCombat = cj.Role != 0;
|
sb.Append("#[derive(Debug)]\n");
|
||||||
var isClass = cj.JobIndex == 0;
|
sb.Append("pub struct DutyInfo {\n");
|
||||||
|
sb.Append(" pub name: LocalisedText,\n");
|
||||||
|
sb.Append(" pub high_end: bool,\n");
|
||||||
|
sb.Append(" pub content_kind: ContentKind,\n");
|
||||||
|
sb.Append("}\n\n");
|
||||||
|
|
||||||
string value;
|
sb.Append("#[derive(Debug, Clone, Copy)]\n");
|
||||||
if (isCombat) {
|
sb.Append("#[allow(unused)]\n");
|
||||||
value = isClass
|
sb.Append("#[repr(u32)]\n");
|
||||||
? $"ClassJob::Class(Class::{name})"
|
sb.Append("pub enum ContentKind {\n");
|
||||||
: $"ClassJob::Job(Job::{name})";
|
foreach (var kind in this.Data[Language.English].GetExcelSheet<ContentType>()!) {
|
||||||
} else {
|
var name = kind.Name.TextValue().Replace(" ", "").Replace("&", "");
|
||||||
value = $"ClassJob::NonCombat(NonCombatJob::{name})";
|
if (name.Length > 0) {
|
||||||
}
|
sb.Append($" {name} = {kind.RowId},\n");
|
||||||
|
|
||||||
sb.Append($" {cj.RowId} => {value},\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sb.Append(" };\n");
|
|
||||||
sb.Append("}\n");
|
|
||||||
|
|
||||||
return sb.ToString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GenerateRoulettes() {
|
sb.Append(" Other(u32),\n");
|
||||||
var sb = DefaultHeader(true);
|
sb.Append("}\n\n");
|
||||||
sb.Append('\n');
|
|
||||||
sb.Append("#[derive(Debug)]\n");
|
|
||||||
sb.Append("pub struct RouletteInfo {\n");
|
|
||||||
sb.Append(" pub name: LocalisedText,\n");
|
|
||||||
sb.Append(" pub pvp: bool,\n");
|
|
||||||
sb.Append("}\n\n");
|
|
||||||
|
|
||||||
sb.Append("lazy_static::lazy_static! {\n");
|
sb.Append("impl ContentKind {\n");
|
||||||
sb.Append(" pub static ref ROULETTES: HashMap<u32, RouletteInfo> = maplit::hashmap! {\n");
|
|
||||||
|
|
||||||
foreach (var cr in this.Data[Language.English].GetExcelSheet<ContentRoulette>()!) {
|
sb.Append(" fn from_u32(kind: u32) -> Self {\n");
|
||||||
if (cr.RowId == 0) {
|
sb.Append(" match kind {\n");
|
||||||
continue;
|
foreach (var kind in this.Data[Language.English].GetExcelSheet<ContentType>()!) {
|
||||||
}
|
var name = kind.Name.TextValue().Replace(" ", "").Replace("&", "");
|
||||||
|
if (name.Length > 0) {
|
||||||
var name = this.GetLocalisedStruct<ContentRoulette>(cr.RowId, row => row.Name, 12);
|
sb.Append($" {kind.RowId} => Self::{name},\n");
|
||||||
if (name == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
var pvp = cr.IsPvP
|
|
||||||
? "true"
|
|
||||||
: "false";
|
|
||||||
|
|
||||||
sb.Append($" {cr.RowId} => RouletteInfo {{\n");
|
|
||||||
sb.Append($" name: {name},\n");
|
|
||||||
sb.Append($" pvp: {pvp},\n");
|
|
||||||
sb.Append(" },\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sb.Append(" };\n");
|
|
||||||
sb.Append("}\n");
|
|
||||||
|
|
||||||
return sb.ToString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GenerateWorlds() {
|
sb.Append(" x => Self::Other(x),\n");
|
||||||
var sb = DefaultHeader();
|
sb.Append(" }\n");
|
||||||
sb.Append("use ffxiv_types::World;\n\n");
|
sb.Append(" }\n\n");
|
||||||
sb.Append("lazy_static::lazy_static! {\n");
|
|
||||||
sb.Append(" pub static ref WORLDS: HashMap<u32, World> = maplit::hashmap! {\n");
|
|
||||||
|
|
||||||
foreach (var world in this.Data[Language.English].GetExcelSheet<World>()!) {
|
sb.Append(" pub fn as_u32(self) -> u32 {\n");
|
||||||
if (world.RowId == 0 || !world.IsPublic || world.UserType == 0 || world.DataCenter.Row == 0) {
|
sb.Append(" match self {\n");
|
||||||
continue;
|
foreach (var kind in this.Data[Language.English].GetExcelSheet<ContentType>()!) {
|
||||||
}
|
var name = kind.Name.TextValue().Replace(" ", "").Replace("&", "");
|
||||||
|
if (name.Length > 0) {
|
||||||
var name = world.Name.TextValue();
|
sb.Append($" Self::{name} => {kind.RowId},\n");
|
||||||
if (name.Length <= 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.Append($" {world.RowId} => World::{name},\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sb.Append(" };\n");
|
|
||||||
sb.Append("}\n");
|
|
||||||
|
|
||||||
return sb.ToString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GenerateTerritoryNames() {
|
sb.Append(" Self::Other(x) => x,\n");
|
||||||
var sb = DefaultHeader(true);
|
sb.Append(" }\n");
|
||||||
sb.Append("\nlazy_static::lazy_static! {\n");
|
sb.Append(" }\n");
|
||||||
sb.Append(" pub static ref TERRITORY_NAMES: HashMap<u32, LocalisedText> = maplit::hashmap! {\n");
|
|
||||||
|
|
||||||
foreach (var tt in this.Data[Language.English].GetExcelSheet<TerritoryType>()!) {
|
sb.Append("}\n\n");
|
||||||
if (tt.RowId == 0 || tt.PlaceName.Row == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
var name = this.GetLocalisedStruct<TerritoryType>(
|
sb.Append("lazy_static::lazy_static! {\n");
|
||||||
tt.RowId,
|
sb.Append(" pub static ref DUTIES: HashMap<u32, DutyInfo> = maplit::hashmap! {\n");
|
||||||
row => row.PlaceName.Value!.Name,
|
|
||||||
8
|
|
||||||
);
|
|
||||||
if (name == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.Append($" {tt.RowId} => {name},\n");
|
foreach (var cfc in this.Data[Language.English].GetExcelSheet<ContentFinderCondition>()!) {
|
||||||
|
if (cfc.RowId == 0) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
sb.Append(" };\n");
|
var name = this.GetLocalisedStruct<ContentFinderCondition>(cfc.RowId, row => row.Name, 12, true);
|
||||||
sb.Append("}\n");
|
if (name == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
return sb.ToString();
|
var highEnd = cfc.HighEndDuty ? "true" : "false";
|
||||||
|
var contentType = cfc.ContentType.Value;
|
||||||
|
var contentKind = contentType?.Name?.TextValue().Replace(" ", "").Replace("&", "");
|
||||||
|
if (string.IsNullOrEmpty(contentKind)) {
|
||||||
|
contentKind = $"Other({contentType?.RowId ?? 0})";
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.Append($" {cfc.RowId} => DutyInfo {{\n");
|
||||||
|
sb.Append($" name: {name},\n");
|
||||||
|
sb.Append($" high_end: {highEnd},\n");
|
||||||
|
sb.Append($" content_kind: ContentKind::{contentKind},\n");
|
||||||
|
sb.Append(" },\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GenerateAutoTranslate() {
|
sb.Append(" };\n");
|
||||||
var sb = DefaultHeader(true);
|
sb.Append("}\n");
|
||||||
sb.Append("\nlazy_static::lazy_static! {\n");
|
|
||||||
sb.Append(" pub static ref AUTO_TRANSLATE: HashMap<(u32, u32), LocalisedText> = maplit::hashmap! {\n");
|
|
||||||
|
|
||||||
var parser = AutoTranslate.Parser();
|
return sb.ToString();
|
||||||
foreach (var row in this.Data[Language.English].GetExcelSheet<Completion>()!) {
|
}
|
||||||
var lookup = row.LookupTable.TextValue();
|
|
||||||
if (lookup is not ("" or "@")) {
|
|
||||||
var (sheetName, selector) = parser.ParseOrThrow(lookup);
|
|
||||||
var sheetType = typeof(Completion)
|
|
||||||
.Assembly
|
|
||||||
.GetType($"Lumina.Excel.GeneratedSheets.{sheetName}")!;
|
|
||||||
var getSheet = this.Data[Language.English]
|
|
||||||
.GetType()
|
|
||||||
.GetMethod("GetExcelSheet", Type.EmptyTypes)!
|
|
||||||
.MakeGenericMethod(sheetType);
|
|
||||||
var sheets = this.Data.ToDictionary(
|
|
||||||
pair => pair.Key,
|
|
||||||
pair => {
|
|
||||||
var sheet = (ExcelSheetImpl) getSheet.Invoke(pair.Value, null)!;
|
|
||||||
return (sheet, sheet.GetRowParsers().ToArray());
|
|
||||||
});
|
|
||||||
|
|
||||||
var columns = new List<int>();
|
private string GenerateJobs() {
|
||||||
var rows = new List<Range>();
|
var sb = DefaultHeader();
|
||||||
if (selector.HasValue) {
|
sb.Append("use ffxiv_types::jobs::{ClassJob, Class, Job, NonCombatJob};\n\n");
|
||||||
columns.Clear();
|
sb.Append("lazy_static::lazy_static! {\n");
|
||||||
rows.Clear();
|
sb.Append(" pub static ref JOBS: HashMap<u32, ClassJob> = maplit::hashmap! {\n");
|
||||||
|
|
||||||
foreach (var part in selector.Value) {
|
foreach (var cj in this.Data[Language.English].GetExcelSheet<ClassJob>()!) {
|
||||||
switch (part) {
|
if (cj.RowId == 0) {
|
||||||
case IndexRange range: {
|
continue;
|
||||||
var start = (int) range.Start;
|
}
|
||||||
var end = (int) (range.End + 1);
|
|
||||||
rows.Add(start..end);
|
var name = cj.NameEnglish.TextValue().Replace(" ", "");
|
||||||
break;
|
if (name.Length <= 0) {
|
||||||
}
|
continue;
|
||||||
case SingleRow single: {
|
}
|
||||||
var idx = (int) single.Row;
|
|
||||||
rows.Add(idx..(idx + 1));
|
var isCombat = cj.Role != 0;
|
||||||
break;
|
var isClass = cj.JobIndex == 0;
|
||||||
}
|
|
||||||
case ColumnSpecifier col:
|
string value;
|
||||||
columns.Add((int) col.Column);
|
if (isCombat) {
|
||||||
break;
|
value = isClass
|
||||||
|
? $"ClassJob::Class(Class::{name})"
|
||||||
|
: $"ClassJob::Job(Job::{name})";
|
||||||
|
} else {
|
||||||
|
value = $"ClassJob::NonCombat(NonCombatJob::{name})";
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.Append($" {cj.RowId} => {value},\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.Append(" };\n");
|
||||||
|
sb.Append("}\n");
|
||||||
|
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GenerateRoulettes() {
|
||||||
|
var sb = DefaultHeader(true);
|
||||||
|
sb.Append('\n');
|
||||||
|
sb.Append("#[derive(Debug)]\n");
|
||||||
|
sb.Append("pub struct RouletteInfo {\n");
|
||||||
|
sb.Append(" pub name: LocalisedText,\n");
|
||||||
|
sb.Append(" pub pvp: bool,\n");
|
||||||
|
sb.Append("}\n\n");
|
||||||
|
|
||||||
|
sb.Append("lazy_static::lazy_static! {\n");
|
||||||
|
sb.Append(" pub static ref ROULETTES: HashMap<u32, RouletteInfo> = maplit::hashmap! {\n");
|
||||||
|
|
||||||
|
foreach (var cr in this.Data[Language.English].GetExcelSheet<ContentRoulette>()!) {
|
||||||
|
if (cr.RowId == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var name = this.GetLocalisedStruct<ContentRoulette>(cr.RowId, row => row.Name, 12);
|
||||||
|
if (name == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var pvp = cr.IsPvP
|
||||||
|
? "true"
|
||||||
|
: "false";
|
||||||
|
|
||||||
|
sb.Append($" {cr.RowId} => RouletteInfo {{\n");
|
||||||
|
sb.Append($" name: {name},\n");
|
||||||
|
sb.Append($" pvp: {pvp},\n");
|
||||||
|
sb.Append(" },\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.Append(" };\n");
|
||||||
|
sb.Append("}\n");
|
||||||
|
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GenerateWorlds() {
|
||||||
|
var sb = DefaultHeader();
|
||||||
|
sb.Append("use ffxiv_types::World;\n\n");
|
||||||
|
sb.Append("lazy_static::lazy_static! {\n");
|
||||||
|
sb.Append(" pub static ref WORLDS: HashMap<u32, World> = maplit::hashmap! {\n");
|
||||||
|
|
||||||
|
foreach (var world in this.Data[Language.English].GetExcelSheet<World>()!) {
|
||||||
|
if (world.RowId == 0 || !world.IsPublic || world.UserType == 0 || world.DataCenter.Row == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var name = world.Name.TextValue();
|
||||||
|
if (name.Length <= 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.Append($" {world.RowId} => World::{name},\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.Append(" };\n");
|
||||||
|
sb.Append("}\n");
|
||||||
|
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GenerateTerritoryNames() {
|
||||||
|
var sb = DefaultHeader(true);
|
||||||
|
sb.Append("\nlazy_static::lazy_static! {\n");
|
||||||
|
sb.Append(" pub static ref TERRITORY_NAMES: HashMap<u32, LocalisedText> = maplit::hashmap! {\n");
|
||||||
|
|
||||||
|
foreach (var tt in this.Data[Language.English].GetExcelSheet<TerritoryType>()!) {
|
||||||
|
if (tt.RowId == 0 || tt.PlaceName.Row == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var name = this.GetLocalisedStruct<TerritoryType>(
|
||||||
|
tt.RowId,
|
||||||
|
row => row.PlaceName.Value!.Name,
|
||||||
|
8
|
||||||
|
);
|
||||||
|
if (name == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.Append($" {tt.RowId} => {name},\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.Append(" };\n");
|
||||||
|
sb.Append("}\n");
|
||||||
|
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GenerateAutoTranslate() {
|
||||||
|
var sb = DefaultHeader(true);
|
||||||
|
sb.Append("\nlazy_static::lazy_static! {\n");
|
||||||
|
sb.Append(" pub static ref AUTO_TRANSLATE: HashMap<(u32, u32), LocalisedText> = maplit::hashmap! {\n");
|
||||||
|
|
||||||
|
var parser = AutoTranslate.Parser();
|
||||||
|
foreach (var row in this.Data[Language.English].GetExcelSheet<Completion>()!) {
|
||||||
|
var lookup = row.LookupTable.TextValue();
|
||||||
|
if (lookup is not ("" or "@")) {
|
||||||
|
var (sheetName, selector) = parser.ParseOrThrow(lookup);
|
||||||
|
var sheetType = typeof(Completion)
|
||||||
|
.Assembly
|
||||||
|
.GetType($"Lumina.Excel.GeneratedSheets.{sheetName}")!;
|
||||||
|
var getSheet = this.Data[Language.English]
|
||||||
|
.GetType()
|
||||||
|
.GetMethod("GetExcelSheet", Type.EmptyTypes)!
|
||||||
|
.MakeGenericMethod(sheetType);
|
||||||
|
var sheets = this.Data.ToDictionary(
|
||||||
|
pair => pair.Key,
|
||||||
|
pair => {
|
||||||
|
var sheet = (ExcelSheetImpl) getSheet.Invoke(pair.Value, null)!;
|
||||||
|
return (sheet, sheet.GetRowParsers().ToArray());
|
||||||
|
});
|
||||||
|
|
||||||
|
var columns = new List<int>();
|
||||||
|
var rows = new List<Range>();
|
||||||
|
if (selector.HasValue) {
|
||||||
|
columns.Clear();
|
||||||
|
rows.Clear();
|
||||||
|
|
||||||
|
foreach (var part in selector.Value) {
|
||||||
|
switch (part) {
|
||||||
|
case IndexRange range: {
|
||||||
|
var start = (int) range.Start;
|
||||||
|
var end = (int) (range.End + 1);
|
||||||
|
rows.Add(start..end);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
case SingleRow single: {
|
||||||
|
var idx = (int) single.Row;
|
||||||
|
rows.Add(idx..(idx + 1));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ColumnSpecifier col:
|
||||||
|
columns.Add((int) col.Column);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (columns.Count == 0) {
|
if (columns.Count == 0) {
|
||||||
columns.Add(0);
|
columns.Add(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rows.Count == 0) {
|
if (rows.Count == 0) {
|
||||||
rows.Add(..);
|
rows.Add(..);
|
||||||
}
|
}
|
||||||
|
|
||||||
var builder = new StringBuilder();
|
var builder = new StringBuilder();
|
||||||
foreach (var range in rows) {
|
foreach (var range in rows) {
|
||||||
var validRows = sheets[Language.English]
|
var validRows = sheets[Language.English]
|
||||||
.Item2
|
.Item2
|
||||||
.Select(parser => parser.RowId)
|
.Select(parser => parser.RowId)
|
||||||
.ToArray();
|
.ToArray();
|
||||||
for (var i = range.Start.Value; i < range.End.Value; i++) {
|
for (var i = range.Start.Value; i < range.End.Value; i++) {
|
||||||
if (!validRows.Contains((uint) i)) {
|
if (!validRows.Contains((uint) i)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.Clear();
|
builder.Clear();
|
||||||
|
|
||||||
builder.Append($" ({row.Group}, {i}) => LocalisedText {{\n");
|
builder.Append($" ({row.Group}, {i}) => LocalisedText {{\n");
|
||||||
|
|
||||||
var lines = 0;
|
var lines = 0;
|
||||||
foreach (var (lang, (_, parsers)) in sheets) {
|
foreach (var (lang, (_, parsers)) in sheets) {
|
||||||
// take the first column that works
|
// take the first column that works
|
||||||
foreach (var col in columns) {
|
foreach (var col in columns) {
|
||||||
var rowParser = parsers.FirstOrDefault(parser => parser.RowId == i);
|
var rowParser = parsers.FirstOrDefault(parser => parser.RowId == i);
|
||||||
if (rowParser != null) {
|
if (rowParser != null) {
|
||||||
var name = rowParser.ReadColumn<SeString>(col)!;
|
var name = rowParser.ReadColumn<SeString>(col)!;
|
||||||
var text = name.TextValue().Replace("\"", "\\\"");
|
var text = name.TextValue().Replace("\"", "\\\"");
|
||||||
if (text.Length > 0) {
|
if (text.Length > 0) {
|
||||||
builder.Append($" {Languages[lang]}: \"{text}\",\n");
|
builder.Append($" {Languages[lang]}: \"{text}\",\n");
|
||||||
lines += 1;
|
lines += 1;
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.Append(" },\n");
|
|
||||||
|
|
||||||
if (lines != 4) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.Append(builder);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
builder.Append(" },\n");
|
||||||
var text = this.GetLocalisedStruct<Completion>(row.RowId, row => row.Text, 8);
|
|
||||||
if (text != null) {
|
if (lines != 4) {
|
||||||
sb.Append($" ({row.Group}, {row.RowId}) => {text},\n");
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.Append(builder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
var text = this.GetLocalisedStruct<Completion>(row.RowId, row => row.Text, 8);
|
||||||
sb.Append(" };\n");
|
if (text != null) {
|
||||||
sb.Append("}\n");
|
sb.Append($" ({row.Group}, {row.RowId}) => {text},\n");
|
||||||
|
|
||||||
return sb.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private string GenerateTreasureMaps() {
|
|
||||||
var sb = DefaultHeader(true);
|
|
||||||
sb.Append("\nlazy_static::lazy_static! {\n");
|
|
||||||
sb.Append(" pub static ref TREASURE_MAPS: HashMap<u32, LocalisedText> = maplit::hashmap! {\n");
|
|
||||||
sb.Append(" 0 => LocalisedText {\n");
|
|
||||||
sb.Append(" en: \"All Levels\",\n");
|
|
||||||
sb.Append(" ja: \"レベルを指定しない\",\n");
|
|
||||||
sb.Append(" de: \"Jede Stufe\",\n");
|
|
||||||
sb.Append(" fr: \"Tous niveaux\",\n");
|
|
||||||
sb.Append(" },\n");
|
|
||||||
|
|
||||||
var i = 1;
|
|
||||||
foreach (var row in this.Data[Language.English].GetExcelSheet<TreasureHuntRank>()!) {
|
|
||||||
// IS THIS RIGHT?
|
|
||||||
if (row.TreasureHuntTexture != 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
SeString? GetMapName(TreasureHuntRank thr) {
|
|
||||||
var name = thr.KeyItemName.Value?.Name;
|
|
||||||
return string.IsNullOrEmpty(name?.TextValue())
|
|
||||||
? thr.ItemName.Value?.Name
|
|
||||||
: name;
|
|
||||||
}
|
|
||||||
|
|
||||||
var name = this.GetLocalisedStruct<TreasureHuntRank>(row.RowId, GetMapName, 8);
|
|
||||||
if (!string.IsNullOrEmpty(name)) {
|
|
||||||
sb.Append($" {i++} => {name},\n");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sb.Append(" };\n");
|
|
||||||
sb.Append("}\n");
|
|
||||||
|
|
||||||
return sb.ToString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sb.Append(" };\n");
|
||||||
|
sb.Append("}\n");
|
||||||
|
|
||||||
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
private string GenerateTreasureMaps() {
|
||||||
|
var sb = DefaultHeader(true);
|
||||||
|
sb.Append("\nlazy_static::lazy_static! {\n");
|
||||||
|
sb.Append(" pub static ref TREASURE_MAPS: HashMap<u32, LocalisedText> = maplit::hashmap! {\n");
|
||||||
|
sb.Append(" 0 => LocalisedText {\n");
|
||||||
|
sb.Append(" en: \"All Levels\",\n");
|
||||||
|
sb.Append(" ja: \"レベルを指定しない\",\n");
|
||||||
|
sb.Append(" de: \"Jede Stufe\",\n");
|
||||||
|
sb.Append(" fr: \"Tous niveaux\",\n");
|
||||||
|
sb.Append(" },\n");
|
||||||
|
|
||||||
|
var i = 1;
|
||||||
|
foreach (var row in this.Data[Language.English].GetExcelSheet<TreasureHuntRank>()!) {
|
||||||
|
// IS THIS RIGHT?
|
||||||
|
if (row.TreasureHuntTexture != 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
SeString? GetMapName(TreasureHuntRank thr) {
|
||||||
|
var name = thr.KeyItemName.Value?.Name;
|
||||||
|
return string.IsNullOrEmpty(name?.TextValue())
|
||||||
|
? thr.ItemName.Value?.Name
|
||||||
|
: name;
|
||||||
|
}
|
||||||
|
|
||||||
|
var name = this.GetLocalisedStruct<TreasureHuntRank>(row.RowId, GetMapName, 8);
|
||||||
|
if (!string.IsNullOrEmpty(name)) {
|
||||||
|
sb.Append($" {i++} => {name},\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.Append(" };\n");
|
||||||
|
sb.Append("}\n");
|
||||||
|
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,36 +2,36 @@
|
||||||
using Lumina.Text;
|
using Lumina.Text;
|
||||||
using Lumina.Text.Payloads;
|
using Lumina.Text.Payloads;
|
||||||
|
|
||||||
namespace SourceGenerator {
|
namespace SourceGenerator;
|
||||||
internal static class SeStringExtensions {
|
|
||||||
internal static string TextValue(this SeString str) {
|
|
||||||
var payloads = str.Payloads
|
|
||||||
.Select(p => {
|
|
||||||
if (p is TextPayload text) {
|
|
||||||
return p.Data[0] == 0x03
|
|
||||||
? text.RawString[1..]
|
|
||||||
: text.RawString;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (p.Data.Length <= 1) {
|
internal static class SeStringExtensions {
|
||||||
return "";
|
internal static string TextValue(this SeString str) {
|
||||||
}
|
var payloads = str.Payloads
|
||||||
|
.Select(p => {
|
||||||
if (p.Data[1] == 0x1F) {
|
if (p is TextPayload text) {
|
||||||
return "-";
|
return p.Data[0] == 0x03
|
||||||
}
|
? text.RawString[1..]
|
||||||
|
: text.RawString;
|
||||||
if (p.Data.Length > 2 && p.Data[1] == 0x20) {
|
}
|
||||||
var value = p.Data.Length > 4
|
|
||||||
? p.Data[3] - 1
|
|
||||||
: p.Data[2];
|
|
||||||
return ((char) (48 + value)).ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (p.Data.Length <= 1) {
|
||||||
return "";
|
return "";
|
||||||
});
|
}
|
||||||
|
|
||||||
return string.Join("", payloads);
|
if (p.Data[1] == 0x1F) {
|
||||||
}
|
return "-";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p.Data.Length > 2 && p.Data[1] == 0x20) {
|
||||||
|
var value = p.Data.Length > 4
|
||||||
|
? p.Data[3] - 1
|
||||||
|
: p.Data[2];
|
||||||
|
return ((char) (48 + value)).ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return "";
|
||||||
|
});
|
||||||
|
|
||||||
|
return string.Join("", payloads);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue