using singleton for playername now
This commit is contained in:
16
player_variables.cs
Normal file
16
player_variables.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
@@ -17,7 +17,8 @@ config/icon="res://assets/textures/debug/dummy-player-normal.png"
|
|||||||
|
|
||||||
[autoload]
|
[autoload]
|
||||||
|
|
||||||
Essential="*res://src/essential.cs"
|
Essential="res://src/essential.cs"
|
||||||
|
PlayerVariables="*res://player_variables.cs"
|
||||||
|
|
||||||
[display]
|
[display]
|
||||||
|
|
||||||
|
@@ -44,7 +44,6 @@ layer_1/tile_data = PackedInt32Array(-262141, 0, 0, -196605, 0, 0, -196604, 0, 0
|
|||||||
metadata/_edit_lock_ = true
|
metadata/_edit_lock_ = true
|
||||||
|
|
||||||
[node name="player" parent="." instance=ExtResource("2_0skrb")]
|
[node name="player" parent="." instance=ExtResource("2_0skrb")]
|
||||||
playerName = "Yannik"
|
|
||||||
|
|
||||||
[node name="main_cam" parent="player" index="2"]
|
[node name="main_cam" parent="player" index="2"]
|
||||||
limit_left = -1791
|
limit_left = -1791
|
||||||
|
@@ -28,7 +28,7 @@ public partial class console : PopupPanel
|
|||||||
public void OnLineEditTextSubmitted(string command)
|
public void OnLineEditTextSubmitted(string command)
|
||||||
{
|
{
|
||||||
line.Clear();
|
line.Clear();
|
||||||
if (command.Length != 0) textblock.AddText(GetParent<player>().playerName + " > " + command + "\n");
|
if (command.Length != 0) textblock.AddText(player_variables.PlayerName + " > " + command + "\n");
|
||||||
Variant args;
|
Variant args;
|
||||||
if (command.Split(' ').Length == 2 && commandDict.ContainsKey(command.Split(' ')[0].ToLower()))
|
if (command.Split(' ').Length == 2 && commandDict.ContainsKey(command.Split(' ')[0].ToLower()))
|
||||||
{
|
{
|
||||||
@@ -102,12 +102,9 @@ public partial class console : PopupPanel
|
|||||||
}
|
}
|
||||||
public void playername(string name)
|
public void playername(string name)
|
||||||
{
|
{
|
||||||
if (GetParent().Name == "player")
|
player_variables.PlayerName = name;
|
||||||
{
|
player_variables.ClearPlayerName();
|
||||||
GetParent<player>().playerName = name;
|
textblock.AddText("Your new name is now: " + player_variables.PlayerName + "\n");
|
||||||
GetParent<player>().ClearPlayerName();
|
|
||||||
textblock.AddText("Your new name is now: " + GetParent<player>().playerName + "\n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
public void reload() => GetTree().ReloadCurrentScene();
|
public void reload() => GetTree().ReloadCurrentScene();
|
||||||
}
|
}
|
||||||
|
@@ -4,8 +4,6 @@ using System.Text.RegularExpressions;
|
|||||||
|
|
||||||
public partial class player : CharacterBody2D
|
public partial class player : CharacterBody2D
|
||||||
{
|
{
|
||||||
|
|
||||||
[Export] public string playerName;
|
|
||||||
[Export] public float speed = 1;
|
[Export] public float speed = 1;
|
||||||
public bool allowMovement = true;
|
public bool allowMovement = true;
|
||||||
public Vector2 movement;
|
public Vector2 movement;
|
||||||
@@ -15,18 +13,10 @@ public partial class player : CharacterBody2D
|
|||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
ClearPlayerName();
|
|
||||||
animatedSprite = GetNode<AnimatedSprite2D>("animated_sprite_2d");
|
animatedSprite = GetNode<AnimatedSprite2D>("animated_sprite_2d");
|
||||||
rotCenter = GetNode<Marker2D>("rotation_center");
|
rotCenter = GetNode<Marker2D>("rotation_center");
|
||||||
dialogRayCast = GetNode<RayCast2D>("rotation_center/ray_cast_2d");
|
dialogRayCast = GetNode<RayCast2D>("rotation_center/ray_cast_2d");
|
||||||
}
|
}
|
||||||
public void ClearPlayerName()
|
|
||||||
{
|
|
||||||
playerName = Regex.Replace(playerName, @"\[[^]]+\]", "");
|
|
||||||
playerName = Regex.Replace(playerName, @"<[^>]*>", "");
|
|
||||||
if (playerName.Length > 12)
|
|
||||||
playerName = playerName.Substring(0, 12);
|
|
||||||
}
|
|
||||||
public override void _PhysicsProcess(double delta)
|
public override void _PhysicsProcess(double delta)
|
||||||
{
|
{
|
||||||
if (allowMovement) movement = Input.GetVector("move_left", "move_right", "move_up", "move_down");
|
if (allowMovement) movement = Input.GetVector("move_left", "move_right", "move_up", "move_down");
|
||||||
@@ -38,7 +28,7 @@ public partial class player : CharacterBody2D
|
|||||||
{
|
{
|
||||||
if (Input.IsActionJustPressed("ui_accept") && dialogRayCast.IsColliding() && allowMovement)
|
if (Input.IsActionJustPressed("ui_accept") && dialogRayCast.IsColliding() && allowMovement)
|
||||||
GetNode<dialog_bubble>("dialog_bubble").GetDialog(dialogRayCast.GetCollider().Get("file").AsString(), dialogRayCast.GetCollider().Get("title").AsString(),
|
GetNode<dialog_bubble>("dialog_bubble").GetDialog(dialogRayCast.GetCollider().Get("file").AsString(), dialogRayCast.GetCollider().Get("title").AsString(),
|
||||||
(Area2D)dialogRayCast.GetCollider(), playerName, dialogRayCast.GetCollider().Get("introducedVillager").AsBool());
|
(Area2D)dialogRayCast.GetCollider(), player_variables.PlayerName, dialogRayCast.GetCollider().Get("introducedVillager").AsBool());
|
||||||
|
|
||||||
//animation system (with controller support wich cant get normalized vector)
|
//animation system (with controller support wich cant get normalized vector)
|
||||||
if (allowMovement == false)
|
if (allowMovement == false)
|
||||||
|
Reference in New Issue
Block a user