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

Commit

Permalink
fix: merge the saving files
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Apr 30, 2023
1 parent 5893683 commit 22b275c
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 52 deletions.
24 changes: 24 additions & 0 deletions Resources/DangerousStatus.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[
2,
3,
5,
6,
7,
9,
10,
15,
17,
193,
423,
482,
561,
564,
620,
910,
926,
1343,
1345,
1346,
1348,
2965
]
5 changes: 5 additions & 0 deletions Resources/InvincibleStatus.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
151,
198,
3012
]
1 change: 1 addition & 0 deletions Resources/NoHostileNames.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
3 changes: 2 additions & 1 deletion RotationSolver.Basic/Actions/BaseAction_BasicInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FFXIVClientStructs.FFXIV.Client.Game;
using RotationSolver.Basic.Configuration;
using Action = Lumina.Excel.GeneratedSheets.Action;

namespace RotationSolver.Basic.Actions;
Expand Down Expand Up @@ -92,7 +93,7 @@ public virtual unsafe uint MPNeed

public uint SortKey => CoolDownGroup;

public float AnimationLockTime => IActionHelper.AnimationLockTime.TryGetValue(AdjustedID, out var time) ? time : 0.6f;
public float AnimationLockTime => OtherConfiguration.AnimationLockTime.TryGetValue(AdjustedID, out var time) ? time : 0.6f;

public BaseAction(ActionID actionID, ActionOption option = ActionOption.None)
{
Expand Down
3 changes: 2 additions & 1 deletion RotationSolver.Basic/Actions/BaseItem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using FFXIVClientStructs.FFXIV.Client.Game;
using Lumina.Excel.GeneratedSheets;
using RotationSolver.Basic.Configuration;

namespace RotationSolver.Basic.Actions;

Expand Down Expand Up @@ -65,7 +66,7 @@ public bool IsInCooldown

public uint SortKey { get; }

public float AnimationLockTime => IActionHelper.AnimationLockTime.TryGetValue(AdjustedID, out var time) ? time : 1.1f;
public float AnimationLockTime => OtherConfiguration.AnimationLockTime.TryGetValue(AdjustedID, out var time) ? time : 1.1f;

public bool IsActionSequencer => false;

Expand Down
49 changes: 47 additions & 2 deletions RotationSolver.Basic/Configuration/OtherConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace RotationSolver.Basic.Configuration;

public class OtherConfiguration
{
public static SortedList<uint, float> AnimationLockTime = new SortedList<uint, float>();

public static Dictionary<uint, string[]> NoHostileNames = new Dictionary<uint, string[]>();

public static SortedSet<uint> DangerousStatus = new SortedSet<uint>()
Expand Down Expand Up @@ -44,11 +46,25 @@ public class OtherConfiguration

public static void Init()
{
if (!Directory.Exists(Service.Interface.ConfigDirectory.FullName))
{
Directory.CreateDirectory(Service.Interface.ConfigDirectory.FullName);
}
Task.Run(() => InitOne(ref DangerousStatus, nameof(DangerousStatus)));

Task.Run(() => InitOne(ref InvincibleStatus, nameof(InvincibleStatus)));

Task.Run(() => InitOne(ref NoHostileNames, nameof(NoHostileNames)));

Task.Run(() => InitOne(ref AnimationLockTime, nameof(AnimationLockTime)));
}

public static void Save()
{
SaveDangerousStatus();
SaveInvincibleStatus();
SaveNoHostileNames();
SaveAnimationLockTime();
}

public static void SaveDangerousStatus()
Expand All @@ -66,8 +82,21 @@ public static void SaveNoHostileNames()
Task.Run(() => Save(NoHostileNames, nameof(NoHostileNames)));
}

public static void SaveAnimationLockTime()
{
Task.Run(() => Save(AnimationLockTime, nameof(AnimationLockTime)));
}

private static string GetFilePath(string name)
=> Service.Interface.ConfigDirectory.FullName + $"\\{name}.json";
{
var directory = Service.Interface.ConfigDirectory.FullName;
#if DEBUG
var dir = @"E:\OneDrive - stu.zafu.edu.cn\PartTime\FFXIV\RotationSolver\Resources";
if (Directory.Exists(dir)) directory = dir;
#endif

return directory + $"\\{name}.json";
}

private static void Save<T>(T value, string name)
=> SavePath(value, GetFilePath(name));
Expand All @@ -92,6 +121,22 @@ private static void InitOne<T>(ref T value, string name)
PluginLog.Warning(ex, $"Failed to load {name}.");
}
}
else SavePath(value, path);
else
{
try
{
var client = new HttpClient();
var str = client.GetStringAsync($"https://raw.githubusercontent.com/ArchiDog1998/RotationSolver/main/Resources/{name}.json").Result;

File.WriteAllText(path, str);
value = JsonConvert.DeserializeObject<T>(str);
}
catch
{
SavePath(value, path);
}
}
}


}
35 changes: 1 addition & 34 deletions RotationSolver.Basic/Helpers/IActionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,7 @@ namespace RotationSolver.Basic.Helpers;

