added a cheat console
This commit is contained in:
@@ -120,6 +120,11 @@ hotkey_fullscreen={
|
||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194342,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
console={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194334,"key_label":0,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[internationalization]
|
||||
|
||||
|
34
scenes/gui/console.tscn
Normal file
34
scenes/gui/console.tscn
Normal file
@@ -0,0 +1,34 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://bt4pohi6srcvi"]
|
||||
|
||||
[ext_resource type="Script" path="res://src/scene-scripts/console.cs" id="1_c6bre"]
|
||||
|
||||
[node name="console" type="CanvasLayer"]
|
||||
script = ExtResource("1_c6bre")
|
||||
|
||||
[node name="panel_container" type="PanelContainer" parent="."]
|
||||
anchors_preset = 10
|
||||
anchor_right = 1.0
|
||||
grow_horizontal = 2
|
||||
|
||||
[node name="v_box_container" type="VBoxContainer" parent="panel_container"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="rich_text_label" type="RichTextLabel" parent="panel_container/v_box_container"]
|
||||
custom_minimum_size = Vector2(0, 150)
|
||||
layout_mode = 2
|
||||
bbcode_enabled = true
|
||||
scroll_following = true
|
||||
|
||||
[node name="line_edit" type="LineEdit" parent="panel_container/v_box_container"]
|
||||
layout_mode = 2
|
||||
placeholder_text = "Type in cheat or command. Use \"help\" for help."
|
||||
max_length = 200
|
||||
clear_button_enabled = true
|
||||
flat = true
|
||||
draw_control_chars = true
|
||||
select_all_on_focus = true
|
||||
caret_blink = true
|
||||
caret_blink_interval = 0.5
|
||||
caret_force_displayed = true
|
||||
|
||||
[connection signal="text_submitted" from="panel_container/v_box_container/line_edit" to="." method="OnLineEditTextSubmitted"]
|
@@ -1,8 +1,9 @@
|
||||
[gd_scene load_steps=14 format=3 uid="uid://bxaheg7l4h1ip"]
|
||||
[gd_scene load_steps=15 format=3 uid="uid://bxaheg7l4h1ip"]
|
||||
|
||||
[ext_resource type="Script" path="res://src/scene-scripts/player.cs" id="1_qehox"]
|
||||
[ext_resource type="Texture2D" uid="uid://olceowuycu8c" path="res://assets/textures/debug/dummy-player-atlas.png" id="2_yu1q5"]
|
||||
[ext_resource type="PackedScene" uid="uid://bkm7365u1mm3o" path="res://scenes/gui/dialog_bubble.tscn" id="3_8f573"]
|
||||
[ext_resource type="PackedScene" uid="uid://bt4pohi6srcvi" path="res://scenes/gui/console.tscn" id="4_kw3hh"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_tokqm"]
|
||||
atlas = ExtResource("2_yu1q5")
|
||||
@@ -139,3 +140,6 @@ 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
|
||||
|
56
src/scene-scripts/console.cs
Normal file
56
src/scene-scripts/console.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using Godot;
|
||||
|
||||
public partial class console : CanvasLayer
|
||||
{
|
||||
public RichTextLabel textblock;
|
||||
public LineEdit line;
|
||||
public string error = "Not found! :(";
|
||||
public override void _Ready()
|
||||
{
|
||||
textblock = GetNode<RichTextLabel>("panel_container/v_box_container/rich_text_label");
|
||||
line = GetNode<LineEdit>("panel_container/v_box_container/line_edit");
|
||||
}
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (Input.IsActionJustPressed("console"))
|
||||
{
|
||||
Visible = !Visible;
|
||||
line.GrabFocus();
|
||||
if (GetParent().Name == "player") GetParent<player>().allowMovement = !Visible;
|
||||
}
|
||||
}
|
||||
public void OnLineEditTextSubmitted(string command)
|
||||
{
|
||||
command = command.ToLower();
|
||||
line.Clear();
|
||||
if (command.Length != 0) textblock.AddText("\n>" + command);
|
||||
Variant args;
|
||||
if (command.Split(' ').Length == 2)
|
||||
{
|
||||
int i = command.IndexOf(" ") + 1;
|
||||
args = command.Substring(i);
|
||||
Call(command.Split(' ')[0], args);
|
||||
}
|
||||
if (command.Split(' ').Length > 2)
|
||||
{
|
||||
int i = command.IndexOf(" ") + 1;
|
||||
args = command.Substring(i).Split(' ');
|
||||
Callv(command.Split(' ')[0], args.AsGodotArray());
|
||||
}
|
||||
else Call(command);
|
||||
}
|
||||
|
||||
|
||||
public void help()
|
||||
{
|
||||
textblock.AddText("\n============ Help ============");
|
||||
textblock.AddText("\n1. consoleclear - Clears the console");
|
||||
textblock.AddText("\n2. speed <value> - Multiplies the player speed by the given value");
|
||||
}
|
||||
public void consoleclear() => textblock.Clear();
|
||||
public void speed(float multiplier)
|
||||
{
|
||||
if (GetParent().Name == "player") GetParent<player>().speedMultiplier = Mathf.Clamp(multiplier, 0.01f, 15f);
|
||||
textblock.AddText("\nSet speed to " + Mathf.Clamp(multiplier, 0.01f, 15f));
|
||||
}
|
||||
}
|
@@ -7,6 +7,7 @@ public partial class player : CharacterBody2D
|
||||
|
||||
[Export] public string playerName;
|
||||
[Export] public int speed = 200;
|
||||
public float speedMultiplier = 1;
|
||||
public bool allowMovement = true;
|
||||
public Vector2 movement;
|
||||
public AnimatedSprite2D animatedSprite;
|
||||
@@ -29,7 +30,7 @@ public partial class player : CharacterBody2D
|
||||
if (allowMovement) movement = Input.GetVector("move_left", "move_right", "move_up", "move_down");
|
||||
else movement = Vector2.Zero;
|
||||
if (movement.Length() != 0) rotCenter.Rotation = new Vector2((float)Math.Round(movement.X, 0), (float)Math.Round(movement.Y, 0)).Angle();
|
||||
MoveAndCollide(movement * speed * (float)delta);
|
||||
MoveAndCollide(movement * speed * speedMultiplier * (float)delta);
|
||||
}
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
|
Reference in New Issue
Block a user