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

Commit

Permalink
feat: timeline drawing first commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Mar 6, 2024
1 parent d9b08e6 commit df13743
Show file tree
Hide file tree
Showing 16 changed files with 415 additions and 196 deletions.

This file was deleted.

153 changes: 7 additions & 146 deletions RotationSolver.Basic/Configuration/Timeline/DrawingTimeline.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
using ECommons.Configuration;
using ECommons.DalamudServices;
using ECommons.GameFunctions;
using RotationSolver.Basic.Configuration.Timeline.TimelineCondition;
using XIVPainter;
using XIVPainter.Element;
using XIVPainter.Vfx;
using Action = Lumina.Excel.GeneratedSheets.Action;
using RotationSolver.Basic.Configuration.Timeline.TimelineCondition;
using RotationSolver.Basic.Configuration.Timeline.TimelineDrawing;


namespace RotationSolver.Basic.Configuration.Timeline;

[Description("Drawing Timeline")]
internal class DrawingTimeline : BaseTimelineItem
{
private IDisposable[] _drawings = [];
public ITimelineCondition Condition { get; set; } = new TrueTimelineCondition();
public StaticVfxConfig StaticVfxConfig { get; set; }
public ObjectVfxConfig ObjectConfig { get; set; }
public ActionVfxConfig ActionConfig { get; set; }
public ObjectGetter ObjectGetter { get; set; } = new();
public DrawingType Type { get; set; }
public List<IDrawingGetter> DrawingGetters { get; set; } = [];

private IDisposable[] _drawings = [];

public uint ActionID { get; set; }
public DrawingTimeline()
{
Time = 5;
Expand All @@ -45,7 +35,8 @@ protected override void OnEnable()
{
item.Dispose();
}
_drawings = CreateDrawing();

_drawings = [.. DrawingGetters.SelectMany(i => i.GetDrawing())];

#if DEBUG
//Svc.Log.Debug($"Added the state {item2.State} to timeline.");
Expand All @@ -62,134 +53,4 @@ protected override void OnDisable()
_drawings = [];
base.OnDisable();
}

private IDisposable[] CreateDrawing()
{
switch (Type)
{
case DrawingType.Ground:
if (string.IsNullOrEmpty(StaticVfxConfig.Path)) break;

return [new StaticVfx(StaticVfxConfig.Path, StaticVfxConfig.Position, StaticVfxConfig.Rotation, StaticVfxConfig.Scale)];

case DrawingType.Object:
return [..ObjectGetter.GetObjects().Select(GetObjectDrawing)];

case DrawingType.Action:
return [.. ObjectGetter.GetObjects().Select(GetActionDrawing)];
}
return [];
}

private IDisposable? GetObjectDrawing(GameObject obj)
{
switch (ObjectConfig.Type)
{
case ObjectVfxConfig.ObjectType.Single:
return new Single1(obj, ObjectConfig.Radius);

case ObjectVfxConfig.ObjectType.Stack2:
return new Share2(obj, ObjectConfig.Radius);

case ObjectVfxConfig.ObjectType.Stack4:
return new Share4(obj, ObjectConfig.Radius);

case ObjectVfxConfig.ObjectType.General:
if (string.IsNullOrEmpty(StaticVfxConfig.Path)) break;

var result = new StaticVfx(StaticVfxConfig.Path, obj, StaticVfxConfig.Scale)
{
LocationOffset = StaticVfxConfig.Position,
RotateAddition = StaticVfxConfig.Rotation,
};
if (ObjectConfig.TargetOnTarget)
{
result.Target = obj.TargetObject;
}
return result;
}
return null;
}

private IDisposable? GetActionDrawing(GameObject obj)
{
if (ActionID == 0) return null;
var action = Svc.Data.GetExcelSheet<Action>()?.GetRow(ActionID);
if (action == null) return null;
var omen = action.Omen.Value?.Path?.RawString;
omen = string.IsNullOrEmpty(omen) ? StaticVfxConfig.Path : omen.Omen();

var x = ActionConfig.X ?? (action.XAxisModifier > 0 ? action.XAxisModifier / 2 : action.EffectRange);
var y = ActionConfig.Y ?? action.EffectRange;
var scale = new Vector3(x, XIVPainterMain.HeightScale, y);

if (action.TargetArea)
{
var location = StaticVfxConfig.Position;
if (obj is BattleChara battle)
{
unsafe
{
var info = battle.Struct()->GetCastInfo;
if (info->IsCasting != 0)
{
location = info->CastLocation;
}
}
}
return new StaticVfx(omen, location, 0, scale);
}
else
{
return new StaticVfx(omen, obj, scale)
{
RotateAddition = StaticVfxConfig.Rotation / 180 * MathF.PI,
LocationOffset = StaticVfxConfig.Position,
};
}
}
}