public static class IActionHelper
{
public static SortedList<uint, float> AnimationLockTime { get; private set; } = new SortedList<uint, float>();

public static async void GetAnimationLockTimeAsync(string directory)
{
#if DEBUG
directory = @"E:\OneDrive - stu.zafu.edu.cn\PartTime\FFXIV\RotationSolver\Resources";
if (!Directory.Exists(directory)) return;
#endif
var filename = $"{nameof(AnimationLockTime)}.json";
var filePath = Path.Combine(directory, filename);
if (File.Exists(filePath))
{
var str = File.ReadAllText(filePath);
AnimationLockTime = JsonConvert.DeserializeObject<SortedList<uint, float>>(str);
}
else
{
try
{
var client = new HttpClient();
var str = await client.GetStringAsync($"https://raw.githubusercontent.com/ArchiDog1998/RotationSolver/main/Resources/{nameof(AnimationLockTime)}.json");
File.WriteAllText(filePath, str);

AnimationLockTime = JsonConvert.DeserializeObject<SortedList<uint, float>>(str);
}
catch (Exception ex)
{
PluginLog.Warning(ex, "Failed to download the animation lock time.");
}
}

}

public static ActionID[] MovingActions = new ActionID[]
public static ActionID[] MovingActions { get; } = new ActionID[]
{
ActionID.EnAvant,
ActionID.Plunge,
Expand Down
14 changes: 1 addition & 13 deletions RotationSolver/RotationSolverPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public unsafe RotationSolverPlugin(DalamudPluginInterface pluginInterface)
MajorUpdater.Enable();
OtherConfiguration.Init();
ActionSequencerUpdater.Enable(pluginInterface.ConfigDirectory.FullName + "\\Conditions");
IActionHelper.GetAnimationLockTimeAsync(pluginInterface.ConfigDirectory.FullName);
SocialUpdater.Enable();
_dis.Add(new Watcher());
_dis.Add(new MovingController());
Expand All @@ -81,7 +80,6 @@ public unsafe RotationSolverPlugin(DalamudPluginInterface pluginInterface)
});
}


internal static void ChangeUITranslation()
{
_comboConfigWindow.WindowName = LocalizationManager.RightLang.ConfigWindow_Header
Expand Down Expand Up @@ -109,17 +107,7 @@ public void Dispose()
SocialUpdater.Disable();

IconSet.Dispose();

#if DEBUG
var directory = @"E:\OneDrive - stu.zafu.edu.cn\PartTime\FFXIV\RotationSolver\Resources";
#else
var directory = Service.Interface.ConfigDirectory.FullName;
#endif
if (!Directory.Exists(directory)) return;

//Default values.
var path = Path.Combine(directory, $"{nameof(IActionHelper.AnimationLockTime)}.json");
File.WriteAllText(path, JsonConvert.SerializeObject(IActionHelper.AnimationLockTime, Formatting.Indented));
OtherConfiguration.Save();
}

private void OnOpenConfigUi()
Expand Down
3 changes: 2 additions & 1 deletion RotationSolver/Watcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Dalamud.Plugin.Ipc;
using Dalamud.Utility.Signatures;
using FFXIVClientStructs.FFXIV.Client.Game;
using RotationSolver.Basic.Configuration;
using RotationSolver.Localization;
using System.Text.RegularExpressions;

Expand Down Expand Up @@ -89,7 +90,7 @@ private static void ActionFromSelf(uint sourceId, ActionEffectSet set, uint id)

if(set.Action.ClassJob.Row > 0 || Enum.IsDefined((ActionID)id))
{
IActionHelper.AnimationLockTime[id] = set.AnimationLock;
OtherConfiguration.AnimationLockTime[id] = set.AnimationLock;
}

if (!set.TargetEffects.Any()) return;
Expand Down

0 comments on commit 22b275c

Please sign in to comment.