tightly couple player transform sync and player info

This commit is contained in:
JohnCorby 2022-01-07 14:46:50 -08:00
parent ce37ecff9e
commit 3271efe0c5
3 changed files with 19 additions and 28 deletions

View File

@ -4,6 +4,7 @@ using QSB.Animation.Player.Thrusters;
using QSB.Audio;
using QSB.CampfireSync.WorldObjects;
using QSB.ClientServerStateSync;
using QSB.Instruments;
using QSB.ItemSync.WorldObjects.Items;
using QSB.Messaging;
using QSB.Player.Messages;
@ -25,7 +26,9 @@ namespace QSB.Player
public uint PlayerId { get; }
public string Name { get; set; }
public PlayerHUDMarker HudMarker { get; set; }
public PlayerTransformSync TransformSync { get; set; }
public PlayerTransformSync TransformSync { get; }
public AnimationSync AnimationSync { get; }
public InstrumentsManager InstrumentsManager { get; }
public ClientState State { get; set; }
public EyeState EyeState { get; set; }
public bool IsDead { get; set; }
@ -114,11 +117,10 @@ namespace QSB.Player
public bool ProbeActive { get; set; }
// Conversation
public int CurrentCharacterDialogueTreeId { get; set; }
public int CurrentCharacterDialogueTreeId { get; set; } = -1;
public GameObject CurrentDialogueBox { get; set; }
// Animation
public AnimationSync AnimationSync => QSBPlayerManager.GetSyncObject<AnimationSync>(PlayerId);
public bool PlayingInstrument => AnimationSync.CurrentType
is not AnimationType.PlayerSuited
and not AnimationType.PlayerUnsuited;
@ -181,10 +183,12 @@ namespace QSB.Player
}
}
public PlayerInfo(uint id)
public PlayerInfo(PlayerTransformSync transformSync)
{
PlayerId = id;
CurrentCharacterDialogueTreeId = -1;
PlayerId = transformSync.NetId.Value;
TransformSync = transformSync;
AnimationSync = transformSync.GetComponent<AnimationSync>();
InstrumentsManager = transformSync.GetComponent<InstrumentsManager>();
}
public void UpdateObjectsFromStates()

View File

@ -53,20 +53,6 @@ namespace QSB.Player
return player;
}
public static void AddPlayer(uint id)
{
DebugLog.DebugWrite($"Create Player : id<{id}>", MessageType.Info);
var player = new PlayerInfo(id);
PlayerList.Add(player);
OnAddPlayer?.Invoke(id);
}
public static void RemovePlayer(uint id)
{
DebugLog.DebugWrite($"Remove Player : id<{id}>", MessageType.Info);
PlayerList.RemoveAll(x => x.PlayerId == id);
}
public static bool PlayerExists(uint id) =>
id is not (uint.MaxValue or 0) && PlayerList.Any(x => x.PlayerId == id);

View File

@ -1,4 +1,5 @@
using QSB.Animation.Player;
using OWML.Common;
using QSB.Animation.Player;
using QSB.Audio;
using QSB.Instruments;
using QSB.Messaging;
@ -48,9 +49,11 @@ namespace QSB.Player.TransformSync
public override void Start()
{
var player = new PlayerInfo(this);
QSBPlayerManager.PlayerList.Add(player);
base.Start();
QSBPlayerManager.AddPlayer(PlayerId);
Player.TransformSync = this;
QSBPlayerManager.OnAddPlayer?.Invoke(PlayerId);
DebugLog.DebugWrite($"Create Player : id<{PlayerId}>", MessageType.Info);
}
protected override void OnSceneLoaded(OWScene oldScene, OWScene newScene, bool isInUniverse)
@ -88,11 +91,9 @@ namespace QSB.Player.TransformSync
// TODO : Maybe move this to a leave event...? Would ensure everything could finish up before removing the player
QSBPlayerManager.OnRemovePlayer?.Invoke(PlayerId);
base.OnDestroy();
if (QSBPlayerManager.PlayerExists(PlayerId))
{
Player.HudMarker?.Remove();
QSBPlayerManager.RemovePlayer(PlayerId);
}
Player.HudMarker?.Remove();
QSBPlayerManager.PlayerList.RemoveAll(x => x.PlayerId == PlayerId);
DebugLog.DebugWrite($"Remove Player : id<{PlayerId}>", MessageType.Info);
}
protected override Transform InitLocalTransform()