public class ObjectGetter
{
public GameObject[] GetObjects()
{
return [];
}
}

public struct ActionVfxConfig
{
public float? X { get; set; }
public float? Y { get; set; }
}

public struct ObjectVfxConfig
{
public enum ObjectType
{
Single,
Stack2,
Stack4,
General,
}

public float Radius { get; set; }
public bool TargetOnTarget { get; set; }
public ObjectType Type { get; set; }
}

public struct StaticVfxConfig
{
public string Path { get; set; }
public Vector3 Position { get; set; }
public float Rotation { get; set; }
public Vector3 Scale { get; set; }
}

public enum DrawingType
{
Ground,
Object,
Action,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Newtonsoft.Json.Linq;
using RotationSolver.Basic.Configuration.Conditions;
using RotationSolver.Basic.Configuration.Timeline.TimelineDrawing;

namespace RotationSolver.Basic.Configuration.Timeline.TimelineCondition;
internal class ITimelineConditionConverter : JsonCreationConverter<ITimelineCondition>
{
protected override ITimelineCondition? Create(JObject jObject)
{
if (FieldExists(nameof(ActionDrawingGetter.ActionID), jObject))
{
//return new ActionDrawingGetter();
}

return new TrueTimelineCondition();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace RotationSolver.Basic.Configuration.Timeline.TimelineCondition;
public class ObjectGetter
{
public bool CanGet(GameObject obj)
{
return true;
}

public GameObject[] TargetGetter(GameObject obj)
{
return [];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using ECommons.DalamudServices;
using ECommons.GameFunctions;
using RotationSolver.Basic.Configuration.Timeline.TimelineCondition;
using XIVPainter;
using XIVPainter.Vfx;
using Action = Lumina.Excel.GeneratedSheets.Action;

namespace RotationSolver.Basic.Configuration.Timeline.TimelineDrawing;

[Description("Action Drawing")]
internal class ActionDrawingGetter : IDrawingGetter
{
public uint ActionID { get; set; }
public string Path { get; set; } = "";
public float? X { get; set; }
public float? Y { get; set; }
public Vector3 Position { get; set; }
public float Rotation { get; set; }
public ObjectGetter ObjectGetter { get; set; } = new();

public IDisposable[] GetDrawing()
{
var objs = Svc.Objects.Where(ObjectGetter.CanGet);
if (objs.Any())
{
return [.. objs.Select(GetActionDrawing).OfType<IDisposable>()];
}

var item = GetActionDrawing(null);
if (item == null) return [];
return [item];
}

private IDisposable? GetActionDrawing(GameObject? obj)
{
if (ActionID == 0) return null;
var action = Svc.Data.GetExcelSheet<Action>()?.GetRow(ActionID);
if (action == null) return null;
var omen = action.Omen.Value?.Path?.RawString;
omen = string.IsNullOrEmpty(omen) ? Path : omen.Omen();

var x = X ?? (action.XAxisModifier > 0 ? action.XAxisModifier / 2 : action.EffectRange);
var y = Y ?? action.EffectRange;
var scale = new Vector3(x, XIVPainterMain.HeightScale, y);

if (action.TargetArea)
{
var location = Position;
if (obj is BattleChara battle)
{
unsafe
{
var info = battle.Struct()->GetCastInfo;
if (info->IsCasting != 0)
{
location = info->CastLocation;
}
}
}
return new StaticVfx(omen, location, 0, scale);
}
else
{
if(obj != null)
{
return new StaticVfx(omen, obj, scale)
{
RotateAddition = Rotation / 180 * MathF.PI,
LocationOffset = Position,
};
}
else
{
return new StaticVfx(omen, Position, Rotation, scale);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace RotationSolver.Basic.Configuration.Timeline.TimelineDrawing;
internal interface IDrawingGetter
{
IDisposable[] GetDrawing();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Newtonsoft.Json.Linq;
using RotationSolver.Basic.Configuration.Conditions;

namespace RotationSolver.Basic.Configuration.Timeline.TimelineDrawing;

internal class IDrawingGetterConverter : JsonCreationConverter<IDrawingGetter>
{
protected override IDrawingGetter? Create(JObject jObject)
{
if (FieldExists(nameof(ActionDrawingGetter.ActionID), jObject))
{
return new ActionDrawingGetter();
}
else if (FieldExists(nameof(ObjectDrawingGetter.IsActorEffect), jObject))
{
return new ObjectDrawingGetter();
}
else if (FieldExists(nameof(StaticDrawingGetter.Text), jObject))
{
return new StaticDrawingGetter();
}

return null;
}
}
Loading

0 comments on commit df13743

Please sign in to comment.