:: MacroGS[widget]
<<widget 'gs'>>

	<<set $callStackIndent += 1>>
	<<run $callStack.push([_args[0],$callStackIndent])>>

	<<set _recursion_limit = 50>>

	<<if Array.isArray(_args[0])>>
		<<set _args = _args[0]>>
	<</if>>

	<<set _destintation = _args[0]>>

	<<if !$gt_history>>
		<<set $gt_history to {}>>
	<</if>>
	<<set _ts to Math.floor(Date.now() / 10000)>>
	<<if !$gt_history[_ts]>>
		<<set $gt_history[_ts] to {}>>
	<</if>>
	<<if !$gt_history[_ts][_destintation]>>
		<<set $gt_history[_ts][_destintation] to 0>>
	<</if>>
	<<set $gt_history[_ts][_destintation] += 1>>

	<<set _temp_history to {}>>
	<<for _time,_history range  $gt_history>>
		<<if _time > _ts - 10>>
			<<set _temp_history[_time] = _history>>
		<</if>>
	<</for>>
	<<set $gt_history to _temp_history>>

	<<if !$location_var>>
		<<set $location_var to {}>>
	<</if>>

	<<if !$location_var[_destintation]>>
		<<set $location_var[_destintation] to []>>
	<<else>>
		<<if !$location_var_stack>>
			<<set $location_var_stack = {}>>
		<</if>>
		<<if !$location_var_stack[_destintation]>>
			<<set $location_var_stack[_destintation] = []>>
		<</if>>
		<<run $location_var_stack[_destintation].push($location_var[_destintation])>>
		<<set $location_var[_destintation] to []>>
	<</if>>

	<<for _i = 1; _i < 10; _i++>>
		<<set $location_var[_destintation][(_i-1)] to _args[_i]>>
	<</for>>

	<<if !$hereStack>>
		<<set $hereStack to []>>
	<</if>>
	<<run $hereStack.push($here)>>

	<<run console.log("GS: "+_args[0],$location_var[_destintation],$gt_history)>>

	<<if $gt_history[_ts][_destintation] <= _recursion_limit>>
		<!-- We need to use _args[0] here because we can't rely on _destination not being changed in subpassages -->
		<<set $here = _destintation>>
		<<set $ARGS = $location_var[$here]>>
		<<if Story.has(_args[0]+'_before')>>
			<<include `_args[0]+'_before'`>>
		<</if>>
		
		<<include _args[0]>>

		<<if Story.has(_args[0]+'_after')>>
			<<include `_args[0]+'_after'`>>
		<</if>>
	<<else>>
		<<run console.error('RECURSION LIMIT REACHED',_destintation,$gt_history)>>
	<</if>>

	<<if _terminateGS>>
		<!-- There was a GT somewhere in the include. Let's not fuck up the vars. Just reset everything the GT doesn't need -->
		<<set $hereStack to []>>
		<<set $location_var_stack = {}>>
	<<else>>
		<<set _destintation = _args[0]>>

		<<if $location_var_stack and $location_var_stack[_destintation] and $location_var_stack[_destintation].length > 0>>
			<<set $location_var[_destintation] = $location_var_stack[_destintation].pop()>>
		<<else>>
			<<set $location_var[_destintation] = null>>
		<</if>>

		<<set $here to $hereStack.pop()>>
		<<set $ARGS to $location_var[$here]>>
	<</if>>
	<<set $callStackIndent -= 1>>
<</widget>>
