extends "res://db/MBase.gd"

var m_name = null
var m_thumb = null
var m_level = null
var mscene = load("res://db/MScene.gd")

func _init(row_idx):
	m_level = row_idx
	table = Global.database.get_table_by_name("levels")
	
	var datas = table.get_data_at_row_idx(m_level)
	m_name = _get_name(datas)
	m_thumb = _get_thumb(datas)

func object_to_find():
	var count = 0
	var datas = _scenes().get_data_by_prop_name_and_data("level", String(m_level))
	
	if datas.size() != 0:
		count = datas.size()
	
	return count as String

func reset():
	var scene_detail = null
	var t = Global.database.get_table_by_name("scenes")
	
	for row_index in range(0, t.m_rows_count):
		scene_detail = mscene.new(row_index)
		if scene_detail.label() != null:
			scene_detail.set_lock(int(false))

func _scenes():
	return Global.database.get_table_by_name("scenes")

func object_finding():
	var count = 0
	
	for datas in _scenes().get_dictionary_by_prop_name_and_data("level", String(m_level)):
		if int(datas['lock']) == 1:
			count = count + 1
	
	return count as String

func name():
	return m_name

func thumbnail():
	return m_thumb

## PRIVATE
func _get_name(datas):
	return _get_data(datas, 0) as String

func _get_thumb(datas):
	return _get_data(datas, 1) as String
