// Autociv control class with sub classes that will be have an instance at init()
class HostEnhancedControls
{
	constructor()
	{
		this.controls = {}
		for (let className of Object.keys(HostEnhancedControls))
			this.controls[className] = new HostEnhancedControls[className]()
	}
}
var g_HostEnhancedControls; // Created at init


function HostEnhanced_initBots()
{
	botManagerHostEnhanced.get("ban").load(true);
	HostEnhanced_InitSharedCommands();
}


/*
function autociv_patchSession()
{
	Engine.GetGUIObjectByName("pauseOverlay").size = "0% 0% 100% 30%"
}
*/
/*
function autociv_SetChatTextFromConfig()
{
	const that = autociv_SetChatTextFromConfig
	that.default_size = that.default_size ?? Engine.GetGUIObjectByName("chatPanel").size
	that.default_font = that.default_font ?? Engine.GetGUIObjectByName("chatLines").children[0].font

	const changeSize = Engine.ConfigDB_GetValue("user", "autociv.session.chatPanel.size.change") == "true"
	const size = changeSize ? Engine.ConfigDB_GetValue("user", "autociv.session.chatPanel.size") : that.default_size
	Engine.GetGUIObjectByName("chatPanel").size = size

	const changeFont = Engine.ConfigDB_GetValue("user", "autociv.session.chatText.font.change") == "true"
	const font = changeFont ? Engine.ConfigDB_GetValue("user", "autociv.session.chatText.font") : that.default_font
	for (let child of Engine.GetGUIObjectByName("chatLines").children)
		child.font = font
}
*/
/*
function getGuiObjectsWithHotkey()
{
	let dict = {}
	let internal = 0

	let traverse = parent => parent.children.forEach(child =>
	{
		if (child.name.startsWith("__internal("))
			++internal

		if (child.hotkey)
			dict[child.hotkey] = child

		traverse(child)
	})

	while (true)
	{
		let object = Engine.GetGUIObjectByName(`__internal(${internal})`)
		if (!object)
			break

		// Go to root
		while (object.parent != null)
			object = object.parent

		traverse(object)
		++internal
	}
	return dict
}
*/
/*
var g_hotkeyObjectChange = {
	"camera.follow": ["onPress", "onKeyDown"]
}
*/

autociv_patchApplyN("init", function (target, that, args)
{
	let result = target.apply(that, args)

	//autociv_changeSomeHotkeysToKeyDownAsPressTypeCantBeDiscardedFromBeingCalledForSomeReason()
	
	if ( typeof(autociv_InitBots) == "function" ) {
		log("debug session~HostEnhanced.js:autociv_InitBots function found - initiating - autocivmod enabled");
		autociv_InitBots(); 
	} else {
		log("debug session~HostEnhanced.js:autociv_InitBots function not found - autociv mod disabled");
		//autociv_InitBots(); 
	}
	//autociv_initBots()
	//autociv_patchSession()
	//autociv_addVersionLabel()
	//autociv_SetCorpsesMax(Engine.ConfigDB_GetValue("user", "autociv.session.graphics.corpses.max"))
	//autociv_SetChatTextFromConfig()
	HostEnhanced_initBots()
	g_HostEnhancedControls = new HostEnhancedControls()

	/*
	registerConfigChangeHandler(changes =>
	{
		if (changes.has("autociv.session.graphics.corpses.max"))
			autociv_SetCorpsesMax(Engine.ConfigDB_GetValue("user", "autociv.session.graphics.corpses.max"))

		autociv_SetChatTextFromConfig()
	})
	*/
	return result
})
