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

Commit

Permalink
feat: add timeline ui stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Feb 28, 2024
1 parent 635cf32 commit 4cda9b1
Show file tree
Hide file tree
Showing 15 changed files with 379 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ internal class IConditionConverter : JsonCreationConverter<ICondition>
return null;
}
}

private static bool FieldExists(string fieldName, JObject jObject)
{
return jObject[fieldName] != null;
}
}

internal abstract class JsonCreationConverter<T> : JsonConverter
Expand Down Expand Up @@ -77,4 +72,9 @@ public override void WriteJson(JsonWriter writer, object? value, JsonSerializer

return target;
}

protected static bool FieldExists(string fieldName, JObject jObject)
{
return jObject[fieldName] != null;
}
}
3 changes: 3 additions & 0 deletions RotationSolver.Basic/Configuration/Configs.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Dalamud.Configuration;
using ECommons.DalamudServices;
using ECommons.ExcelServices;
using RotationSolver.Basic.Configuration.Timeline;

namespace RotationSolver.Basic.Configuration;

Expand Down Expand Up @@ -748,6 +749,8 @@ public const string

public Dictionary<uint, string> DutyRotationChoice { get; set; } = [];

public Dictionary<uint, Dictionary<string, List<ITimelineItem>>> Timeline { get; set; } = [];

public void Save()
{
#if DEBUG
Expand Down
17 changes: 17 additions & 0 deletions RotationSolver.Basic/Configuration/Timeline/ActionTimelineItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace RotationSolver.Basic.Configuration.Timeline;
internal class ActionTimelineItem : ITimelineItem
{
public ActionID ID { get; set; } = ActionID.None;
public float Time { get; set; } = 3;
public float Duration { get; set; } = 3;

public bool InPeriod(TimelineItem item)
{
var time = item.Time - DataCenter.RaidTimeRaw;

if (time < 0) return false;

if (time > Time || Time - time > 3) return false;
return true;
}
}
8 changes: 8 additions & 0 deletions RotationSolver.Basic/Configuration/Timeline/ITimelineItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace RotationSolver.Basic.Configuration.Timeline;

internal interface ITimelineItem
{
public float Time { get; set; }
public float Duration { get; set; }
public bool InPeriod(TimelineItem item);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Newtonsoft.Json.Linq;
using RotationSolver.Basic.Configuration.Conditions;

namespace RotationSolver.Basic.Configuration.Timeline;

internal class ITimelineItemConverter : JsonCreationConverter<ITimelineItem>
{
protected override ITimelineItem? Create(JObject jObject)
{
if (FieldExists(nameof(ActionTimelineItem.ID), jObject))
{
return new ActionTimelineItem();
}
else if (FieldExists(nameof(StateTimelineItem.State), jObject))
{
return new StateTimelineItem();
}
return null;
}
}
18 changes: 18 additions & 0 deletions RotationSolver.Basic/Configuration/Timeline/StateTimelineItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace RotationSolver.Basic.Configuration.Timeline;

internal class StateTimelineItem : ITimelineItem
{
public AutoStatus State { get; set; }
public float Time { get; set; } = 3;
public float Duration { get; set; } = 3;

public bool InPeriod(TimelineItem item)
{
var time = item.Time - DataCenter.RaidTimeRaw;

if (time < 0) return false;

if (time > Time || Time - time > Duration) return false;
return true;
}
}
5 changes: 1 addition & 4 deletions RotationSolver.Basic/DataCenter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Dalamud.Game.ClientState.Conditions;
using Dalamud.Game.ClientState.Objects.SubKinds;
using ECommons.DalamudServices;
using ECommons.ExcelServices;
using ECommons.GameHelpers;
Expand Down Expand Up @@ -117,16 +116,14 @@ public static IAction? CommandNextAction
{
get
{
if (ActionSequencerAction != null) return ActionSequencerAction;

var next = NextActs.FirstOrDefault();

while (next != null && NextActs.Count > 0 && (next.DeadTime < DateTime.Now || IActionHelper.IsLastAction(true, next.Act)))
{
NextActs.RemoveAt(0);
next = NextActs.FirstOrDefault();
}
return next?.Act;
return next?.Act ?? ActionSequencerAction;
}
}
public static Job Job { get; set; }
Expand Down
3 changes: 1 addition & 2 deletions RotationSolver.Basic/RotationSolver.Basic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@
<PrivateAssets>all</PrivateAssets>
</ProjectReference>

<ProjectReference Include="..\RotationSolver.SourceGenerators\RotationSolver.SourceGenerators.csproj" OutputItemType="Analyzer"
ExcludeAssets="All" />
<ProjectReference Include="..\RotationSolver.SourceGenerators\RotationSolver.SourceGenerators.csproj" OutputItemType="Analyzer" ExcludeAssets="All" />

<None Include="..\COPYING.LESSER">
<Pack>True</Pack>
Expand Down
3 changes: 2 additions & 1 deletion RotationSolver/RotationSolverPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using ECommons.GameHelpers;
using ECommons.ImGuiMethods;
using RotationSolver.Basic.Configuration;
using RotationSolver.Basic.Configuration.Timeline;
using RotationSolver.Commands;
using RotationSolver.Data;
using RotationSolver.Helpers;
Expand Down Expand Up @@ -44,7 +45,7 @@ public RotationSolverPlugin(DalamudPluginInterface pluginInterface)
try
{
Service.Config = JsonConvert.DeserializeObject<Configs>(
File.ReadAllText(Svc.PluginInterface.ConfigFile.FullName))
File.ReadAllText(Svc.PluginInterface.ConfigFile.FullName), new ITimelineItemConverter())
?? new Configs();
}
catch (Exception ex)
Expand Down
6 changes: 4 additions & 2 deletions RotationSolver/UI/ConditionDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private static IEnumerable<MemberInfo> GetAllMethods(this Type? type, Func<Type,
return methods.Union(type.BaseType.GetAllMethods(getFunc));
}

public static void DrawByteEnum<T>(string name, ref T value) where T : struct, Enum
public static bool DrawByteEnum<T>(string name, ref T value) where T : struct, Enum
{
var values = Enum.GetValues<T>().Where(i => i.GetAttribute<ObsoleteAttribute>() == null).ToHashSet().ToArray();
var index = Array.IndexOf(values, value);
Expand All @@ -97,7 +97,9 @@ public static void DrawByteEnum<T>(string name, ref T value) where T : struct, E
if (ImGuiHelper.SelectableCombo(name, names, ref index))
{
value = values[index];
return true;
}
return false;
}

public static bool DrawDragFloat(ConfigUnitType type, string name, ref float value)
Expand Down Expand Up @@ -401,7 +403,7 @@ private static void DrawAfter(this ActionCondition actionCondition, ICustomRotat

ActionSelectorPopUp(popUpKey, _actionsList, rotation, item => actionCondition.ID = (ActionID)item.ID);

if (actionCondition._action?.GetTexture(out var icon) ?? false || IconSet.GetTexture(4, out icon))
if ((actionCondition._action?.GetTexture(out var icon) ?? false) || IconSet.GetTexture(4, out icon))
{
var cursor = ImGui.GetCursorPos();
if (ImGuiHelper.NoPaddingNoColorImageButton(icon.ImGuiHandle, Vector2.One * IconSize, actionCondition.GetHashCode().ToString()))
Expand Down
Loading

0 comments on commit 4cda9b1

Please sign in to comment.