Skip to content

Commit

Permalink
fix:fix scenes path wrong
Browse files Browse the repository at this point in the history
docs:add docs to prevent from coding the scenes path to gdscript
  • Loading branch information
limuy2022 committed Jul 6, 2024
1 parent 0c98614 commit cf391d5
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 11 deletions.
12 changes: 10 additions & 2 deletions docs/code-style-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.注意

- 请一定不要直接在代码中出现硬编码的场景路径等资源,我们要求做到,可以随时重构而不导致任何问题发生,代码的健壮性是我们考虑的重要因素
12 changes: 10 additions & 2 deletions docs/code-style.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
4 changes: 3 additions & 1 deletion scenes/multi_game.gd
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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)
4 changes: 3 additions & 1 deletion scenes/multi_game/enter.gd
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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)
6 changes: 5 additions & 1 deletion scenes/multi_game/multi_game.tscn
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion scenes/multi_game/multi_join.tscn
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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!"
Expand Down
7 changes: 5 additions & 2 deletions scenes/multi_game/select.gd
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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)
4 changes: 3 additions & 1 deletion scenes/starter.tscn
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"]

0 comments on commit cf391d5

Please sign in to comment.