Skip to content

Commit

Permalink
style: 修正命名规范
Browse files Browse the repository at this point in the history
- 给未添加 class_name 的 .gd 添加 class_name
- 使用 <class_name>Scn 作为存储场景的常量名
- 修正 chapter_menu 中使用重名变量(chapter_id)的错误
  • Loading branch information
cutekibry committed Feb 11, 2024
1 parent c7ab8cf commit 0e3803f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 33 deletions.
32 changes: 16 additions & 16 deletions levels/chapter_menu/chapter_menu.gd
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
extends Node2D

class_name ChapterMenu


const BaseLevel := preload("res://levels/base_level/base_level.tscn")
const LevelButton := preload("res://levels/chapter_menu/level_menu/level_button/level_button.tscn")
const LevelMenu := preload("res://levels/chapter_menu/level_menu/level_menu.tscn")
const BaseLevelScn := preload("res://levels/base_level/base_level.tscn")
const LevelButtonScn := preload("res://levels/chapter_menu/level_menu/level_button/level_button.tscn")
const LevelMenuScn := preload("res://levels/chapter_menu/level_menu/level_menu.tscn")

# Called when the node enters the scene tree for the first time.

Expand All @@ -13,28 +13,28 @@ const button_width : int = 50
const button_heigth : int = 50

func init() -> void:
var chap_num : int = len(BaseLevel.instantiate().DATA)
for chapter_id in range(0, chap_num):
# print(chapter_id)
var level_num : int = len(BaseLevel.instantiate().DATA[chapter_id])
var button = LevelButton.instantiate();
var x : int = button_width * (chapter_id % 9) + 60
var y : int = button_heigth * (chapter_id / 9) + 100
button.init(chapter_id, level_num, Vector2(x, y), 0)
var chap_num : int = len(BaseLevelScn.instantiate().DATA)
for lvl_id in range(0, chap_num):
# print(lvl_id)
var level_num : int = len(BaseLevelScn.instantiate().DATA[lvl_id])
var button = LevelButtonScn.instantiate();
var x : int = button_width * (lvl_id % 9) + 60
var y : int = button_heigth * (lvl_id / 9) + 100
button.init(lvl_id, level_num, Vector2(x, y), 0)
button.enter_chapter.connect(_is_choose_chapter)
add_child(button)


func _ready():
# print("ready")
init()
#print(BaseLevel.instantiate().DATA[chapter_id])
#print(BaseLevelScn.instantiate().DATA[chapter_id])
# print(chapter_num)


func _is_choose_chapter(chapter_id : int, level_num : int):
var level_menu = LevelMenu.instantiate()
level_menu.init(chapter_id, level_num)
func _is_choose_chapter(chap_id : int, level_num : int):
var level_menu = LevelMenuScn.instantiate()
level_menu.init(chap_id, level_num)
# print("here ready to change scene to ", chapter_id)
get_tree().root.add_child(level_menu)
queue_free()
22 changes: 11 additions & 11 deletions levels/chapter_menu/level_menu/level_menu.gd
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
extends Node2D


class_name LevelMenu

const CHAP_NAMES = ["=P", "Add and Multiply", "()", "Equal?", "<>"]

const I_NUMBER = ["I","II","III","VI","V"]

const LevelButton := preload("res://levels/chapter_menu/level_menu/level_button/level_button.tscn")
const BaseLevel := preload("res://levels/base_level/base_level.tscn")
const Credits := preload("res://objects/credits/credits.tscn")
const LevelButtonScn := preload("res://levels/chapter_menu/level_menu/level_button/level_button.tscn")
const BaseLevelScn := preload("res://levels/base_level/base_level.tscn")
const CreditsScn := preload("res://objects/credits/credits.tscn")

# Called when the node enters the scene tree for the first time.

Expand All @@ -19,21 +19,21 @@ const button_heigth : int = 50
func init(chap_id : int, lvl_num : int) -> void:
#print("init?")

if chap_id == len(BaseLevel.instantiate().DATA):
add_child(Credits.instantiate())
if chap_id == len(BaseLevelScn.instantiate().DATA):
add_child(CreditsScn.instantiate())
$Title.set_text("")
return


if lvl_num == -1:
lvl_num = len(BaseLevel.instantiate().DATA[chap_id])
lvl_num = len(BaseLevelScn.instantiate().DATA[chap_id])

$Title.set_text("Ch." + I_NUMBER[chap_id] + " " + CHAP_NAMES[chap_id])

chapter_id = chap_id
for level_id in range(0, lvl_num):
#print(level_id)
var button = LevelButton.instantiate();
var button = LevelButtonScn.instantiate();
var x : int = button_width * (level_id % 7) + 60
var y : int = button_heigth * (level_id / 7) + 100
button.init(chapter_id, level_id, Vector2(x, y), 1)
Expand All @@ -50,7 +50,7 @@ func _ready():


func _on_button_enter_level(chap_id: int, lvl_id: int) -> void:
var base_level := BaseLevel.instantiate()
var base_level := BaseLevelScn.instantiate()

# print(chap_id, lvl_id)

Expand All @@ -64,8 +64,8 @@ func _input(event: InputEvent):
_on_back_button_pressed()

func _on_back_button_pressed():
var ChapterMenu = load("res://levels/chapter_menu/chapter_menu.tscn")
var chapter_menu = ChapterMenu.instantiate()
var ChapterMenuScn = load("res://levels/chapter_menu/chapter_menu.tscn")
var chapter_menu = ChapterMenuScn.instantiate()

chapter_menu.init()
get_tree().root.add_child(chapter_menu)
Expand Down
4 changes: 2 additions & 2 deletions objects/card_base/card_base.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ extends Area2D

class_name CardBase

const Card := preload("res://objects/card/card.tscn")
const CardScn := preload("res://objects/card/card.tscn")
const FADE_MOVE_AMOUNT := 70

signal card_put
Expand Down Expand Up @@ -42,7 +42,7 @@ func draw_card():
set_card_count(card_count - 1)
$SFXPickUp.play()
Input.set_default_cursor_shape(Input.CURSOR_DRAG)
new_card_node = Card.instantiate()
new_card_node = CardScn.instantiate()
new_card_node.set_word($Word.get_word())
new_card_node.set_position(position)
$Cards.add_child(new_card_node)
Expand Down
10 changes: 6 additions & 4 deletions objects/main_menu/main_menu.gd
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
extends Node2D

const ChapterMenu = preload("res://levels/chapter_menu/chapter_menu.tscn")
const BaseLevel := preload("res://levels/base_level/base_level.tscn")
class_name MainMenu

const ChapterMenuScn := preload("res://levels/chapter_menu/chapter_menu.tscn")
const BaseLevelScn := preload("res://levels/base_level/base_level.tscn")

signal enter_level()

Expand All @@ -10,15 +12,15 @@ func _ready():


func _on_start_button_pressed():
var base_level := BaseLevel.instantiate()
var base_level := BaseLevelScn.instantiate()

# print(chap_id, lvl_id)

base_level.init(0, 0)
get_tree().root.add_child(base_level)
enter_level.emit()
queue_free()
#get_tree().root.add_child(ChapterMenu.instantiate())
#get_tree().root.add_child(ChapterMenuScn.instantiate())
#queue_free()


Expand Down

0 comments on commit 0e3803f

Please sign in to comment.