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()
|
||||
|
||||
@@ -2,68 +2,57 @@ extends Control
|
||||
|
||||
@export var template: PackedScene = load("res://scenes/UI/choose_scenes/parts/Template.tscn")
|
||||
|
||||
func _ready():
|
||||
_load_button_access_scenes()
|
||||
func _ready() -> void:
|
||||
for level in Global.database.levels:
|
||||
_apply_scene(level)
|
||||
|
||||
## PRIVATE
|
||||
func _load_button_access_scenes():
|
||||
for row_index in range(0, Global.database.get_table_by_name("levels").m_rows_count):
|
||||
_apply_scene(load("res://db/MLevel.gd").new(row_index), row_index)
|
||||
|
||||
func _apply_scene(level, index):
|
||||
$MarginContainer.add_child(_load_scene(level.name()))
|
||||
var node = _build_path(level.name())
|
||||
|
||||
func _apply_scene(level: LevelEntry) -> void:
|
||||
$MarginContainer.add_child(_load_scene(level.name))
|
||||
var node := _build_path(level.name)
|
||||
_configure_select(level, node)
|
||||
configure_reset(level, node, index, false)
|
||||
configure_reset(level, node, false)
|
||||
configure_counter(level, node)
|
||||
|
||||
func _load_scene(p_name):
|
||||
var template_instance = template.instantiate()
|
||||
func _load_scene(p_name: String) -> Node:
|
||||
var template_instance := template.instantiate()
|
||||
template_instance.set_name(p_name)
|
||||
|
||||
return template_instance
|
||||
|
||||
func _build_path(p_name):
|
||||
func _build_path(p_name: String) -> String:
|
||||
return "MarginContainer/" + p_name
|
||||
|
||||
func _load_texture(thumbnail):
|
||||
return load(thumbnail)
|
||||
|
||||
func _configure_select(level, node):
|
||||
var selector = get_node(node+"/MarginContainer/CenterAlign/MainButton")
|
||||
var thumbnail = get_node(node+"/MarginContainer/CenterAlign/MainButton/MarginStich/ThumbnailLevel")
|
||||
|
||||
thumbnail.set_texture(_load_texture(level.thumbnail()))
|
||||
var handler = Event.level_pressed(level.name())
|
||||
func _configure_select(level: LevelEntry, node: String) -> void:
|
||||
var selector := get_node(node + "/MarginContainer/CenterAlign/MainButton")
|
||||
var thumbnail: TextureRect = get_node(node + "/MarginContainer/CenterAlign/MainButton/MarginStich/ThumbnailLevel")
|
||||
thumbnail.texture = load(level.thumb)
|
||||
var handler := Event.level_pressed(level.name)
|
||||
if handler.is_valid():
|
||||
selector.pressed.connect(handler)
|
||||
|
||||
func configure_reset(level, node, index, animate):
|
||||
var reset = get_node(node+"/MarginContainer/CenterAlign/MainButton/TabAlign/ButtonReset")
|
||||
var animation = get_node(node+"/AnimationPlayer")
|
||||
func configure_reset(level: LevelEntry, node: String, animate: bool) -> void:
|
||||
var reset: BaseButton = get_node(node + "/MarginContainer/CenterAlign/MainButton/TabAlign/ButtonReset")
|
||||
var animation: AnimationPlayer = get_node(node + "/AnimationPlayer")
|
||||
if int(level.object_finding()) == 0:
|
||||
_configure_reset_disable(animation, reset, animate)
|
||||
else:
|
||||
_configure_reset_enable(animation, reset, level, node, index)
|
||||
_configure_reset_enable(animation, reset, level, node)
|
||||
|
||||
func _configure_reset_disable(animation, reset, animate = false):
|
||||
func _configure_reset_disable(animation: AnimationPlayer, reset: BaseButton, animate: bool = false) -> void:
|
||||
animation.play("SlideReset")
|
||||
if !animate:
|
||||
if not animate:
|
||||
animation.seek(1, false)
|
||||
|
||||
reset.set_disabled(true)
|
||||
reset.set_default_cursor_shape(CURSOR_ARROW)
|
||||
reset.mouse_default_cursor_shape = CURSOR_ARROW
|
||||
for c in reset.pressed.get_connections():
|
||||
reset.pressed.disconnect(c["callable"])
|
||||
|
||||
func _configure_reset_enable(animation, reset, level, node, index):
|
||||
func _configure_reset_enable(animation: AnimationPlayer, reset: BaseButton, level: LevelEntry, node: String) -> void:
|
||||
animation.play_backwards("SlideReset")
|
||||
reset.set_disabled(false)
|
||||
reset.set_default_cursor_shape(CURSOR_POINTING_HAND)
|
||||
reset.pressed.connect(Event._on_reset_level.bind(level, node, index, self))
|
||||
reset.mouse_default_cursor_shape = CURSOR_POINTING_HAND
|
||||
reset.pressed.connect(Event._on_reset_level.bind(level, node, level.index, self))
|
||||
|
||||
func configure_counter(level, node):
|
||||
var count = get_node(node+"/MarginContainer/CenterAlign/MainButton/TabAlign/ButtonCount/MarginBottom/Label")
|
||||
|
||||
count.set_text(level.object_finding()+" / "+level.object_to_find())
|
||||
func configure_counter(level: LevelEntry, node: String) -> void:
|
||||
var count: Label = get_node(node + "/MarginContainer/CenterAlign/MainButton/TabAlign/ButtonCount/MarginBottom/Label")
|
||||
count.text = level.object_finding() + " / " + level.object_to_find()
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
extends CenterContainer
|
||||
|
||||
func _ready():
|
||||
print("[ending_#ready]")
|
||||
func _ready() -> void:
|
||||
$AudioStreamPlayer.play()
|
||||
|
||||
func _on_Timer_timeout():
|
||||
print("[ending#_on_Timer_timeout]")
|
||||
func _on_Timer_timeout() -> void:
|
||||
Global.goto_scene("res://scenes/Main.tscn")
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
extends Control
|
||||
|
||||
func _ready():
|
||||
func _ready() -> void:
|
||||
get_node("LabelLoading").text = tr("LOADING")
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
extends Node
|
||||
|
||||
func _ready():
|
||||
func _ready() -> void:
|
||||
_apply_translation()
|
||||
_apply_settings_language()
|
||||
_apply_settings_gyroscope()
|
||||
@@ -9,50 +9,46 @@ func _ready():
|
||||
_apply_settings_fullscreen()
|
||||
|
||||
## PRIVATE
|
||||
func _apply_translation():
|
||||
func _apply_translation() -> void:
|
||||
$VBoxContainer/langue/VBoxContainer/Label.text = tr("SETTINGS_LABEL_LANGUE")
|
||||
$VBoxContainer/gyroscope/HBoxContainer/Label.text = tr("SETTINGS_LABEL_GYROSCOPE")
|
||||
|
||||
func _apply_settings_language():
|
||||
var data = $VBoxContainer/langue/VBoxContainer/data
|
||||
|
||||
func _apply_settings_language() -> void:
|
||||
var data: ItemList = $VBoxContainer/langue/VBoxContainer/data
|
||||
data.add_item("English", load("res://assets/ui/flags/english.png"), true) # id : 0
|
||||
data.add_item("Français", load("res://assets/ui/flags/french.png"), true) # id : 1
|
||||
|
||||
data.select(Setting.get_setting_language())
|
||||
|
||||
func _apply_settings_gyroscope():
|
||||
func _apply_settings_gyroscope() -> void:
|
||||
$VBoxContainer/gyroscope/HBoxContainer/data.button_pressed = Setting.get_setting_gyrosocpe()
|
||||
|
||||
func _apply_settings_sound_ambient():
|
||||
func _apply_settings_sound_ambient() -> void:
|
||||
$VBoxContainer/ambient_sound/HBoxContainer/data.button_pressed = Setting.get_setting_ambient_sound()
|
||||
|
||||
func _apply_settings_resolution():
|
||||
var data = $VBoxContainer/resolution/VBoxContainer/data
|
||||
|
||||
data.add_item("2560 x 1440", null, true) # id : 0
|
||||
data.add_item("1920 x 1080", null, true) # id : 1
|
||||
data.add_item("1280 x 720", null, true) # id : 2
|
||||
data.add_item("854 x 576", null, true) # id : 3
|
||||
|
||||
func _apply_settings_resolution() -> void:
|
||||
var data: ItemList = $VBoxContainer/resolution/VBoxContainer/data
|
||||
data.add_item("2560 x 1440", null, true)
|
||||
data.add_item("1920 x 1080", null, true)
|
||||
data.add_item("1280 x 720", null, true)
|
||||
data.add_item("854 x 576", null, true)
|
||||
for index in range(4):
|
||||
if data.get_item_text(index).split(' x ') == Setting.get_setting_resolution():
|
||||
if data.get_item_text(index).split(" x ") == Setting.get_setting_resolution():
|
||||
data.select(index)
|
||||
|
||||
func _apply_settings_fullscreen():
|
||||
func _apply_settings_fullscreen() -> void:
|
||||
$VBoxContainer/fullscreen/HBoxContainer/data.button_pressed = Setting.get_setting_fullscreen()
|
||||
|
||||
func _on_gyroscope_pressed():
|
||||
Setting.set_setting_gyroscope(int($VBoxContainer/gyroscope/HBoxContainer/data.button_pressed))
|
||||
func _on_gyroscope_pressed() -> void:
|
||||
Setting.set_setting_gyroscope($VBoxContainer/gyroscope/HBoxContainer/data.button_pressed)
|
||||
|
||||
func _on_ambient_sound_pressed():
|
||||
Setting.set_setting_ambient_sound(int($VBoxContainer/ambient_sound/HBoxContainer/data.button_pressed))
|
||||
func _on_ambient_sound_pressed() -> void:
|
||||
Setting.set_setting_ambient_sound($VBoxContainer/ambient_sound/HBoxContainer/data.button_pressed)
|
||||
|
||||
func _on_langue_item_selected(index):
|
||||
func _on_langue_item_selected(index: int) -> void:
|
||||
Setting.set_setting_language(index)
|
||||
|
||||
func _on_resolution_item_selected(index):
|
||||
func _on_resolution_item_selected(index: int) -> void:
|
||||
Setting.set_setting_resolution($VBoxContainer/resolution/VBoxContainer/data.get_item_text(index))
|
||||
|
||||
func _on_fullscreen_item_selected():
|
||||
Setting.set_setting_fullscreen(int($VBoxContainer/fullscreen/HBoxContainer/data.button_pressed))
|
||||
func _on_fullscreen_item_selected() -> void:
|
||||
Setting.set_setting_fullscreen($VBoxContainer/fullscreen/HBoxContainer/data.button_pressed)
|
||||
|
||||
+129
-148
@@ -1,79 +1,65 @@
|
||||
extends Node3D
|
||||
|
||||
const TIME_MAX = 3000 # msec
|
||||
const GYROSCOPE_MAX_DIFF = 0.5
|
||||
const OFFSET_CAMERA_MAX = 0.12
|
||||
const OFFSET_STEP_CHANGE = 0.01
|
||||
const RAY_LENGTH = 1000
|
||||
const TIME_MAX := 3000 # msec
|
||||
const GYROSCOPE_MAX_DIFF := 0.5
|
||||
const OFFSET_CAMERA_MAX := 0.12
|
||||
const OFFSET_STEP_CHANGE := 0.01
|
||||
const RAY_LENGTH := 1000
|
||||
|
||||
@export var object_first: PackedScene = load("res://scenes/levels/parts/ObjectListFirst.tscn")
|
||||
@export var object_std: PackedScene = load("res://scenes/levels/parts/ObjectListStandard.tscn")
|
||||
@export var object_last: PackedScene = load("res://scenes/levels/parts/ObjectListLast.tscn")
|
||||
|
||||
@onready var gyroscope_value_old = Vector3(0, 0, 0)
|
||||
@onready var table = Global.database.get_table_by_name("scenes")
|
||||
@onready var meshes = {}
|
||||
@onready var from = null
|
||||
@onready var to = null
|
||||
@onready var mlevel = load("res://db/MLevel.gd")
|
||||
@onready var mscene = load("res://db/MScene.gd")
|
||||
@onready var victory_condition = 0
|
||||
@onready var victory_progress = 0
|
||||
@onready var last_button = null
|
||||
@onready var animation_player = null
|
||||
var gyroscope_value_old := Vector3(0, 0, 0)
|
||||
var meshes: Dictionary[String, SceneEntry] = {}
|
||||
var from = null
|
||||
var to = null
|
||||
var victory_condition: String = "0"
|
||||
var victory_progress: String = "0"
|
||||
var last_button: Node = null
|
||||
|
||||
func _ready():
|
||||
_load_translations()
|
||||
func _ready() -> void:
|
||||
_load_meshes()
|
||||
_load_back_button()
|
||||
_load_prepare_victory_condition()
|
||||
_load_hud_menu()
|
||||
_load_ambient_sound()
|
||||
|
||||
func _load_translations():
|
||||
pass
|
||||
func _load_meshes() -> void:
|
||||
for scene in Global.database.scenes_for_level(Global.current_scene_int):
|
||||
meshes[scene.key] = scene
|
||||
create_dissolve_mesh(scene.key)
|
||||
|
||||
func _load_meshes():
|
||||
var scene_detail = null
|
||||
|
||||
for row_index in range(0, table.m_rows_count):
|
||||
scene_detail = mscene.new(row_index)
|
||||
|
||||
if scene_detail.key() != null:
|
||||
meshes[scene_detail.key()] = scene_detail
|
||||
create_dissolve_mesh(scene_detail.key())
|
||||
|
||||
func _load_back_button():
|
||||
func _load_back_button() -> void:
|
||||
$Quit/TextureButton.pressed.connect(Event._on_main_scene_pressed)
|
||||
|
||||
func _load_prepare_victory_condition():
|
||||
var level = mlevel.new(Global.current_scene_int)
|
||||
|
||||
func _load_prepare_victory_condition() -> void:
|
||||
var level := Global.database.level_by_index(Global.current_scene_int)
|
||||
if level == null:
|
||||
return
|
||||
victory_condition = level.object_to_find()
|
||||
victory_progress = level.object_finding()
|
||||
|
||||
func _load_hud_menu():
|
||||
var counter = 0
|
||||
var scene = null
|
||||
var label_counter = null
|
||||
|
||||
func _load_hud_menu() -> void:
|
||||
var counter := 0
|
||||
var label_counter: String = ""
|
||||
for key in meshes:
|
||||
scene = meshes[key]
|
||||
var scene: SceneEntry = meshes[key]
|
||||
_create_button_info(scene, counter, label_counter)
|
||||
label_counter = scene.label_counter()
|
||||
counter = counter + 1
|
||||
label_counter = scene.label_counter
|
||||
counter += 1
|
||||
|
||||
func _load_ambient_sound():
|
||||
func _load_ambient_sound() -> void:
|
||||
if Setting.get_setting_ambient_sound():
|
||||
$AmbientSound.play()
|
||||
$AmbientSound.stream_paused = false
|
||||
|
||||
func _create_button_info(scene, counter, label_counter):
|
||||
var button = _search_button_to_use(counter)
|
||||
var label_name = scene.label()
|
||||
func _create_button_info(scene: SceneEntry, counter: int, label_counter: String) -> void:
|
||||
var button := _search_button_to_use(counter)
|
||||
var label_name := scene.label
|
||||
|
||||
if label_counter != null and label_counter == scene.label_counter():
|
||||
label_name = last_button.get_node("Label").text + " " + str(scene.counter())
|
||||
if label_counter != "" and label_counter == scene.label_counter:
|
||||
label_name = last_button.get_node("Label").text + " " + str(scene.counter)
|
||||
_configure_button_object(last_button, scene, label_name)
|
||||
_create_animation_warning(_get_node_animated().get_node("Label"), label_name)
|
||||
else:
|
||||
@@ -83,194 +69,189 @@ func _create_button_info(scene, counter, label_counter):
|
||||
|
||||
last_button = button
|
||||
|
||||
func _get_node_animated():
|
||||
return $ListObjects/ListContainer.get_child($ListObjects/ListContainer.get_child_count() - 1 )
|
||||
func _get_node_animated() -> Node:
|
||||
return $ListObjects/ListContainer.get_child($ListObjects/ListContainer.get_child_count() - 1)
|
||||
|
||||
func _search_button_to_use(counter):
|
||||
func _search_button_to_use(counter: int) -> Node:
|
||||
if counter == 0:
|
||||
return object_first.instantiate()
|
||||
elif counter == meshes.size() - 1:
|
||||
return object_last.instantiate()
|
||||
else:
|
||||
return object_std.instantiate()
|
||||
return object_std.instantiate()
|
||||
|
||||
func _configure_button_object(button, scene, label):
|
||||
func _configure_button_object(button: Node, scene: SceneEntry, label: String) -> void:
|
||||
button.get_node("Label").set_text(label)
|
||||
button.set_meta("animation", label)
|
||||
button.set_meta("name", scene.label())
|
||||
button.set_meta("counter", scene.counter())
|
||||
button.set_meta("name", scene.label)
|
||||
button.set_meta("counter", scene.counter)
|
||||
button.set_meta("counted", 0)
|
||||
|
||||
func _create_animation_slide(node, p_name):
|
||||
func _create_animation_slide(node: Node, p_name: String) -> void:
|
||||
_add_animation_to_player(p_name, GameAnimation.level_hud_slide(node))
|
||||
|
||||
func _create_animation_warning(node, p_name):
|
||||
func _create_animation_warning(node: Node, p_name: String) -> void:
|
||||
_add_animation_to_player(p_name, GameAnimation.level_hud_warning(node))
|
||||
|
||||
func _add_animation_to_player(p_name: String, anim: Animation) -> void:
|
||||
var player = $ListObjects/AnimationPlayer
|
||||
var lib = player.get_animation_library("")
|
||||
var player: AnimationPlayer = $ListObjects/AnimationPlayer
|
||||
var lib := player.get_animation_library("")
|
||||
if lib == null:
|
||||
lib = AnimationLibrary.new()
|
||||
player.add_animation_library("", lib)
|
||||
lib.add_animation(p_name, anim)
|
||||
|
||||
func _process(_delta):
|
||||
func _process(_delta: float) -> void:
|
||||
_check_dissolve_mesh()
|
||||
_check_change_angle_camera()
|
||||
_check_victory_condition()
|
||||
|
||||
func create_dissolve_mesh(key):
|
||||
var mesh = _node_to_mesh(key)
|
||||
func create_dissolve_mesh(key: String) -> void:
|
||||
var mesh := _node_to_mesh(key)
|
||||
if mesh == null:
|
||||
return
|
||||
var material = mesh.get_active_material(0)
|
||||
var material := mesh.get_active_material(0)
|
||||
if material == null:
|
||||
return
|
||||
material.set_shader_parameter("dissolve_amount", 0.0)
|
||||
|
||||
func _check_dissolve_mesh():
|
||||
func _check_dissolve_mesh() -> void:
|
||||
# Event dissolve in object searched by gamer
|
||||
for key in meshes:
|
||||
if bool(meshes[key].lock()) == true and meshes[key].mesh() != null:
|
||||
var mesh = _node_to_mesh(key)
|
||||
if mesh == null:
|
||||
continue
|
||||
if meshes[key].tick_reference() == 0:
|
||||
meshes[key].set_tick_reference(Time.get_ticks_msec())
|
||||
_node_object_list(key)
|
||||
GameAnimation.start_dissolve(mesh, mesh.get_active_material(0))
|
||||
var scene: SceneEntry = meshes[key]
|
||||
if not scene.lock or scene.dissolved:
|
||||
continue
|
||||
var mesh := _node_to_mesh(key)
|
||||
if mesh == null:
|
||||
continue
|
||||
if scene.dissolve_tick_reference == 0:
|
||||
scene.dissolve_tick_reference = Time.get_ticks_msec()
|
||||
_node_object_list(key)
|
||||
GameAnimation.start_dissolve(mesh, mesh.get_active_material(0))
|
||||
if Time.get_ticks_msec() < scene.dissolve_tick_reference + TIME_MAX:
|
||||
scene.dissolve_value += 0.01
|
||||
else:
|
||||
_clean_mesh(key)
|
||||
|
||||
if Time.get_ticks_msec() < meshes[key].tick_reference() + TIME_MAX:
|
||||
meshes[key].set_value(meshes[key].value() + 0.01)
|
||||
else:
|
||||
_clean_mesh(key)
|
||||
func _clean_mesh(key: String) -> void:
|
||||
var level := Global.database.level_by_index(Global.current_scene_int)
|
||||
if level != null:
|
||||
victory_progress = level.object_finding()
|
||||
var mesh := _node_to_mesh(key)
|
||||
if mesh != null:
|
||||
mesh.call_deferred("free")
|
||||
meshes[key].dissolved = true
|
||||
|
||||
func _clean_mesh(key):
|
||||
victory_progress = mlevel.new(Global.current_scene_int).object_finding()
|
||||
_node_to_mesh(key).call_deferred("free")
|
||||
meshes[key].set_mesh(null)
|
||||
func _check_change_angle_camera() -> void:
|
||||
var camera: Camera3D = $"MainCamera"
|
||||
var gyroscope := Input.get_gyroscope()
|
||||
|
||||
func _check_change_angle_camera():
|
||||
var camera = $"MainCamera"
|
||||
var gyroscope = Input.get_gyroscope()
|
||||
|
||||
if camera.h_offset >= -OFFSET_CAMERA_MAX:
|
||||
if _action_pressed("ui_left") or _action_gyroscope("left", gyroscope):
|
||||
print("[warcraft#_ready] move camera angle to left")
|
||||
$"Main Camera3D".h_offset -= OFFSET_STEP_CHANGE
|
||||
|
||||
|
||||
if camera.h_offset <= OFFSET_CAMERA_MAX:
|
||||
if _action_pressed("ui_right") or _action_gyroscope("right", gyroscope):
|
||||
print("[warcraft#_ready] move camera angle to right")
|
||||
$"Main Camera3D".h_offset += OFFSET_STEP_CHANGE
|
||||
|
||||
|
||||
if camera.v_offset >= -OFFSET_CAMERA_MAX:
|
||||
if _action_pressed("ui_down") or _action_gyroscope("down", gyroscope):
|
||||
print("[warcraft#_ready] move camera angle to down")
|
||||
$"Main Camera3D".v_offset -= OFFSET_STEP_CHANGE
|
||||
|
||||
|
||||
if camera.v_offset <= OFFSET_CAMERA_MAX:
|
||||
if _action_pressed("ui_up") or _action_gyroscope("up", gyroscope):
|
||||
print("[warcraft#_ready] move camera angle to up")
|
||||
$"Main Camera3D".v_offset += OFFSET_STEP_CHANGE
|
||||
|
||||
|
||||
gyroscope_value_old = gyroscope
|
||||
|
||||
func _action_pressed(action):
|
||||
func _action_pressed(action: String) -> bool:
|
||||
return Input.is_action_pressed(action)
|
||||
|
||||
func _action_gyroscope(action, gyroscope):
|
||||
if Setting.get_setting_gyrosocpe():
|
||||
var expression = Expression.new()
|
||||
|
||||
expression.parse("_gyroscope_changed_"+action+"(gyroscope)", ["gyroscope"])
|
||||
|
||||
if expression.execute([gyroscope], self):
|
||||
return true
|
||||
else:
|
||||
return false
|
||||
else:
|
||||
func _action_gyroscope(action: String, gyroscope: Vector3) -> bool:
|
||||
if not Setting.get_setting_gyrosocpe():
|
||||
return false
|
||||
var expression := Expression.new()
|
||||
expression.parse("_gyroscope_changed_" + action + "(gyroscope)", ["gyroscope"])
|
||||
return bool(expression.execute([gyroscope], self))
|
||||
|
||||
func _gyroscope_changed_left(gyroscope):
|
||||
func _gyroscope_changed_left(gyroscope: Vector3) -> bool:
|
||||
return (gyroscope.abs().y - gyroscope_value_old.abs().y) > GYROSCOPE_MAX_DIFF and \
|
||||
gyroscope.y < gyroscope_value_old.y
|
||||
|
||||
func _gyroscope_changed_right(gyroscope):
|
||||
func _gyroscope_changed_right(gyroscope: Vector3) -> bool:
|
||||
return (gyroscope.abs().y - gyroscope_value_old.abs().y) > GYROSCOPE_MAX_DIFF and \
|
||||
gyroscope.y > gyroscope_value_old.y
|
||||
|
||||
func _gyroscope_changed_down(gyroscope):
|
||||
func _gyroscope_changed_down(gyroscope: Vector3) -> bool:
|
||||
return (gyroscope.abs().z - gyroscope_value_old.abs().z) > GYROSCOPE_MAX_DIFF and \
|
||||
gyroscope.z > gyroscope_value_old.z or \
|
||||
(gyroscope.abs().x - gyroscope_value_old.abs().x) > GYROSCOPE_MAX_DIFF and \
|
||||
gyroscope.x > gyroscope_value_old.x
|
||||
|
||||
func _gyroscope_changed_up(gyroscope):
|
||||
func _gyroscope_changed_up(gyroscope: Vector3) -> bool:
|
||||
return (gyroscope.abs().z - gyroscope_value_old.abs().z) > GYROSCOPE_MAX_DIFF and \
|
||||
gyroscope.z < gyroscope_value_old.z or \
|
||||
(gyroscope.abs().x - gyroscope_value_old.abs().x) > GYROSCOPE_MAX_DIFF and \
|
||||
gyroscope.x < gyroscope_value_old.x
|
||||
|
||||
func _start_dissolve(key):
|
||||
if bool(meshes[key].lock()) == false:
|
||||
meshes[key].set_lock(int(true))
|
||||
$ObjectFind.stream = meshes[key].audio_sound()
|
||||
$ObjectFind.play()
|
||||
func _start_dissolve(key: String) -> void:
|
||||
if not meshes.has(key):
|
||||
return
|
||||
var scene: SceneEntry = meshes[key]
|
||||
if scene.lock:
|
||||
return
|
||||
scene.lock = true
|
||||
Global.database.save()
|
||||
$ObjectFind.stream = scene.audio_sound()
|
||||
$ObjectFind.play()
|
||||
|
||||
func _check_victory_condition():
|
||||
func _check_victory_condition() -> void:
|
||||
if victory_condition == victory_progress:
|
||||
print("[levels#_check_victory_condition] \\o/\\o/ \\o/ \\o/ \\o/\\o/")
|
||||
print("[levels#_check_victory_condition] Win !!")
|
||||
Global.goto_scene("res://scenes/UI/ending/Ending.tscn")
|
||||
|
||||
func _node_to_mesh(key):
|
||||
return get_node_or_null(meshes[key].mesh())
|
||||
|
||||
func _node_to_area(key):
|
||||
return get_node_or_null(meshes[key].mesh() + "/Area3D")
|
||||
|
||||
func _node_object_list(key):
|
||||
var animation_played = null
|
||||
func _node_to_mesh(key: String) -> MeshInstance3D:
|
||||
if not meshes.has(key):
|
||||
return null
|
||||
return get_node_or_null(meshes[key].mesh_path()) as MeshInstance3D
|
||||
|
||||
func _node_object_list(key: String) -> void:
|
||||
var animation_played: String = ""
|
||||
for child in $ListObjects/ListContainer.get_children():
|
||||
if child.has_meta("name"):
|
||||
if child.get_meta("name") == meshes[key].label():
|
||||
child.set_meta("counted", child.get_meta("counted") + 1)
|
||||
|
||||
if child.get_meta("counter") == child.get_meta("counted"):
|
||||
animation_played = child.get_meta("name")
|
||||
else:
|
||||
var diff = child.get_meta("counter") - child.get_meta("counted")
|
||||
var txt = child.get_meta("name")
|
||||
if diff != 1:
|
||||
txt = txt + " " + str(diff)
|
||||
animation_played = child.get_meta("animation")
|
||||
child.get_node("Label").set_text(txt)
|
||||
|
||||
$ListObjects/AnimationPlayer.queue(animation_played)
|
||||
if not child.has_meta("name"):
|
||||
continue
|
||||
if child.get_meta("name") != meshes[key].label:
|
||||
continue
|
||||
child.set_meta("counted", child.get_meta("counted") + 1)
|
||||
if child.get_meta("counter") == child.get_meta("counted"):
|
||||
animation_played = child.get_meta("name")
|
||||
else:
|
||||
var diff: int = child.get_meta("counter") - child.get_meta("counted")
|
||||
var txt: String = child.get_meta("name")
|
||||
if diff != 1:
|
||||
txt = txt + " " + str(diff)
|
||||
animation_played = child.get_meta("animation")
|
||||
child.get_node("Label").set_text(txt)
|
||||
$ListObjects/AnimationPlayer.queue(animation_played)
|
||||
|
||||
func _input(event):
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event is InputEventMouseButton or event is InputEventScreenTouch:
|
||||
var camera = $"MainCamera"
|
||||
var camera: Camera3D = $"MainCamera"
|
||||
from = camera.project_ray_origin(event.position)
|
||||
to = from + camera.project_ray_normal(event.position) * RAY_LENGTH
|
||||
|
||||
func _physics_process(_delta):
|
||||
var space_state = get_world_3d().direct_space_state
|
||||
func _physics_process(_delta: float) -> void:
|
||||
var space_state := get_world_3d().direct_space_state
|
||||
if from != null and to != null:
|
||||
_check_collider(space_state)
|
||||
|
||||
func _check_collider(space_state):
|
||||
var query = PhysicsRayQueryParameters3D.create(from, to)
|
||||
func _check_collider(space_state: PhysicsDirectSpaceState3D) -> void:
|
||||
var query := PhysicsRayQueryParameters3D.create(from, to)
|
||||
query.collision_mask = 1
|
||||
query.collide_with_bodies = false
|
||||
query.collide_with_areas = true
|
||||
var result = space_state.intersect_ray(query)
|
||||
var result := space_state.intersect_ray(query)
|
||||
from = null
|
||||
to = null
|
||||
if result.has("collider"):
|
||||
var node = result["collider"].get_parent()
|
||||
var node: Node = result["collider"].get_parent()
|
||||
if node != null:
|
||||
_start_dissolve(node.name)
|
||||
|
||||
Reference in New Issue
Block a user