changed state system

This commit is contained in:
Mister_Nebula 2021-04-18 18:42:22 +01:00
parent 5c1bf51987
commit ea0620b7c0
15 changed files with 53 additions and 93 deletions

View File

@ -32,7 +32,7 @@ namespace QSB.Animation.Events
public override void OnReceiveRemote(bool server, ToggleMessage message)
{
var player = QSBPlayerManager.GetPlayer(message.AboutId);
player?.UpdateState(State.Suit, message.ToggleValue);
player.PlayerStates.SuitedUp = message.ToggleValue;
if (!QSBCore.HasWokenUp || !player.IsReady)
{
@ -46,7 +46,7 @@ namespace QSB.Animation.Events
public override void OnReceiveLocal(bool server, ToggleMessage message)
{
QSBPlayerManager.LocalPlayer.UpdateState(State.Suit, message.ToggleValue);
QSBPlayerManager.LocalPlayer.PlayerStates.SuitedUp = message.ToggleValue;
var animator = QSBPlayerManager.LocalPlayer.AnimationSync;
var type = message.ToggleValue ? AnimationType.PlayerSuited : AnimationType.PlayerUnsuited;
animator.CurrentType = type;

View File

@ -7,14 +7,22 @@ namespace QSB.Player.Events
{
public string PlayerName { get; set; }
public bool PlayerReady { get; set; }
public State PlayerState { get; set; }
public PlayerState PlayerState { get; set; }
public override void Deserialize(QNetworkReader reader)
{
base.Deserialize(reader);
PlayerName = reader.ReadString();
PlayerReady = reader.ReadBoolean();
PlayerState = (State)reader.ReadInt32();
PlayerState = new PlayerState
{
FlashlightActive = reader.ReadBoolean(),
SuitedUp = reader.ReadBoolean(),
ProbeLauncherEquipped = reader.ReadBoolean(),
SignalscopeEquipped = reader.ReadBoolean(),
TranslatorEquipped = reader.ReadBoolean(),
ProbeActive = reader.ReadBoolean()
};
}
public override void Serialize(QNetworkWriter writer)
@ -22,7 +30,12 @@ namespace QSB.Player.Events
base.Serialize(writer);
writer.Write(PlayerName);
writer.Write(PlayerReady);
writer.Write((int)PlayerState);
writer.Write(PlayerState.FlashlightActive);
writer.Write(PlayerState.SuitedUp);
writer.Write(PlayerState.ProbeLauncherEquipped);
writer.Write(PlayerState.SignalscopeEquipped);
writer.Write(PlayerState.TranslatorEquipped);
writer.Write(PlayerState.ProbeActive);
}
}
}

View File

@ -26,7 +26,7 @@ namespace QSB.Player.Events
AboutId = player.PlayerId,
PlayerName = player.Name,
PlayerReady = player.IsReady,
PlayerState = player.State
PlayerState = player.PlayerStates
};
public override void OnReceiveRemote(bool server, PlayerStateMessage message)

View File

