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

var m_langue = null
var m_gyroscope = null
var m_ambient_sound = null
var m_resolution = null
var m_fullscreen = null
var m_version = null

const ROW_ID = 0
const LANGUE_ID = 0
const GYRSOCPE_ID = 1
const AMBIENT_SOUND = 2
const RESOLUTION = 3
const FULLSCREEN = 4
const VERSION = 5

func _init():
	table = Global.database.get_table_by_name("settings")
	var datas = table.get_data_at_row_idx(ROW_ID)

	m_langue = _get_data(datas, LANGUE_ID)
	m_gyroscope = _get_data(datas, GYRSOCPE_ID)
	m_ambient_sound = _get_data(datas, AMBIENT_SOUND)
	m_resolution = _get_data(datas, RESOLUTION)
	m_fullscreen = _get_data(datas, FULLSCREEN)
	m_version = _get_data(datas, VERSION)

func get_langue():
	return m_langue as int

func get_gyroscope():
	return int(m_gyroscope) as bool

func get_ambient_sound():
	return int(m_ambient_sound) as bool

func get_resolution():
	return m_resolution.split(" x ")

func get_fullscreen():
	return int(m_fullscreen) as bool

func get_version():
	return "v"+String(m_version)

func set_langue(value):
	m_langue = _set_data(LANGUE_ID, ROW_ID, value)
	
	return get_langue()

func set_gyroscope(value):
	m_gyroscope = _set_data(GYRSOCPE_ID, ROW_ID, value)
	
	return get_gyroscope()
	
func set_ambient_sound(value):
	m_ambient_sound = _set_data(AMBIENT_SOUND, ROW_ID, value)
	
	return get_ambient_sound()

func set_resolution(value):
	m_resolution = _set_data(RESOLUTION, ROW_ID, value)
	
	return get_resolution()

func set_fullscreen(value):
	m_fullscreen = _set_data(FULLSCREEN, ROW_ID, value)
	
	return get_fullscreen()
