Use BDD for list scenes

This commit is contained in:
VAILLANT Jeremy
2021-05-13 23:15:05 +02:00
parent 8dbbbe7629
commit 23e8bef1b8
3 changed files with 113 additions and 29 deletions
+32 -7
View File
@@ -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]")
+71 -2
View File
@@ -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")
+10 -20
View File
@@ -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"]