mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-21 09:39:56 +00:00
animation system uses player registry (#123)
This commit is contained in:
parent
5dce7a8a03
commit
52238374c5
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OWML.ModHelper.Events;
|
||||
using QSB.Messaging;
|
||||
using UnityEngine;
|
||||
@ -29,8 +28,6 @@ namespace QSB.Animation
|
||||
private float _sendTimer;
|
||||
private float _lastSentJumpChargeFraction;
|
||||
|
||||
private static readonly Dictionary<uint, AnimationSync> PlayerAnimSyncs = new Dictionary<uint, AnimationSync>();
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_anim = gameObject.AddComponent<Animator>();
|
||||
@ -53,7 +50,7 @@ namespace QSB.Animation
|
||||
mirror.Init(_anim, _bodyAnim);
|
||||
}
|
||||
|
||||
PlayerAnimSyncs[netId.Value] = this;
|
||||
PlayerRegistry.AnimationSyncs.Add(this);
|
||||
|
||||
for (var i = 0; i < _anim.parameterCount; i++)
|
||||
{
|
||||
@ -145,10 +142,12 @@ namespace QSB.Animation
|
||||
|
||||
private void OnClientReceiveMessage(AnimTriggerMessage message)
|
||||
{
|
||||
if (PlayerAnimSyncs.TryGetValue(message.SenderId, out var animSync) && animSync != this)
|
||||
var animationSync = PlayerRegistry.GetAnimationSync(message.SenderId);
|
||||
if (animationSync == null || animationSync == this)
|
||||
{
|
||||
animSync.HandleTrigger((AnimTrigger)message.TriggerId, message.Value);
|
||||
return;
|
||||
}
|
||||
animationSync.HandleTrigger((AnimTrigger)message.TriggerId, message.Value);
|
||||
}
|
||||
|
||||
private void HandleTrigger(AnimTrigger trigger, float value)
|
||||
|
@ -2,18 +2,20 @@
|
||||
using System.Linq;
|
||||
using QSB.Events;
|
||||
using QSB.TransformSync;
|
||||
using QSB.Animation;
|
||||
|
||||
namespace QSB
|
||||
{
|
||||
public static class PlayerRegistry
|
||||
{
|
||||
public static PlayerInfo LocalPlayer => GetPlayer(PlayerTransformSync.LocalInstance.netId.Value);
|
||||
|
||||
public static List<PlayerInfo> PlayerList { get; } = new List<PlayerInfo>();
|
||||
public static List<TransformSync.TransformSync> TransformSyncs { get; } = new List<TransformSync.TransformSync>();
|
||||
|
||||
public static List<TransformSync.TransformSync> TransformSyncs { get; } = new List<TransformSync.TransformSync>();
|
||||
public static List<TransformSync.TransformSync> LocalTransformSyncs => TransformSyncs.Where(t => t.hasAuthority).ToList();
|
||||
|
||||
|
||||
public static List<AnimationSync> AnimationSyncs { get; } = new List<AnimationSync>();
|
||||
|
||||
public static PlayerInfo CreatePlayer(uint id)
|
||||
{
|
||||
if (PlayerExists(id))
|
||||
@ -51,5 +53,10 @@ namespace QSB
|
||||
return TransformSyncs.Single(x => x.netId.Value == id);
|
||||
}
|
||||
|
||||
public static AnimationSync GetAnimationSync(uint id)
|
||||
{
|
||||
return AnimationSyncs.SingleOrDefault(x => x.netId.Value == id);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user