sci2-ts 0.0.0-stage → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (357) hide show
  1. package/CHANGELOG.md +78 -0
  2. package/LICENSE +21 -0
  3. package/README.md +113 -2
  4. package/apps/viewer/editor.html +43 -0
  5. package/apps/viewer/explore.html +27 -0
  6. package/apps/viewer/index.html +26 -0
  7. package/apps/viewer/package.json +27 -0
  8. package/apps/viewer/play.html +26 -0
  9. package/apps/viewer/plugin.d.ts +18 -0
  10. package/apps/viewer/plugin.js +75 -0
  11. package/apps/viewer/plugin.ts +84 -0
  12. package/apps/viewer/src/adlib.d.ts +20 -0
  13. package/apps/viewer/src/adlib.js +55 -0
  14. package/apps/viewer/src/adlib.ts +62 -0
  15. package/apps/viewer/src/app.d.ts +5 -0
  16. package/apps/viewer/src/app.js +5 -0
  17. package/apps/viewer/src/app.ts +5 -0
  18. package/apps/viewer/src/asset-index.d.ts +22 -0
  19. package/apps/viewer/src/asset-index.js +74 -0
  20. package/apps/viewer/src/asset-index.ts +90 -0
  21. package/apps/viewer/src/audio.d.ts +28 -0
  22. package/apps/viewer/src/audio.js +102 -0
  23. package/apps/viewer/src/audio.ts +110 -0
  24. package/apps/viewer/src/editor-handles.d.ts +63 -0
  25. package/apps/viewer/src/editor-handles.js +332 -0
  26. package/apps/viewer/src/editor-handles.ts +368 -0
  27. package/apps/viewer/src/editor-languages.d.ts +23 -0
  28. package/apps/viewer/src/editor-languages.js +157 -0
  29. package/apps/viewer/src/editor-languages.ts +135 -0
  30. package/apps/viewer/src/editor.css +213 -0
  31. package/apps/viewer/src/editor.d.ts +1 -0
  32. package/apps/viewer/src/editor.js +393 -0
  33. package/apps/viewer/src/editor.ts +412 -0
  34. package/apps/viewer/src/explore/classes.d.ts +7 -0
  35. package/apps/viewer/src/explore/classes.js +63 -0
  36. package/apps/viewer/src/explore/classes.ts +61 -0
  37. package/apps/viewer/src/explore/context.d.ts +33 -0
  38. package/apps/viewer/src/explore/context.js +96 -0
  39. package/apps/viewer/src/explore/context.ts +124 -0
  40. package/apps/viewer/src/explore/explore.css +93 -0
  41. package/apps/viewer/src/explore/explore.d.ts +1 -0
  42. package/apps/viewer/src/explore/explore.js +102 -0
  43. package/apps/viewer/src/explore/explore.ts +104 -0
  44. package/apps/viewer/src/explore/inspect.d.ts +5 -0
  45. package/apps/viewer/src/explore/inspect.js +208 -0
  46. package/apps/viewer/src/explore/inspect.ts +279 -0
  47. package/apps/viewer/src/explore/live.d.ts +22 -0
  48. package/apps/viewer/src/explore/live.js +318 -0
  49. package/apps/viewer/src/explore/live.ts +365 -0
  50. package/apps/viewer/src/explore/map.d.ts +11 -0
  51. package/apps/viewer/src/explore/map.js +182 -0
  52. package/apps/viewer/src/explore/map.ts +193 -0
  53. package/apps/viewer/src/files.d.ts +21 -0
  54. package/apps/viewer/src/files.js +69 -0
  55. package/apps/viewer/src/files.ts +72 -0
  56. package/apps/viewer/src/game-profile.d.ts +19 -0
  57. package/apps/viewer/src/game-profile.js +4 -0
  58. package/apps/viewer/src/game-profile.ts +26 -0
  59. package/apps/viewer/src/main.d.ts +1 -0
  60. package/apps/viewer/src/main.js +473 -0
  61. package/apps/viewer/src/main.ts +527 -0
  62. package/apps/viewer/src/music.d.ts +14 -0
  63. package/apps/viewer/src/music.js +32 -0
  64. package/apps/viewer/src/music.ts +34 -0
  65. package/apps/viewer/src/opl-worklet.d.ts +1 -0
  66. package/apps/viewer/src/opl-worklet.js +47 -0
  67. package/apps/viewer/src/opl-worklet.ts +55 -0
  68. package/apps/viewer/src/overlay.d.ts +31 -0
  69. package/apps/viewer/src/overlay.js +103 -0
  70. package/apps/viewer/src/overlay.ts +123 -0
  71. package/apps/viewer/src/play.css +14 -0
  72. package/apps/viewer/src/play.d.ts +1 -0
  73. package/apps/viewer/src/play.js +179 -0
  74. package/apps/viewer/src/play.ts +177 -0
  75. package/apps/viewer/src/saves.d.ts +10 -0
  76. package/apps/viewer/src/saves.js +50 -0
  77. package/apps/viewer/src/saves.ts +51 -0
  78. package/apps/viewer/src/session.d.ts +91 -0
  79. package/apps/viewer/src/session.js +301 -0
  80. package/apps/viewer/src/session.ts +321 -0
  81. package/apps/viewer/src/sound-preview.d.ts +7 -0
  82. package/apps/viewer/src/sound-preview.js +214 -0
  83. package/apps/viewer/src/sound-preview.ts +228 -0
  84. package/apps/viewer/src/style.css +64 -0
  85. package/apps/viewer/vite.config.ts +25 -0
  86. package/bin/sci-ts.mjs +9 -0
  87. package/lib/994.sc +49 -0
  88. package/lib/995.sc +53 -0
  89. package/lib/996.sc +299 -0
  90. package/lib/997.sc +198 -0
  91. package/lib/998.sc +338 -0
  92. package/lib/999.sc +189 -0
  93. package/lib/resources.d.ts +2 -0
  94. package/lib/resources.js +84 -0
  95. package/lib/resources.ts +88 -0
  96. package/lib/system.sh +62 -0
  97. package/package.json +75 -4
  98. package/packages/content/room.schema.json +267 -0
  99. package/packages/content/src/index.d.ts +3 -0
  100. package/packages/content/src/index.js +3 -0
  101. package/packages/content/src/index.ts +3 -0
  102. package/packages/content/src/room.d.ts +111 -0
  103. package/packages/content/src/room.js +886 -0
  104. package/packages/content/src/room.ts +1011 -0
  105. package/packages/content/src/target.d.ts +80 -0
  106. package/packages/content/src/target.js +1 -0
  107. package/packages/content/src/target.ts +60 -0
  108. package/packages/content/src/yarn.d.ts +90 -0
  109. package/packages/content/src/yarn.js +214 -0
  110. package/packages/content/src/yarn.ts +261 -0
  111. package/packages/sci/src/analysis/game.d.ts +90 -0
  112. package/packages/sci/src/analysis/game.js +221 -0
  113. package/packages/sci/src/analysis/game.ts +305 -0
  114. package/packages/sci/src/analysis/runtime.d.ts +58 -0
  115. package/packages/sci/src/analysis/runtime.js +133 -0
  116. package/packages/sci/src/analysis/runtime.ts +163 -0
  117. package/packages/sci/src/audio/adlib.d.ts +73 -0
  118. package/packages/sci/src/audio/adlib.js +280 -0
  119. package/packages/sci/src/audio/adlib.ts +329 -0
  120. package/packages/sci/src/audio/index.d.ts +43 -0
  121. package/packages/sci/src/audio/index.js +99 -0
  122. package/packages/sci/src/audio/index.ts +122 -0
  123. package/packages/sci/src/audio/midi.d.ts +92 -0
  124. package/packages/sci/src/audio/midi.js +242 -0
  125. package/packages/sci/src/audio/midi.ts +262 -0
  126. package/packages/sci/src/audio/opl2.d.ts +74 -0
  127. package/packages/sci/src/audio/opl2.js +283 -0
  128. package/packages/sci/src/audio/opl2.ts +283 -0
  129. package/packages/sci/src/audio/sol.d.ts +32 -0
  130. package/packages/sci/src/audio/sol.js +81 -0
  131. package/packages/sci/src/audio/sol.ts +100 -0
  132. package/packages/sci/src/audio/write.d.ts +35 -0
  133. package/packages/sci/src/audio/write.js +91 -0
  134. package/packages/sci/src/audio/write.ts +108 -0
  135. package/packages/sci/src/gfx/cel.d.ts +36 -0
  136. package/packages/sci/src/gfx/cel.js +82 -0
  137. package/packages/sci/src/gfx/cel.ts +110 -0
  138. package/packages/sci/src/gfx/palette.d.ts +24 -0
  139. package/packages/sci/src/gfx/palette.js +49 -0
  140. package/packages/sci/src/gfx/palette.ts +56 -0
  141. package/packages/sci/src/gfx/pic-file.d.ts +46 -0
  142. package/packages/sci/src/gfx/pic-file.js +114 -0
  143. package/packages/sci/src/gfx/pic-file.ts +155 -0
  144. package/packages/sci/src/gfx/pic.d.ts +27 -0
  145. package/packages/sci/src/gfx/pic.js +34 -0
  146. package/packages/sci/src/gfx/pic.ts +53 -0
  147. package/packages/sci/src/gfx/quantize.d.ts +42 -0
  148. package/packages/sci/src/gfx/quantize.js +199 -0
  149. package/packages/sci/src/gfx/quantize.ts +218 -0
  150. package/packages/sci/src/gfx/view-file.d.ts +62 -0
  151. package/packages/sci/src/gfx/view-file.js +182 -0
  152. package/packages/sci/src/gfx/view-file.ts +233 -0
  153. package/packages/sci/src/gfx/view.d.ts +28 -0
  154. package/packages/sci/src/gfx/view.js +45 -0
  155. package/packages/sci/src/gfx/view.ts +62 -0
  156. package/packages/sci/src/index.d.ts +38 -0
  157. package/packages/sci/src/index.js +38 -0
  158. package/packages/sci/src/index.ts +38 -0
  159. package/packages/sci/src/motion/pathfinding.d.ts +40 -0
  160. package/packages/sci/src/motion/pathfinding.js +140 -0
  161. package/packages/sci/src/motion/pathfinding.ts +147 -0
  162. package/packages/sci/src/resource/archive.d.ts +16 -0
  163. package/packages/sci/src/resource/archive.js +51 -0
  164. package/packages/sci/src/resource/archive.ts +56 -0
  165. package/packages/sci/src/resource/lzs.d.ts +12 -0
  166. package/packages/sci/src/resource/lzs.js +64 -0
  167. package/packages/sci/src/resource/lzs.ts +66 -0
  168. package/packages/sci/src/resource/manager.d.ts +45 -0
  169. package/packages/sci/src/resource/manager.js +158 -0
  170. package/packages/sci/src/resource/manager.ts +184 -0
  171. package/packages/sci/src/resource/map.d.ts +18 -0
  172. package/packages/sci/src/resource/map.js +34 -0
  173. package/packages/sci/src/resource/map.ts +44 -0
  174. package/packages/sci/src/resource/types.d.ts +37 -0
  175. package/packages/sci/src/resource/types.js +45 -0
  176. package/packages/sci/src/resource/types.ts +57 -0
  177. package/packages/sci/src/script/assembly.d.ts +67 -0
  178. package/packages/sci/src/script/assembly.js +748 -0
  179. package/packages/sci/src/script/assembly.ts +714 -0
  180. package/packages/sci/src/script/compiler.d.ts +75 -0
  181. package/packages/sci/src/script/compiler.js +993 -0
  182. package/packages/sci/src/script/compiler.ts +1040 -0
  183. package/packages/sci/src/script/disasm.d.ts +81 -0
  184. package/packages/sci/src/script/disasm.js +318 -0
  185. package/packages/sci/src/script/disasm.ts +323 -0
  186. package/packages/sci/src/script/kernel-names.d.ts +6 -0
  187. package/packages/sci/src/script/kernel-names.js +165 -0
  188. package/packages/sci/src/script/kernel-names.ts +165 -0
  189. package/packages/sci/src/script/opcodes.d.ts +22 -0
  190. package/packages/sci/src/script/opcodes.js +45 -0
  191. package/packages/sci/src/script/opcodes.ts +72 -0
  192. package/packages/sci/src/script/script.d.ts +56 -0
  193. package/packages/sci/src/script/script.js +63 -0
  194. package/packages/sci/src/script/script.ts +111 -0
  195. package/packages/sci/src/script/sexpr.d.ts +45 -0
  196. package/packages/sci/src/script/sexpr.js +151 -0
  197. package/packages/sci/src/script/sexpr.ts +139 -0
  198. package/packages/sci/src/script/vocab.d.ts +15 -0
  199. package/packages/sci/src/script/vocab.js +44 -0
  200. package/packages/sci/src/script/vocab.ts +48 -0
  201. package/packages/sci/src/script/world.d.ts +25 -0
  202. package/packages/sci/src/script/world.js +65 -0
  203. package/packages/sci/src/script/world.ts +70 -0
  204. package/packages/sci/src/text/font.d.ts +37 -0
  205. package/packages/sci/src/text/font.js +103 -0
  206. package/packages/sci/src/text/font.ts +125 -0
  207. package/packages/sci/src/text/message.d.ts +69 -0
  208. package/packages/sci/src/text/message.js +171 -0
  209. package/packages/sci/src/text/message.ts +205 -0
  210. package/packages/sci/src/vm/kernels/arrays.d.ts +19 -0
  211. package/packages/sci/src/vm/kernels/arrays.js +182 -0
  212. package/packages/sci/src/vm/kernels/arrays.ts +164 -0
  213. package/packages/sci/src/vm/kernels/audio.d.ts +70 -0
  214. package/packages/sci/src/vm/kernels/audio.js +347 -0
  215. package/packages/sci/src/vm/kernels/audio.ts +349 -0
  216. package/packages/sci/src/vm/kernels/core.d.ts +5 -0
  217. package/packages/sci/src/vm/kernels/core.js +87 -0
  218. package/packages/sci/src/vm/kernels/core.ts +91 -0
  219. package/packages/sci/src/vm/kernels/graphics.d.ts +141 -0
  220. package/packages/sci/src/vm/kernels/graphics.js +467 -0
  221. package/packages/sci/src/vm/kernels/graphics.ts +502 -0
  222. package/packages/sci/src/vm/kernels/index.d.ts +8 -0
  223. package/packages/sci/src/vm/kernels/index.js +29 -0
  224. package/packages/sci/src/vm/kernels/index.ts +32 -0
  225. package/packages/sci/src/vm/kernels/lists.d.ts +6 -0
  226. package/packages/sci/src/vm/kernels/lists.js +127 -0
  227. package/packages/sci/src/vm/kernels/lists.ts +111 -0
  228. package/packages/sci/src/vm/kernels/motion.d.ts +7 -0
  229. package/packages/sci/src/vm/kernels/motion.js +204 -0
  230. package/packages/sci/src/vm/kernels/motion.ts +194 -0
  231. package/packages/sci/src/vm/kernels/palette.d.ts +82 -0
  232. package/packages/sci/src/vm/kernels/palette.js +292 -0
  233. package/packages/sci/src/vm/kernels/palette.ts +303 -0
  234. package/packages/sci/src/vm/kernels/saves.d.ts +45 -0
  235. package/packages/sci/src/vm/kernels/saves.js +123 -0
  236. package/packages/sci/src/vm/kernels/saves.ts +149 -0
  237. package/packages/sci/src/vm/kernels/system.d.ts +62 -0
  238. package/packages/sci/src/vm/kernels/system.js +110 -0
  239. package/packages/sci/src/vm/kernels/system.ts +128 -0
  240. package/packages/sci/src/vm/kernels/text.d.ts +13 -0
  241. package/packages/sci/src/vm/kernels/text.js +338 -0
  242. package/packages/sci/src/vm/kernels/text.ts +328 -0
  243. package/packages/sci/src/vm/memory.d.ts +138 -0
  244. package/packages/sci/src/vm/memory.js +168 -0
  245. package/packages/sci/src/vm/memory.ts +266 -0
  246. package/packages/sci/src/vm/replace.d.ts +11 -0
  247. package/packages/sci/src/vm/replace.js +14 -0
  248. package/packages/sci/src/vm/replace.ts +16 -0
  249. package/packages/sci/src/vm/savegame.d.ts +89 -0
  250. package/packages/sci/src/vm/savegame.js +161 -0
  251. package/packages/sci/src/vm/savegame.ts +188 -0
  252. package/packages/sci/src/vm/value.d.ts +17 -0
  253. package/packages/sci/src/vm/value.js +12 -0
  254. package/packages/sci/src/vm/value.ts +25 -0
  255. package/packages/sci/src/vm/vm.d.ts +155 -0
  256. package/packages/sci/src/vm/vm.js +1053 -0
  257. package/packages/sci/src/vm/vm.ts +914 -0
  258. package/tools/adlib-render.d.ts +1 -0
  259. package/tools/adlib-render.js +49 -0
  260. package/tools/adlib-render.ts +42 -0
  261. package/tools/analyze.d.ts +1 -0
  262. package/tools/analyze.js +25 -0
  263. package/tools/analyze.ts +25 -0
  264. package/tools/art/build.d.ts +34 -0
  265. package/tools/art/build.js +175 -0
  266. package/tools/art/build.ts +153 -0
  267. package/tools/art.d.ts +1 -0
  268. package/tools/art.js +31 -0
  269. package/tools/art.ts +29 -0
  270. package/tools/asm.d.ts +1 -0
  271. package/tools/asm.js +61 -0
  272. package/tools/asm.ts +55 -0
  273. package/tools/cli.d.ts +1 -0
  274. package/tools/cli.js +99 -0
  275. package/tools/cli.ts +100 -0
  276. package/tools/editor-server.d.ts +29 -0
  277. package/tools/editor-server.js +162 -0
  278. package/tools/editor-server.ts +176 -0
  279. package/tools/explore.d.ts +1 -0
  280. package/tools/explore.js +305 -0
  281. package/tools/explore.ts +250 -0
  282. package/tools/game/audio.d.ts +19 -0
  283. package/tools/game/audio.js +143 -0
  284. package/tools/game/audio.ts +130 -0
  285. package/tools/game/build.d.ts +46 -0
  286. package/tools/game/build.js +259 -0
  287. package/tools/game/build.ts +283 -0
  288. package/tools/game/defaults.d.ts +26 -0
  289. package/tools/game/defaults.js +82 -0
  290. package/tools/game/defaults.ts +83 -0
  291. package/tools/game/font.d.ts +3 -0
  292. package/tools/game/font.js +124 -0
  293. package/tools/game/font.ts +126 -0
  294. package/tools/game/kit.d.ts +7 -0
  295. package/tools/game/kit.js +7 -0
  296. package/tools/game/kit.ts +10 -0
  297. package/tools/game/new.d.ts +8 -0
  298. package/tools/game/new.js +39 -0
  299. package/tools/game/new.ts +38 -0
  300. package/tools/game/target.d.ts +7 -0
  301. package/tools/game/target.js +41 -0
  302. package/tools/game/target.ts +42 -0
  303. package/tools/game/template/resources.ts.tmpl +43 -0
  304. package/tools/game/template/rooms/1.room.yaml +9 -0
  305. package/tools/game/template/rooms/1.yarn +17 -0
  306. package/tools/game/template/scripts/0.sc +24 -0
  307. package/tools/game.d.ts +1 -0
  308. package/tools/game.js +77 -0
  309. package/tools/game.ts +70 -0
  310. package/tools/mod-build.d.ts +28 -0
  311. package/tools/mod-build.js +173 -0
  312. package/tools/mod-build.ts +179 -0
  313. package/tools/mod-target.d.ts +16 -0
  314. package/tools/mod-target.js +26 -0
  315. package/tools/mod-target.ts +32 -0
  316. package/tools/mod.d.ts +1 -0
  317. package/tools/mod.js +47 -0
  318. package/tools/mod.ts +45 -0
  319. package/tools/msg.d.ts +1 -0
  320. package/tools/msg.js +40 -0
  321. package/tools/msg.ts +36 -0
  322. package/tools/node-files.d.ts +3 -0
  323. package/tools/node-files.js +34 -0
  324. package/tools/node-files.ts +33 -0
  325. package/tools/patches.d.ts +3 -0
  326. package/tools/patches.js +13 -0
  327. package/tools/patches.ts +13 -0
  328. package/tools/pic-build.d.ts +9 -0
  329. package/tools/pic-build.js +26 -0
  330. package/tools/pic-build.ts +27 -0
  331. package/tools/pic.d.ts +1 -0
  332. package/tools/pic.js +64 -0
  333. package/tools/pic.ts +61 -0
  334. package/tools/play.d.ts +1 -0
  335. package/tools/play.js +54 -0
  336. package/tools/play.ts +54 -0
  337. package/tools/png.d.ts +16 -0
  338. package/tools/png.js +124 -0
  339. package/tools/png.ts +123 -0
  340. package/tools/res.d.ts +1 -0
  341. package/tools/res.js +48 -0
  342. package/tools/res.ts +50 -0
  343. package/tools/scenario.d.ts +1 -0
  344. package/tools/scenario.js +74 -0
  345. package/tools/scenario.ts +80 -0
  346. package/tools/site/build.d.ts +8 -0
  347. package/tools/site/build.js +110 -0
  348. package/tools/site/build.ts +116 -0
  349. package/tools/site/markdown.d.ts +11 -0
  350. package/tools/site/markdown.js +88 -0
  351. package/tools/site/markdown.ts +84 -0
  352. package/tools/view-build.d.ts +34 -0
  353. package/tools/view-build.js +47 -0
  354. package/tools/view-build.ts +71 -0
  355. package/tools/view.d.ts +1 -0
  356. package/tools/view.js +54 -0
  357. package/tools/view.ts +52 -0
