From 26a0c8f33df8fc00bb9d696f3b991e6414fc4332 Mon Sep 17 00:00:00 2001 From: VAILLANT Jeremy Date: Thu, 13 May 2021 23:15:05 +0200 Subject: [PATCH] Use BDD for list scenes --- scenes/Global.gd | 39 ++++++++++++--- scenes/UI/ChooseScene.gd | 73 +++++++++++++++++++++++++++- scenes/UI/ChooseScene.tscn | 30 ++++-------- scenes/levels/warcraft/WarCraft.tscn | 2 +- 4 files changed, 114 insertions(+), 30 deletions(-) diff --git a/scenes/Global.gd b/scenes/Global.gd index 1022131..6c0a2a7 100644 --- a/scenes/Global.gd +++ b/scenes/Global.gd @@ -2,14 +2,19 @@ extends Control const TICKS_TIME_MAX = 100 # msec -var current_scene = null -var loader = null -var wait_frames = 1 - -var database = null +onready var current_scene = null +onready var loader = null +onready var wait_frames = 1 +onready var database = null +onready var table_settings = null +onready var data_settings = null +onready var table_levels = null +onready var data_levels = null +onready var table_scenes = null +onready var data_scenes = null func _ready(): - print("[global#_ready] get root scene") + print("[global#_ready]") _initialize_current_scene() _initialize_database() @@ -26,7 +31,7 @@ func goto_scene(path): Loading.get_node("ColorRect/CenterContainer/VBoxContainer/ProgressBar").set_max(loader.get_stage_count()) func gyroscope_enabled(): - if Input.get_gyroscope(): + if _gyroscope_enabled(): return true else: return false @@ -57,6 +62,7 @@ func _process(_delta): ## PRIVATE func _initialize_current_scene(): + print("[global#_initialize_current_scene]") var root = get_tree().get_root() current_scene = root.get_child(root.get_child_count() - 1) @@ -77,6 +83,25 @@ func _initialize_database(): OS.set_exit_code(1) database = database_manager.get_db_by_id(db_id) + + table_settings = database.get_table_by_name("settings") + data_settings = table_settings.get_data_at_row_idx(0) + + table_levels = database.get_table_by_name("levels") + +func _get_settings_data(name, index, table, datas): + print("[global#_get_settings_data] name : "+String(name)) + var data = null + + if table.get_prop_at(index).get_prop_name() == name: + data = datas[index].get_data() + + return data + +func _gyroscope_enabled(): + print("[global#_gyroscope_enabled]") + for index in range(0, table_settings.get_props_count()): + _get_settings_data("gyroscope", index, table_settings, data_settings) func _update_progress(): print("[global#update_progress]") diff --git a/scenes/UI/ChooseScene.gd b/scenes/UI/ChooseScene.gd index 128bf22..18b95fb 100644 --- a/scenes/UI/ChooseScene.gd +++ b/scenes/UI/ChooseScene.gd @@ -1,5 +1,11 @@ extends Control +onready var levels = Array() + +func _ready(): + print("[choose_scene#_ready]") + _apply_scenes() + # Load scene warcraft func _on_WarCraft_pressed(): Global.goto_scene("res://scenes/levels/warcraft/WarCraft.tscn") @@ -7,5 +13,68 @@ func _on_WarCraft_pressed(): func _on_Lightmap_pressed(): Global.goto_scene("res://developers/aurelien/CheckLightmap.tscn") -func _on_Dagger_pressed(): - Global.goto_scene("res://developers/jeremy/Dagger.tscn") +func _on_warcraft_pressed(): + Global.goto_scene("res://scenes/levels/warcraft/WarCraft.tscn") + +func _on_develop_pressed(): + Global.goto_scene("res://developers/aurelien/CheckLightmap.tscn") + +## PRIVATE +func _apply_scenes(): + var table = Global.table_levels + var datas = null + var name = null + var thumb = null + var resource = null + + for row_index in range(0, Global.table_levels.m_rows_count): + datas = Global.table_levels.get_data_at_row_idx(row_index) + + for index in range(0, table.get_props_count()): + if name == null: + name = _get_name(index, table, datas) + if thumb == null: + thumb = _get_thumb(index, table, datas) + if resource == null: + resource = _get_resource(index, table, datas) + + _apply_scene(name, thumb, resource) + name = null + thumb = null + resource = null + +func _get_name(index, table, datas): + if table.get_prop_at(index).get_prop_name() == "name": + return datas[index].get_data() + +func _get_thumb(index, table, datas): + if table.get_prop_at(index).get_prop_name() == "thumb": + return datas[index].get_data() + +func _get_resource(index, table, datas): + if table.get_prop_at(index).get_prop_name() == "resource": + return datas[index].get_data() + +func _apply_scene(name, thumb, resource): + $games/Container/HBoxContainer.add_child(_configure_vbox()) + _configure_button(thumb, resource, name) + $games/Container/HBoxContainer/VBoxContainer.add_child(_configure_label(name)) + +func _configure_vbox(): + var vbox = VBoxContainer.new() + vbox.set_name("VBoxContainer") + + return vbox + +func _configure_label(name): + var label = Label.new() + label.set_text(name) + + return label + +func _configure_button(thumb, _resource, name): + var thumbnail = TextureButton.new() + $games/Container/HBoxContainer/VBoxContainer.add_child(thumbnail) + thumbnail.set_normal_texture(load(thumb)) + thumbnail.connect("pressed", self, "_on_"+name.to_lower()+"_pressed") + diff --git a/scenes/UI/ChooseScene.tscn b/scenes/UI/ChooseScene.tscn index a646304..d532ca3 100644 --- a/scenes/UI/ChooseScene.tscn +++ b/scenes/UI/ChooseScene.tscn @@ -20,10 +20,10 @@ __meta__ = { } [node name="GridContainer" type="GridContainer" parent="games"] -margin_left = 25.0 -margin_top = 26.2599 -margin_right = 824.0 -margin_bottom = 601.26 +margin_left = 503.586 +margin_top = 300.0 +margin_right = 1302.59 +margin_bottom = 604.0 __meta__ = { "_edit_use_anchors_": false } @@ -49,23 +49,13 @@ __meta__ = { "_edit_use_anchors_": false } -[node name="Dagger" type="TextureButton" parent="games/GridContainer"] -margin_top = 308.0 -margin_right = 150.0 -margin_bottom = 458.0 -mouse_default_cursor_shape = 2 -texture_normal = ExtResource( 2 ) +[node name="Container" type="Control" parent="games"] +margin_right = 824.0 +margin_bottom = 300.0 -[node name="Label" type="Label" parent="games/GridContainer/Dagger"] -margin_right = 44.0 -margin_bottom = 14.0 -text = "Dagger" -align = 1 -valign = 1 -__meta__ = { -"_edit_use_anchors_": false -} +[node name="HBoxContainer" type="VBoxContainer" parent="games/Container"] +margin_right = 824.0 +margin_bottom = 300.0 [connection signal="pressed" from="games/GridContainer/WarCraft" to="." method="_on_WarCraft_pressed"] [connection signal="pressed" from="games/GridContainer/Lightmap" to="." method="_on_Lightmap_pressed"] -[connection signal="pressed" from="games/GridContainer/Dagger" to="." method="_on_Dagger_pressed"] diff --git a/scenes/levels/warcraft/WarCraft.tscn b/scenes/levels/warcraft/WarCraft.tscn index 1407378..4b7b9ec 100644 --- a/scenes/levels/warcraft/WarCraft.tscn +++ b/scenes/levels/warcraft/WarCraft.tscn @@ -113,7 +113,7 @@ cell_center_y = false cell_center_z = false baked_meshes = [ SubResource( 2 ) ] data = { -"cells": PoolIntArray( 0, 0, 536870915, 65531, 0, 3, 65532, 0, 3, 65533, 0, 3, 65534, 0, 3, 65535, 0, 3, 0, 1, 3, 65531, 1, 3, 65532, 1, 3, 65533, 1, 3, 65534, 1, -1073741821, 65535, 1, 3, 0, 2, 3, 65531, 2, 3, 65532, 2, 3, 65533, 2, 3, 65534, 2, 3, 65535, 2, -1610612733, 0, 65534, 3, 65531, 65534, -1610612733, 65532, 65534, 3, 65533, 65534, 3, 65534, 65534, 3, 65535, 65534, 536870915, 0, 65535, 3, 65531, 65535, -1073741821, 65532, 65535, 3, 65533, 65535, 3, 65534, 65535, 3, 65535, 65535, 3 ) +"cells": PoolIntArray( 0, 0, 3, 65531, 0, 3, 65532, 0, 536870915, 65533, 0, 3, 65534, 0, 3, 65535, 0, 3, 0, 1, -1073741821, 65531, 1, 536870915, 65532, 1, -1610612733, 65533, 1, 3, 65534, 1, 3, 65535, 1, 3, 0, 2, 3, 65531, 2, 3, 65532, 2, 3, 65533, 2, 3, 65534, 2, -1610612733, 65535, 2, 3, 0, 65534, 3, 65531, 65534, 3, 65532, 65534, 3, 65533, 65534, -1073741821, 65534, 65534, 3, 65535, 65534, 3, 0, 65535, 3, 65531, 65535, 3, 65532, 65535, 3, 65533, 65535, 3, 65534, 65535, 536870915, 65535, 65535, -1610612733 ) } __meta__ = { "_editor_clip_": 0,