@ -14,9 +14,9 @@ namespace QSB.Player
{
public uint PlayerId { get; }
public string Name { get; set; }
public bool IsReady { get; set; }
public bool IsReady { get; set; } // TODO : move into PlayerStates
public PlayerHUDMarker HudMarker { get; set; }
public State State { get; set; } // TODO : decide if this is worth it (instead of having seperate variables for each thing)
public PlayerState PlayerStates { get; set; }
// Body Objects
public OWCamera Camera { get; set; }
@ -49,8 +49,8 @@ namespace QSB.Player
&& AnimationSync.CurrentType != AnimationType.PlayerUnsuited;
// Misc
public bool IsInMoon;
public bool IsInShrine;
public bool IsInMoon; // TODO : move into PlayerStates
public bool IsInShrine; // TODO : move into PlayerStates
public IQSBQuantumObject EntangledObject;
public PlayerInfo(uint id)
@ -59,37 +59,20 @@ namespace QSB.Player
CurrentDialogueID = -1;
}
public void UpdateState(State state, bool value)
{
var states = State;
if (value)
{
FlagsHelper.Set(ref states, state);
}
else
{
FlagsHelper.Unset(ref states, state);
}
State = states;
}
public void UpdateStateObjects()
{
if (OWInput.GetInputMode() == InputMode.None)
{
return;
}
FlashLight?.UpdateState(FlagsHelper.IsSet(State, State.Flashlight));
Translator?.ChangeEquipState(FlagsHelper.IsSet(State, State.Translator));
ProbeLauncher?.ChangeEquipState(FlagsHelper.IsSet(State, State.ProbeLauncher));
Signalscope?.ChangeEquipState(FlagsHelper.IsSet(State, State.Signalscope));
FlashLight?.UpdateState(PlayerStates.FlashlightActive);
Translator?.ChangeEquipState(PlayerStates.TranslatorEquipped);
ProbeLauncher?.ChangeEquipState(PlayerStates.ProbeLauncherEquipped);
Signalscope?.ChangeEquipState(PlayerStates.SignalscopeEquipped);
QSBCore.UnityEvents.RunWhen(() => QSBPlayerManager.GetSyncObject<AnimationSync>(PlayerId) != null,
() => QSBPlayerManager.GetSyncObject<AnimationSync>(PlayerId).SetSuitState(FlagsHelper.IsSet(State, State.Suit)));
() => QSBPlayerManager.GetSyncObject<AnimationSync>(PlayerId).SetSuitState(PlayerStates.SuitedUp));
}
public bool GetState(State state)
=> FlagsHelper.IsSet(State, state);
private QSBTool GetToolByType(ToolType type)
{
return CameraBody?.GetComponentsInChildren<QSBTool>()

12
QSB/Player/PlayerState.cs Normal file
View File

@ -0,0 +1,12 @@
namespace QSB.Player
{
public class PlayerState
{
public bool FlashlightActive { get; set; }
public bool SuitedUp { get; set; }
public bool ProbeLauncherEquipped { get; set; }
public bool SignalscopeEquipped { get; set; }
public bool TranslatorEquipped { get; set; }
public bool ProbeActive { get; set; }
}
}

View File

@ -79,7 +79,7 @@ namespace QSB.Player
var player = GetPlayer(message.AboutId);
player.Name = message.PlayerName;
player.IsReady = message.PlayerReady;
player.State = message.PlayerState;
player.PlayerStates = message.PlayerState;
if (LocalPlayer.IsReady)
{
player.UpdateStateObjects();

View File

@ -1,16 +0,0 @@
using System;
namespace QSB.Player
{
[Flags]
public enum State
{
None = 0,
Flashlight = 1,
Suit = 2,
ProbeLauncher = 4,
Signalscope = 8,
Translator = 16,
ProbeActive = 32
}
}

View File

@ -32,11 +32,11 @@ namespace QSB.ProbeSync.Events
public override void OnReceiveRemote(bool server, ToggleMessage message)
{
var player = QSBPlayerManager.GetPlayer(message.AboutId);
player.UpdateState(State.ProbeActive, message.ToggleValue);
player.PlayerStates.ProbeActive = message.ToggleValue;
player.Probe?.SetState(message.ToggleValue);
}
public override void OnReceiveLocal(bool server, ToggleMessage message) =>
QSBPlayerManager.LocalPlayer.UpdateState(State.ProbeActive, message.ToggleValue);
QSBPlayerManager.LocalPlayer.PlayerStates.ProbeActive = message.ToggleValue;
}
}

View File

@ -32,11 +32,11 @@ namespace QSB.ProbeSync.Events
public override void OnReceiveRemote(bool server, ToggleMessage message)
{
var player = QSBPlayerManager.GetPlayer(message.AboutId);
player.UpdateState(State.ProbeLauncher, message.ToggleValue);
player.PlayerStates.ProbeLauncherEquipped = message.ToggleValue;
player.ProbeLauncher?.ChangeEquipState(message.ToggleValue);
}
public override void OnReceiveLocal(bool server, ToggleMessage message) =>
QSBPlayerManager.LocalPlayer.UpdateState(State.ProbeLauncher, message.ToggleValue);
QSBPlayerManager.LocalPlayer.PlayerStates.ProbeLauncherEquipped = message.ToggleValue;
}
}

View File

@ -70,7 +70,7 @@ namespace QSB.ProbeSync.TransformSync
DebugLog.ToConsole($"DisabledSocket is null for {PlayerId}! (ProbeLauncher null? : {Player.ProbeLauncher == null})", MessageType.Error);
return;
}
if (Player.GetState(State.ProbeActive) || ReferenceSector?.AttachedObject == null)
if (Player.PlayerStates.ProbeActive || ReferenceSector?.AttachedObject == null)
{
return;
}

