Replace M* table-wrapper classes with typed Resources; add type hints
Two related cleanups from the best-practice audit: Task 3 — typed Resources instead of MBase / MScene / MLevel / MSetting The old model classes wrapped the godot_db_manager Table API: each row read went through table.get_data_at_row_idx(int), Cell.get_data(), and 'as int' / 'as String' casts that don't actually parse anything in Godot 4. m_value, m_lock, m_label, ... members shadowed the cell indirection. Setters round-tripped through table.edit_data() + Global.database.save_db(). That's a lot of plumbing for what is, in the end, three flat tables of static strings. Introduce three @export-typed Resources: db/scene_entry.gd class_name SceneEntry db/level_entry.gd class_name LevelEntry db/settings_data.gd class_name SettingsData Rewrite scripts/Database.gd so Database.DB holds: settings: SettingsData levels: Array[LevelEntry] scenes: Array[SceneEntry] Build them once at startup from ahog.json, and serialise back to the same JSON shape on save() so existing progress files keep working. LevelEntry carries its own object_to_find / object_finding / reset methods (talking to Global.database for cross-table lookups), and SceneEntry carries its own mesh_path / audio_sound. Per-scene dissolve state (value, tick_reference, dissolved) lives on SceneEntry as non-exported runtime fields. Delete db/MBase.gd / db/MScene.gd / db/MLevel.gd / db/MSetting.gd. Update consumers: - scripts/Setting.gd: read/write Global.database.settings directly, call Global.database.save() after each setter. - scenes/levels/Levels.gd: iterate Global.database.scenes_for_level( current_scene_int) instead of mscene.new(i) for every row; scene state reads (scene.lock, scene.mesh, scene.counter, ...) replace scene.lock() / scene.mesh() / scene.counter() method calls; runtime dissolve state lives on the SceneEntry instance instead of mutable m_value / m_tick_reference members on MScene; 'dissolved' flag replaces set_mesh(null) signalling. - scenes/UI/choose_scenes/ChooseScene.gd: iterate Global.database .levels; level.name / level.thumb property access in place of level.name() / level.thumbnail(). configure_reset() loses its redundant index argument (LevelEntry knows its own index). - scripts/event.gd: _on_reset_level signature now takes LevelEntry, reset path drops index forwarding. Task 2 — type hints across the remaining scripts scripts/Global.gd, scenes/Main.gd, scenes/UI/ending/Ending.gd, scenes/UI/loading/Loading.gd, scenes/UI/settings/Settings.gd: add typed parameters and -> return annotations. current_scene_int is now 'int = -1' (sentinel) so callers don't fall into Variant comparisons; event.gd:_on_reset_level resets it to -1 instead of null. Settings.gd no longer wraps button_pressed in int() before passing to the now-typed bool setters. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
+15
-21
@@ -4,55 +4,49 @@ extends Node
|
||||
@export var setting: PackedScene = load("res://scenes/UI/settings/Settings.tscn")
|
||||
@export var choose_scene: PackedScene = load("res://scenes/UI/choose_scenes/ChooseScene.tscn")
|
||||
|
||||
@onready var current_scene = "title"
|
||||
@onready var stream_button = preload("res://assets/sounds/click-button.ogg")
|
||||
@onready var home = $MarginContainer/HBoxContainer/UI_summary/PanelWood/VBoxContainer/CenterContainer/TextureRect
|
||||
@onready var stream_button: AudioStream = preload("res://assets/sounds/click-button.ogg")
|
||||
@onready var home: TextureButton = $MarginContainer/HBoxContainer/UI_summary/PanelWood/VBoxContainer/CenterContainer/TextureRect
|
||||
|
||||
func _ready():
|
||||
func _ready() -> void:
|
||||
_translation()
|
||||
home.set_focus_mode(2)
|
||||
home.focus_mode = Control.FOCUS_ALL
|
||||
home.grab_focus()
|
||||
_apply_scene(title)
|
||||
_configure_sound()
|
||||
|
||||
func _configure_sound():
|
||||
stream_button.set_loop(false)
|
||||
func _configure_sound() -> void:
|
||||
if stream_button is AudioStreamOggVorbis:
|
||||
stream_button.loop = false
|
||||
$MarginContainer/HBoxContainer/UI_summary/ClickButton.stream = stream_button
|
||||
|
||||
## PRIVATE
|
||||
func _translation():
|
||||
func _translation() -> void:
|
||||
$MarginContainer/HBoxContainer/UI_summary/PanelWood/VBoxContainer/ButtonPuzzle/Label.text = tr("MAIN_BUTTON_PUZZLES")
|
||||
$MarginContainer/HBoxContainer/UI_summary/PanelWood/VBoxContainer/ButtonSetting/Label.text = tr("MAIN_BUTTON_SETTINGS")
|
||||
$MarginContainer/HBoxContainer/UI_summary/PanelWood/VBoxContainer/ButtonQuit/Label.text = tr("MAIN_BUTTON_QUIT")
|
||||
$MarginContainer/HBoxContainer/UI_summary/PanelWood/VBoxContainer/ContainerVersion/LabelVersion.text = Setting.get_setting_version()
|
||||
|
||||
func _apply_scene(actual_scene):
|
||||
var node = get_node("MarginContainer/HBoxContainer/MarginContainer/")
|
||||
|
||||
func _apply_scene(actual_scene: PackedScene) -> void:
|
||||
var node := get_node("MarginContainer/HBoxContainer/MarginContainer/")
|
||||
if node.get_child_count() != 0:
|
||||
node.get_child(0).queue_free()
|
||||
|
||||
node.add_child(actual_scene.instantiate())
|
||||
|
||||
# Load scene for select game
|
||||
func _on_ButtonPuzzle_pressed():
|
||||
func _on_ButtonPuzzle_pressed() -> void:
|
||||
_sound_button()
|
||||
_apply_scene(choose_scene)
|
||||
|
||||
# Load scene settings
|
||||
func _on_ButtonSetting_pressed():
|
||||
func _on_ButtonSetting_pressed() -> void:
|
||||
_sound_button()
|
||||
_apply_scene(setting)
|
||||
|
||||
# Click to icon game
|
||||
func _on_TextureRect_pressed():
|
||||
func _on_TextureRect_pressed() -> void:
|
||||
_sound_button()
|
||||
_apply_scene(title)
|
||||
|
||||
# Quit the game
|
||||
func _on_ButtonQuit_pressed():
|
||||
func _on_ButtonQuit_pressed() -> void:
|
||||
_sound_button()
|
||||
get_tree().quit(0)
|
||||
|
||||
func _sound_button():
|
||||
func _sound_button() -> void:
|
||||
$MarginContainer/HBoxContainer/UI_summary/ClickButton.play()
|
||||
|
||||
Reference in New Issue
Block a user