package/lib/996.sc ADDED
@@ -0,0 +1,299 @@
1
+ ;;; Talk: text on screen, who says it, the lines of message files said one after another,
2
+ ;;; and conversations as menus of topics.
3
+ (script 996)
4
+ (include "system.sh")
5
+
6
+ ;; A box of text over the room: drawn by the interpreter into a bitmap, shown as a screen
7
+ ;; item in the UI plane. Set text (and font, colours, width, x, y), then init.
8
+ (class TextItem of Obj
9
+ (properties
10
+ x 0 y 0 z 0
11
+ view -1 loop 0 cel 0
12
+ priority 100 fixPriority 1
13
+ plane 0
14
+ bitmap 0
15
+ scaleSignal 0 scaleX 128 scaleY 128
16
+ text 0
17
+ font 0
18
+ fore 0
19
+ back 255
20
+ skip 254
21
+ mode 0 ; 0 left, 1 centred
22
+ borderColor 0
23
+ textLeft 0 textTop 0 textRight -1 textBottom -1
24
+ width 200
25
+ height 0)
26
+
27
+ (method (init &tmp r)
28
+ ;; As tall as the text needs, with a 4-pixel margin inside the border.
29
+ (= r (Array ARRAY_NEW 4 0))
30
+ (TextSize r text font (- width 8))
31
+ (= height (+ (Array ARRAY_AT r 3) 9))
32
+ (Array ARRAY_FREE r)
33
+ (= textLeft 4)
34
+ (= textTop 4)
35
+ (= textRight (- width 5))
36
+ (= textBottom (- height 5))
37
+ (= plane uiPlane)
38
+ (= bitmap (CreateTextBitmap 0 width height self))
39
+ (AddScreenItem self))
40
+
41
+ (method (onMe theX theY)
42
+ (return (and (>= theX x) (< theX (+ x width)) (>= theY y) (< theY (+ y height)))))
43
+
44
+ (method (dispose)
45
+ (DeleteScreenItem self)
46
+ (if bitmap (Bitmap 1 bitmap) (= bitmap 0))
47
+ (super dispose:)))
48
+
49
+ ;; Shows a line until it's been there long enough to read, or the player clicks; then
50
+ ;; cues whoever asked. The narrator speaks for no one in particular.
51
+ (class Narrator of Obj
52
+ (properties
53
+ caller 0
54
+ box 0
55
+ until 0 ; the game time it goes
56
+ font 0
57
+ x -1 ; -1: centred
58
+ y 16
59
+ width 220)
60
+
61
+ (method (say txt whoCares)
62
+ (self clear:)
63
+ (if (and talking (!= talking self)) (talking clear:))
64
+ (= caller (if (> argc 1) whoCares else 0))
65
+ (= box
66
+ ((TextItem new:)
67
+ text: txt
68
+ font: font
69
+ width: width
70
+ x: (if (== x -1) (/ (- SCREEN_WIDTH width) 2) else x)
71
+ y: y
72
+ yourself:))
73
+ (box init:)
74
+ (= talking self)
75
+ ;; Two seconds, and more for longer lines.
76
+ (= until (+ gameTime 120 (* 3 (String STRING_LENGTH txt)))))
77
+
78
+ (method (doit)
79
+ (if (and box (>= gameTime until)) (self done:)))
80
+
81
+ ;; A click while a line is up dismisses it (and nothing else).
82
+ (method (handleEvent event)
83
+ (if (and box (== (event type?) EV_MOUSE_DOWN))
84
+ (event claimed: TRUE)
85
+ (self done:)
86
+ (return TRUE))
87
+ (return FALSE))
88
+
89
+ (method (clear)
90
+ (if box (box dispose:) (= box 0))
91
+ (if (== talking self) (= talking 0)))
92
+
93
+ (method (done &tmp c)
94
+ (self clear:)
95
+ (= c caller)
96
+ (= caller 0)
97
+ (if c (c cue:))))
98
+
99
+ ;; Someone with a name: their lines start with it.
100
+ (class Talker of Narrator
101
+ (properties
102
+ line 0)
103
+
104
+ (method (say txt whoCares)
105
+ (if line (String ARRAY_FREE line))
106
+ (= line (String 11 "%s: %s" name txt))
107
+ (super say: line &rest whoCares)))
108
+
109
+ ;; Someone with a portrait: a view whose loop 0 is the bust, loop 1 the mouth (moving while
110
+ ;; they talk) and loop 2 the eyes, every cel the same size and placed at one point (the
111
+ ;; bottom middle). The room's talker hands its parts to init: mouth bust eyes frame, where
112
+ ;; frame is drawn first (the bust). The text goes beside the portrait.
113
+ (class PortraitTalker of Talker
114
+ (properties
115
+ mouth 0 bust 0 eyes 0 frame 0
116
+ priority 150)
117
+
118
+ (method (init theMouth theBust theEyes theFrame)
119
+ (= mouth theMouth)
120
+ (= bust theBust)
121
+ (= eyes theEyes)
122
+ (= frame theFrame))
123
+
124
+ (method (say txt whoCares &tmp portrait)
125
+ (self init:)
126
+ (= portrait (if frame frame else bust))
127
+ (if portrait
128
+ (= x (+ (portrait x?) (/ (CelWide (portrait view?) 0 0) 2) 6))
129
+ (= y (+ (- (portrait y?) (CelHigh (portrait view?) 0 0)) 1))
130
+ (= width (- (- SCREEN_WIDTH x) 8)))
131
+ (super say: txt &rest whoCares)
132
+ (self showPart: frame priority)
133
+ (self showPart: bust priority)
134
+ (self showPart: eyes (+ priority 1))
135
+ (self showPart: mouth (+ priority 1))
136
+ (if mouth (mouth setCycle: Forward)))
137
+
138
+ (method (showPart part pri)
139
+ (if part
140
+ (part init:)
141
+ (part plane: uiPlane setPri: pri)))
142
+
143
+ (method (clear)
144
+ (if frame (frame dispose:))
145
+ (if bust (bust dispose:))
146
+ (if eyes (eyes dispose:))
147
+ (if mouth (mouth dispose:))
148
+ (super clear:)))
149
+
150
+ ;; Says the lines of a message file for a noun, verb and condition, in sequence:
151
+ ;; (messager say: noun verb [cond [seq [caller [module]]]]). Each line goes to its talker.
152
+ ;; Returns whether there was anything to say; cues the caller after the last line.
153
+ (class Messager of Obj
154
+ (properties
155
+ caller 0
156
+ module 0
157
+ noun 0 verb 0 cond 0 seq 0
158
+ buffer 0)
159
+
160
+ (method (say n v c s whoCares mod)
161
+ (= noun n)
162
+ (= verb v)
163
+ (= cond (if (> argc 2) c else 0))
164
+ (= seq (if (and (> argc 3) s) s else 1))
165
+ (= module (if (and (> argc 5) (!= mod -1)) mod else curRoomNum))
166
+ (if (not (Message 2 module noun verb cond seq))
167
+ (return FALSE))
168
+ (= caller (if (> argc 4) whoCares else 0))
169
+ (self sayNext:)
170
+ (return TRUE))
171
+
172
+ (method (sayNext &tmp c talker)
173
+ (if (not buffer) (= buffer (String ARRAY_NEW 400)))
174
+ (if (Message 2 module noun verb cond seq)
175
+ (= talker (Message 0 module noun verb cond seq buffer))
176
+ (++ seq)
177
+ ((self findTalker: talker) say: buffer self)
178
+ else
179
+ (= c caller)
180
+ (= caller 0)
181
+ (if c (c cue:))))
182
+
183
+ ;; Who says lines with this talker number.
184
+ (method (findTalker n)
185
+ (cond
186
+ ((and (== n TALKER_HERO) heroTalker) (return heroTalker))
187
+ ((and (>= n ROOM_TALKERS) curRoom (curRoom respondsTo: #findTalker)) (return (curRoom findTalker: n)))
188
+ (else (return narrator))))
189
+
190
+ (method (cue)
191
+ (self sayNext:)))
192
+
193
+ ;; One choice in a Menu.
194
+ (class MenuItem of TextItem
195
+ (properties
196
+ value 0)
197
+
198
+ (method (dispose)
199
+ ;; Its text was made for it (a literal string is left alone).
200
+ (String ARRAY_FREE text)
201
+ (super dispose:)))
202
+
203
+ ;; Choices in boxes, one under another; the first click on one ends it. While it's open it
204
+ ;; gets every click (it's the `dialog`). The caller hears the choice by `choose: value`.
205
+ (class Menu of Obj
206
+ (properties
207
+ items 0
208
+ caller 0
209
+ y 20
210
+ width 240)
211
+
212
+ (method (add v txt &tmp item)
213
+ (if (not items) (= items (List new:)))
214
+ (= item ((MenuItem new:) value: v text: txt width: width x: (/ (- SCREEN_WIDTH width) 2) y: y yourself:))
215
+ (item init:)
216
+ (+= y (+ (item height?) 2))
217
+ (items add: item)
218
+ (return self))
219
+
220
+ (method (show whoCares)
221
+ (= caller whoCares)
222
+ (= dialog self))
223
+
224
+ (method (handleEvent event &tmp item v c)
225
+ (event claimed: TRUE)
226
+ (if (!= (event type?) EV_MOUSE_DOWN) (return TRUE))
227
+ (= item (items firstTrue: #onMe (event x?) (event y?)))
228
+ (if item
229
+ (= v (item value?))
230
+ (= c caller)
231
+ (self dispose:)
232
+ (c choose: v))
233
+ (return TRUE))
234
+
235
+ (method (dispose)
236
+ (if (== dialog self) (= dialog 0))
237
+ (if items
238
+ (items eachElementDo: #dispose)
239
+ (items dispose:)
240
+ (= items 0))
241
+ (super dispose:)))
242
+
243
+ ;; A conversation with something: talking to it opens a menu of topics, choosing one says
244
+ ;; the answer, and the menu comes back until the player says goodbye.
245
+ ;; (teller init: client modNum sayNoun verb rootNoun)
246
+ ;; Topic n's label is the message rootNoun/verb/n, its answer sayNoun/verb/n. A room can
247
+ ;; leave topics out (showCases: topic offered? ...), or answer one with a script
248
+ ;; (sayMessage, with the topic in iconValue).
249
+ (class Teller of Obj
250
+ (properties
251
+ client 0
252
+ modNum -1
253
+ sayNoun 0
254
+ verb 0
255
+ rootNoun 0
256
+ actionVerb V_TALK
257
+ iconValue 0
258
+ hidden 0) ; topics left out, by number
259
+
260
+ (method (init who mod sn v rn)
261
+ (= client who)
262
+ (= modNum mod)
263
+ (= sayNoun sn)
264
+ (= verb v)
265
+ (= rootNoun rn)
266
+ (client actions: self))
267
+
268
+ (method (handleVerb v)
269
+ (if (== v actionVerb)
270
+ (self showMenu:)
271
+ (return TRUE))
272
+ (return FALSE))
273
+
274
+ (method (showCases first &tmp i)
275
+ (if (not hidden) (= hidden (Array ARRAY_NEW 141 0)))
276
+ (for ((= i 0)) (< i argc) ((+= i 2))
277
+ (Array ARRAY_AT_PUT hidden [first i] (not [first (+ i 1)]))))
278
+
279
+ (method (showMenu &tmp menu topic buf)
280
+ (self showCases:)
281
+ (= menu (Menu new:))
282
+ (for ((= topic 1)) (Message 2 modNum rootNoun verb topic 1) ((++ topic))
283
+ (if (not (and hidden (Array ARRAY_AT hidden topic)))
284
+ (= buf (String ARRAY_NEW 200))
285
+ (Message 0 modNum rootNoun verb topic 1 buf)
286
+ (menu add: topic buf)))
287
+ (menu add: 0 "Goodbye.")
288
+ (menu show: self))
289
+
290
+ (method (choose v)
291
+ (= iconValue v)
292
+ (if v (self sayMessage:)))
293
+
294
+ (method (sayMessage)
295
+ (messager say: sayNoun verb iconValue 0 self modNum))
296
+
297
+ ;; An answer is over: the topics again.
298
+ (method (cue)
299
+ (self showMenu:)))
package/lib/997.sc ADDED
@@ -0,0 +1,198 @@
1
+ ;;; Motion: movers that walk actors, polygons that say where they can walk, and cyclers
2
+ ;;; that animate props.
3
+ (script 997)
4
+ (include "system.sh")
5
+
6
+ ;; Walks its client in a straight line to (x, y), a step (xStep, yStep) every
7
+ ;; moveSpeed cycles. The interpreter does the stepping (InitBresen, DoBresen) and sends
8
+ ;; moveDone on arrival; the client then calls motionCue:, which cues the caller.
9
+ (class Motion of Obj
10
+ (properties
11
+ client 0
12
+ caller 0
13
+ x 0 y 0
14
+ dx 0 dy 0
15
+ b-moveCnt 0 b-i1 0 b-i2 0 b-di 0 b-xAxis 0 b-incr 0
16
+ completed 0)
17
+
18
+ (method (init who toX toY whoCares)
19
+ (= client who)
20
+ (= caller (if (> argc 3) whoCares else 0))
21
+ (= completed FALSE)
22
+ (self setTarget: toX toY))
23
+
24
+ (method (setTarget toX toY)
25
+ (= x toX)
26
+ (= y toY)
27
+ (= b-moveCnt gameTime)
28
+ (client setHeading: (GetAngle (client x?) (client y?) x y))
29
+ (InitBresen self))
30
+
31
+ (method (doit)
32
+ (if (>= (- gameTime b-moveCnt) (client moveSpeed?))
33
+ (= b-moveCnt gameTime)
34
+ (DoBresen self)))
35
+
36
+ (method (moveDone)
37
+ (= completed TRUE))
38
+
39
+ ;; The client is done with this mover: it goes, and the caller hears about it.
40
+ (method (motionCue &tmp c)
41
+ (= c caller)
42
+ (client mover: 0)
43
+ (self dispose:)
44
+ (if c (c cue:))))
45
+
46
+ (class MoveTo of Motion)
47
+
48
+ ;; Walks around the room's obstacles: AvoidPath finds the way, and the mover walks it a
49
+ ;; corner at a time.
50
+ (class PolyPath of Motion
51
+ (properties
52
+ points 0 ; the path: x y pairs, ending in PATH_END
53
+ value 0) ; where in it the next corner is
54
+
55
+ (method (init who toX toY whoCares &tmp polygons)
56
+ (= client who)
57
+ (= caller (if (> argc 3) whoCares else 0))
58
+ (= completed FALSE)
59
+ (= polygons
60
+ (if (and curRoom (curRoom obstacles?))
61
+ ((curRoom obstacles?) elements?)
62
+ else 0))
63
+ (= points (AvoidPath (who x?) (who y?) toX toY polygons))
64
+ ;; The first point is where the client stands.
65
+ (= value 2)
66
+ (self nextPoint:))
67
+
68
+ (method (nextPoint &tmp px py)
69
+ (= px (Array ARRAY_AT points value))
70
+ (= py (Array ARRAY_AT points (+ value 1)))
71
+ (+= value 2)
72
+ (if (== px PATH_END)
73
+ (= completed TRUE)
74
+ else
75
+ (self setTarget: px py)))
76
+
77
+ (method (moveDone)
78
+ (self nextPoint:))
79
+
80
+ (method (dispose)
81
+ (if points (Array ARRAY_FREE points) (= points 0))
82
+ (super dispose:)))
83
+
84
+ ;; An area that limits walking: (poly type: PT_BARRED init: x1 y1 x2 y2 ...).
85
+ (class Polygon of Obj
86
+ (properties
87
+ size 0 ; corners
88
+ points 0 ; x y pairs
89
+ type PT_BARRED
90
+ dynamic 0)
91
+
92
+ (method (init first &tmp i)
93
+ (= size (/ argc 2))
94
+ (= points (Array ARRAY_NEW argc 0))
95
+ (for ((= i 0)) (< i argc) ((++ i))
96
+ (Array ARRAY_AT_PUT points i [first i]))
97
+ (return self))
98
+
99
+ (method (dispose)
100
+ (if points (Array ARRAY_FREE points) (= points 0))
101
+ (super dispose:)))
102
+
103
+ ;; Changes its client's cel every cycleSpeed cycles.
104
+ (class Cycle of Obj
105
+ (properties
106
+ client 0
107
+ caller 0
108
+ cycleDir 1
109
+ cycleCnt 0
110
+ completed 0)
111
+
112
+ (method (init who whoCares)
113
+ (= client who)
114
+ (= caller (if (> argc 1) whoCares else 0))
115
+ (= cycleCnt gameTime)
116
+ (= completed FALSE))
117
+
118
+ ;; The cel to show now: the next one if it's time, else the current one.
119
+ (method (nextCel)
120
+ (if (< (- gameTime cycleCnt) (client cycleSpeed?))
121
+ (return (client cel?)))
122
+ (= cycleCnt gameTime)
123
+ (return (+ (client cel?) cycleDir)))
124
+
125
+ (method (lastCel)
126
+ (return (- (NumCels client) 1)))
127
+
128
+ (method (cycleDone &tmp c)
129
+ (= completed TRUE)
130
+ (= c caller)
131
+ (client cycler: 0)
132
+ (self dispose:)
133
+ (if c (c cue:))))
134
+
135
+ ;; Round and round.
136
+ (class Forward of Cycle
137
+ (method (doit &tmp c)
138
+ (= c (self nextCel:))
139
+ (if (> c (self lastCel:)) (= c 0))
140
+ (client cel: c)))
141
+
142
+ ;; Round and round while the client moves; cel 0 when it stands.
143
+ (class Walk of Forward
144
+ (method (doit)
145
+ (if (client mover?)
146
+ (super doit:)
147
+ else
148
+ (client cel: 0))))
149
+
150
+ ;; To the last cel, then done.
151
+ (class End of Cycle
152
+ (method (doit &tmp c)
153
+ (= c (self nextCel:))
154
+ (if (> c (self lastCel:))
155
+ (self cycleDone:)
156
+ else
157
+ (client cel: c))))
158
+
159
+ ;; Back to cel 0, then done.
160
+ (class Beg of Cycle
161
+ (method (init who)
162
+ (super init: &rest who)
163
+ (= cycleDir -1))
164
+
165
+ (method (doit &tmp c)
166
+ (= c (self nextCel:))
167
+ (if (< c 0)
168
+ (self cycleDone:)
169
+ else
170
+ (client cel: c))))
171
+
172
+ ;; Sizes its client by how far up the screen it stands: frontSize percent at frontY,
173
+ ;; backSize at backY, in between in proportion.
174
+ (class Scaler of Obj
175
+ (properties
176
+ client 0
177
+ frontSize 100 backSize 100
178
+ frontY 190 backY 0)
179
+
180
+ (method (init who fs bs fy by)
181
+ (= client who)
182
+ (= frontSize fs)
183
+ (= backSize bs)
184
+ (= frontY fy)
185
+ (= backY by)
186
+ (self doit:))
187
+
188
+ (method (doit &tmp y pct)
189
+ (= y (client y?))
190
+ (= pct
191
+ (cond
192
+ ((>= y frontY) frontSize)
193
+ ((<= y backY) backSize)
194
+ (else (+ backSize (/ (* (- frontSize backSize) (- y backY)) (- frontY backY))))))
195
+ (client
196
+ scaleX: (/ (* pct 128) 100)
197
+ scaleY: (/ (* pct 128) 100)
198
+ scaleSignal: (| (client scaleSignal?) SCALE_ON))))