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:
-11
@@ -1,11 +0,0 @@
|
||||
extends Node
|
||||
|
||||
var table = null
|
||||
|
||||
func _get_data(datas, index):
|
||||
return datas[index].get_data()
|
||||
|
||||
func _set_data(prop_id, row_id, data):
|
||||
table.edit_data(prop_id, row_id, str(data))
|
||||
Global.database.save_db()
|
||||
return data
|
||||
@@ -1 +0,0 @@
|
||||
uid://bbyxkqilmfqeh
|
||||
@@ -1,57 +0,0 @@
|
||||
extends "res://db/MBase.gd"
|
||||
|
||||
var m_name = null
|
||||
var m_thumb = null
|
||||
var m_level = null
|
||||
var mscene = load("res://db/MScene.gd")
|
||||
|
||||
func _init(row_idx):
|
||||
m_level = row_idx
|
||||
table = Global.database.get_table_by_name("levels")
|
||||
|
||||
var datas = table.get_data_at_row_idx(m_level)
|
||||
m_name = _get_name(datas)
|
||||
m_thumb = _get_thumb(datas)
|
||||
|
||||
func object_to_find():
|
||||
var count = 0
|
||||
var datas = _scenes().get_data_by_prop_name_and_data("level", str(m_level))
|
||||
|
||||
if datas.size() != 0:
|
||||
count = datas.size()
|
||||
|
||||
return str(count)
|
||||
|
||||
func reset():
|
||||
var scene_detail = null
|
||||
var t = Global.database.get_table_by_name("scenes")
|
||||
|
||||
for row_index in range(0, t.m_rows_count):
|
||||
scene_detail = mscene.new(row_index)
|
||||
if scene_detail.label() != null:
|
||||
scene_detail.set_lock(int(false))
|
||||
|
||||
func _scenes():
|
||||
return Global.database.get_table_by_name("scenes")
|
||||
|
||||
func object_finding():
|
||||
var count = 0
|
||||
|
||||
for datas in _scenes().get_dictionary_by_prop_name_and_data("level", str(m_level)):
|
||||
if int(datas['lock']) == 1:
|
||||
count = count + 1
|
||||
|
||||
return str(count)
|
||||
|
||||
func name():
|
||||
return m_name
|
||||
|
||||
func thumbnail():
|
||||
return m_thumb
|
||||
|
||||
## PRIVATE
|
||||
func _get_name(datas):
|
||||
return str(_get_data(datas, 0))
|
||||
|
||||
func _get_thumb(datas):
|
||||
return str(_get_data(datas, 1))
|
||||
@@ -1 +0,0 @@
|
||||
uid://dtjnnc3165bhc
|
||||
@@ -1,99 +0,0 @@
|
||||
extends "res://db/MBase.gd"
|
||||
|
||||
var m_value = 0
|
||||
var m_lock = null
|
||||
var m_label = null
|
||||
var m_label_counter = null
|
||||
var m_tick_reference = 0
|
||||
var m_key = null
|
||||
var m_level = null
|
||||
var m_mesh = null
|
||||
var m_counter = null
|
||||
var m_row_id = null
|
||||
|
||||
const LOCK_ID = 0
|
||||
const LABEL_ID = 1
|
||||
const KEY_ID = 2
|
||||
const LEVEL_ID = 3
|
||||
const MESH_ID = 4
|
||||
const LABEL_COUNTER = 5
|
||||
const COUNTER_ID = 6
|
||||
|
||||
func _init(row_index):
|
||||
table = Global.database.get_table_by_name("scenes")
|
||||
m_row_id = row_index
|
||||
var datas = table.get_data_at_row_idx(m_row_id)
|
||||
|
||||
if _get_level(datas) == Global.current_scene_int:
|
||||
m_key = _get_key(datas)
|
||||
m_lock = _get_lock(datas)
|
||||
m_label = _get_label(datas)
|
||||
m_label_counter = _get_label_counter(datas)
|
||||
m_mesh = _get_mesh(datas)
|
||||
m_counter = _get_counter(datas)
|
||||
|
||||
func key():
|
||||
return m_key
|
||||
|
||||
func label():
|
||||
return m_label
|
||||
|
||||
func label_counter():
|
||||
return m_label_counter
|
||||
|
||||
func lock():
|
||||
return m_lock
|
||||
|
||||
func set_lock(p_value):
|
||||
m_lock = _set_data(LOCK_ID, m_row_id, p_value)
|
||||
|
||||
func mesh():
|
||||
return m_mesh
|
||||
|
||||
func tween():
|
||||
return m_mesh + "/Tween"
|
||||
|
||||
func set_mesh(p_value):
|
||||
m_mesh = p_value
|
||||
|
||||
func tick_reference():
|
||||
return m_tick_reference
|
||||
|
||||
func set_tick_reference(p_value):
|
||||
m_tick_reference = p_value
|
||||
|
||||
func value():
|
||||
return m_value
|
||||
|
||||
func set_value(p_value):
|
||||
m_value = p_value
|
||||
|
||||
func audio_sound():
|
||||
var stream = load("res://assets/sounds/objects/" + label() + ".ogg")
|
||||
stream.set_loop(false)
|
||||
return stream
|
||||
|
||||
func counter():
|
||||
return m_counter
|
||||
|
||||
## PRIVATE
|
||||
func _get_lock(datas):
|
||||
return bool(int(_get_data(datas, LOCK_ID)))
|
||||
|
||||
func _get_label(datas):
|
||||
return str(_get_data(datas, LABEL_ID))
|
||||
|
||||
func _get_key(datas):
|
||||
return str(_get_data(datas, KEY_ID))
|
||||
|
||||
func _get_level(datas):
|
||||
return int(_get_data(datas, LEVEL_ID))
|
||||
|
||||
func _get_mesh(datas):
|
||||
return "HiddenObjectsItems/" + str(_get_data(datas, MESH_ID))
|
||||
|
||||
func _get_label_counter(datas):
|
||||
return str(_get_data(datas, LABEL_COUNTER))
|
||||
|
||||
func _get_counter(datas):
|
||||
return int(_get_data(datas, COUNTER_ID))
|
||||
@@ -1 +0,0 @@
|
||||
uid://cntdl3tocn0tv
|
||||
@@ -1,70 +0,0 @@
|
||||
extends "res://db/MBase.gd"
|
||||
|
||||
var m_langue = null
|
||||
var m_gyroscope = null
|
||||
var m_ambient_sound = null
|
||||
var m_resolution = null
|
||||
var m_fullscreen = null
|
||||
var m_version = null
|
||||
|
||||
const ROW_ID = 0
|
||||
const LANGUE_ID = 0
|
||||
const GYRSOCPE_ID = 1
|
||||
const AMBIENT_SOUND = 2
|
||||
const RESOLUTION = 3
|
||||
const FULLSCREEN = 4
|
||||
const VERSION = 5
|
||||
|
||||
func _init():
|
||||
table = Global.database.get_table_by_name("settings")
|
||||
var datas = table.get_data_at_row_idx(ROW_ID)
|
||||
|
||||
m_langue = _get_data(datas, LANGUE_ID)
|
||||
m_gyroscope = _get_data(datas, GYRSOCPE_ID)
|
||||
m_ambient_sound = _get_data(datas, AMBIENT_SOUND)
|
||||
m_resolution = _get_data(datas, RESOLUTION)
|
||||
m_fullscreen = _get_data(datas, FULLSCREEN)
|
||||
m_version = _get_data(datas, VERSION)
|
||||
|
||||
func get_langue():
|
||||
return int(m_langue)
|
||||
|
||||
func get_gyroscope():
|
||||
return bool(int(m_gyroscope))
|
||||
|
||||
func get_ambient_sound():
|
||||
return bool(int(m_ambient_sound))
|
||||
|
||||
func get_resolution():
|
||||
return m_resolution.split(" x ")
|
||||
|
||||
func get_fullscreen():
|
||||
return bool(int(m_fullscreen))
|
||||
|
||||
func get_version():
|
||||
return "v" + str(m_version)
|
||||
|
||||
func set_langue(value):
|
||||
m_langue = _set_data(LANGUE_ID, ROW_ID, value)
|
||||
|
||||
return get_langue()
|
||||
|
||||
func set_gyroscope(value):
|
||||
m_gyroscope = _set_data(GYRSOCPE_ID, ROW_ID, value)
|
||||
|
||||
return get_gyroscope()
|
||||
|
||||
func set_ambient_sound(value):
|
||||
m_ambient_sound = _set_data(AMBIENT_SOUND, ROW_ID, value)
|
||||
|
||||
return get_ambient_sound()
|
||||
|
||||
func set_resolution(value):
|
||||
m_resolution = _set_data(RESOLUTION, ROW_ID, value)
|
||||
|
||||
return get_resolution()
|
||||
|
||||
func set_fullscreen(value):
|
||||
m_fullscreen = _set_data(FULLSCREEN, ROW_ID, value)
|
||||
|
||||
return get_fullscreen()
|
||||
@@ -1 +0,0 @@
|
||||
uid://bf50wtagbmftd
|
||||
@@ -0,0 +1,22 @@
|
||||
class_name LevelEntry extends Resource
|
||||
|
||||
# A single row from the 'levels' table of ahog.json.
|
||||
|
||||
@export var index: int = -1
|
||||
@export var name: String = ""
|
||||
@export var thumb: String = ""
|
||||
|
||||
func object_to_find() -> String:
|
||||
return str(Global.database.scenes_for_level(index).size())
|
||||
|
||||
func object_finding() -> String:
|
||||
var count := 0
|
||||
for s in Global.database.scenes_for_level(index):
|
||||
if s.lock:
|
||||
count += 1
|
||||
return str(count)
|
||||
|
||||
func reset() -> void:
|
||||
for s in Global.database.scenes_for_level(index):
|
||||
s.lock = false
|
||||
Global.database.save()
|
||||
@@ -0,0 +1 @@
|
||||
uid://dp7cvr2c75gj5
|
||||
@@ -0,0 +1,25 @@
|
||||
class_name SceneEntry extends Resource
|
||||
|
||||
# A single hidden-object row from the 'scenes' table of ahog.json.
|
||||
|
||||
@export var lock: bool = false
|
||||
@export var label: String = ""
|
||||
@export var key: String = ""
|
||||
@export var level: int = -1
|
||||
@export var mesh: String = ""
|
||||
@export var label_counter: String = ""
|
||||
@export var counter: int = 1
|
||||
|
||||
# Runtime-only state for the dissolve animation tracker (not persisted).
|
||||
var dissolve_value: float = 0.0
|
||||
var dissolve_tick_reference: int = 0
|
||||
var dissolved: bool = false
|
||||
|
||||
func mesh_path() -> String:
|
||||
return "HiddenObjectsItems/" + mesh
|
||||
|
||||
func audio_sound() -> AudioStream:
|
||||
var stream: AudioStream = load("res://assets/sounds/objects/%s.ogg" % label)
|
||||
if stream is AudioStreamOggVorbis:
|
||||
stream.loop = false
|
||||
return stream
|
||||
@@ -0,0 +1 @@
|
||||
uid://ciro4yspcb6bi
|
||||
@@ -0,0 +1,13 @@
|
||||
class_name SettingsData extends Resource
|
||||
|
||||
# Single-row 'settings' table from ahog.json.
|
||||
|
||||
@export var langue: int = 0
|
||||
@export var gyroscope: bool = false
|
||||
@export var ambient_sound: bool = false
|
||||
@export var resolution: String = "1280 x 720"
|
||||
@export var fullscreen: bool = false
|
||||
@export var version: String = "1.0.0"
|
||||
|
||||
func resolution_split() -> PackedStringArray:
|
||||
return resolution.split(" x ")
|
||||
@@ -0,0 +1 @@
|
||||
uid://dbgb8gs3fddt0
|
||||
Reference in New Issue
Block a user