a munch adventure
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.
 
 
 
 

232 line
5.6 KiB

  1. "use strict"
  2. let activeModal = null;
  3. const newline = String.fromCharCode(160);
  4. const version = "0.1.3";
  5. let state;
  6. let refreshHook;
  7. const tags = {
  8. "prey": {
  9. name: "Prey",
  10. desc: "You can be eaten in this story"
  11. },
  12. "pred": {
  13. name: "Predator",
  14. desc: "You can eat others in this story"
  15. },
  16. "fatal": {
  17. name: "Fatal Vore",
  18. desc: "Vore may result in death"
  19. },
  20. "non-fatal": {
  21. name: "Non-Fatal Vore",
  22. desc: "Vore may result in endo or other safe outcomes"
  23. },
  24. "soft-digestion": {
  25. name: "Soft Digestion",
  26. desc: "Non-graphic depictions of digestion"
  27. },
  28. "hard-digestion": {
  29. name: "Hard Digestion",
  30. desc: "Gory, gross digestion"
  31. },
  32. "oral-vore": {
  33. name: "Oral Vore",
  34. desc: "The classic"
  35. },
  36. "hard-vore": {
  37. name: "Hard Vore",
  38. desc: "Biting, chewing, and other gory means of consumption"
  39. },
  40. "macro-micro": {
  41. name: "Macro/Micro",
  42. desc: "Characters will have significant size differences"
  43. }
  44. };
  45. function print(lines) {
  46. const bigDiv = document.createElement("div");
  47. ([newline].concat(lines)).forEach(line => {
  48. const log = document.querySelector("#log");
  49. const div = document.createElement("div");
  50. div.innerHTML = line;
  51. bigDiv.appendChild(div);
  52. });
  53. log.appendChild(bigDiv);
  54. log.scrollTop = log.scrollHeight;
  55. }
  56. function printRandom(list) {
  57. let choice = Math.floor(Math.random() * list.length)
  58. print(list[choice])
  59. }
  60. function refresh() {
  61. updateRoom(state);
  62. updateStatDisplay(state.info, "world");
  63. updateStatDisplay(state.player.stats, "player");
  64. updateStatDisplay(state.world[state.player.location].data.stats, "area");
  65. if (refreshHook) {
  66. refreshHook(state)
  67. }
  68. }
  69. function switchModal(to) {
  70. closeModal(activeModal);
  71. openModal(to);
  72. }
  73. function closeModal(modal) {
  74. const div = document.querySelector("#" + modal);
  75. div.classList.remove("modal");
  76. div.classList.add("hidden-modal");
  77. }
  78. function openModal(modal) {
  79. const div = document.querySelector("#" + modal);
  80. div.classList.remove("hidden-modal");
  81. div.classList.add("modal");
  82. activeModal = modal;
  83. }
  84. function returnToStart() {
  85. stopAllSound();
  86. stopAllTimers(state);
  87. setBackgroundColor(0, 0, 0);
  88. log.innerHTML = "";
  89. document.querySelector("#game").classList.remove("scene");
  90. document.querySelector("#game").classList.add("hidden-scene");
  91. document.querySelector("#pick").classList.remove("hidden-scene");
  92. document.querySelector("#pick").classList.add("scene");
  93. }
  94. // set up the game
  95. function init(story) {
  96. state = {
  97. player: {
  98. items: {
  99. keys: [
  100. ]
  101. },
  102. rooms: {
  103. },
  104. flags: {
  105. }
  106. },
  107. };
  108. initWorld(story);
  109. initGame(story);
  110. story.intro.setup();
  111. initGamePostSetup();
  112. refreshHook = story.refresh;
  113. story.intro.intro();
  114. goToRoom(story.intro.start);
  115. }
  116. // set up the load screen
  117. function initStart() {
  118. const versionFields = document.querySelectorAll(".version");
  119. const select = document.querySelector("#game-select");
  120. const options = {};
  121. versionFields.forEach(field => {
  122. field.textContent = "Version: " + version;
  123. });
  124. stories.forEach(story => {
  125. const option = document.createElement("option");
  126. option.value = story.id;
  127. option.textContent = story.info.name;
  128. select.appendChild(option);
  129. options[story.id] = story;
  130. })
  131. select.addEventListener("change", event => {
  132. const holder = document.querySelector("#tags");
  133. holder.innerHTML = "";
  134. const story = stories.filter(s => s.id == [event.target.value])[0];
  135. initAudio(story);
  136. story.preload.forEach(sound => loadAudio(sound));
  137. story.info.tags.forEach(tag => {
  138. const div = document.createElement("div");
  139. div.textContent = tags[tag].name;
  140. div.dataset.tooltip = tags[tag].desc;
  141. div.classList.add("tag");
  142. div.classList.add("tooltip");
  143. holder.appendChild(div);
  144. })
  145. document.querySelector("#description").innerText = story.info.desc;
  146. document.querySelector("#start-button").style.display = "block";
  147. });
  148. const start = document.querySelector("#start-button");
  149. start.addEventListener("click", (event) => {
  150. init(options[select.value]);
  151. document.querySelector("#pick").classList.remove("scene");
  152. document.querySelector("#pick").classList.add("hidden-scene");
  153. document.querySelector("#game").classList.remove("hidden-scene");
  154. document.querySelector("#game").classList.add("scene");
  155. });
  156. const gameMenuButton = document.querySelector("#game-menu-button");
  157. const menuSettings = document.querySelector("#menu-button-settings");
  158. const menuQuit = document.querySelector("#menu-button-quit");
  159. const menuResume = document.querySelector("#menu-button-resume");
  160. const menuSettingsVolume = document.querySelector("#menu-slider-volume");
  161. const menuSettingsClose = document.querySelector("#menu-button-settings-close");
  162. const menuQuitYes = document.querySelector("#menu-button-quit-yes");
  163. const menuQuitNo = document.querySelector("#menu-button-quit-no");
  164. gameMenuButton.addEventListener("click", () => openModal("menu"));
  165. menuSettings.addEventListener("click", () => switchModal("settings"));
  166. menuQuit.addEventListener("click", () => switchModal("quit"));
  167. menuResume.addEventListener("click", () => closeModal("menu"));
  168. menuSettingsVolume.addEventListener("input", () => {
  169. setVolume(parseFloat(menuSettingsVolume.value));
  170. })
  171. menuSettingsClose.addEventListener("click", () => switchModal("menu"));
  172. menuQuitYes.addEventListener("click", () => {
  173. closeModal("quit");
  174. returnToStart();
  175. });
  176. menuQuitNo.addEventListener("click", () => switchModal("menu"));
  177. }
  178. window.addEventListener("load", initStart);