View File

@ -143,6 +143,7 @@
<Compile Include="Instruments\InstrumentsManager.cs" />
<Compile Include="Messaging\BoolMessage.cs" />
<Compile Include="Player\Patches\PlayerPatches.cs" />
<Compile Include="Player\PlayerState.cs" />
<Compile Include="PoolSync\CustomNomaiRemoteCameraPlatform.cs" />
<Compile Include="PoolSync\CustomNomaiRemoteCameraStreaming.cs" />
<Compile Include="ItemSync\Events\DropItemEvent.cs" />
@ -300,11 +301,9 @@
<Compile Include="Messaging\MessageHandler.cs" />
<Compile Include="Events\EventType.cs" />
<Compile Include="Player\PlayerInfo.cs" />
<Compile Include="Player\State.cs" />
<Compile Include="DeathSync\RespawnOnDeath.cs" />
<Compile Include="Player\QSBPlayerManager.cs" />
<Compile Include="Player\TransformSync\PlayerCameraSync.cs" />
<Compile Include="Utility\FlagsHelper.cs" />
<Compile Include="Player\PlayerHUDMarker.cs" />
<Compile Include="Tools\PlayerToolsManager.cs" />
<Compile Include="Utility\QuaternionHelper.cs" />

View File

@ -32,11 +32,11 @@ namespace QSB.Tools.Events
public override void OnReceiveRemote(bool server, ToggleMessage message)
{
var player = QSBPlayerManager.GetPlayer(message.AboutId);
player.UpdateState(State.Flashlight, message.ToggleValue);
player.PlayerStates.FlashlightActive = message.ToggleValue;
player.FlashLight?.UpdateState(message.ToggleValue);
}
public override void OnReceiveLocal(bool server, ToggleMessage message) =>
QSBPlayerManager.LocalPlayer.UpdateState(State.Flashlight, message.ToggleValue);
QSBPlayerManager.LocalPlayer.PlayerStates.FlashlightActive = message.ToggleValue;
}
}

View File

@ -32,11 +32,11 @@ namespace QSB.Tools.Events
public override void OnReceiveRemote(bool server, ToggleMessage message)
{
var player = QSBPlayerManager.GetPlayer(message.AboutId);
player.UpdateState(State.Signalscope, message.ToggleValue);
player.PlayerStates.SignalscopeEquipped = message.ToggleValue;
player.Signalscope?.ChangeEquipState(message.ToggleValue);
}
public override void OnReceiveLocal(bool server, ToggleMessage message) =>
QSBPlayerManager.LocalPlayer.UpdateState(State.Signalscope, message.ToggleValue);
QSBPlayerManager.LocalPlayer.PlayerStates.SignalscopeEquipped = message.ToggleValue;
}
}

View File

@ -32,11 +32,11 @@ namespace QSB.Tools.Events
public override void OnReceiveRemote(bool server, ToggleMessage message)
{
var player = QSBPlayerManager.GetPlayer(message.AboutId);
player.UpdateState(State.Translator, message.ToggleValue);
player.PlayerStates.TranslatorEquipped = message.ToggleValue;
player.Translator?.ChangeEquipState(message.ToggleValue);
}
public override void OnReceiveLocal(bool server, ToggleMessage message) =>
QSBPlayerManager.LocalPlayer.UpdateState(State.Translator, message.ToggleValue);
QSBPlayerManager.LocalPlayer.PlayerStates.TranslatorEquipped = message.ToggleValue;
}
}

View File

@ -1,31 +0,0 @@
namespace QSB.Utility
{
// Stolen from here : https://stackoverflow.com/questions/3261451/using-a-bitmask-in-c-sharp
public static class FlagsHelper
{
public static bool IsSet<T>(T flags, T flag) where T : struct
{
var flagsValue = (int)(object)flags;
var flagValue = (int)(object)flag;
return (flagsValue & flagValue) != 0;
}
public static void Set<T>(ref T flags, T flag) where T : struct
{
var flagsValue = (int)(object)flags;
var flagValue = (int)(object)flag;
flags = (T)(object)(flagsValue | flagValue);
}
public static void Unset<T>(ref T flags, T flag) where T : struct
{
var flagsValue = (int)(object)flags;
var flagValue = (int)(object)flag;
flags = (T)(object)(flagsValue & ~flagValue);
}
}
}