Skip to content

Commit

Permalink
Change to ExdSheets 2
Browse files Browse the repository at this point in the history
  • Loading branch information
WorkingRobot committed Aug 6, 2024
1 parent ff7d769 commit fa45ac0
Show file tree
Hide file tree
Showing 16 changed files with 181 additions and 185 deletions.
2 changes: 1 addition & 1 deletion Benchmark/Craftimizer.Benchmark.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<PackageReference Include="BenchmarkDotNet" Version="0.13.10" />
<PackageReference Include="BenchmarkDotNet.Diagnostics.dotTrace" Version="0.13.10" />
<PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.13.10" />
<PackageReference Include="Meziantou.Analyzer" Version="2.0.162">
<PackageReference Include="Meziantou.Analyzer" Version="2.0.163">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
7 changes: 4 additions & 3 deletions Craftimizer/Craftimizer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@

<ItemGroup>
<PackageReference Include="DalamudPackager" Version="2.1.13" />
<PackageReference Include="ExdSheets" Version="1.2.2" />
<PackageReference Include="Lumina" Version="3.15.2" ExcludeAssets="all" />
<PackageReference Include="ExdSheets" Version="2.1.0" />
<PackageReference Include="Lumina" Version="4.1.1" ExcludeAssets="all" />
<PackageReference Include="Microsoft.Extensions.ObjectPool" Version="9.0.0-preview.1.24081.5" ExcludeAssets="all" />
<PackageReference Include="MathNet.Numerics" Version="5.0.0" />
<PackageReference Include="Meziantou.Analyzer" Version="2.0.162">
<PackageReference Include="Meziantou.Analyzer" Version="2.0.163">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
8 changes: 4 additions & 4 deletions Craftimizer/ImGuiUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public static void ViolinPlot(in ViolinData data, Vector2 size)
}
}

