Skip to content

Commit

Permalink
0.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
maltiez2 committed Dec 12, 2023
1 parent d274fd3 commit 65fb1b4
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 19 deletions.
8 changes: 4 additions & 4 deletions AnimationManager/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
"Client": {
"commandName": "Executable",
"executablePath": "dotnet",
"commandLineArgs": "\"$(VINTAGE_STORY)/Vintagestory.dll\" --tracelog --addModPath \"$(ProjectDir)/bin/$(Configuration)/Mods\" \"-o\" \"test_fsm_2\"",
"workingDirectory": "$(VINTAGE_STORY)"
"commandLineArgs": "\"D:/Projects/Firearms/game/Vintagestory.dll\" --tracelog --addModPath \"$(ProjectDir)/bin/$(Configuration)/Mods\" \"-o\" \"test_fsm_2\"",
"workingDirectory": "D:/Projects/Firearms/game"
},
"Server": {
"commandName": "Executable",
"executablePath": "dotnet",
"commandLineArgs": "\"$(VINTAGE_STORY)/VintagestoryServer.dll\" --tracelog --addModPath \"$(ProjectDir)/bin/$(Configuration)/Mods\" \"-o\" \"test_fsm_2\"",
"workingDirectory": "$(VINTAGE_STORY)"
"commandLineArgs": "\"D:/Projects/Firearms/game/VintagestoryServer.dll\" --tracelog --addModPath \"$(ProjectDir)/bin/$(Configuration)/Mods\" \"-o\" \"test_fsm_2\"",
"workingDirectory": "D:/Projects/Firearms/game"
}
}
}
8 changes: 6 additions & 2 deletions AnimationManager/src/API/External.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public AnimationSequence(AnimationId animationId, params RunParameters[] paramet

Requests = requests.ToArray();
}

public static implicit operator AnimationSequence(AnimationRequest request) => new(request);
public static implicit operator AnimationSequence(AnimationRequest[] requests) => new(requests);
}

