:: dynamicHousing[include]
	<<set _housingData = $location_var[$here][0]>>

	<<set _currentRoom ??= ($dynamicHousingRoom ?? _housingData.entry)>>
	<<set $dynamicHousingRoom = _currentRoom>>
	<<set _currentRoomData = _housingData.room(_currentRoom)>>

	<<gs 'dynamicHousingEventHandling'>>
    <<if !_eventStopsRendering>>

		<h2>_currentRoomData.title</h2>
		<<image _currentRoomData.image>>
		<p>_currentRoomData.description</p>

		<<for _connection range _currentRoomData.connections ?? []>>
			<<if typeof _connection === 'string'>>
				<<if _connection.first() == '#'>>
					<<set _connection = _housingData.connections[_connection.substring(1)]>>
					<<set _flags = setup.mergeDeep({capture:['_connection']},_connection.flags??{})>>
					<<ConnectedLocation _connection.label _connection.destination '' _connection.image _connection.time _flags>>
				<<elseif _housingData.roomExists(_connection)>>
					<<set _destination = _housingData.room(_connection)>>
					<<ConnectedLocationCode _destination.title _destination.image 1 `{capture:['_connection']}`>>
						<<set $dynamicHousingRoom = _connection>>
						<<travel  _housingData.passage>>
					<</ConnectedLocationCode>>
				<</if>>
			<<else>>
				<<ConnectedLocation _connection.label _connection.destination '' _connection.image _connection.time _connection.flags>>
			<</if>>
		<</for>>

		<<for _tag range _currentRoomData.tags ?? []>>
			<<run _tags.push(_tag)>>
		<</for>>

		<<if _currentRoomData.passage>>
			<<gs _currentRoomData.passage>>
		<</if>>

	<</if>>

:: dynamicHousingEventHandling[event]
	<<set $eventReturnLocation = new LocationIdentifier(passage())>>

	<<set _temporaryEvents = {}>>
	<<set _eventPassages = Story.lookup("tags", $eventReturnLocation.passage+'_events')>>
	<<for _eventPassage range _eventPassages>>
		<<gs _eventPassage.title>>
	<</for>>

	<<set _eventsRegisteredForPassageAndTags = $events.registeredByPassage($eventReturnLocation.passage)>>

	<<set _targetPassageTags = $eventReturnLocation.tags>>
	<<run _targetPassageTags = _targetPassageTags.concatUnique(_currentRoomData.tags ?? [])>>
	<<for _targetPassageTag range _targetPassageTags>>
		<<set _eventsRegisteredForPassageAndTags = _eventsRegisteredForPassageAndTags.concat($events.registeredByTag(_targetPassageTag))>>
		<<set _eventPassages = Story.lookup("tags", _targetPassageTag+'_events')>>
		<<for _eventPassage range _eventPassages>>
			<<gs _eventPassage.title>>
		<</for>>
	<</for>>

	<!--<<set _allEvents = _eventsRegisteredForPassageAndTags.concat(_temporaryEvents).sortByPriority();>>-->
	<<set _allEvents = setup.mergeDeep({},_eventsRegisteredForPassageAndTags,_temporaryEvents)>>

	<<include 'eventsExecute'>>


:: dynamicHousingWidgets[widget]
	<<widget 'dynamicHousing'>>
		/*
			Args
				0 Data (Object: use the object, string: look up data in $housing)
		 */

		<<set _housingData = $housing.house(_args[0])>>

		<<gs 'dynamicHousing' _housingData>>
	<</widget>>