diff --git a/docs/code-style-zh.md b/docs/code-style-zh.md index 0223492..6396d16 100644 --- a/docs/code-style-zh.md +++ b/docs/code-style-zh.md @@ -4,6 +4,14 @@ - 你需要使用[gdtoolkit](https://github.com/Scony/godot-gdscript-toolkit)和rustfmt进行格式化,你可以通过将`script/pre-commit`复制到`.git/hooks`来自动执行这个过程 -## 2.命名规范 +## 2.规范 -- 对于所有节点的名称,我们规定采用**大驼峰**格式 +- 请遵循Godot官方提出的[风格指南](https://docs.godotengine.org/zh-cn/4.x/tutorials/best_practices/project_organization.html#style-guide) + +- 对于gdscript,请遵循[GDScript风格指南](https://docs.godotengine.org/zh-cn/4.x/tutorials/scripting/gdscript/gdscript_styleguide.html) + +- 对于Rust,请确保通过了clippy等工具的基本检查 + +## 3.注意 + +- 请一定不要直接在代码中出现硬编码的场景路径等资源,我们要求做到,可以随时重构而不导致任何问题发生,代码的健壮性是我们考虑的重要因素 diff --git a/docs/code-style.md b/docs/code-style.md index e9067c9..48c9ead 100644 --- a/docs/code-style.md +++ b/docs/code-style.md @@ -4,6 +4,14 @@ - You need to use [gdtoolkit](https://github.com/Scony/godot-gdscript-toolkit) and rustfmt to format the code.You can copy `script/pre-commit` to `.git/hooks` to do that automatically -## 2.Naming Conventions +## 2.Standards -- For the names of all nodes, we stipulate the use of PascalCase format. +- Please adhere to the [style guide](https://docs.godotengine.org/en/stable/tutorials/best_practices/project_organization.html#style-guide) proposed by the official Godot. + +- For GDScript, follow the [GDScript Style Guide](https://docs.godotengine.org/en/stable/tutorials/scripting/gdscript/gdscript_styleguide.html). + +- For Rust, ensure that basic checks with tools like clippy have been passed. + +## 3.Notes + +- Please avoid hardcoding scene paths or other resources directly in the code at all costs. We require that it should be possible to refactor at any time without causing any issues. The robustness of the code is an important factor we consider. diff --git a/scenes/multi_game.gd b/scenes/multi_game.gd index f69653e..6eed1b2 100644 --- a/scenes/multi_game.gd +++ b/scenes/multi_game.gd @@ -1,5 +1,7 @@ extends Button +@export var multi_join: PackedScene + # Called when the node enters the scene tree for the first time. func _ready() -> void: @@ -12,4 +14,4 @@ func _process(_delta: float) -> void: func _on_pressed() -> void: - get_tree().change_scene_to_file("res://scenes/multi_join.tscn") + get_tree().change_scene_to_packed(multi_join) diff --git a/scenes/multi_game/enter.gd b/scenes/multi_game/enter.gd index c63c990..a78a771 100644 --- a/scenes/multi_game/enter.gd +++ b/scenes/multi_game/enter.gd @@ -1,5 +1,7 @@ extends MultiEnter +@export var fight_scene: PackedScene + # Called when the node enters the scene tree for the first time. func _ready() -> void: @@ -22,4 +24,4 @@ func _on_pressed() -> void: return var state = self.connect_to_server(Global.connected_ip) if state: - get_tree().change_scene_to_file("res://scenes/fight.tscn") + get_tree().change_scene_to_packed(fight_scene) diff --git a/scenes/multi_game/multi_game.tscn b/scenes/multi_game/multi_game.tscn index 14ccfb9..f555a9a 100644 --- a/scenes/multi_game/multi_game.tscn +++ b/scenes/multi_game/multi_game.tscn @@ -1,6 +1,8 @@ -[gd_scene load_steps=2 format=3 uid="uid://dertwnnfyebti"] +[gd_scene load_steps=4 format=3 uid="uid://dertwnnfyebti"] [ext_resource type="Script" path="res://scenes/multi_game/select.gd" id="1_d5ypr"] +[ext_resource type="PackedScene" uid="uid://vmiwhsyggblr" path="res://scenes/multi_game/multi_join.tscn" id="2_0kwui"] +[ext_resource type="PackedScene" uid="uid://shdywgibimvd" path="res://scenes/multi_game/multi_set_up.tscn" id="3_wjc7w"] [node name="MultiGame" type="Control"] layout_mode = 3 @@ -24,6 +26,8 @@ offset_bottom = 20.0 grow_horizontal = 2 grow_vertical = 2 script = ExtResource("1_d5ypr") +multi_join = ExtResource("2_0kwui") +multi_set_up = ExtResource("3_wjc7w") [node name="Join" type="Button" parent="Select"] layout_mode = 2 diff --git a/scenes/multi_game/multi_join.tscn b/scenes/multi_game/multi_join.tscn index dcc2340..a833a69 100644 --- a/scenes/multi_game/multi_join.tscn +++ b/scenes/multi_game/multi_join.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=2 format=3 uid="uid://vmiwhsyggblr"] +[gd_scene load_steps=3 format=3 uid="uid://vmiwhsyggblr"] [ext_resource type="Script" path="res://scenes/multi_game/enter.gd" id="1_8dfk5"] +[ext_resource type="PackedScene" uid="uid://cibwxaqnuodid" path="res://scenes/fight.tscn" id="2_r8315"] [node name="MultiGame" type="Control"] layout_mode = 3 @@ -24,6 +25,7 @@ grow_horizontal = 2 grow_vertical = 0 text = "OK" script = ExtResource("1_8dfk5") +fight_scene = ExtResource("2_r8315") [node name="WrongDialog" type="AcceptDialog" parent="Ok"] title = "Warning!" diff --git a/scenes/multi_game/select.gd b/scenes/multi_game/select.gd index 38e40c1..a405df7 100644 --- a/scenes/multi_game/select.gd +++ b/scenes/multi_game/select.gd @@ -1,5 +1,8 @@ extends VBoxContainer +@export var multi_join: PackedScene +@export var multi_set_up: PackedScene + # Called when the node enters the scene tree for the first time. func _ready() -> void: @@ -12,8 +15,8 @@ func _process(_delta: float) -> void: func _on_join_pressed() -> void: - get_tree().change_scene_to_file("res://scenes/multi_join.tscn") + get_tree().change_scene_to_packed(multi_join) func _on_setup_pressed() -> void: - get_tree().change_scene_to_file("res://scenes/multi_set_up.tscn") + get_tree().change_scene_to_packed(multi_set_up) diff --git a/scenes/starter.tscn b/scenes/starter.tscn index 1f55b74..a8b1028 100644 --- a/scenes/starter.tscn +++ b/scenes/starter.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=2 format=3 uid="uid://dg0blw2bcacx5"] +[gd_scene load_steps=3 format=3 uid="uid://dg0blw2bcacx5"] [ext_resource type="Script" path="res://scenes/multi_game.gd" id="1_joi1g"] +[ext_resource type="PackedScene" uid="uid://vmiwhsyggblr" path="res://scenes/multi_game/multi_join.tscn" id="2_s6vvx"] [node name="Starter" type="Control"] layout_mode = 3 @@ -25,5 +26,6 @@ grow_horizontal = 2 grow_vertical = 2 text = "Multi Player" script = ExtResource("1_joi1g") +multi_join = ExtResource("2_s6vvx") [connection signal="pressed" from="MultiPlay" to="MultiPlay" method="_on_pressed"]