diff options
Diffstat (limited to 'code/pawn/component/camera')
| -rw-r--r-- | code/pawn/component/camera/BaseCameraComponent.cs | 16 | ||||
| -rw-r--r-- | code/pawn/component/camera/PlayerCameraComponent.cs | 11 | ||||
| -rw-r--r-- | code/pawn/component/camera/SpectatorCameraComponent.cs | 45 |
3 files changed, 43 insertions, 29 deletions
diff --git a/code/pawn/component/camera/BaseCameraComponent.cs b/code/pawn/component/camera/BaseCameraComponent.cs index 401d702..b19b2f9 100644 --- a/code/pawn/component/camera/BaseCameraComponent.cs +++ b/code/pawn/component/camera/BaseCameraComponent.cs @@ -4,25 +4,23 @@ namespace MurderGame; public class BaseCameraComponent : EntityComponent<Player>, ISingletonComponent
{
-
public virtual void Simulate( IClient cl )
{
-
}
+
public virtual void FrameSimulate( IClient cl )
{
-
}
+
public virtual void BuildInput()
{
-
}
public virtual InventoryComponent GetObservedInventory()
{
return Entity.Inventory;
}
-
+
public virtual float GetObservedHealth()
{
return Entity.Health;
@@ -30,17 +28,17 @@ public class BaseCameraComponent : EntityComponent<Player>, ISingletonComponent public virtual Team GetObservedTeam()
{
- return Entity.Team;
+ return Entity.Team;
}
-
+
public virtual string GetObservedName()
{
var characterName = Entity.CharacterName;
return string.IsNullOrWhiteSpace( characterName ) ? Entity.Client.Name : characterName;
}
-
+
public virtual string GetObservedColour()
{
- return Entity.HexColor;
+ return Entity.HexColor;
}
}
diff --git a/code/pawn/component/camera/PlayerCameraComponent.cs b/code/pawn/component/camera/PlayerCameraComponent.cs index 5ec9f7b..4ac0e2d 100644 --- a/code/pawn/component/camera/PlayerCameraComponent.cs +++ b/code/pawn/component/camera/PlayerCameraComponent.cs @@ -10,13 +10,13 @@ public class PlayerCameraComponent : BaseCameraComponent // Set field of view to whatever the user chose in options
Camera.FieldOfView = Screen.CreateVerticalFieldOfView( Game.Preferences.FieldOfView );
}
+
public override void FrameSimulate( IClient cl )
{
-
- var pl = Entity as Player;
+ var pl = Entity;
// Update rotation every frame, to keep things smooth
- if (pl.PlayerRagdoll != null && pl.LifeState == LifeState.Dead)
+ if ( pl.PlayerRagdoll != null && pl.LifeState == LifeState.Dead )
{
Camera.Position = pl.PlayerRagdoll.Position;
Camera.FirstPersonViewer = pl.PlayerRagdoll;
@@ -35,12 +35,15 @@ public class PlayerCameraComponent : BaseCameraComponent Camera.ZNear = 8 * pl.Scale;
}
+
public override void BuildInput()
{
if ( Game.LocalClient.Components.TryGet<DevCamera>( out var _ ) )
+ {
return;
+ }
- var pl = Entity as Player;
+ var pl = Entity;
var viewAngles = (pl.ViewAngles + Input.AnalogLook).Normal;
pl.ViewAngles = viewAngles.WithPitch( viewAngles.pitch.Clamp( -89f, 89f ) );
}
diff --git a/code/pawn/component/camera/SpectatorCameraComponent.cs b/code/pawn/component/camera/SpectatorCameraComponent.cs index 215b9ca..9dce4c3 100644 --- a/code/pawn/component/camera/SpectatorCameraComponent.cs +++ b/code/pawn/component/camera/SpectatorCameraComponent.cs @@ -1,6 +1,6 @@ -using Sandbox;
-using System.Collections.Generic;
+using System.Collections.Generic;
using System.Linq;
+using Sandbox;
namespace MurderGame;
@@ -17,7 +17,8 @@ public partial class SpectatorCameraComponent : BaseCameraComponent Target = null;
return;
}
- if (Target == null || !Target.IsValid() || Target.LifeState == LifeState.Dead)
+
+ if ( Target == null || !Target.IsValid() || Target.LifeState == LifeState.Dead )
{
FindNextTarget( targets, false );
return;
@@ -36,7 +37,10 @@ public partial class SpectatorCameraComponent : BaseCameraComponent public override void FrameSimulate( IClient cl )
{
- if ( Target == null || !Target.IsValid() || Target.LifeState == LifeState.Dead ) return;
+ if ( Target == null || !Target.IsValid() || Target.LifeState == LifeState.Dead )
+ {
+ return;
+ }
Camera.Rotation = Target.EyeRotation;
Camera.FieldOfView = Screen.CreateVerticalFieldOfView( Game.Preferences.FieldOfView );
@@ -47,27 +51,36 @@ public partial class SpectatorCameraComponent : BaseCameraComponent private List<IClient> GetTargets()
{
- return Game.Clients.Where(c => c.Pawn is Player player && player.Team != Team.Spectator && player.LifeState == LifeState.Alive).ToList();
+ return Game.Clients.Where( c =>
+ c.Pawn is Player player && player.Team != Team.Spectator && player.LifeState == LifeState.Alive ).ToList();
}
-
- private void FindNextTarget(List<IClient> targets, bool backwards)
+
+ private void FindNextTarget( List<IClient> targets, bool backwards )
{
if ( !backwards )
{
- if ( ++TargetIndex >= targets.Count ) TargetIndex = 0;
- }
- else {
- if ( --TargetIndex < 0 ) TargetIndex = targets.Count - 1;
+ if ( ++TargetIndex >= targets.Count )
+ {
+ TargetIndex = 0;
+ }
+ }
+ else
+ {
+ if ( --TargetIndex < 0 )
+ {
+ TargetIndex = targets.Count - 1;
+ }
}
+
var nextTarget = targets[TargetIndex];
Target = (Player)nextTarget.Pawn;
}
-
+
public override InventoryComponent GetObservedInventory()
{
return Target?.Inventory;
}
-
+
public override float GetObservedHealth()
{
return Target?.Health ?? base.GetObservedHealth();
@@ -77,13 +90,13 @@ public partial class SpectatorCameraComponent : BaseCameraComponent {
return Target?.Team ?? base.GetObservedTeam();
}
-
+
public override string GetObservedName()
{
var characterName = Target?.CharacterName ?? "";
- return string.IsNullOrWhiteSpace( characterName ) ? (Target?.Client.Name ?? "Unknown") : characterName;
+ return string.IsNullOrWhiteSpace( characterName ) ? Target?.Client.Name ?? "Unknown" : characterName;
}
-
+
public override string GetObservedColour()
{
return Target?.HexColor ?? base.GetObservedColour();
|
