From 914512435d37d9f1e1ea4c045afd4ec5612b7534 Mon Sep 17 00:00:00 2001 From: Leonardo Bishop Date: Sun, 30 Jul 2023 02:45:36 +0100 Subject: Replace movement controllers --- .../component/movement/BaseControllerComponent.cs | 104 +++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 code/pawn/component/movement/BaseControllerComponent.cs (limited to 'code/pawn/component/movement/BaseControllerComponent.cs') diff --git a/code/pawn/component/movement/BaseControllerComponent.cs b/code/pawn/component/movement/BaseControllerComponent.cs new file mode 100644 index 0000000..d9b24c6 --- /dev/null +++ b/code/pawn/component/movement/BaseControllerComponent.cs @@ -0,0 +1,104 @@ +using Sandbox; +using System; +using System.Collections.Generic; + +namespace MurderGame; + +/// +/// Component designed for movement, only 1 per pawn. +/// +public class BaseControllerComponent : EntityComponent, ISingletonComponent +{ + + public virtual void Simulate( IClient cl ) + { + + } + public virtual void FrameSimulate( IClient cl ) + { + + } + public virtual void BuildInput() + { + + } + public Vector3 WishVelocity { get; set; } + + internal HashSet Events = new( StringComparer.OrdinalIgnoreCase ); + + internal HashSet Tags; + /// + /// Call OnEvent for each event + /// + public virtual void RunEvents( BaseControllerComponent additionalController ) + { + if ( Events == null ) return; + + foreach ( var e in Events ) + { + OnEvent( e ); + additionalController?.OnEvent( e ); + } + } + + /// + /// An event has been triggered - maybe handle it + /// + public virtual void OnEvent( string name ) + { + + } + + /// + /// Returns true if we have this event + /// + public bool HasEvent( string eventName ) + { + if ( Events == null ) return false; + return Events.Contains( eventName ); + } + + /// + /// + public bool HasTag( string tagName ) + { + if ( Tags == null ) return false; + return Tags.Contains( tagName ); + } + + + /// + /// Allows the controller to pass events to other systems + /// while staying abstracted. + /// For example, it could pass a "jump" event, which could then + /// be picked up by the playeranimator to trigger a jump animation, + /// and picked up by the player to play a jump sound. + /// + public void AddEvent( string eventName ) + { + // TODO - shall we allow passing data with the event? + + if ( Events == null ) Events = new HashSet(); + + if ( Events.Contains( eventName ) ) + return; + + Events.Add( eventName ); + } + + + /// + /// + public void SetTag( string tagName ) + { + // TODO - shall we allow passing data with the event? + + Tags ??= new HashSet(); + + if ( Tags.Contains( tagName ) ) + return; + + Tags.Add( tagName ); + } +} + -- cgit v1.2.3-70-g09d2