class VersionControl{
	static versionUpdate(variables: TwineSugarCube.SugarCubeStoryVariables, toVersion:number = 0){
		let versionOfVariables:number = variables.version || 0;
		toVersion ||= Config.saves.version;

		console.log(`Updating from Version ${versionOfVariables}`);



		if(versionOfVariables < 5 && toVersion >= 5)
			variables.inventory = new setup.Inventory();
		if(versionOfVariables < 6)
			variables.events = new setup.Events();
		if(versionOfVariables < 9){
			let inventoryData = clone(variables.inventory._containers);
			variables.inventory.clear();
			for(const [containerId, containerData] of Object.entries(inventoryData)){
				for (const [itemId, itemCount] of Object.entries(containerData)) {
					variables.inventory.set(itemId,itemCount as number,containerId);
				}
			}
		}
		if(versionOfVariables < 12){
			if(variables['grupTipe']){
				variables.q['school'].groups[['cool','jocks','nerds','gopniks','outcasts','teachers'][variables['grupTipe'] - 1]].member = true;
			}
		}
		
		if(versionOfVariables < 14){
			variables.pc._makeupAmount = variables.pc['_pcs_makeup'];
			variables.pc._makeupQuality= 2;
			variables.pc._leghair = variables.pc['pcs_leghair'];
		}
		/*
		if(versionOfVariables < 16){
			if(variables.housing._home == 'parents_home')			variables.housing._home = 'homeParents';
			if(variables.housing._access.includes('parents_home'))	variables.housing._access.push('homeParents');
		}

		if(versionOfVariables < 17){
			variables.weather = new setup.Weather();
		}

		if(versionOfVariables < 18){
			variables.jobs = new setup.Jobs();
			variables.phone = new setup.Phone();
			variables.time._timedEvents = {_system:{nextId:0},events:{}};
		}

		if(versionOfVariables < 19){
			variables.startCharacter = 'sg_starting_category';	//Not very accurate, but good enough
		}

		if(versionOfVariables < 20){
			variables.alarmClock = {
				on:variables.budilnikOn,
				hourWeekend:variables.timerEnd,
				minuteWeekend:variables.timerEndM,
				hour:variables.timer,
				minute:variables.timerM,
				holidayIsWeekend:variables.alarm_holiday
			};
		}

		if(versionOfVariables < 22)
			variables.actions ??= {};

		if(versionOfVariables < 23){
			variables.npc = function(npcId){return State.variables.npcs.npc(npcId);}
			variables.quest = function(questId){return State.variables.q.quest(questId);}
			for(const[questId,questObject] of Object.entries(variables.q)){
				if(questObject instanceof setup.Quest)
					variables.q._quests[questId] = questObject;
			}
		}

		if(versionOfVariables < 101){
			for(const[effectId,effectExpiration] of Object.entries(variables.pc._effects)){
				variables.pc._effects[effectId] = {expiration:effectExpiration};
			}
		}

		if(versionOfVariables < 102){
			variables.larg = function(i){return State.variables.location_var[State.variables.here][i]};
		}

		if(versionOfVariables < 103){
			variables.pc._drugs = new setup.Drugs(variables.pc._drugs);
			variables.pc._mood = new setup.Mood(variables.pc._moodlets);
			variables.pc._pain = new setup.Pain(variables.pc._pain);
		}
		
		*/
		variables.version = toVersion;
		
	}
}

setup.VersionControl = VersionControl;