77 lines
2.0 KiB
GDScript
77 lines
2.0 KiB
GDScript
extends Control
|
|
|
|
export (PackedScene) var template = load("res://scenes/levels/Template.tscn")
|
|
|
|
onready var levels = Array()
|
|
|
|
func _ready():
|
|
_apply_scenes()
|
|
|
|
# Load scene warcraft
|
|
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(_load_scene(name),
|
|
_load_texture(thumb),
|
|
_build_path(name),
|
|
_build_method(name))
|
|
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 _build_path(name):
|
|
return "MarginContainer/HBoxContainer/"+name+"/TextureRect"
|
|
|
|
func _build_method(name):
|
|
return "_on_"+name.to_lower()+"_pressed"
|
|
|
|
func _load_scene(name):
|
|
var template_instance = template.instance()
|
|
template_instance.set_name(name)
|
|
|
|
return template_instance
|
|
|
|
func _load_texture(thumbnail):
|
|
return load(thumbnail)
|
|
|
|
func _apply_scene(instance, thumb, node, method):
|
|
$MarginContainer/HBoxContainer.add_child(instance)
|
|
var button = get_node(node+"/TextureButton")
|
|
button.set_normal_texture(thumb)
|
|
button.connect("pressed", self, method)
|
|
|