Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
fix: add an original cooldown.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Mar 31, 2023
1 parent 0d1b695 commit 0931f48
Show file tree
Hide file tree
Showing 15 changed files with 239 additions and 129 deletions.
59 changes: 2 additions & 57 deletions RotationSolver.Basic/Attributes/LinkDescriptionAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,74 +3,19 @@
using System;
using ImGuiScene;
using Dalamud.Interface.Internal;
using RotationSolver.Basic.Data;

namespace RotationSolver.Basic.Attributes;

[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
public class LinkDescriptionAttribute : Attribute
{
static readonly SortedDictionary<string, TextureWrap> _TextureCache = new SortedDictionary<string, TextureWrap>();

static readonly List<string> _loadingTexture = new List<string>();

public TextureWrap Texture { get; private set; }
public TextureWrap Texture => IconSet.GetTexture(Path);
public string Description { get; private set; }
public string Path { get; }
public LinkDescriptionAttribute(string path, string description = "")
{
Path = path;
LoadTexture(path);
Description = description;
}

private void LoadTexture(string path)
{
if(_TextureCache.TryGetValue(path,out var t))
{
Texture = t;
return;
}
if (_loadingTexture.Contains(path))
{
return;
}
_loadingTexture.Add(path);

try
{
Task.Run(async () =>
{
var bytes = await LoadBytes(path);
_TextureCache[path] = Texture = TryLoadImage(bytes);
});
}
catch
{
}
}

private static async Task<byte[]> LoadBytes(string url)
{
var data = await Util.HttpClient.GetAsync(url);
if (data.StatusCode == HttpStatusCode.NotFound)
return null;

data.EnsureSuccessStatusCode();
return await data.Content.ReadAsByteArrayAsync();
}

private static TextureWrap TryLoadImage(byte[] bytes)
{
if (bytes == null)
return null;

try
{
return Service.Interface.UiBuilder.LoadImage(bytes);
}
catch
{
return null;
}
}
}
1 change: 1 addition & 0 deletions RotationSolver.Basic/Configuration/PluginConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ public class PluginConfiguration : IPluginConfiguration
public float ControlWindowNextSizeRatio = 1.5f;
public float ControlProgressHeight = 8;
public bool ShowCooldownWindow = false;
public bool UseOriginalCooldown = true;

public Dictionary<StateCommandType, KeyRecord> KeyState { get; set; } = new Dictionary<StateCommandType, KeyRecord>();
public Dictionary<SpecialCommandType, KeyRecord> KeySpecial { get; set; } = new Dictionary<SpecialCommandType, KeyRecord>();
Expand Down
84 changes: 74 additions & 10 deletions RotationSolver.Basic/Data/IconSet.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using ImGuiScene;
using Dalamud.Utility;
using ImGuiScene;
using RotationSolver.Basic.Rotations;
using System.Collections.Generic;
using System.Net;

namespace RotationSolver.Basic.Data;

Expand All @@ -22,38 +24,100 @@ public enum IconType : byte

public static class IconSet
{
private static readonly Dictionary<uint, TextureWrap> _textures = new Dictionary<uint, TextureWrap>();
private static readonly HashSet<uint> _loadingTexture = new HashSet<uint>();
static readonly Dictionary<uint, TextureWrap> _texturesIds = new Dictionary<uint, TextureWrap>();
static readonly HashSet<uint> _loadingTextureID = new HashSet<uint>();

static readonly SortedDictionary<string, TextureWrap> _texturesPath = new SortedDictionary<string, TextureWrap>();
static readonly HashSet<string> _loadingTexturePath = new HashSet<string>();

public static TextureWrap GetTexture(this ITexture text) => GetTexture(text?.IconID ?? 0);

public static TextureWrap GetTexture(uint id)
{
if (!_textures.TryGetValue(id, out var texture))
if (!_texturesIds.TryGetValue(id, out var texture))
{
if (!_loadingTexture.Contains(id))
if (!_loadingTextureID.Contains(id))
{
_loadingTexture.Add(id);
_loadingTextureID.Add(id);
Task.Run(() =>
{
texture = Service.GetTextureIcon(id);
_textures[id] = texture;
_texturesIds[id] = texture;
});
}

if (!_textures.TryGetValue(0, out texture))
if (!_texturesIds.TryGetValue(0, out texture))
{
texture = Service.GetTextureIcon(0);
_textures[0] = texture;
_texturesIds[0] = texture;
}
return texture;
}

return texture;
}

public static TextureWrap GetTexture(string path)
{
if (!_texturesPath.TryGetValue(path, out var t))
{
if (!_loadingTexturePath.Contains(path))
{
_loadingTexturePath.Add(path);

try
{
Task.Run(async () =>
{
if (path.StartsWith("https:"))
{
var bytes = await LoadBytes(path);
_texturesPath[path] = TryLoadImage(bytes);
}
else if(path.StartsWith("ui/"))
{
_texturesPath[path] = Service.GetTexture(path);
}
});
}
finally { }
}
return null;
}
return t;
}

private static async Task<byte[]> LoadBytes(string url)
{
var data = await Util.HttpClient.GetAsync(url);
if (data.StatusCode == HttpStatusCode.NotFound)
return null;

data.EnsureSuccessStatusCode();
return await data.Content.ReadAsByteArrayAsync();
}

private static TextureWrap TryLoadImage(byte[] bytes)
{
if (bytes == null)
return null;

try
{
return Service.Interface.UiBuilder.LoadImage(bytes);
}
catch
{
return null;
}
}
public static void Dispose()
{
foreach (var item in _textures.Values)
foreach (var item in _texturesIds.Values)
{
item?.Dispose();
}
foreach (var item in _texturesPath.Values)
{
item?.Dispose();
}
Expand Down
1 change: 1 addition & 0 deletions RotationSolver.Basic/Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public unsafe static T[] GetAddon<T>() where T : struct
public static ExcelSheet<T> GetSheet<T>() where T : ExcelRow => DataManager.GetExcelSheet<T>();

internal static TextureWrap GetTextureIcon(uint id) => DataManager.GetImGuiTextureIcon(id);
internal static TextureWrap GetTexture(string path) => DataManager.GetImGuiTexture(path);

[PluginService]
private static DataManager DataManager { get; set; }
Expand Down
15 changes: 13 additions & 2 deletions RotationSolver.Default/Melee/NIN_Default.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ private static void SetNinjustus(INinAction act)
_ninActionAim = act;
}

protected override IAction CountDownAction(float remainTime)
{
if(DoNinjutsus(out var act)) return act;

if (remainTime < 5) SetNinjustus(Suiton);

if (remainTime < 7 && Hide.CanUse(out var hide)) return hide;

if (remainTime < 10) SetNinjustus(Huton);

return base.CountDownAction(remainTime);
}

private bool ChoiceNinjutsus(out IAction act)
{
act = null;
Expand Down Expand Up @@ -219,7 +232,6 @@ private bool DoNinjutsus(out IAction act)
return true;
}
}
//ClearNinjutsus();
return false;
}