public enum AnimationPlayerAction : byte
Expand Down Expand Up @@ -163,10 +166,11 @@ private AnimationData(string code, bool cyclic = false)
private AnimationData(string code, Entity entity, bool cyclic = false)
{
if (entity == null) throw new ArgumentException("Entity cannot be null", nameof(entity));

entity.Properties.Client.AnimationsByMetaCode.TryGetValue(Code, out AnimationMetaData? metaData);

Code = code ?? throw new ArgumentException("Animation code cannot be null", nameof(code));

entity.Properties.Client.AnimationsByMetaCode.TryGetValue(Code, out AnimationMetaData? metaData);

Shape = entity.Properties.Client.LoadedShapeForEntity;
ElementWeight = metaData?.ElementWeight;
ElementBlendMode = metaData?.ElementBlendMode;
Expand Down
8 changes: 4 additions & 4 deletions AnimationManager/src/AnimationManagerModSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class AnimationManagerLibSystem : ModSystem, API.IAnimationManagerSystem
internal event OnBeforeRenderCallback? OnHeldItemBeforeRender;

private ICoreAPI? mApi;
private PlayerModelAnimationManager? mManager;
private AnimationManager? mManager;
private ShaderProgram? mShaderProgram;

public bool Register(API.AnimationId id, API.AnimationData animation) => mManager?.Register(id, animation) ?? false;
Expand All @@ -39,7 +39,7 @@ public override void StartClientSide(ICoreClientAPI api)
LoadAnimatedItemShaders();

Synchronizer synchronizer = new();
mManager = new PlayerModelAnimationManager(api, synchronizer);
mManager = new AnimationManager(api, synchronizer);
RegisterHandlers(mManager);
synchronizer.Init(
api,
Expand Down Expand Up @@ -77,13 +77,13 @@ public void OnBeforeRender(Vintagestory.API.Common.IAnimator animator, float dt)
OnHeldItemBeforeRender?.Invoke(animator, dt);
}

private void RegisterHandlers(PlayerModelAnimationManager manager)
private void RegisterHandlers(AnimationManager manager)
{
Patches.AnimatorBasePatch.OnElementPoseUsedCallback += manager.OnApplyAnimation;
Patches.AnimatorBasePatch.OnFrameCallback += manager.OnFrameHandler;
OnHeldItemBeforeRender += manager.OnFrameHandler;
}
private void UnregisterHandlers(PlayerModelAnimationManager? manager)
private void UnregisterHandlers(AnimationManager? manager)
{
if (manager == null) return;
Patches.AnimatorBasePatch.OnElementPoseUsedCallback -= manager.OnApplyAnimation;
Expand Down
9 changes: 4 additions & 5 deletions AnimationManager/src/AnimatorBasePatch.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using HarmonyLib;
using System;
using System.Reflection;
using Vintagestory.API.Common;
using Vintagestory.API.Common.Entities;
Expand All @@ -17,7 +16,7 @@ static class AnimatorBasePatch
public static void Patch(string harmonyId)
{
new Harmony(harmonyId).Patch(
AccessTools.Method(typeof(AnimationManager), nameof(AnimationManager.OnClientFrame)),
AccessTools.Method(typeof(Vintagestory.API.Common.AnimationManager), nameof(Vintagestory.API.Common.AnimationManager.OnClientFrame)),
prefix: new HarmonyMethod(AccessTools.Method(typeof(AnimatorBasePatch), nameof(OnFrame)))
);

Expand All @@ -30,13 +29,13 @@ public static void Patch(string harmonyId)
public static void Unpatch(string harmonyId)
{
new Harmony(harmonyId).Unpatch(AccessTools.Method(typeof(ShapeElement), nameof(GetLocalTransformMatrix)), HarmonyPatchType.Prefix, harmonyId);
new Harmony(harmonyId).Unpatch(AccessTools.Method(typeof(AnimationManager), nameof(AnimationManager.OnClientFrame)), HarmonyPatchType.Prefix, harmonyId);
new Harmony(harmonyId).Unpatch(AccessTools.Method(typeof(Vintagestory.API.Common.AnimationManager), nameof(Vintagestory.API.Common.AnimationManager.OnClientFrame)), HarmonyPatchType.Prefix, harmonyId);
}

public static void OnFrame(AnimationManager __instance, float dt)
public static void OnFrame(Vintagestory.API.Common.AnimationManager __instance, float dt)
{
#pragma warning disable S3011 // Reflection should not be used to increase accessibility of classes, methods, or fields
Entity? entity = (Entity?)typeof(AnimationManager)
Entity? entity = (Entity?)typeof(Vintagestory.API.Common.AnimationManager)
.GetField("entity", BindingFlags.NonPublic | BindingFlags.Instance)
?.GetValue(__instance);
#pragma warning restore S3011 // Reflection should not be used to increase accessibility of classes, methods, or fields
Expand Down
4 changes: 2 additions & 2 deletions AnimationManager/src/Implementation/Animator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,11 @@ public void SetUpDebugWindow()
ImGuiNET.ImGui.Text($"Modifier: -");

if (mStopped)
ImGuiNET.ImGui.SliderFloat("Prev. progress", ref mPreviousProgress, 0, 1);
ImGuiNET.ImGui.SliderFloat($"Prev. progress ({mCurrentAnimation.GetHashCode()})", ref mPreviousProgress, 0, 1);
else
{
ImGuiNET.ImGui.BeginDisabled();
ImGuiNET.ImGui.SliderFloat("Prev. progress", ref mPreviousProgress, 0, 1);
ImGuiNET.ImGui.SliderFloat($"Prev. progress ({mCurrentAnimation.GetHashCode()})", ref mPreviousProgress, 0, 1);
ImGuiNET.ImGui.EndDisabled();
}

Expand Down
4 changes: 2 additions & 2 deletions AnimationManager/src/Implementation/Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace AnimationManagerLib
{
public class PlayerModelAnimationManager : API.IAnimationManager
public class AnimationManager : API.IAnimationManager
{
private readonly ICoreClientAPI mClientApi;
private readonly ISynchronizer mSynchronizer;
Expand All @@ -23,7 +23,7 @@ public class PlayerModelAnimationManager : API.IAnimationManager
private readonly Dictionary<AnimationTarget, AnimationFrame> mAnimationFrames = new();
private readonly HashSet<Guid> mSynchronizedPackets = new();

internal PlayerModelAnimationManager(ICoreClientAPI api, ISynchronizer synchronizer)
internal AnimationManager(ICoreClientAPI api, ISynchronizer synchronizer)
{
mClientApi = api;
mSynchronizer = synchronizer;
Expand Down

0 comments on commit 65fb1b4

Please sign in to comment.