Editor.tw 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. :: editor
  2. <<set _changedFiles = JSON.parse(localStorage.getItem("SweetCube.Modifications") ?? '{}')>>
  3. <div id="editorToolbar">
  4. <<=$editor.passage>>
  5. <<button 'Save'>>
  6. <<run setup.editorSave($editor.passage,setup.editor.getValue())>>
  7. <</button>>
  8. <<button 'Return'>>
  9. <<gt $editor.returnPassage $editor.returnArgs[0]>>
  10. <</button>>
  11. <<set _allPassageNames = Story.lookupWith((p)=>true).map((p)=>p.title)>>
  12. <<autocomplete "_openPassageName" _allPassageNames>>
  13. <<set $editor.passage = _openPassageName>>
  14. <<goto 'editor'>>
  15. <</autocomplete>>
  16. </div>
  17. <div id="editor">
  18. </div>
  19. <div id="commonTasks" class="collapsable collapsed">
  20. <h2>Common Tasks</h2>
  21. <div class="comment">
  22. This is an example of help that could be provided here.
  23. </div>
  24. <h3>Passage Links</h3>
  25. <h4>Goto</h4>
  26. <div>
  27. You use a goto-command to get from one passage to another.
  28. Each goto-command creates a new entry in the history.
  29. The player can navigate between these steps using the arrow-buttons in the Topbar (if this isn't disabled).
  30. This system breaks if goto-commands are chained.
  31. <b>You should therefore avoid executing a goto-commands without user-input!</b>
  32. </div>
  33. <div>
  34. <code>&lt;&lt;goto 'passage2'&gt;&gt;</code><br/>
  35. This is the SugarCube-native way to execute a goto-command. Use it if no arguments have to be sent to the next passage.
  36. </div>
  37. <div>
  38. <code>&lt;&lt;gt 'passage2' 'arg0' 'arg1'&gt;&gt;</code><br/>
  39. This command behaves as it does in QSP: send the user to a passage and set some arguments for the receiving passage.
  40. Not that the <b>arguments are not separated by commas</b>.
  41. </div>
  42. <div>
  43. <code>&lt;&lt;run setup.qsp_gt('passage2' , 'arg0' , 'arg1')&gt;&gt;</code><br/>
  44. This is the syntax you'll find in the auto-translated files.
  45. It provides support for some weird edge cases (mostly concerning dynamic code).
  46. If you don't need that, use one of the two previous approaches.
  47. </div>
  48. </div>
  49. <div id="passageLinks" class="collapsable collapsed">
  50. <h2>Passage Links</h2>
  51. <<set _passageLinks = setup.getPassageLinks($editor.passage)>>
  52. <<for _passageId, _passageLinkArray range _passageLinks>>
  53. <<capture _passageId>>
  54. <div>
  55. <<link _passageId>>
  56. <<set $editor.passage = _passageId>>
  57. <<goto 'editor'>>
  58. <</link>>: <<=_passageLinkArray.length>>x
  59. </div>
  60. <</capture>>
  61. <</for>>
  62. <h2>Links to this passage</h2>
  63. <<set _passageLinksToCurrentPassage = setup.getPassageLinksToPassage($editor.passage)>>
  64. <<for _passageId range _passageLinksToCurrentPassage>>
  65. <<capture _passageId>>
  66. <div>
  67. <<link _passageId>>
  68. <<set $editor.passage = _passageId>>
  69. <<goto 'editor'>>
  70. <</link>>
  71. </div>
  72. <</capture>>
  73. <</for>>
  74. <div class="comment">
  75. These lists might be incomplete. Some connections can not be detected automatically or it isn't efficient to do so.
  76. </div>
  77. </div>
  78. <div id="changedFiles" class="collapsable collapsed">
  79. <h2>Changed Files</h2>
  80. <div class="changedPassages">
  81. <<for _passage, _changes range _changedFiles>>
  82. <<set _diffId = "diff_"+_passage>>
  83. <<capture _passage _changes _diffId>>
  84. <div class="changedPassage">
  85. <h3 class="passageName">_passage</h3>
  86. <<link "Open">>
  87. <<set $editor.passage=_passage>>
  88. <<goto 'editor'>>
  89. <</link>>
  90. <<linkreplace "Diff">>
  91. <<run setup.placeDiffInDom(_passage,window.SweetCube.originalPassageContents[_passage],_changes,"#"+_diffId)>>
  92. <</linkreplace>>
  93. <<link "Delete">>
  94. <<run delete _changedFiles[_passage]>>
  95. <<run localStorage.setItem("SweetCube.Modifications",JSON.stringify(_changedFiles))>>
  96. <<run location.reload()>>
  97. <</link>>
  98. <code @id=_diffId class="diff"></code>
  99. </div>
  100. <</capture>>
  101. <</for>>
  102. </div>
  103. </div>
  104. <<done>>
  105. <<run setup.startEditor('editor',Story.get($editor.passage).text)>>
  106. <<run $(".collapsable > h2:first-of-type").on("click",function() {$(this).parent('.collapsable').toggleClass('collapsed');})>>
  107. <</done>>