From 4e0ec4994f9e35fa749b9433516c78fa6cfa19ab Mon Sep 17 00:00:00 2001 From: cmod31 Date: Thu, 23 Feb 2023 08:11:42 +0100 Subject: [PATCH] player variables uses getter and setter instead of function --- player_variables.cs | 16 ---------------- project.godot | 2 +- scenes/player.tscn | 6 +++--- src/player_variables.cs | 19 +++++++++++++++++++ src/scene-scripts/console/console.cs | 1 - src/scene-scripts/player.cs | 11 +++++++++++ 6 files changed, 34 insertions(+), 21 deletions(-) delete mode 100644 player_variables.cs create mode 100644 src/player_variables.cs diff --git a/player_variables.cs b/player_variables.cs deleted file mode 100644 index d644b44..0000000 --- a/player_variables.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Godot; -using System; -using System.Text.RegularExpressions; - -public partial class player_variables : Node -{ - public static string PlayerName = "Yannik"; - - public static void ClearPlayerName() //normal getter setter crashes for some reason - { - PlayerName = Regex.Replace(PlayerName, @"\[[^]]+\]", ""); - PlayerName = Regex.Replace(PlayerName, @"<[^>]*>", ""); - if (PlayerName.Length > 12) - PlayerName = PlayerName.Substring(0, 12); - } -} diff --git a/project.godot b/project.godot index df7c6a8..8581f33 100644 --- a/project.godot +++ b/project.godot @@ -18,7 +18,7 @@ config/icon="res://assets/textures/debug/dummy-player-normal.png" [autoload] Essential="res://src/essential.cs" -PlayerVariables="*res://player_variables.cs" +PlayerVariables="*res://src/player_variables.cs" [display] diff --git a/scenes/player.tscn b/scenes/player.tscn index d248f6d..0af4f4b 100644 --- a/scenes/player.tscn +++ b/scenes/player.tscn @@ -86,8 +86,7 @@ animations = [{ }] [sub_resource type="CapsuleShape2D" id="CapsuleShape2D_38v5o"] -radius = 7.99997 -height = 32.0 +height = 50.0 [node name="player" type="CharacterBody2D"] process_mode = 1 @@ -142,7 +141,8 @@ visible = false position = Vector2(0, 38) rotation = 1.57345 shape = SubResource("CapsuleShape2D_38v5o") -metadata/_edit_lock_ = true [node name="console" parent="." instance=ExtResource("4_kw3hh")] visible = false + +[connection signal="animation_changed" from="animated_sprite_2d" to="." method="OnAnimationChanged"] diff --git a/src/player_variables.cs b/src/player_variables.cs new file mode 100644 index 0000000..980cee2 --- /dev/null +++ b/src/player_variables.cs @@ -0,0 +1,19 @@ +using Godot; +using System; +using System.Text.RegularExpressions; + +public partial class player_variables : Node +{ + private static string _playername = "Yannik"; + public static string PlayerName + { + get { return _playername; } + set + { + _playername = Regex.Replace(value, @"\[[^]]+\]", ""); + _playername = Regex.Replace(_playername, @"<[^>]*>", ""); + if (PlayerName.Length > 12) + _playername = PlayerName.Substring(0, 12); + } + } +} diff --git a/src/scene-scripts/console/console.cs b/src/scene-scripts/console/console.cs index bd6331f..a0bf48a 100644 --- a/src/scene-scripts/console/console.cs +++ b/src/scene-scripts/console/console.cs @@ -103,7 +103,6 @@ public partial class console : PopupPanel public void playername(string name) { player_variables.PlayerName = name; - player_variables.ClearPlayerName(); textblock.AddText("Your new name is now: " + player_variables.PlayerName + "\n"); } public void reload() => GetTree().ReloadCurrentScene(); diff --git a/src/scene-scripts/player.cs b/src/scene-scripts/player.cs index 46002cb..961a286 100644 --- a/src/scene-scripts/player.cs +++ b/src/scene-scripts/player.cs @@ -57,4 +57,15 @@ public partial class player : CharacterBody2D animatedSprite.SpeedScale = Math.Abs(movement.Y * speed * 1.3f); } } + public void OnAnimationChanged() + { + if (animatedSprite.Animation == "move_side") + { + //GetNode("collision_shape").Shape + } + else + { + + } + } }