mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-10 21:40:19 +00:00
cleanup
This commit is contained in:
parent
6b12393212
commit
22316145ea
@ -20,11 +20,6 @@ namespace QSB
|
||||
|
||||
public static PlayerInfo GetPlayer(uint id)
|
||||
{
|
||||
if (id == uint.MaxValue || id == 0U)
|
||||
{
|
||||
DebugLog.ToConsole("Warning - tried to create player with id 0", MessageType.Warning);
|
||||
return default;
|
||||
}
|
||||
var player = PlayerList.FirstOrDefault(x => x.PlayerId == id);
|
||||
if (player != null)
|
||||
{
|
||||
@ -72,13 +67,12 @@ namespace QSB
|
||||
|
||||
public static T GetSyncObject<T>(uint id) where T : PlayerSyncObject
|
||||
{
|
||||
return GetSyncObjects<T>().FirstOrDefault(x => x != null && x.NetId == id);
|
||||
return GetSyncObjects<T>().FirstOrDefault(x => x != null && x.AttachedNetId == id);
|
||||
}
|
||||
|
||||
public static bool IsBelongingToLocalPlayer(uint id)
|
||||
{
|
||||
var behaviours = Resources.FindObjectsOfTypeAll<NetworkBehaviour>();
|
||||
return behaviours.Where(x => x.netId.Value == id).First().isLocalPlayer;
|
||||
return PlayerSyncObjects.Any(x => x != null && x.AttachedNetId == id && x.isLocalPlayer);
|
||||
}
|
||||
|
||||
public static uint GetPlayerOfObject(this PlayerSyncObject syncObject)
|
||||
@ -106,7 +100,7 @@ namespace QSB
|
||||
|
||||
public static List<uint> GetPlayerNetIds(PlayerInfo player)
|
||||
{
|
||||
var ints = Enumerable.Range((int)player.PlayerId, PlayerSyncObjects.DistinctBy(x => x.NetId).Count(x => x.Player.PlayerId == player.PlayerId)).Select(x => (uint)x).ToList();
|
||||
var ints = Enumerable.Range((int)player.PlayerId, PlayerSyncObjects.DistinctBy(x => x.AttachedNetId).Count(x => x.Player.PlayerId == player.PlayerId)).Select(x => (uint)x).ToList();
|
||||
return ints;
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ namespace QSB
|
||||
{
|
||||
public abstract class PlayerSyncObject : NetworkBehaviour
|
||||
{
|
||||
public uint NetId => GetComponent<NetworkIdentity>()?.netId.Value ?? uint.MaxValue;
|
||||
public uint AttachedNetId => GetComponent<NetworkIdentity>()?.netId.Value ?? uint.MaxValue;
|
||||
public uint PlayerId => this.GetPlayerOfObject();
|
||||
public uint PreviousPlayerId { get; set; }
|
||||
public PlayerInfo Player => PlayerRegistry.GetPlayer(PlayerId);
|
||||
|
@ -21,7 +21,7 @@ namespace QSB.TransformSync
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
DebugLog.DebugWrite($"Awake of {NetId} ({GetType().Name})");
|
||||
DebugLog.DebugWrite($"Awake of {AttachedNetId} ({GetType().Name})");
|
||||
PlayerRegistry.PlayerSyncObjects.Add(this);
|
||||
DontDestroyOnLoad(gameObject);
|
||||
QSBSceneManager.OnSceneLoaded += OnSceneLoaded;
|
||||
@ -34,7 +34,7 @@ namespace QSB.TransformSync
|
||||
|
||||
protected void Init()
|
||||
{
|
||||
DebugLog.DebugWrite($"Init of {NetId} ({Player.PlayerId}.{GetType().Name})");
|
||||
DebugLog.DebugWrite($"Init of {AttachedNetId} ({Player.PlayerId}.{GetType().Name})");
|
||||
ReferenceSector = QSBSectorManager.Instance.GetStartPlanetSector();
|
||||
SyncedTransform = hasAuthority ? InitLocalTransform() : InitRemoteTransform();
|
||||
if (!hasAuthority)
|
||||
@ -64,13 +64,13 @@ namespace QSB.TransformSync
|
||||
|
||||
if (SyncedTransform == null)
|
||||
{
|
||||
DebugLog.ToConsole($"SyncedTransform {NetId} ({Player.PlayerId}.{GetType().Name}) is null!");
|
||||
DebugLog.ToConsole($"SyncedTransform {AttachedNetId} ({Player.PlayerId}.{GetType().Name}) is null!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ReferenceSector == null)
|
||||
{
|
||||
DebugLog.ToConsole($"Error - {NetId} ({Player.PlayerId}.{GetType().Name}) doesn't have a reference sector", MessageType.Error);
|
||||
DebugLog.ToConsole($"Error - {AttachedNetId} ({Player.PlayerId}.{GetType().Name}) doesn't have a reference sector", MessageType.Error);
|
||||
}
|
||||
|
||||
UpdateTransform();
|
||||
@ -82,7 +82,7 @@ namespace QSB.TransformSync
|
||||
{
|
||||
if (ReferenceSector.Sector == null)
|
||||
{
|
||||
DebugLog.ToConsole($"Sector is null for referencesector for {NetId} ({Player.PlayerId}.{GetType().Name})!", MessageType.Error);
|
||||
DebugLog.ToConsole($"Sector is null for referencesector for {AttachedNetId} ({Player.PlayerId}.{GetType().Name})!", MessageType.Error);
|
||||
}
|
||||
transform.position = ReferenceSector.Transform.InverseTransformPoint(SyncedTransform.position);
|
||||
transform.rotation = ReferenceSector.Transform.InverseTransformRotation(SyncedTransform.rotation);
|
||||
|
Loading…
x
Reference in New Issue
Block a user