You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Scene.svelte 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <main>
  2. {#if showIntro}
  3. <h1>{level.name}</h1>
  4. <div class="story">
  5. <p></p>
  6. {@html level.pages[page]}
  7. <p></p>
  8. </div>
  9. <div class="controls">
  10. {page + 1}/{level.pages.length}
  11. <button on:click={previous} disabled={page == 0}>Back</button>
  12. {#if page < level.pages.length - 1}
  13. <button on:click={next}>Next</button>
  14. {:else}
  15. <button on:click={begin}>Begin</button>
  16. {/if}
  17. <button on:click={begin} disabled={page == level.pages.length - 1}>Skip</button>
  18. </div>
  19. {:else}
  20. <CircuitSim components={components} nodes={nodes} />
  21. {/if}
  22. </main>
  23. <style>
  24. h1 {
  25. margin-bottom: 0px;
  26. text-align: center;
  27. }
  28. .story {
  29. max-width: 800px;
  30. margin: auto;
  31. }
  32. .story p:first-child {
  33. margin: 0px;
  34. }
  35. .controls {
  36. text-align: center;
  37. }
  38. </style>
  39. <script>
  40. export let level;
  41. import CircuitSim from './CircuitSim.svelte';
  42. import * as availableComponents from './circuit-components.js';
  43. let components = level.components.map(name => {
  44. if (availableComponents[name] == null) {
  45. throw new Error(name, "is not a valid component name");
  46. }
  47. return {name, ctor: availableComponents[name]};
  48. });
  49. let nodes = [];
  50. let y = 0;
  51. for (let name of level.inputs) {
  52. let n = new availableComponents.Input(-4, y, name);
  53. n.protected = true;
  54. nodes.push(n);
  55. y += 2;
  56. }
  57. y = 0;
  58. for (let name of level.outputs) {
  59. let n = new availableComponents.Output(4, y, name);
  60. n.protected = true;
  61. nodes.push(n);
  62. y += 2;
  63. }
  64. let page = 0;
  65. let showIntro = true;
  66. function previous() {
  67. if (page > 0) {
  68. page -= 1;
  69. }
  70. }
  71. function next() {
  72. if (page < level.pages.length - 1) {
  73. page += 1;
  74. }
  75. }
  76. function begin() {
  77. showIntro = false;
  78. }
  79. </script>