From 56d03ac23dcf6dbd2b68667ec54ecb487ae16350 Mon Sep 17 00:00:00 2001 From: pennyrigate Date: Sat, 7 Jan 2023 14:23:37 -0500 Subject: [PATCH] moved debug to scene --- game.gd | 11 ---- objects/debug.tscn | 115 +++++++++++++++++++++++++++++++++++++++ objects/player/player.gd | 15 +---- project.godot | 6 ++ 4 files changed, 122 insertions(+), 25 deletions(-) create mode 100644 objects/debug.tscn diff --git a/game.gd b/game.gd index a06b551..d46f3d5 100644 --- a/game.gd +++ b/game.gd @@ -109,17 +109,6 @@ func _process(delta): #CRT FILTER if Input.is_action_just_pressed("crt"): viewport_container.material.set_shader_param("enabled",!viewport_container.material.get_shader_param("enabled")) - #Restart scene - if Input.is_action_just_pressed("debug_restart"): - if Game.score > Game.high_score: Game.high_score = Game.score - Game.score = 0 - Game.golds = 0 - Game.stars = [false,false,false,false,false] - Game.shards = 0 - Game.arrows = 0 - Game.lives = 2 - Game.ac_climb.stop() - get_tree().reload_current_scene() #Fullscreen if Input.is_action_just_pressed("fullscreen"): print(fullscreen) diff --git a/objects/debug.tscn b/objects/debug.tscn new file mode 100644 index 0000000..52cf19e --- /dev/null +++ b/objects/debug.tscn @@ -0,0 +1,115 @@ +[gd_scene load_steps=4 format=2] + +[sub_resource type="GDScript" id=5] +script/source = "extends CanvasLayer + +#Console by hazel + +export var max_lines: int = 10 +export var opacity: float = 0.5 + +onready var console: Label = $Console +onready var line_edit = $LineEdit + +var lines: int = 0 + +var time: float = 0.0 +var n: int = 0 + +var debug = false + +func _ready(): + #Auto do debug when playtesting + if not OS.is_debug_build(): + console.visible = false + debug = false + else: + console.visible = false + debug = true + $Console/Panel.modulate.a = opacity + console.modulate.a = opacity + +func _physics_process(delta): + #DEBUG + if debug == true: + #Show console + if Input.is_action_just_pressed(\"debug_show\"): + console.visible = !console.visible + #Restart scene + if Input.is_action_just_pressed(\"debug_restart\"): + if Game.score > Game.high_score: Game.high_score = Game.score + Game.score = 0 + Game.golds = 0 + Game.stars = [false,false,false,false,false] + Game.shards = 0 + Game.arrows = 0 + Game.lives = 2 + Game.ac_climb.stop() + get_tree().reload_current_scene() + #Move player to mouse + if Input.is_action_pressed(\"debug_move_player\"): + Game.get_map().get_node(\"Player\").position = get_viewport().get_mouse_position() + Debug.print(get_viewport().get_mouse_position()) + #Debug 1 + if Input.is_action_just_pressed(\"debug_1\"): + Game.save() + #Debug 2 + if Input.is_action_just_pressed(\"debug_2\"): + var save = ConfigFile.new() + save.load(str(\"user://file\") + str(1) + str(\".pr\")) + Game.score = save.get_value(str(Game.current_level),\"Score\",0) + +func print(text): + lines += 1 + if lines > 1: + console.text += \"\\n\" + if lines > 10: + var n = console.text.find(\"\\n\") + var t = console.text + t.erase(0, n+1) + lines -= 1 + console.text = t + str(text) + else: + console.text += str(text) + + +func _on_visible_toggled(button_pressed): + if button_pressed: + console.visible = true + else: + console.visible = false +" + +[sub_resource type="InputEventAction" id=4] +action = "toggle_console" + +[sub_resource type="ShortCut" id=3] +shortcut = SubResource( 4 ) + +[node name="Debug" type="CanvasLayer"] +layer = 128 +script = SubResource( 5 ) + +[node name="Console" type="Label" parent="."] +anchor_right = 1.0 +margin_bottom = 14.0 +size_flags_vertical = 0 + +[node name="Panel" type="Panel" parent="Console"] +show_behind_parent = true +anchor_right = 1.0 +anchor_bottom = 1.0 + +[node name="VisibleToggle" type="CheckBox" parent="."] +visible = false +anchor_left = 1.0 +anchor_right = 1.0 +margin_left = -22.0 +margin_top = 173.0 +margin_right = 57.0 +margin_bottom = 197.0 +pressed = true +shortcut = SubResource( 3 ) +text = "Console" + +[connection signal="toggled" from="VisibleToggle" to="." method="_on_visible_toggled"] diff --git a/objects/player/player.gd b/objects/player/player.gd index 71179ae..32150d0 100644 --- a/objects/player/player.gd +++ b/objects/player/player.gd @@ -74,8 +74,6 @@ func _physics_process(delta): velocity.y = 0 #Apply velocity move_and_slide(velocity,Vector2.UP) - #Debug - debug() func _process_idle(): if anims.get_current_animation() != "idle": anims.play("idle") @@ -253,7 +251,7 @@ func die(): Game.arrows = 0 Game.lives = 2 Game.ac_climb.stop() - get_tree().reload_current_scene() + Game.change_map(load("res://maps/map01.tscn")) func _on_AnimationPlayer_animation_finished(anim_name): @@ -273,14 +271,3 @@ func _on_AnimationPlayer_animation_finished(anim_name): else: current_state = State.FALL return -func debug(): - #Move player to mouse - if Input.is_action_pressed("debug_move_player"): - position = get_viewport().get_mouse_position() - print(get_viewport().get_mouse_position()) - if Input.is_action_just_pressed("debug_1"): - Game.save() - if Input.is_action_just_pressed("debug_2"): - var save = ConfigFile.new() - save.load(str("user://file") + str(1) + str(".pr")) - Game.score = save.get_value(str(Game.current_level),"Score",0) diff --git a/project.godot b/project.godot index 9b127d7..80174c4 100644 --- a/project.godot +++ b/project.godot @@ -17,6 +17,7 @@ config/icon="res://icon.png" [autoload] Game="*res://game.tscn" +Debug="*res://objects/debug.tscn" [display] @@ -108,6 +109,11 @@ debug_2={ "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":50,"physical_scancode":0,"unicode":0,"echo":false,"script":null) ] } +debug_show={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":72,"physical_scancode":0,"unicode":0,"echo":false,"script":null) + ] +} [physics]