From 23e93eb67470a4301da6c2ed0aad173cf22f2d1d Mon Sep 17 00:00:00 2001 From: HumanoidSandvichDispenser Date: Fri, 26 May 2023 17:42:50 -0700 Subject: [PATCH] move swordstate into weaponstate --- Items/Weapons/Sword.cs | 4 +-- Items/Weapons/Sword.tscn | 18 ++++++------ State/Character/PlayerMoveState.cs | 3 +- State/Character/PlayerState.cs | 3 +- State/Sword/SwordState.cs | 18 ------------ .../{Sword => Weapon}/SwordAnticipateState.cs | 8 +++--- State/{Sword => Weapon}/SwordAttackState.cs | 12 ++++---- State/{Sword => Weapon}/SwordIdleState.cs | 10 +++---- State/Weapon/SwordState.cs | 5 ++++ State/{Sword => Weapon}/SwordStateMachine.cs | 13 ++++----- State/Weapon/WeaponState.cs | 18 ++++++++++++ State/Weapon/WeaponStateMachine.cs | 28 +++++++++++++++++++ 12 files changed, 85 insertions(+), 55 deletions(-) delete mode 100644 State/Sword/SwordState.cs rename State/{Sword => Weapon}/SwordAnticipateState.cs (81%) rename State/{Sword => Weapon}/SwordAttackState.cs (85%) rename State/{Sword => Weapon}/SwordIdleState.cs (73%) create mode 100644 State/Weapon/SwordState.cs rename State/{Sword => Weapon}/SwordStateMachine.cs (68%) create mode 100644 State/Weapon/WeaponState.cs create mode 100644 State/Weapon/WeaponStateMachine.cs diff --git a/Items/Weapons/Sword.cs b/Items/Weapons/Sword.cs index 9b23b70..a06c424 100644 --- a/Items/Weapons/Sword.cs +++ b/Items/Weapons/Sword.cs @@ -2,7 +2,7 @@ using Godot; using SupaLidlGame.BoundingBoxes; using SupaLidlGame.Characters; using SupaLidlGame.Extensions; -using SupaLidlGame.State.Sword; +using SupaLidlGame.State.Weapon; namespace SupaLidlGame.Items.Weapons { @@ -42,7 +42,7 @@ namespace SupaLidlGame.Items.Weapons public double NPCAnticipateTime { get; set; } [Export] - public SwordStateMachine StateMachine { get; set; } + public WeaponStateMachine StateMachine { get; set; } public override bool IsParryable { get; protected set; } diff --git a/Items/Weapons/Sword.tscn b/Items/Weapons/Sword.tscn index 75ff400..3ffcd8a 100644 --- a/Items/Weapons/Sword.tscn +++ b/Items/Weapons/Sword.tscn @@ -1,13 +1,13 @@ -[gd_scene load_steps=35 format=3 uid="uid://d72ehtv1ks0e"] +[gd_scene load_steps=35 format=3 uid="uid://dvqap2uhcah63"] [ext_resource type="Script" path="res://Items/Weapons/Sword.cs" id="1_mlo73"] -[ext_resource type="Script" path="res://State/Sword/SwordStateMachine.cs" id="2_rje2m"] -[ext_resource type="Script" path="res://State/Sword/SwordIdleState.cs" id="3_qh2cs"] +[ext_resource type="Script" path="res://State/Weapon/WeaponStateMachine.cs" id="2_vwirq"] +[ext_resource type="Script" path="res://State/Weapon/SwordIdleState.cs" id="3_nw6r0"] [ext_resource type="Texture2D" uid="uid://dp7osg05ip5oo" path="res://Assets/Sprites/sword.png" id="3_r75ni"] [ext_resource type="PackedScene" uid="uid://du5vhccg75nrq" path="res://BoundingBoxes/Hitbox.tscn" id="3_up3ob"] +[ext_resource type="Script" path="res://State/Weapon/SwordAnticipateState.cs" id="4_j3cud"] [ext_resource type="PackedScene" uid="uid://cojxmcin13ihm" path="res://Utils/Trail.tscn" id="4_pt6lq"] -[ext_resource type="Script" path="res://State/Sword/SwordAnticipateState.cs" id="4_ycuhw"] -[ext_resource type="Script" path="res://State/Sword/SwordAttackState.cs" id="5_30003"] +[ext_resource type="Script" path="res://State/Weapon/SwordAttackState.cs" id="5_hmisb"] [ext_resource type="Texture2D" uid="uid://do1bui3bblkk7" path="res://Assets/Sprites/sword-swing.png" id="5_pywek"] [ext_resource type="AudioStream" uid="uid://c4n7ioxpukdwi" path="res://Assets/Sounds/parry.wav" id="6_8nxjm"] @@ -350,21 +350,21 @@ Knockback = 64.0 Anchor = NodePath("Anchor") [node name="State" type="Node" parent="." node_paths=PackedStringArray("InitialState")] -script = ExtResource("2_rje2m") +script = ExtResource("2_vwirq") InitialState = NodePath("Idle") [node name="Idle" type="Node" parent="State" node_paths=PackedStringArray("AnticipateState", "Sword")] -script = ExtResource("3_qh2cs") +script = ExtResource("3_nw6r0") AnticipateState = NodePath("../Anticipate") Sword = NodePath("../..") [node name="Anticipate" type="Node" parent="State" node_paths=PackedStringArray("Sword", "AttackState")] -script = ExtResource("4_ycuhw") +script = ExtResource("4_j3cud") Sword = NodePath("../..") AttackState = NodePath("../Attack") [node name="Attack" type="Node" parent="State" node_paths=PackedStringArray("Sword", "AnticipateState", "IdleState")] -script = ExtResource("5_30003") +script = ExtResource("5_hmisb") Sword = NodePath("../..") AnticipateState = NodePath("../Anticipate") IdleState = NodePath("../Idle") diff --git a/State/Character/PlayerMoveState.cs b/State/Character/PlayerMoveState.cs index 1b26508..165f6ed 100644 --- a/State/Character/PlayerMoveState.cs +++ b/State/Character/PlayerMoveState.cs @@ -1,5 +1,4 @@ using Godot; -using SupaLidlGame.Items; namespace SupaLidlGame.State.Character { @@ -29,7 +28,7 @@ namespace SupaLidlGame.State.Character { if (@event.IsActionPressed("roll")) { - if (Character.Inventory.SelectedItem is Weapon weapon) + if (Character.Inventory.SelectedItem is Items.Weapon weapon) { if (!weapon.IsUsing) { diff --git a/State/Character/PlayerState.cs b/State/Character/PlayerState.cs index 7ba5557..f50da3c 100644 --- a/State/Character/PlayerState.cs +++ b/State/Character/PlayerState.cs @@ -1,5 +1,4 @@ using Godot; -using SupaLidlGame.Items; using SupaLidlGame.Characters; namespace SupaLidlGame.State.Character @@ -33,7 +32,7 @@ namespace SupaLidlGame.State.Character "ui_up", "ui_down"); Vector2 mousePos = Character.GetGlobalMousePosition(); Vector2 dirToMouse = Character.GlobalPosition.DirectionTo(mousePos); - if (Character.Inventory.SelectedItem is Weapon weapon) + if (Character.Inventory.SelectedItem is Items.Weapon weapon) { if (!weapon.IsUsing) { diff --git a/State/Sword/SwordState.cs b/State/Sword/SwordState.cs deleted file mode 100644 index 2443d1d..0000000 --- a/State/Sword/SwordState.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Godot; - -namespace SupaLidlGame.State.Sword -{ - public abstract partial class SwordState : Node, IState - { - public virtual SwordState Use() => null; - - public abstract IState Enter(IState previousState); - - public virtual void Exit(IState nextState) - { - - } - - public virtual IState Process(double delta) => null; - } -} diff --git a/State/Sword/SwordAnticipateState.cs b/State/Weapon/SwordAnticipateState.cs similarity index 81% rename from State/Sword/SwordAnticipateState.cs rename to State/Weapon/SwordAnticipateState.cs index 955a124..a40ef3b 100644 --- a/State/Sword/SwordAnticipateState.cs +++ b/State/Weapon/SwordAnticipateState.cs @@ -1,8 +1,8 @@ using Godot; -namespace SupaLidlGame.State.Sword +namespace SupaLidlGame.State.Weapon { - public partial class SwordAnticipateState : SwordState + public partial class SwordAnticipateState : WeaponState { [Export] public SupaLidlGame.Items.Weapons.Sword Sword { get; set; } @@ -12,7 +12,7 @@ namespace SupaLidlGame.State.Sword private double _anticipateTime; - public override SwordState Enter(IState prevState) + public override WeaponState Enter(IState prevState) { Sword.EnableParry(); @@ -33,7 +33,7 @@ namespace SupaLidlGame.State.Sword return null; } - public override SwordState Process(double delta) + public override WeaponState Process(double delta) { // go into attack state if anticipation time is delta if ((_anticipateTime -= delta) <= 0) diff --git a/State/Sword/SwordAttackState.cs b/State/Weapon/SwordAttackState.cs similarity index 85% rename from State/Sword/SwordAttackState.cs rename to State/Weapon/SwordAttackState.cs index 7b10ee1..9e258c6 100644 --- a/State/Sword/SwordAttackState.cs +++ b/State/Weapon/SwordAttackState.cs @@ -1,8 +1,8 @@ using Godot; -namespace SupaLidlGame.State.Sword +namespace SupaLidlGame.State.Weapon { - public partial class SwordAttackState : SwordState + public partial class SwordAttackState : WeaponState { [Export] public SupaLidlGame.Items.Weapons.Sword Sword { get; set; } @@ -21,7 +21,7 @@ namespace SupaLidlGame.State.Sword private bool _isAlternate = false; - public override SwordState Enter(IState prevState) + public override WeaponState Enter(IState prevState) { //Sword.AnimationPlayer.Stop(); Sword.Attack(); @@ -46,12 +46,12 @@ namespace SupaLidlGame.State.Sword return null; } - public override void Exit(IState nextState) + public override void Exit(IState nextState) { Sword.Deattack(); } - public override SwordState Use() + public override WeaponState Use() { if (_useDuration <= 0) { @@ -66,7 +66,7 @@ namespace SupaLidlGame.State.Sword return null; } - public override SwordState Process(double delta) + public override WeaponState Process(double delta) { if (_attackDuration > 0) { diff --git a/State/Sword/SwordIdleState.cs b/State/Weapon/SwordIdleState.cs similarity index 73% rename from State/Sword/SwordIdleState.cs rename to State/Weapon/SwordIdleState.cs index 72cfaa6..39fd3ff 100644 --- a/State/Sword/SwordIdleState.cs +++ b/State/Weapon/SwordIdleState.cs @@ -1,8 +1,8 @@ using Godot; -namespace SupaLidlGame.State.Sword +namespace SupaLidlGame.State.Weapon { - public partial class SwordIdleState : SwordState + public partial class SwordIdleState : WeaponState { [Export] public SwordAnticipateState AnticipateState { get; set; } @@ -12,7 +12,7 @@ namespace SupaLidlGame.State.Sword private double _attackCooldown; - public override SwordState Enter(IState prevState) + public override WeaponState Enter(IState prevState) { if (prevState is SwordAttackState) { @@ -21,7 +21,7 @@ namespace SupaLidlGame.State.Sword return null; } - public override SwordState Use() + public override WeaponState Use() { if (_attackCooldown <= 0) { @@ -31,7 +31,7 @@ namespace SupaLidlGame.State.Sword return AnticipateState; } - public override SwordState Process(double delta) + public override WeaponState Process(double delta) { if (_attackCooldown > 0) { diff --git a/State/Weapon/SwordState.cs b/State/Weapon/SwordState.cs new file mode 100644 index 0000000..69a8811 --- /dev/null +++ b/State/Weapon/SwordState.cs @@ -0,0 +1,5 @@ +using Godot; + +namespace SupaLidlGame.State.Weapon +{ +} diff --git a/State/Sword/SwordStateMachine.cs b/State/Weapon/SwordStateMachine.cs similarity index 68% rename from State/Sword/SwordStateMachine.cs rename to State/Weapon/SwordStateMachine.cs index 583e20f..1d068b6 100644 --- a/State/Sword/SwordStateMachine.cs +++ b/State/Weapon/SwordStateMachine.cs @@ -1,12 +1,11 @@ using Godot; -namespace SupaLidlGame.State.Sword +namespace SupaLidlGame.State.Weapon { - public partial class SwordStateMachine : StateMachine - { - [Export] - public override SwordState InitialState { get; set; } +} +/* + public void Use() { var state = CurrentState.Use(); @@ -24,5 +23,5 @@ namespace SupaLidlGame.State.Sword ChangeState(s); } } - } -} + + */ diff --git a/State/Weapon/WeaponState.cs b/State/Weapon/WeaponState.cs new file mode 100644 index 0000000..fd20588 --- /dev/null +++ b/State/Weapon/WeaponState.cs @@ -0,0 +1,18 @@ +using Godot; + +namespace SupaLidlGame.State.Weapon +{ + public abstract partial class WeaponState : Node, IState + { + public virtual WeaponState Use() => null; + + public abstract IState Enter(IState previousState); + + public virtual void Exit(IState nextState) + { + + } + + public virtual IState Process(double delta) => null; + } +} diff --git a/State/Weapon/WeaponStateMachine.cs b/State/Weapon/WeaponStateMachine.cs new file mode 100644 index 0000000..bc75894 --- /dev/null +++ b/State/Weapon/WeaponStateMachine.cs @@ -0,0 +1,28 @@ +using Godot; + +namespace SupaLidlGame.State.Weapon +{ + public partial class WeaponStateMachine : StateMachine + { + [Export] + public override WeaponState InitialState { get; set; } + + public void Use() + { + var state = CurrentState.Use(); + if (state is not null) + { + ChangeState(state); + } + } + + public void Process(double delta) + { + var state = CurrentState.Process(delta); + if (state is WeaponState s) + { + ChangeState(s); + } + } + } +}