/// <reference path="../_system/events/NavigationOverride.ts" />

Config.macros.ifAssignmentError = false;

Config.navigation.override = setup.navigationOverride;

Config.passages.nobr = true; //vgl. https://www.motoslave.net/sugarcube/2/docs/#config-api-property-passages-nobr
Config.history.maxStates = 3;

Config.saves.isAllowed = function () {
	if(tags().includes("noSave"))
        return false;
    return true;
};

Save.onLoad.add(function (save) {
	console.log("Loading savegame",save);
	let saveVars = save.state.history.last().variables;
    setup.settingsApply(saveVars.settings);
});

setup.settingsApply = function(settings){
	if(!settings)
		return;
	console.warn('Aplly settings',settings);
	switch(settings.autosave){
		case 'ALWAYS':
			Config.saves.autosave = true;
			break;
		case 'AWAKE':
			Config.saves.autosave = ['sleepAwake','autosave'];
			break;
		case 'NONE':
			Config.saves.autosave = ()=>false;
			break;
	}
	switch(settings.ui?.sidebarRight){
		case true:
			$("#ui-bar").addClass("uiBarRight");
			break;
		default:

			break;
	}
	if(settings.ui?.css)
		importStyles(settings.ui?.css.split("\n"));
	if(settings.maxStates)
		Config.history.maxStates = settings.maxStates;
}