Expand All @@ -234,7 +246,6 @@ protected override bool GeneralGCD(out IAction act)
if (ChoiceNinjutsus(out act)) return true;
if (DoNinjutsus(out act)) return true;

//用真北取消隐匿
if (Configs.GetBool("AutoUnhide"))
{
StatusHelper.StatusOff(StatusID.Hidden);
Expand Down
20 changes: 10 additions & 10 deletions RotationSolver/Localization/EnumTranslations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ internal static class EnumTranslations
_ => string.Empty,
};

internal static string ToName(this ActionConditonType type) => type switch
internal static string ToName(this ActionConditionType type) => type switch
{
ActionConditonType.Elapsed => LocalizationManager.RightLang.ActionConditionType_Elapsed,
ActionConditonType.ElapsedGCD => LocalizationManager.RightLang.ActionConditionType_ElapsedGCD,
ActionConditonType.Remain => LocalizationManager.RightLang.ActionConditionType_Remain,
ActionConditonType.RemainGCD => LocalizationManager.RightLang.ActionConditionType_RemainGCD,
ActionConditonType.ShouldUse => LocalizationManager.RightLang.ActionConditionType_ShouldUse,
ActionConditonType.EnoughLevel => LocalizationManager.RightLang.ActionConditionType_EnoughLevel,
ActionConditonType.IsCoolDown => LocalizationManager.RightLang.ActionConditionType_IsCoolDown,
ActionConditonType.CurrentCharges => LocalizationManager.RightLang.ActionConditionType_CurrentCharges,
ActionConditonType.MaxCharges => LocalizationManager.RightLang.ActionConditionType_MaxCharges,
ActionConditionType.Elapsed => LocalizationManager.RightLang.ActionConditionType_Elapsed,
ActionConditionType.ElapsedGCD => LocalizationManager.RightLang.ActionConditionType_ElapsedGCD,
ActionConditionType.Remain => LocalizationManager.RightLang.ActionConditionType_Remain,
ActionConditionType.RemainGCD => LocalizationManager.RightLang.ActionConditionType_RemainGCD,
ActionConditionType.ShouldUse => LocalizationManager.RightLang.ActionConditionType_ShouldUse,
ActionConditionType.EnoughLevel => LocalizationManager.RightLang.ActionConditionType_EnoughLevel,
ActionConditionType.IsCoolDown => LocalizationManager.RightLang.ActionConditionType_IsCoolDown,
ActionConditionType.CurrentCharges => LocalizationManager.RightLang.ActionConditionType_CurrentCharges,
ActionConditionType.MaxCharges => LocalizationManager.RightLang.ActionConditionType_MaxCharges,
_ => string.Empty,
};

Expand Down
1 change: 1 addition & 0 deletions RotationSolver/Localization/Strings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ internal partial class Strings
public string ConfigWindow_Control_IsWindowLock { get; set; } = "Lock";

public string ConfigWindow_Control_ShowItemsCooldown { get; set; } = "Show Items' Cooldown";
public string ConfigWindow_Control_UseOriginalCooldown { get; set; } = "Show Original Cooldown";

public string ConfigWindow_Control_CooldownActionOneLine { get; set; } = "The count of cooldown actions in one line.";
public string ConfigWindow_Control_BackgroundColor { get; set; } = "Control Window's Background";
Expand Down
Loading

0 comments on commit 0931f48

Please sign in to comment.