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

Commit

Permalink
fix: fixed default config.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Aug 14, 2023
1 parent c5dc82a commit d26ee2e
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 49 deletions.
1 change: 1 addition & 0 deletions Resources/AnimationLockTime.json
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@
"25871": 0.6,
"25872": 0.1,
"25873": 0.6,
"25875": 0.6,
"25882": 0.6,
"25885": 0.6,
"26762": 0.1,
Expand Down
61 changes: 19 additions & 42 deletions RotationSolver.Basic/Configuration/Configs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,18 @@ namespace RotationSolver.Basic.Configuration;
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
public class PluginConfig : IPluginConfiguration
{
[JsonProperty]
private Dictionary<Job, JobConfig> _jobsConfig = new()
public static PluginConfig Create()
{
{Job.WAR, new JobConfig()
{
Ints = new DictionConfig<JobConfigInt, int>(new()
{
{JobConfigInt.HostileType, 0 },
})
} },

{Job.PLD, new JobConfig()
{
Ints = new DictionConfig<JobConfigInt, int>(new()
{
{JobConfigInt.HostileType, 0 },
})
} },

{Job.DRK, new JobConfig()
{
Ints = new DictionConfig<JobConfigInt, int>(new()
{
{JobConfigInt.HostileType, 0 },
})
} },
var result = new PluginConfig();
result.SetValue(Job.WAR, JobConfigInt.HostileType, 0);
result.SetValue(Job.DRK, JobConfigInt.HostileType, 0);
result.SetValue(Job.PLD, JobConfigInt.HostileType, 0);
result.SetValue(Job.GNB, JobConfigInt.HostileType, 0);
return result;
}

{Job.GNB, new JobConfig()
{
Ints = new DictionConfig<JobConfigInt, int>(new()
{
{JobConfigInt.HostileType, 0 },
})
} },
};
[JsonProperty]
private Dictionary<Job, JobConfig> _jobsConfig = new();
public GlobalConfig GlobalConfig { get; private set; } = new();
public int Version { get; set; } = 7;

Expand Down Expand Up @@ -340,7 +317,7 @@ public enum PluginConfigBool : byte

[Default(true)] RecordCastingArea,

[Default(true)] AutoOpenChest,
[Default(false)] AutoOpenChest,
[Default(true)] AutoCloseChestWindow,
}

Expand Down Expand Up @@ -445,27 +422,27 @@ public DefaultAttribute(object @default, object min = null, object max = null)
}
}

[Serializable] public class DictionConfig<TConfig, Tvalue> where TConfig : struct, Enum
[Serializable] public class DictionConfig<TConfig, TValue> where TConfig : struct, Enum
{
[JsonProperty]
private Dictionary<TConfig, Tvalue> configs = new ();
private Dictionary<TConfig, TValue> configs = new ();

private readonly SortedList<TConfig, Tvalue> _defaults;
private readonly SortedList<TConfig, TValue> _defaults;

public DictionConfig(SortedList<TConfig, Tvalue> @default = null)
public DictionConfig(SortedList<TConfig, TValue> @default = null)
{
_defaults = @default;
}

public Tvalue GetValue(TConfig command)
public TValue GetValue(TConfig command)
=> configs.TryGetValue(command, out var value) ? value
: GetDefault(command);

public Tvalue GetDefault(TConfig command)
public TValue GetDefault(TConfig command)
=> _defaults?.TryGetValue(command, out var value) ?? false ? value
: (Tvalue)command.GetAttribute<DefaultAttribute>()?.Default ?? default;
: (TValue)command.GetAttribute<DefaultAttribute>()?.Default ?? default;

public void SetValue(TConfig command, Tvalue value)
public void SetValue(TConfig command, TValue value)
=> configs[command] = value;
}
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
5 changes: 3 additions & 2 deletions RotationSolver/Localization/Localization.json
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,9 @@
"ConfigWindow_Auto_ActionUsage_Description": "Which actions Rotation Solver can use.",
"ConfigWindow_Extra_Others": "Others",
"ConfigWindow_Extra_Description": "Rotation Solver focus on rotation itself. These are side features. If there are some plugins can do that, these feature will be deleted.",
"ConfigWindow_Auto_Description": "Change the strategy or usage of the automatical using actions.",
"ConfigWindow_Auto_Description": "Change the strategy or usage of the automatically using actions.",
"ConfigWindow_Auto_ActionCondition": "Action Condition",
"ConfigWindow_Auto_ActionCondition_Description": "This will change the strategy of Rotation Solver to use these actions.",
"ConfigWindow_Target_Config": "Configuration"
"ConfigWindow_Target_Config": "Configuration",
"ConfigWindow_Search_Result": "Searching Result"
}
3 changes: 2 additions & 1 deletion RotationSolver/Localization/Strings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -653,8 +653,9 @@ internal partial class Strings
public string ConfigWindow_Auto_ActionUsage_Description { get; set; } = "Which actions Rotation Solver can use.";
public string ConfigWindow_Extra_Others { get; set; } = "Others";
public string ConfigWindow_Extra_Description { get; set; } = "Rotation Solver focus on rotation itself. These are side features. If there are some plugins can do that, these feature will be deleted.";
public string ConfigWindow_Auto_Description { get; set; } = "Change the strategy or usage of the automatical using actions.";
public string ConfigWindow_Auto_Description { get; set; } = "Change the strategy or usage of the automatically using actions.";
public string ConfigWindow_Auto_ActionCondition { get; set; } = "Action Condition";
public string ConfigWindow_Auto_ActionCondition_Description { get; set; } = "This will change the strategy of Rotation Solver to use these actions.";
public string ConfigWindow_Target_Config { get; set; } = "Configuration";
public string ConfigWindow_Search_Result { get; set; } = "Searching Result";
}
7 changes: 5 additions & 2 deletions RotationSolver/RotationSolverPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ public RotationSolverPlugin(DalamudPluginInterface pluginInterface)
{
Service.Config = JsonConvert.DeserializeObject<PluginConfig>(
File.ReadAllText(Svc.PluginInterface.ConfigFile.FullName))
?? new PluginConfig();
?? PluginConfig.Create();
}
catch(Exception ex)
{
PluginLog.Warning(ex, "Failed to load config");
Service.Config = new PluginConfig();
Service.Config = PluginConfig.Create(); ;
}

