gs.tw 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. :: MacroGS[widget]
  2. <<widget 'gs'>>
  3. <<set _recursion_limit = 50>>
  4. <<set _destintation = _args[0]>>
  5. <<if !$gt_history>>
  6. <<set $gt_history to {}>>
  7. <</if>>
  8. <<set _ts to Math.floor(Date.now() / 10000)>>
  9. <<if !$gt_history[_ts]>>
  10. <<set $gt_history[_ts] to {}>>
  11. <</if>>
  12. <<if !$gt_history[_ts][_destintation]>>
  13. <<set $gt_history[_ts][_destintation] to 0>>
  14. <</if>>
  15. <<set $gt_history[_ts][_destintation] += 1>>
  16. <<set _temp_history to {}>>
  17. <<for _time,_history range $gt_history>>
  18. <<if _time > _ts - 10>>
  19. <<set _temp_history[_time] = _history>>
  20. <</if>>
  21. <</for>>
  22. <<set $gt_history to _temp_history>>
  23. <<if !$location_var>>
  24. <<set $location_var to {}>>
  25. <</if>>
  26. <<if !$location_var[_destintation]>>
  27. <<set $location_var[_destintation] to []>>
  28. <<else>>
  29. <<if !$location_var_stack>>
  30. <<set $location_var_stack = {}>>
  31. <</if>>
  32. <<if !$location_var_stack[_destintation]>>
  33. <<set $location_var_stack[_destintation] = []>>
  34. <</if>>
  35. <<run $location_var_stack[_destintation].push($location_var[_destintation])>>
  36. <<set $location_var[_destintation] to []>>
  37. <</if>>
  38. <<for _i = 1; _i < 10; _i++>>
  39. <<set $location_var[_destintation][(_i-1)] to _args[_i]>>
  40. <</for>>
  41. <<if !$hereStack>>
  42. <<set $hereStack to []>>
  43. <</if>>
  44. <<run $hereStack.push($here)>>
  45. <<run console.log("GS: "+_args[0],$location_var[_destintation],$gt_history)>>
  46. <<if $gt_history[_ts][_destintation] <= _recursion_limit>>
  47. <!-- We need to use _args[0] here because we can't rely on _destination not being changed in subpassages -->
  48. <<set $here = _destintation>>
  49. <<set $ARGS = $location_var[$here]>>
  50. <<if Story.has(_args[0]+'_before')>>
  51. <<include `_args[0]+'_before'`>>
  52. <</if>>
  53. <<include _args[0]>>
  54. <<if Story.has(_args[0]+'_after')>>
  55. <<include `_args[0]+'_after'`>>
  56. <</if>>
  57. <<else>>
  58. <<run console.error('RECURSION LIMIT REACHED',_destintation,$gt_history)>>
  59. <</if>>
  60. <<if _terminateGS>>
  61. <!-- There was a GT somewhere in the include. Let's not fuck up the vars. Just reset everything the GT doesn't need -->
  62. <<set $hereStack to []>>
  63. <<set $location_var_stack = {}>>
  64. <<else>>
  65. <<set _destintation = _args[0]>>
  66. <<if $location_var_stack and $location_var_stack[_destintation] and $location_var_stack[_destintation].length > 0>>
  67. <<set $location_var[_destintation] = $location_var_stack[_destintation].pop()>>
  68. <<else>>
  69. <<set $location_var[_destintation] = null>>
  70. <</if>>
  71. <<set $here to $hereStack.pop()>>
  72. <<set $ARGS to $location_var[$here]>>
  73. <</if>>
  74. <</widget>>