Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions Robust.Client/Animus/Actions/AnimusActionAnimationBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Numerics;
using JetBrains.Annotations;
using Robust.Client.Animations;
using Robust.Client.GameObjects;
using Robust.Shared.Animations;
using Robust.Shared.GameObjects;
using Robust.Shared.Maths;
using Robust.Shared.Serialization.Manager.Attributes;

namespace Robust.Client.Animus.Actions;

[ImplicitDataDefinitionForInheritors]
[PublicAPI]
public abstract partial class AnimusActionAnimationBase
{
/// <summary>
/// Simple stopping animation for cases where only rotation and offset were affected.
/// </summary>
protected static readonly Animation StopAnimation = new()
{
Length = TimeSpan.FromSeconds(0),
AnimationTracks =
{
new AnimationTrackComponentProperty()
{
ComponentType = typeof(SpriteComponent),
Property = nameof(SpriteComponent.Rotation),
InterpolationMode = AnimationInterpolationMode.Linear,
KeyFrames =
{
new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(0), 0),
},
},
new AnimationTrackComponentProperty()
{
ComponentType = typeof(SpriteComponent),
Property = nameof(SpriteComponent.Offset),
InterpolationMode = AnimationInterpolationMode.Linear,
KeyFrames =
{
new AnimationTrackProperty.KeyFrame(new Vector2(), 0),
},
},
},
};

public virtual void Initialize(EntityManager entityManager)
{

}

protected abstract Animation? GetNextAnimation(AppearanceSystem appearanceSystem, EntityUid entity, bool restarting);

protected abstract Animation? GetStopAnimation(AppearanceSystem appearanceSystem, EntityUid entity);

internal bool TryNextAnimation(AppearanceSystem appearanceSystem, EntityUid entity, [NotNullWhen(true)] out Animation? anim, bool restarting)
{
anim = GetNextAnimation(appearanceSystem, entity, restarting);
return anim != null;
}

internal bool TryStopAnimation(AppearanceSystem appearanceSystem, EntityUid entity, [NotNullWhen(true)] out Animation? anim)
{
anim = GetStopAnimation(appearanceSystem, entity);
return anim != null;
}
}

public sealed partial class AnimusActionAnimationNull : AnimusActionAnimationBase
{
protected override Animation? GetNextAnimation(AppearanceSystem appearanceSystem, EntityUid entity, bool restarting)
{
return null;
}

protected override Animation? GetStopAnimation(AppearanceSystem appearanceSystem, EntityUid entity)
{
return null;
}
}
33 changes: 33 additions & 0 deletions Robust.Client/Animus/Actions/AnimusActionSpriteChangeBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;

namespace Robust.Client.Animus.Actions;

[ImplicitDataDefinitionForInheritors]
[PublicAPI]
public abstract partial class AnimusActionSpriteChangeBase
{
public abstract void Initialize(Entity<SpriteComponent> entity, EntityManager entityManager);
public abstract void ExecuteSpriteChange(Entity<SpriteComponent> entity);
public abstract void ResetSpriteChange(Entity<SpriteComponent> entity);
}

public sealed partial class AnimusActionSpriteChangeNull : AnimusActionSpriteChangeBase
{
public override void Initialize(Entity<SpriteComponent> entity, EntityManager entityManager)
{

}

public override void ExecuteSpriteChange(Entity<SpriteComponent> entity)
{

}

public override void ResetSpriteChange(Entity<SpriteComponent> entity)
{

}
}
31 changes: 31 additions & 0 deletions Robust.Client/Animus/AnimusComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using Robust.Client.Animus.States;
using Robust.Client.Animus.Timers;
using Robust.Shared.GameObjects;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.Manager.Attributes;

namespace Robust.Client.Animus;

[RegisterComponent]
public sealed partial class AnimusComponent : Component
{
[DataField]
internal List<ProtoId<AnimusPrototype>> StateMachines;

internal readonly List<AnimusInstance> ActiveStateMachines = [];
}

/// <summary>
/// Prototypes are global instances but conditions and other objects may require per-instance data.
/// </summary>
internal sealed class AnimusInstance
{
internal ProtoId<AnimusPrototype> Prototype = default;
internal AnimusStateBase[] States = [];
internal AnimusTimerBase? Timer = null;
internal AnimusStateBase ActiveState = new AnimusStateNull();
internal AnimusStateBase DefaultState = new AnimusStateNull();
internal TimeSpan ActiveStateExitTime = TimeSpan.Zero;
}
36 changes: 36 additions & 0 deletions Robust.Client/Animus/AnimusPrototype.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Collections.Generic;
using Robust.Client.Animus.States;
using Robust.Client.Animus.Timers;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;

namespace Robust.Client.Animus;

[Prototype]
internal sealed partial class AnimusPrototype : IPrototype
{
[ViewVariables]
[IdDataField]
public string ID { get; private set; } = default!;

/// <summary>
/// A collection of possible states for this animus.
/// </summary>
[DataField]
internal List<AnimusStateBase> States = [];

/// <summary>
/// Optional timer for executing an update.
/// Setting this disables periodic condition checks.
/// </summary>
[DataField]
internal AnimusTimerBase? Timer;

/// <summary>
/// The default state to enter when no other state matches their conditions.
/// </summary>
[DataField]
internal AnimusStateBase DefaultState = new AnimusStateNull();

}
Loading
Loading