118 lines
3.1 KiB
GDScript
118 lines
3.1 KiB
GDScript
extends Control
|
|
|
|
const TICKS_TIME_MAX = 100 # msec
|
|
|
|
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]")
|
|
_initialize_current_scene()
|
|
_initialize_database()
|
|
|
|
func goto_scene(path):
|
|
print("[global#goto_scene]")
|
|
loader = ResourceLoader.load_interactive(path)
|
|
if loader == null:
|
|
print("Error loading ....")
|
|
return
|
|
|
|
set_process(true)
|
|
current_scene.queue_free()
|
|
wait_frames = 1
|
|
Loading.get_node("VBoxContainer/ProgressBar").set_max(loader.get_stage_count())
|
|
|
|
func gyroscope_enabled():
|
|
if _gyroscope_enabled():
|
|
return true
|
|
else:
|
|
return false
|
|
|
|
func _process(_delta):
|
|
print("[global#_process]")
|
|
if loader == null:
|
|
set_process(false)
|
|
return
|
|
|
|
if wait_frames > 0:
|
|
wait_frames -= 1
|
|
|
|
var tick = OS.get_ticks_msec()
|
|
|
|
# Use "TICKS_TIME_MAX" to control for how long we block this thread
|
|
while OS.get_ticks_msec() < tick + TICKS_TIME_MAX:
|
|
var err = loader.poll()
|
|
|
|
if err == ERR_FILE_EOF: # Finished loading.
|
|
_set_new_scene()
|
|
break
|
|
elif err == OK:
|
|
_update_progress()
|
|
else:
|
|
loader = null
|
|
break
|
|
|
|
## 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)
|
|
|
|
if current_scene.name != "Main":
|
|
get_node("/root/Loading").hide()
|
|
|
|
func _initialize_database():
|
|
print("[global#_initialize_database]")
|
|
var database_manager = load(gddb_constants.c_addon_main_path + "core/db_man.gd").new()
|
|
var db_id = database_manager.load_database("res://db/ahog.json")
|
|
|
|
if db_id == gddb_types.e_db_invalid_file:
|
|
print("[global#_initialize_database] Error invalid database file !")
|
|
OS.set_exit_code(1)
|
|
|
|
if db_id == gddb_types.e_db_invalid_ver:
|
|
print("[global#_initialize_database] Error invalid database version !")
|
|
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]")
|
|
Loading.visible = true
|
|
Loading.get_node("VBoxContainer/ProgressBar").set_value(loader.get_stage())
|
|
|
|
func _set_new_scene():
|
|
print("[global#set_new_scene]")
|
|
var resource = loader.get_resource()
|
|
loader = null
|
|
current_scene = resource.instance()
|
|
get_node("/root").add_child(current_scene)
|
|
get_node("/root/Loading").hide()
|