private sealed class SearchableComboData<T> where T : class
private sealed class SearchableComboData<T> where T : IEquatable<T>
{
public readonly ImmutableArray<T> items;
public List<T> filteredItems;
Expand All @@ -314,7 +314,7 @@ public SearchableComboData(IEnumerable<T> items, T selectedItem, Func<T, string>

public void SetItem(T selectedItem)
{
if (this.selectedItem != selectedItem)
if (!this.selectedItem.Equals(selectedItem))
{
input = GetString(selectedItem);
this.selectedItem = selectedItem;
Expand Down Expand Up @@ -364,14 +364,14 @@ private void FilterTask(string input, CancellationToken token)
}
private static readonly Dictionary<uint, object> ComboData = [];

private static SearchableComboData<T> GetComboData<T>(uint comboKey, IEnumerable<T> items, T selectedItem, Func<T, string> getString) where T : class =>
private static SearchableComboData<T> GetComboData<T>(uint comboKey, IEnumerable<T> items, T selectedItem, Func<T, string> getString) where T : IEquatable<T> =>
(SearchableComboData<T>)(
ComboData.TryGetValue(comboKey, out var data)
? data
: ComboData[comboKey] = new SearchableComboData<T>(items, selectedItem, getString));

// https://github.com/ocornut/imgui/issues/718#issuecomment-1563162222
public static bool SearchableCombo<T>(string id, ref T selectedItem, IEnumerable<T> items, ImFontPtr selectableFont, float width, Func<T, string> getString, Func<T, string> getId, Action<T> draw) where T : class
public static bool SearchableCombo<T>(string id, ref T selectedItem, IEnumerable<T> items, ImFontPtr selectableFont, float width, Func<T, string> getString, Func<T, string> getId, Action<T> draw) where T : IEquatable<T>
{
var comboKey = ImGui.GetID(id);
var data = GetComboData(comboKey, items, selectedItem, getString);
Expand Down
48 changes: 19 additions & 29 deletions Craftimizer/LuminaSheets.cs
Original file line number Diff line number Diff line change
@@ -1,37 +1,27 @@
using Dalamud.Game;
using Dalamud.Utility;
using ExdSheets;
using Lumina.Excel;
using System.Collections.Concurrent;
using ExdSheets.Sheets;
using Lumina.Data;

namespace Craftimizer.Plugin;

public static class LuminaSheets
{
public static readonly ExcelSheet<Recipe> RecipeSheet = Service.DataManager.GetExcelSheet<Recipe>()!;
public static readonly ExcelSheet<Action> ActionSheet = Service.DataManager.GetExcelSheet<Action>()!;
public static readonly ExcelSheet<CraftAction> CraftActionSheet = Service.DataManager.GetExcelSheet<CraftAction>()!;
public static readonly ExcelSheet<Status> StatusSheet = Service.DataManager.GetExcelSheet<Status>()!;
public static readonly ExcelSheet<Addon> AddonSheet = Service.DataManager.GetExcelSheet<Addon>()!;
public static readonly ExcelSheet<ClassJob> ClassJobSheet = Service.DataManager.GetExcelSheet<ClassJob>()!;
public static readonly ExcelSheet<Item> ItemSheet = Service.DataManager.GetExcelSheet<Item>()!;
public static readonly ExcelSheet<Item> ItemSheetEnglish = Service.DataManager.GetExcelSheet<Item>(ClientLanguage.English)!;
public static readonly ExcelSheet<ENpcResident> ENpcResidentSheet = Service.DataManager.GetExcelSheet<ENpcResident>()!;
public static readonly ExcelSheet<Level> LevelSheet = Service.DataManager.GetExcelSheet<Level>()!;
public static readonly ExcelSheet<Quest> QuestSheet = Service.DataManager.GetExcelSheet<Quest>()!;
public static readonly ExcelSheet<Materia> MateriaSheet = Service.DataManager.GetExcelSheet<Materia>()!;
public static readonly ExcelSheet<BaseParam> BaseParamSheet = Service.DataManager.GetExcelSheet<BaseParam>()!;
public static readonly ExcelSheet<ItemFood> ItemFoodSheet = Service.DataManager.GetExcelSheet<ItemFood>()!;
public static readonly ExcelSheet<SatisfactionSupply> SatisfactionSupplySheet = Service.DataManager.GetExcelSheet<SatisfactionSupply>()!;
private static readonly Module Module = new(Service.DataManager.GameData, Service.DataManager.Language.ToLumina());

private static ConcurrentDictionary<(ExcelSheetImpl, uint), uint> SubRowCountCache { get; } = new();
public static uint? GetSubRowCount<T>(this ExcelSheet<T> sheet, uint row) where T : ExcelRow
{
if (SubRowCountCache.TryGetValue((sheet, row), out var count))
return count;
var parser = sheet.GetRowParser(row);
if (parser == null)
return null;
SubRowCountCache.TryAdd((sheet, row), parser.RowCount);
return parser.RowCount;
}
public static readonly Sheet<Recipe> RecipeSheet = Module.GetSheet<Recipe>();
public static readonly Sheet<Action> ActionSheet = Module.GetSheet<Action>();
public static readonly Sheet<CraftAction> CraftActionSheet = Module.GetSheet<CraftAction>();
public static readonly Sheet<Status> StatusSheet = Module.GetSheet<Status>();
public static readonly Sheet<Addon> AddonSheet = Module.GetSheet<Addon>();
public static readonly Sheet<ClassJob> ClassJobSheet = Module.GetSheet<ClassJob>();
public static readonly Sheet<Item> ItemSheet = Module.GetSheet<Item>();
public static readonly Sheet<Item> ItemSheetEnglish = Module.GetSheet<Item>(Language.English)!;
public static readonly Sheet<ENpcResident> ENpcResidentSheet = Module.GetSheet<ENpcResident>();
public static readonly Sheet<Level> LevelSheet = Module.GetSheet<Level>();
public static readonly Sheet<Quest> QuestSheet = Module.GetSheet<Quest>();
public static readonly Sheet<Materia> MateriaSheet = Module.GetSheet<Materia>();
public static readonly Sheet<BaseParam> BaseParamSheet = Module.GetSheet<BaseParam>();
public static readonly Sheet<ItemFood> ItemFoodSheet = Module.GetSheet<ItemFood>();
public static readonly Sheet<SatisfactionSupply> SatisfactionSupplySheet = Module.GetSheet<SatisfactionSupply>();
}
2 changes: 1 addition & 1 deletion Craftimizer/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public Plugin(IDalamudPluginInterface pluginInterface)
SynthHelperWindow = new();
ListWindow = new();

// Trigger static constructors so a huge hitch doesn't occur on first RecipeNote frame.
// Trigger static constructors so a hitch doesn't occur on first RecipeNote frame.
FoodStatus.Initialize();
ActionUtils.Initialize();

Expand Down
96 changes: 45 additions & 51 deletions Craftimizer/SimulatorUtils.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
using Craftimizer.Simulator;
using Craftimizer.Simulator.Actions;
using Dalamud.Game.Text.SeStringHandling.Payloads;
using Dalamud.Utility;
using FFXIVClientStructs.FFXIV.Client.Game.UI;
using ExdSheets;
using System;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Text;
using Action = ExdSheets.Action;
using Action = ExdSheets.Sheets.Action;
using ActionType = Craftimizer.Simulator.Actions.ActionType;
using ClassJob = Craftimizer.Simulator.ClassJob;
using Condition = Craftimizer.Simulator.Condition;
using Status = ExdSheets.Status;
using Dalamud.Interface.Textures;
using Status = ExdSheets.Sheets.Status;
using Craftimizer.Utils;
using ExdSheets.Sheets;
using Lumina.Text.ReadOnly;
using Lumina.Text.Payloads;

namespace Craftimizer.Plugin;

Expand All @@ -31,33 +29,33 @@ static ActionUtils()
foreach (var actionType in actionTypes)
{
var actionId = actionType.Base().ActionId;
if (LuminaSheets.CraftActionSheet.GetRow(actionId) is CraftAction baseCraftAction)
if (LuminaSheets.CraftActionSheet.TryGetRow(actionId) is { } baseCraftAction)
{
foreach (var classJob in classJobs)
{
ActionRows[(int)actionType, (int)classJob] = (classJob switch
{
ClassJob.Carpenter => baseCraftAction.CRP.Value!,
ClassJob.Blacksmith => baseCraftAction.BSM.Value!,
ClassJob.Armorer => baseCraftAction.ARM.Value!,
ClassJob.Goldsmith => baseCraftAction.GSM.Value!,
ClassJob.Leatherworker => baseCraftAction.LTW.Value!,
ClassJob.Weaver => baseCraftAction.WVR.Value!,
ClassJob.Alchemist => baseCraftAction.ALC.Value!,
ClassJob.Culinarian => baseCraftAction.CUL.Value!,
ClassJob.Carpenter => baseCraftAction.CRP.Value,
ClassJob.Blacksmith => baseCraftAction.BSM.Value,
ClassJob.Armorer => baseCraftAction.ARM.Value,
ClassJob.Goldsmith => baseCraftAction.GSM.Value,
ClassJob.Leatherworker => baseCraftAction.LTW.Value,
ClassJob.Weaver => baseCraftAction.WVR.Value,
ClassJob.Alchemist => baseCraftAction.ALC.Value,
ClassJob.Culinarian => baseCraftAction.CUL.Value,
_ => baseCraftAction
}, null);
}
}
if (LuminaSheets.ActionSheet.GetRow(actionId) is Action baseAction)
if (LuminaSheets.ActionSheet.TryGetRow(actionId) is { } baseAction)
{
var possibleActions = LuminaSheets.ActionSheet.Where(r =>
r.Icon == baseAction.Icon &&
r.ActionCategory.Row == baseAction.ActionCategory.Row &&
r.Name.RawString.Equals(baseAction.Name.RawString, StringComparison.Ordinal));
r.ActionCategory.RowId == baseAction.ActionCategory.RowId &&
r.Name.Equals(baseAction.Name));

foreach (var classJob in classJobs)
ActionRows[(int)actionType, (int)classJob] = (null, possibleActions.First(r => r.ClassJobCategory.Value?.IsClassJob(classJob) ?? false));
ActionRows[(int)actionType, (int)classJob] = (null, possibleActions.First(r => r.ClassJobCategory.ValueNullable?.IsClassJob(classJob) ?? false));
}
}
}
Expand All @@ -70,32 +68,20 @@ public static (CraftAction? CraftAction, Action? Action) GetActionRow(this Actio
public static uint GetId(this ActionType me, ClassJob classJob)
{
var (craftAction, action) = GetActionRow(me, classJob);
if (craftAction != null)
return craftAction.RowId;
if (action != null)
return action.RowId;
return 0;
return craftAction?.RowId ?? action?.RowId ?? 0;
}

public static string GetName(this ActionType me, ClassJob classJob)
{
var (craftAction, action) = GetActionRow(me, classJob);
if (craftAction != null)
return craftAction.Name.ToDalamudString().TextValue;
if (action != null)
return action.Name.ToDalamudString().TextValue;
return "Unknown";
return (craftAction?.Name ?? action?.Name)?.AsSpan().ExtractText() ?? "Unknown";
}

public static ITextureIcon GetIcon(this ActionType me, ClassJob classJob)
{
var (craftAction, action) = GetActionRow(me, classJob);
if (craftAction != null)
return Service.IconManager.GetIconCached(craftAction.Icon);
if (action != null)
return Service.IconManager.GetIconCached(action.Icon);
// Old "Steady Hand" action icon
return Service.IconManager.GetIconCached(1953);
// 1953 = Old "Steady Hand" action icon
return Service.IconManager.GetIconCached(craftAction?.Icon ?? action?.Icon ?? 1953);
}

public static ActionType? GetActionTypeFromId(uint actionId, ClassJob classJob, bool isCraftAction)
Expand Down Expand Up @@ -155,18 +141,18 @@ public static unsafe short GetPlayerLevel(this ClassJob me) =>
PlayerState.Instance()->ClassJobLevels[me.GetExpArrayIdx()];

public static unsafe bool CanPlayerUseManipulation(this ClassJob me) =>
UIState.Instance()->IsUnlockLinkUnlockedOrQuestCompleted(ActionType.Manipulation.GetActionRow(me).Action!.UnlockLink.Row);
UIState.Instance()->IsUnlockLinkUnlockedOrQuestCompleted(ActionType.Manipulation.GetActionRow(me).Action!.Value.UnlockLink.RowId);

public static string GetName(this ClassJob me)
{
var job = LuminaSheets.ClassJobSheet.GetRow(me.GetClassJobIndex())!;
return job.Name.ToDalamudString().TextValue.ToLowerInvariant();
var job = LuminaSheets.ClassJobSheet.GetRow(me.GetClassJobIndex());
return job.Name.ExtractText().ToLowerInvariant();
}

public static string GetNameArticle(this ClassJob me)
{
var job = LuminaSheets.ClassJobSheet.GetRow(me.GetClassJobIndex())!;
if (job.SheetLanguage == Lumina.Data.Language.English)
var job = LuminaSheets.ClassJobSheet.GetRow(me.GetClassJobIndex());
if (LuminaSheets.ClassJobSheet.Language == Lumina.Data.Language.English)
{
if (me is ClassJob.Alchemist or ClassJob.Armorer)
return "an";
Expand All @@ -176,12 +162,12 @@ public static string GetNameArticle(this ClassJob me)

public static string GetAbbreviation(this ClassJob me)
{
var job = LuminaSheets.ClassJobSheet.GetRow(me.GetClassJobIndex())!;
return job.Abbreviation.ToDalamudString().TextValue;
var job = LuminaSheets.ClassJobSheet.GetRow(me.GetClassJobIndex());
return job.Abbreviation.ExtractText();
}

public static Quest GetUnlockQuest(this ClassJob me) =>
LuminaSheets.QuestSheet.GetRow(65720 + (uint)me) ?? throw new ArgumentException($"Could not get unlock quest for {me}", nameof(me));
LuminaSheets.QuestSheet.GetRow(65720 + (uint)me);

public static ushort GetIconId(this ClassJob me) =>
(ushort)(62000 + me.GetClassJobIndex());
Expand Down Expand Up @@ -295,15 +281,23 @@ public static Vector4 GetColor(this Condition me, TimeSpan time)
}

public static string Name(this Condition me) =>
LuminaSheets.AddonSheet.GetRow(me.AddonIds().Name)!.Text.ToDalamudString().TextValue;
LuminaSheets.AddonSheet.GetRow(me.AddonIds().Name).Text.ExtractText();

public static string Description(this Condition me, bool isRelic)
{
var text = LuminaSheets.AddonSheet.GetRow(me.AddonIds().Description)!.Text.ToDalamudString();
for (var i = 0; i < text.Payloads.Count; ++i)
if (text.Payloads[i] is RawPayload)
text.Payloads[i] = new TextPayload(isRelic ? "1.75" : "1.5");
return text.TextValue;
var text = LuminaSheets.AddonSheet.GetRow(me.AddonIds().Description).Text;
if (!text.Any(p => p is { Type: ReadOnlySePayloadType.Macro, MacroCode: MacroCode.Float }))
return text.ExtractText();

ReadOnlySeString finalText = new();
foreach (var payload in text)
{
if (payload is { Type: ReadOnlySePayloadType.Macro, MacroCode: MacroCode.Float })
finalText += new ReadOnlySePayload(ReadOnlySePayloadType.Text, default, Encoding.UTF8.GetBytes(isRelic ? "1.75" : "1.5"));
else
finalText += payload;
}
return finalText.ExtractText();
}
}

Expand Down Expand Up @@ -349,7 +343,7 @@ public static string GetTooltip(this EffectType me, int strength, int duration)
{
var status = me.Status();
var name = new StringBuilder();
name.Append(status.Name.ToDalamudString().TextValue);
name.Append(status.Name.ExtractText());
if (status.MaxStacks != 0)
name.Append($" {strength}");
if (!status.IsPermanent)
Expand Down
21 changes: 10 additions & 11 deletions Craftimizer/Utils/FoodStatus.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Craftimizer.Plugin;
using ExdSheets;
using ExdSheets.Sheets;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
Expand All @@ -25,28 +25,27 @@ static FoodStatus()
var medicines = new Dictionary<uint, Food>();
foreach (var item in LuminaSheets.ItemSheet)
{
var isFood = item.ItemUICategory.Row == 46;
var isMedicine = item.ItemUICategory.Row == 44;
var isFood = item.ItemUICategory.RowId == 46;
var isMedicine = item.ItemUICategory.RowId == 44;
if (!isFood && !isMedicine)
continue;

if (item.ItemAction.Value == null)
if (item.ItemAction.ValueNullable is not { } itemAction)
continue;

if (!(item.ItemAction.Value.Type is 844 or 845 or 846))
if (itemAction.Type is not (844 or 845 or 846))
continue;

var itemFood = LuminaSheets.ItemFoodSheet.GetRow(item.ItemAction.Value.Data[1]);
if (itemFood == null)
if (LuminaSheets.ItemFoodSheet.TryGetRow(itemAction.Data[1]) is not { } itemFood)
continue;

FoodStat? craftsmanship = null, control = null, cp = null;
foreach (var stat in itemFood.Params)
{
if (stat.BaseParam.Row == 0)
if (stat.BaseParam.RowId == 0)
continue;
var foodStat = new FoodStat(stat.IsRelative, stat.Value, stat.Max, stat.ValueHQ, stat.MaxHQ);
switch (stat.BaseParam.Row)
switch (stat.BaseParam.RowId)
{
case Gearsets.ParamCraftsmanship: craftsmanship = foodStat; break;
case Gearsets.ParamControl: control = foodStat; break;
Expand All @@ -71,8 +70,8 @@ static FoodStatus()
FoodItems = foods.ToFrozenDictionary();
MedicineItems = medicines.ToFrozenDictionary();

FoodOrder = FoodItems.OrderByDescending(a => a.Value.Item.LevelItem.Row).Select(a => a.Key).ToImmutableArray();
MedicineOrder = MedicineItems.OrderByDescending(a => a.Value.Item.LevelItem.Row).Select(a => a.Key).ToImmutableArray();
FoodOrder = FoodItems.OrderByDescending(a => a.Value.Item.LevelItem.RowId).Select(a => a.Key).ToImmutableArray();
MedicineOrder = MedicineItems.OrderByDescending(a => a.Value.Item.LevelItem.RowId).Select(a => a.Key).ToImmutableArray();
}

public static void Initialize() { }
Expand Down
Loading

0 comments on commit fa45ac0

Please sign in to comment.