Macro.add('ConnectedLocationCode',{
	tags:[],
	handler  : function () {

		let _connectedLocationData:ConnectedLocation = {
			forPassage : passage(),
			targetPassage:'',
			targetArguments: undefined,
			label: '',
			image: '',
			duration: 0,
			class: 'connectedLocation',
			priority: 0,
			content: '',
			hotkeys: [],
			indecencyBlocked:false,
			capturedVars: {}
		};

		_connectedLocationData.content = this.payload[0].contents;
		_connectedLocationData.label = this.args[0];

		_connectedLocationData.image = this.args[1];

		_connectedLocationData.duration = this.args[2];

		/* ----- Additional Settings ----- */
		let _additionalSettings = this.args[3] ?? {};

		_connectedLocationData.targetPassage = _additionalSettings.targetPassage;

		if(_additionalSettings.class){
			_connectedLocationData.class += " " + _additionalSettings.class;
		}
		if(_additionalSettings.priority){
			_connectedLocationData.priority = _additionalSettings.priority;
		}
		if(_additionalSettings.hotkeys){
			_connectedLocationData.hotkeys = _additionalSettings.hotkeys;
		}
		_connectedLocationData.indecencyBlocked = _additionalSettings.indecencyBlocked ? true : false;

		let _allowedVehicles = _additionalSettings.allowedVehicles;
		if(_allowedVehicles){
			if(!_allowedVehicles.includes(State.variables.pc.vehicleType)){
				return;
			}
		}
		let _capture = _additionalSettings.capture ?? [];

		for(const _key of _capture){
			_connectedLocationData.capturedVars[_key] = clone(State.getVar(_key));
		}


		switch(State.variables.pc.vehicleType){
			case 'car':
				_connectedLocationData.duration = Math.ceil(_connectedLocationData.duration / State.variables.pc.vehicleSpeed);
		}


		State.variables.connectedLocations ??= [];
		State.variables.connectedLocations.push(_connectedLocationData);


			
	}
});