feat: add debug view

Also check generator return value. Also don't update friend list while in content.
This commit is contained in:
Anna 2021-09-25 21:11:38 -04:00
parent 8823597675
commit c07c74924f
5 changed files with 107 additions and 6 deletions

View File

@ -85,7 +85,9 @@ namespace NominaOcculta {
}
public string? GenerateName(int race, int clan, int gender) {
this.InternalGenerateName(race, clan, gender, this.First, this.Last);
if (this.InternalGenerateName(race, clan, gender, this.First, this.Last) == IntPtr.Zero) {
return null;
}
var first = Marshal.PtrToStringUTF8(Marshal.ReadIntPtr(this.First));
var last = Marshal.PtrToStringUTF8(Marshal.ReadIntPtr(this.Last));

View File

@ -11,8 +11,13 @@ namespace NominaOcculta {
private Random Rng { get; } = new();
private Dictionary<(byte, byte, byte), Queue<string>> Names { get; } = new();
internal IReadOnlyDictionary<(byte, byte, byte), Queue<string>> ReadOnlyNames => this.Names;
private Dictionary<string, string> Replacements { get; } = new();
internal IReadOnlyDictionary<string, string> ReadonlyReplacements => this.Replacements;
private Dictionary<string, (byte, byte, byte)?> LastSeenInfo { get; } = new();
internal IReadOnlyDictionary<string, (byte, byte, byte)?> ReadOnlyLastSeenInfo => this.LastSeenInfo;
private readonly int _numRaces;

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Dalamud.Game;
using Dalamud.Game.ClientState.Conditions;
using Dalamud.Game.ClientState.Objects.Enums;
using Dalamud.Game.ClientState.Objects.Types;
using Dalamud.Game.Text;
@ -38,8 +39,19 @@ namespace NominaOcculta {
this.Plugin.Framework.Update -= this.OnFrameworkUpdate;
}
private static readonly ConditionFlag[] DutyFlags = {
ConditionFlag.BoundByDuty,
ConditionFlag.BoundByDuty56,
ConditionFlag.BoundByDuty95,
ConditionFlag.BoundToDuty97,
};
private bool IsInDuty() {
return DutyFlags.Any(flag => this.Plugin.Condition[flag]);
}
private void OnFrameworkUpdate(Framework framework) {
if (this.UpdateTimer.Elapsed < TimeSpan.FromSeconds(5)) {
if (this.UpdateTimer.Elapsed < TimeSpan.FromSeconds(5) || this.IsInDuty()) {
return;
}

View File

@ -1,6 +1,8 @@
using Dalamud.Data;
using Dalamud.Game;
using Dalamud.Game.ClientState;
using Dalamud.Game.ClientState.Conditions;
using Dalamud.Game.ClientState.Keys;
using Dalamud.Game.ClientState.Objects;
using Dalamud.Game.ClientState.Party;
using Dalamud.Game.Command;
@ -25,12 +27,18 @@ namespace NominaOcculta {
[PluginService]
internal CommandManager CommandManager { get; private init; }
[PluginService]
internal Condition Condition { get; private set; }
[PluginService]
internal DataManager DataManager { get; private init; }
[PluginService]
internal Framework Framework { get; private init; }
[PluginService]
internal KeyState KeyState { get; private init; }
[PluginService]
internal PartyList PartyList { get; private init; }
@ -44,21 +52,23 @@ namespace NominaOcculta {
internal GameFunctions Functions { get; }
internal Configuration Config { get; }
internal Commands Commands { get; }
private Commands Commands { get; }
internal NameRepository NameRepository { get; }
internal Obscurer Obscurer { get; }
private Obscurer Obscurer { get; }
internal PluginUi Ui { get; }
#pragma warning disable 8618
public Plugin() {
this.Common = new XivCommonBase(Hooks.NamePlates);
this.Functions = new GameFunctions(this);
this.Config = this.Interface.GetPluginConfig() as Configuration ?? new Configuration();
this.Config = this.Interface!.GetPluginConfig() as Configuration ?? new Configuration();
this.Ui = new PluginUi(this);
this.NameRepository = new NameRepository(this);
this.Obscurer = new Obscurer(this);
this.Commands = new Commands(this);
}
#pragma warning restore 8618
public void Dispose() {
this.Commands.Dispose();

View File

@ -1,4 +1,5 @@
using System;
using Dalamud.Game.ClientState.Keys;
using ImGuiNET;
namespace NominaOcculta {
@ -6,6 +7,7 @@ namespace NominaOcculta {
private Plugin Plugin { get; }
internal bool Visible;
private bool _debug;
internal PluginUi(Plugin plugin) {
this.Plugin = plugin;
@ -51,10 +53,80 @@ namespace NominaOcculta {
ImGui.Separator();
if (ImGui.Button("Reset names")) {
this.Plugin.NameRepository.Reset();
if (this.Plugin.KeyState[VirtualKey.CONTROL] && this.Plugin.KeyState[VirtualKey.SHIFT]) {
this._debug ^= true;
} else {
this.Plugin.NameRepository.Reset();
}
}
if (this._debug) {
if (ImGui.CollapsingHeader("Debug")) {
ImGui.PushID("debug");
try {
this.DrawDebug();
} finally {
ImGui.PopID();
}
}
}
ImGui.End();
}
private void DrawDebug() {
ImGui.TextUnformatted($"Initialised: {this.Plugin.NameRepository.Initialised}");
ImGui.Separator();
if (ImGui.TreeNode("Name queue")) {
foreach (var (info, queue) in this.Plugin.NameRepository.ReadOnlyNames) {
if (ImGui.CollapsingHeader($"{info}")) {
if (ImGui.BeginTable($"{info} table", 2)) {
foreach (var name in queue) {
ImGui.TableNextColumn();
ImGui.TextUnformatted(name);
}
ImGui.EndTable();
}
}
}
ImGui.TreePop();
}
if (ImGui.TreeNode("Replacements")) {
if (ImGui.BeginTable("replacements", 2)) {
foreach (var (name, replacement) in this.Plugin.NameRepository.ReadonlyReplacements) {
ImGui.TableNextColumn();
ImGui.TextUnformatted(name);
ImGui.TableNextColumn();
ImGui.TextUnformatted(replacement);
}
ImGui.EndTable();
}
ImGui.TreePop();
}
if (ImGui.TreeNode("Last seen info")) {
if (ImGui.BeginTable("last seen info", 2)) {
foreach (var (name, info) in this.Plugin.NameRepository.ReadOnlyLastSeenInfo) {
ImGui.TableNextColumn();
ImGui.TextUnformatted(name);
ImGui.TableNextColumn();
ImGui.TextUnformatted($"{info}");
}
ImGui.EndTable();
}
}
ImGui.TreePop();
}
}
}