_rotationConfigWindow = new();
Expand Down Expand Up @@ -119,7 +119,10 @@ public void Dispose()

ECommonsMain.Dispose();

#if DEBUG
#else
Service.Config.Save();
#endif
}

private void OnOpenConfigUi()
Expand Down
6 changes: 6 additions & 0 deletions RotationSolver/UI/RotationConfigWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,12 @@ private void DrawBody()
ImGui.SetCursorPos(ImGui.GetCursorPos() + Vector2.One * 8 * _scale);
if (BeginChild("Rotation Solver Body", -Vector2.One))
{
ImGui.PushFont(ImGuiHelper.GetFont(18));
ImGui.PushStyleColor(ImGuiCol.Text, ImGui.ColorConvertFloat4ToU32(ImGuiColors.DalamudYellow));
ImGui.TextWrapped(LocalizationManager.RightLang.ConfigWindow_Search_Result);
ImGui.PopStyleColor();
ImGui.PopFont();
ImGui.Spacing();
if (_searchResults != null && _searchResults.Any())
{
foreach (var searchable in _searchResults)
Expand Down
4 changes: 2 additions & 2 deletions RotationSolver/Updaters/MajorUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ private unsafe static void CloseWindow()
static uint _lastChest = 0;
private unsafe static void OpenChest()
{
if (!Service.Config.GetValue(Basic.Configuration.PluginConfigBool.AutoOpenChest)) return;
if (!Service.Config.GetValue(PluginConfigBool.AutoOpenChest)) return;
var player = Player.Object;

var treasure = Svc.Objects.FirstOrDefault(o =>
Expand Down Expand Up @@ -254,7 +254,7 @@ private unsafe static void OpenChest()
PluginLog.Error(ex, "Failed to open the chest!");
}

if (!Service.Config.GetValue(Basic.Configuration.PluginConfigBool.AutoOpenChest)) return;
if (!Service.Config.GetValue(PluginConfigBool.AutoCloseChestWindow)) return;
_closeWindowTime = DateTime.Now.AddSeconds(0.1);
}

Expand Down
2 changes: 2 additions & 0 deletions RotationSolver/Updaters/RotationUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,8 @@ internal static ICustomRotation GetChosenRotation(CustomRotationGroup group)
var name = Service.Config.GetJobConfig(group.JobId).RotationChoice;

var rotation = group.Rotations.FirstOrDefault(r => r.GetType().FullName == name);
rotation ??= group.Rotations.FirstOrDefault(r => r.GetType().FullName.Contains("Default", StringComparison.OrdinalIgnoreCase));

rotation ??= group.Rotations.FirstOrDefault();

return rotation;
Expand Down

0 comments on commit d26ee2e

Please sign in to comment.