@zaisma/effects 0.0.0-stage → 1.0.1

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 (123) hide show
  1. package/EFFECT-FILES.md +301 -0
  2. package/LICENSE.txt +93 -0
  3. package/README.md +63 -2
  4. package/batches/chunks.js +294 -0
  5. package/batches/marks.js +160 -0
  6. package/batches/ribbons.js +233 -0
  7. package/batches/shared.js +155 -0
  8. package/batches/sprites.js +447 -0
  9. package/batches/warps.js +222 -0
  10. package/budget.js +115 -0
  11. package/debris.js +173 -0
  12. package/emit.js +143 -0
  13. package/flashes.js +113 -0
  14. package/format.js +365 -0
  15. package/index.d.ts +373 -0
  16. package/index.js +1168 -0
  17. package/library/bubbles_rising.json +47 -0
  18. package/library/bullet_impact.json +588 -0
  19. package/library/campfire.json +235 -0
  20. package/library/candle_flame.json +100 -0
  21. package/library/confetti.json +165 -0
  22. package/library/dash_burst.json +73 -0
  23. package/library/debris_glass.json +96 -0
  24. package/library/debris_metal.json +106 -0
  25. package/library/debris_stone.json +106 -0
  26. package/library/debris_wood.json +101 -0
  27. package/library/dust_motes.json +51 -0
  28. package/library/dust_puff.json +49 -0
  29. package/library/electric_sparks.json +175 -0
  30. package/library/embers_drift.json +55 -0
  31. package/library/exhaust_puff.json +62 -0
  32. package/library/explosion_air.json +232 -0
  33. package/library/explosion_large.json +373 -0
  34. package/library/explosion_magic.json +266 -0
  35. package/library/explosion_medium.json +289 -0
  36. package/library/explosion_small.json +289 -0
  37. package/library/explosion_water.json +177 -0
  38. package/library/falling_leaves.json +54 -0
  39. package/library/fire_burst.json +185 -0
  40. package/library/fire_large.json +279 -0
  41. package/library/fireball.json +288 -0
  42. package/library/fireflies.json +51 -0
  43. package/library/firework_burst.json +127 -0
  44. package/library/footstep.json +270 -0
  45. package/library/fountain_spray.json +80 -0
  46. package/library/frost_burst.json +202 -0
  47. package/library/ground_mist.json +50 -0
  48. package/library/ground_slam.json +122 -0
  49. package/library/heat_haze.json +24 -0
  50. package/library/hit_blade.json +150 -0
  51. package/library/hit_block.json +157 -0
  52. package/library/hit_critical.json +293 -0
  53. package/library/hit_heavy.json +211 -0
  54. package/library/hit_light.json +122 -0
  55. package/library/hit_magic.json +114 -0
  56. package/library/impact.json +417 -0
  57. package/library/impact_heavy.json +279 -0
  58. package/library/index.json +464 -0
  59. package/library/jump_puff.json +46 -0
  60. package/library/landing_heavy.json +105 -0
  61. package/library/landing_puff.json +75 -0
  62. package/library/level_up.json +164 -0
  63. package/library/lightning_arc.json +90 -0
  64. package/library/lightning_strike.json +387 -0
  65. package/library/magic_aura.json +127 -0
  66. package/library/magic_bolt.json +107 -0
  67. package/library/magic_bolt_impact.json +181 -0
  68. package/library/magic_cast.json +115 -0
  69. package/library/magic_charge.json +91 -0
  70. package/library/magic_heal.json +123 -0
  71. package/library/magic_shield.json +89 -0
  72. package/library/magic_teleport.json +177 -0
  73. package/library/mark_bullet_hole.json +20 -0
  74. package/library/mark_crack.json +18 -0
  75. package/library/mark_footprint.json +20 -0
  76. package/library/mark_frost.json +18 -0
  77. package/library/mark_puddle.json +18 -0
  78. package/library/mark_scorch.json +18 -0
  79. package/library/mark_slash.json +18 -0
  80. package/library/mark_splat.json +18 -0
  81. package/library/pickup_collect.json +117 -0
  82. package/library/pickup_glow.json +76 -0
  83. package/library/poison_cloud.json +107 -0
  84. package/library/portal.json +328 -0
  85. package/library/shockwave_air.json +71 -0
  86. package/library/shockwave_ground.json +95 -0
  87. package/library/slide_dust.json +48 -0
  88. package/library/smoke_column.json +93 -0
  89. package/library/smoke_puff.json +48 -0
  90. package/library/smoke_screen.json +87 -0
  91. package/library/sparks_burst.json +85 -0
  92. package/library/sparks_fountain.json +93 -0
  93. package/library/sparks_shower.json +89 -0
  94. package/library/splash_large.json +181 -0
  95. package/library/splash_small.json +111 -0
  96. package/library/steam_vent.json +64 -0
  97. package/library/summon_circle.json +494 -0
  98. package/library/swim_splash.json +77 -0
  99. package/library/torch_flame.json +219 -0
  100. package/library/trail_blade.json +39 -0
  101. package/library/trail_blade_fire.json +90 -0
  102. package/library/trail_dash.json +80 -0
  103. package/library/trail_magic.json +94 -0
  104. package/library/trail_projectile.json +31 -0
  105. package/library/trail_smoke.json +125 -0
  106. package/library/warp_pulse.json +22 -0
  107. package/library/warp_ripple.json +23 -0
  108. package/library/water_ripple.json +69 -0
  109. package/library/waterfall_mist.json +95 -0
  110. package/looks.js +162 -0
  111. package/motion.js +145 -0
  112. package/online.d.ts +79 -0
  113. package/online.js +32 -0
  114. package/package.json +69 -4
  115. package/partners.js +255 -0
  116. package/piece.json +415 -0
  117. package/piece.json.js +416 -0
  118. package/server.d.ts +55 -0
  119. package/server.js +26 -0
  120. package/shapes.js +269 -0
  121. package/sync.js +528 -0
  122. package/tables.js +109 -0
  123. package/weather.js +289 -0
package/piece.json.js ADDED
@@ -0,0 +1,416 @@
1
+ // This piece's statement, piece.json, as a module for its own code to read. "zaisma pieces check --fix" writes it: never edit it.
2
+ export default {
3
+ "statement_version_number": 2,
4
+ "name": "@zaisma/effects",
5
+ "title": "Effects",
6
+ "piece_version": "1.0.1",
7
+ "kind": "foundation",
8
+ "standard": "@zaisma/standard",
9
+ "summary": "Spectacle that holds a phone's frame rate, for three.js: thousands of lit particles, hits, explosions, magic, trails, screen warps, marks on surfaces, debris that bounces and weather, in the look a game picks. An effect is a small file an AI writes; 92 come with it. Flashes light the scene, the character and physics bring effects free, and online every player sees the same effect at once.",
10
+ "license": "PolyForm-Shield-1.0.0",
11
+ "entry_path": "index.js",
12
+ "server_entry_path": "server.js",
13
+ "file_paths": [
14
+ "EFFECT-FILES.md",
15
+ "LICENSE.txt",
16
+ "README.md",
17
+ "batches/chunks.js",
18
+ "batches/marks.js",
19
+ "batches/ribbons.js",
20
+ "batches/shared.js",
21
+ "batches/sprites.js",
22
+ "batches/warps.js",
23
+ "budget.js",
24
+ "debris.js",
25
+ "emit.js",
26
+ "flashes.js",
27
+ "format.js",
28
+ "index.d.ts",
29
+ "index.js",
30
+ "library/bubbles_rising.json",
31
+ "library/bullet_impact.json",
32
+ "library/campfire.json",
33
+ "library/candle_flame.json",
34
+ "library/confetti.json",
35
+ "library/dash_burst.json",
36
+ "library/debris_glass.json",
37
+ "library/debris_metal.json",
38
+ "library/debris_stone.json",
39
+ "library/debris_wood.json",
40
+ "library/dust_motes.json",
41
+ "library/dust_puff.json",
42
+ "library/electric_sparks.json",
43
+ "library/embers_drift.json",
44
+ "library/exhaust_puff.json",
45
+ "library/explosion_air.json",
46
+ "library/explosion_large.json",
47
+ "library/explosion_magic.json",
48
+ "library/explosion_medium.json",
49
+ "library/explosion_small.json",
50
+ "library/explosion_water.json",
51
+ "library/falling_leaves.json",
52
+ "library/fire_burst.json",
53
+ "library/fire_large.json",
54
+ "library/fireball.json",
55
+ "library/fireflies.json",
56
+ "library/firework_burst.json",
57
+ "library/footstep.json",
58
+ "library/fountain_spray.json",
59
+ "library/frost_burst.json",
60
+ "library/ground_mist.json",
61
+ "library/ground_slam.json",
62
+ "library/heat_haze.json",
63
+ "library/hit_blade.json",
64
+ "library/hit_block.json",
65
+ "library/hit_critical.json",
66
+ "library/hit_heavy.json",
67
+ "library/hit_light.json",
68
+ "library/hit_magic.json",
69
+ "library/impact.json",
70
+ "library/impact_heavy.json",
71
+ "library/index.json",
72
+ "library/jump_puff.json",
73
+ "library/landing_heavy.json",
74
+ "library/landing_puff.json",
75
+ "library/level_up.json",
76
+ "library/lightning_arc.json",
77
+ "library/lightning_strike.json",
78
+ "library/magic_aura.json",
79
+ "library/magic_bolt.json",
80
+ "library/magic_bolt_impact.json",
81
+ "library/magic_cast.json",
82
+ "library/magic_charge.json",
83
+ "library/magic_heal.json",
84
+ "library/magic_shield.json",
85
+ "library/magic_teleport.json",
86
+ "library/mark_bullet_hole.json",
87
+ "library/mark_crack.json",
88
+ "library/mark_footprint.json",
89
+ "library/mark_frost.json",
90
+ "library/mark_puddle.json",
91
+ "library/mark_scorch.json",
92
+ "library/mark_slash.json",
93
+ "library/mark_splat.json",
94
+ "library/pickup_collect.json",
95
+ "library/pickup_glow.json",
96
+ "library/poison_cloud.json",
97
+ "library/portal.json",
98
+ "library/shockwave_air.json",
99
+ "library/shockwave_ground.json",
100
+ "library/slide_dust.json",
101
+ "library/smoke_column.json",
102
+ "library/smoke_puff.json",
103
+ "library/smoke_screen.json",
104
+ "library/sparks_burst.json",
105
+ "library/sparks_fountain.json",
106
+ "library/sparks_shower.json",
107
+ "library/splash_large.json",
108
+ "library/splash_small.json",
109
+ "library/steam_vent.json",
110
+ "library/summon_circle.json",
111
+ "library/swim_splash.json",
112
+ "library/torch_flame.json",
113
+ "library/trail_blade.json",
114
+ "library/trail_blade_fire.json",
115
+ "library/trail_dash.json",
116
+ "library/trail_magic.json",
117
+ "library/trail_projectile.json",
118
+ "library/trail_smoke.json",
119
+ "library/warp_pulse.json",
120
+ "library/warp_ripple.json",
121
+ "library/water_ripple.json",
122
+ "library/waterfall_mist.json",
123
+ "looks.js",
124
+ "motion.js",
125
+ "online.d.ts",
126
+ "online.js",
127
+ "partners.js",
128
+ "piece.json.js",
129
+ "server.d.ts",
130
+ "server.js",
131
+ "shapes.js",
132
+ "sync.js",
133
+ "tables.js",
134
+ "weather.js"
135
+ ],
136
+ "server_file_paths": [
137
+ "format.js",
138
+ "index.d.ts",
139
+ "online.d.ts",
140
+ "server.d.ts",
141
+ "server.js",
142
+ "sync.js"
143
+ ],
144
+ "needs": [
145
+ {
146
+ "name": "@zaisma/piece",
147
+ "version_range": "^1.0.0",
148
+ "kind": "piece"
149
+ },
150
+ {
151
+ "name": "@zaisma/net",
152
+ "version_range": "^2.0.0",
153
+ "kind": "piece"
154
+ },
155
+ {
156
+ "name": "three",
157
+ "version_range": ">=0.163.0 <1.0.0",
158
+ "kind": "library"
159
+ }
160
+ ],
161
+ "settings": [
162
+ {
163
+ "name": "look",
164
+ "value_kind": "choice",
165
+ "default_value": "cartoon",
166
+ "minimum_number": null,
167
+ "maximum_number": null,
168
+ "maximum_character_count": null,
169
+ "choices": [
170
+ "cartoon",
171
+ "glowing",
172
+ "faceted",
173
+ "realistic",
174
+ "own"
175
+ ],
176
+ "summary": "How every effect is drawn. cartoon: few big shapes with crisp edges and flat tones. glowing: soft light that blooms. faceted: little low-poly solids with flat faces. realistic: textured, lit by the scene, soft where it thins. own: the look the game gave defineOwnLook. The same effect files play in each."
177
+ },
178
+ {
179
+ "name": "quality_level",
180
+ "value_kind": "choice",
181
+ "default_value": "auto",
182
+ "minimum_number": null,
183
+ "maximum_number": null,
184
+ "maximum_character_count": null,
185
+ "choices": [
186
+ "auto",
187
+ "low",
188
+ "medium",
189
+ "high"
190
+ ],
191
+ "summary": "How much the effects draw. low: 2,000 particles, no flash lights, warps or rain shelter. medium: 6,000 particles, two flash lights. high: 20,000 particles, four flash lights, particles darkened inside the sun's shadow. auto follows the lighting piece's quality when the game gave it, and otherwise starts at medium on phones and tablets, high elsewhere, and steps down while frames run slow."
192
+ },
193
+ {
194
+ "name": "particle_budget_pct",
195
+ "value_kind": "number",
196
+ "default_value": 100,
197
+ "minimum_number": 10,
198
+ "maximum_number": 400,
199
+ "maximum_character_count": null,
200
+ "choices": null,
201
+ "summary": "How many particles may be alive at once, against the quality level's own count: 50 halves it for a game whose own scenes are heavy, 200 doubles it for one built on effects."
202
+ },
203
+ {
204
+ "name": "time_scale_pct",
205
+ "value_kind": "number",
206
+ "default_value": 100,
207
+ "minimum_number": 0,
208
+ "maximum_number": 400,
209
+ "maximum_character_count": null,
210
+ "choices": null,
211
+ "summary": "How fast the effects' own time runs against the game's: 30 for slow motion, 0 freezes every effect where it is."
212
+ },
213
+ {
214
+ "name": "flash_lights_enabled",
215
+ "value_kind": "boolean",
216
+ "default_value": true,
217
+ "minimum_number": null,
218
+ "maximum_number": null,
219
+ "maximum_character_count": null,
220
+ "choices": null,
221
+ "summary": "Whether effects with a flash light the scene. Off, they still glow."
222
+ },
223
+ {
224
+ "name": "marks_enabled",
225
+ "value_kind": "boolean",
226
+ "default_value": true,
227
+ "minimum_number": null,
228
+ "maximum_number": null,
229
+ "maximum_character_count": null,
230
+ "choices": null,
231
+ "summary": "Whether effects leave marks on surfaces: scorches, cracks, splats."
232
+ },
233
+ {
234
+ "name": "warps_enabled",
235
+ "value_kind": "boolean",
236
+ "default_value": true,
237
+ "minimum_number": null,
238
+ "maximum_number": null,
239
+ "maximum_character_count": null,
240
+ "choices": null,
241
+ "summary": "Whether effects bend the picture: shockwave ripples, the shimmer over heat. Never drawn at low quality."
242
+ },
243
+ {
244
+ "name": "shakes_enabled",
245
+ "value_kind": "boolean",
246
+ "default_value": true,
247
+ "minimum_number": null,
248
+ "maximum_number": null,
249
+ "maximum_character_count": null,
250
+ "choices": null,
251
+ "summary": "Whether effects shake the camera. A game's own settings screen turns this off for players who ask."
252
+ },
253
+ {
254
+ "name": "rain_pct",
255
+ "value_kind": "number",
256
+ "default_value": 0,
257
+ "minimum_number": 0,
258
+ "maximum_number": 100,
259
+ "maximum_character_count": null,
260
+ "choices": null,
261
+ "summary": "How hard it rains: 0 is dry, 100 a downpour. Rain falls round the camera, leans with the wind, stays out from under roofs and splashes where it lands."
262
+ },
263
+ {
264
+ "name": "snow_pct",
265
+ "value_kind": "number",
266
+ "default_value": 0,
267
+ "minimum_number": 0,
268
+ "maximum_number": 100,
269
+ "maximum_character_count": null,
270
+ "choices": null,
271
+ "summary": "How hard it snows: 0 is none, 100 a blizzard. Snow drifts with the wind and stays out from under roofs."
272
+ },
273
+ {
274
+ "name": "fog_pct",
275
+ "value_kind": "number",
276
+ "default_value": 0,
277
+ "minimum_number": 0,
278
+ "maximum_number": 100,
279
+ "maximum_character_count": null,
280
+ "choices": null,
281
+ "summary": "How much mist drifts over the ground round the camera, carried by the wind: 0 is none, 100 thick banks."
282
+ },
283
+ {
284
+ "name": "wind_speed_m_per_sec",
285
+ "value_kind": "number",
286
+ "default_value": 0,
287
+ "minimum_number": 0,
288
+ "maximum_number": 40,
289
+ "maximum_character_count": null,
290
+ "choices": null,
291
+ "summary": "How fast the wind blows. It carries every particle by as much as its effect says (wind_pct): smoke leans, rain slants, sparks barely notice."
292
+ },
293
+ {
294
+ "name": "wind_direction_deg",
295
+ "value_kind": "number",
296
+ "default_value": 0,
297
+ "minimum_number": 0,
298
+ "maximum_number": 360,
299
+ "maximum_character_count": null,
300
+ "choices": null,
301
+ "summary": "The way the wind blows toward, in degrees counterclockwise seen from above: 0 toward +x, 90 toward -z."
302
+ },
303
+ {
304
+ "name": "wind_gust_pct",
305
+ "value_kind": "number",
306
+ "default_value": 30,
307
+ "minimum_number": 0,
308
+ "maximum_number": 100,
309
+ "maximum_character_count": null,
310
+ "choices": null,
311
+ "summary": "How much the wind swells and eases: 0 is steady, 100 gusts from still to twice its speed."
312
+ },
313
+ {
314
+ "name": "weather_change_duration_sec",
315
+ "value_kind": "number",
316
+ "default_value": 4,
317
+ "minimum_number": 0,
318
+ "maximum_number": 120,
319
+ "maximum_character_count": null,
320
+ "choices": null,
321
+ "summary": "How long the rain, snow, fog and wind take to reach what they're set to, so the weather turns instead of switching."
322
+ },
323
+ {
324
+ "name": "rain_shelter_enabled",
325
+ "value_kind": "boolean",
326
+ "default_value": true,
327
+ "minimum_number": null,
328
+ "maximum_number": null,
329
+ "maximum_character_count": null,
330
+ "choices": null,
331
+ "summary": "Whether rain and snow stay out from under roofs, from a small picture of the level seen from above that's drawn again only when the camera has moved. Off, and at low quality, they fall to ground_height_m everywhere."
332
+ },
333
+ {
334
+ "name": "ground_height_m",
335
+ "value_kind": "number",
336
+ "default_value": 0,
337
+ "minimum_number": -10000,
338
+ "maximum_number": 10000,
339
+ "maximum_character_count": null,
340
+ "choices": null,
341
+ "summary": "The height of the ground, in metres, where the game gave nothing better: where rain lands and chunks bounce without a physics world or a ray test."
342
+ },
343
+ {
344
+ "name": "footstep_effects_enabled",
345
+ "value_kind": "boolean",
346
+ "default_value": true,
347
+ "minimum_number": null,
348
+ "maximum_number": null,
349
+ "maximum_character_count": null,
350
+ "choices": null,
351
+ "summary": "Whether a character's footfalls raise dust (or a splash in water), with the character piece."
352
+ },
353
+ {
354
+ "name": "landing_effects_enabled",
355
+ "value_kind": "boolean",
356
+ "default_value": true,
357
+ "minimum_number": null,
358
+ "maximum_number": null,
359
+ "maximum_character_count": null,
360
+ "choices": null,
361
+ "summary": "Whether a character's jump and landing raise a puff, bigger the harder it lands, with the character piece."
362
+ },
363
+ {
364
+ "name": "impact_effects_enabled",
365
+ "value_kind": "boolean",
366
+ "default_value": true,
367
+ "minimum_number": null,
368
+ "maximum_number": null,
369
+ "maximum_character_count": null,
370
+ "choices": null,
371
+ "summary": "Whether a physics body that hits something throws an impact, bigger the faster it hit, with the physics piece."
372
+ }
373
+ ],
374
+ "hooks": [
375
+ {
376
+ "name": "before_effect",
377
+ "hook_kind": "decision",
378
+ "summary": "Asked before every effect plays, with { effectName, positionM, scalePct, strengthPct, color, surfaceKind, reason }: reason is play, footstep, landing, jump, body_hit, chunk_landed or shared. Answer it with any field changed (another effect for a boss's footsteps, a tint), or null to stop it."
379
+ },
380
+ {
381
+ "name": "effect_started",
382
+ "hook_kind": "event",
383
+ "summary": "Told when an effect starts, with { playId, effectName, positionM, scalePct, strengthPct, surfaceKind, reason }: where a game plays the sound that goes with it."
384
+ },
385
+ {
386
+ "name": "effect_ended",
387
+ "hook_kind": "event",
388
+ "summary": "Told when an effect's last particle is gone, or it was stopped, with { playId, effectName }."
389
+ },
390
+ {
391
+ "name": "surface_kind_at",
392
+ "hook_kind": "decision",
393
+ "summary": "Asked what the surface is where a free effect or an impact lands, with the piece's guess (stone) and { positionM, reason, bodyId }: answer one of the surface kinds (stone, concrete, metal, wood, dirt, gravel, sand, grass, mud, water, snow, ice, glass, carpet, flesh), from the game's own level."
394
+ },
395
+ {
396
+ "name": "shake",
397
+ "hook_kind": "event",
398
+ "summary": "Told when an effect shakes the camera, with { strengthPct, durationSec }, already faded by its distance: for a game with a camera of its own. With the camera piece given, the piece shakes it itself."
399
+ },
400
+ {
401
+ "name": "quality_changed",
402
+ "hook_kind": "event",
403
+ "summary": "Told when the quality level in use changes, with { qualityLevel, reason }: reason is setting, lighting_quality or slow_frames."
404
+ },
405
+ {
406
+ "name": "weather_changed",
407
+ "hook_kind": "event",
408
+ "summary": "Told while the weather turns and when it settles, with { rainPct, snowPct, fogPct, windSpeedMPerSec, windDirectionDeg, isSettled }: where a game's sound and sky follow it."
409
+ },
410
+ {
411
+ "name": "effects_thinned",
412
+ "hook_kind": "event",
413
+ "summary": "Told, at most once a second, when the device's budget was spent and effects played thinner or not at all, with { effectName, keptPct }."
414
+ }
415
+ ]
416
+ };
package/server.d.ts ADDED
@@ -0,0 +1,55 @@
1
+ /**
2
+ * @zaisma/effects, on the game server: passes each player's shared effects on, holds every player to a rate, keeps
3
+ * the effects that keep playing and the weather for players who join late, and plays effects of its own for the
4
+ * whole room. Plain game server code with no three.js: the same in Zaisma's rooms, in
5
+ * `npx @zaisma/cli play-locally` and on your own server.
6
+ *
7
+ * @example
8
+ * import { defineNetServer } from "./pieces/@zaisma/net/server.js";
9
+ * import { effectsKind } from "./pieces/@zaisma/effects/server.js";
10
+ * const effects = effectsKind({ beforePlay: (play, { playerId, roomState }) => roomState.casters.includes(playerId) });
11
+ * export default defineNetServer({
12
+ * kinds: [effects],
13
+ * onTick(state, room) {
14
+ * if (state.bombGoesOff) effects.onServer(state, room).play("explosion_large", { positionM: state.bombM });
15
+ * },
16
+ * });
17
+ */
18
+ import type { EffectProblem, SurfaceKind } from "./index.js";
19
+ import type { EffectsKind, EffectsKindOptions } from "./online.js";
20
+
21
+ export { PieceError } from "../piece/index.js";
22
+ export type { EffectsKind, EffectsKindOptions, KeptEffect, ServerEffects, SharedEffects, SharedPlayAt, SharedWeather } from "./online.js";
23
+
24
+ /** A player's play as the game server reads it, before it's passed on. */
25
+ export interface ReceivedPlay {
26
+ effectName: string;
27
+ positionM: { x: number; y: number; z: number };
28
+ direction: { x: number; y: number; z: number } | null;
29
+ normal: { x: number; y: number; z: number } | null;
30
+ toPositionM: { x: number; y: number; z: number } | null;
31
+ /** null where the player's game left it at 100. */
32
+ scalePct: number | null;
33
+ strengthPct: number | null;
34
+ color: string | null;
35
+ surfaceKind: SurfaceKind | null;
36
+ seedNumber: number;
37
+ /** When it started, on the room's clock. */
38
+ startedAtMs: number;
39
+ /** A number for an effect the room would keep playing, null for one that plays once. */
40
+ keptId: number | null;
41
+ }
42
+
43
+ export interface ServerEffectsKindOptions extends EffectsKindOptions {
44
+ /** Runs before a player's play is passed on: answer false to refuse it (a spell the player can't cast, a place they aren't near). */
45
+ beforePlay?: (play: ReceivedPlay, from: { playerId: string; roomState: any }) => boolean | void;
46
+ }
47
+
48
+ /** The effects' kind of sync, for defineNetServer's kinds. Throws PieceError "bad_argument", "unknown_argument". */
49
+ export declare function effectsKind(given?: ServerEffectsKindOptions): EffectsKind;
50
+
51
+ /** Checks an effect file: every problem found, none means it plays. */
52
+ export declare function checkEffect(effect: unknown): EffectProblem[];
53
+
54
+ /** How many effects a room keeps playing at once: 64. */
55
+ export declare const MAXIMUM_KEPT_COUNT: number;
package/server.js ADDED
@@ -0,0 +1,26 @@
1
+ // @zaisma/effects, on the game server: passes each player's shared effects on, holds every player to a rate, keeps
2
+ // the effects that keep playing and the weather for players who join late, and plays effects of its own for the
3
+ // whole room. Plain game server code with no three.js: the same in Zaisma's rooms, in
4
+ // `npx @zaisma/cli play-locally` and on your own server.
5
+ //
6
+ // import { defineNetServer } from "@zaisma/net/server.js";
7
+ // import { effectsKind } from "@zaisma/effects/server.js";
8
+ // const effects = effectsKind({ beforePlay: (play, { playerId, roomState }) => roomState.casters.includes(playerId) });
9
+ // export default defineNetServer({ kinds: [effects], onTick(state, room) {
10
+ // effects.onServer(state, room).play("explosion_large", { positionM: { x: 0, y: 0, z: 0 } });
11
+ // } });
12
+ import { defineKind } from "../net/server.js";
13
+ import { effectsKindFrom } from "./sync.js";
14
+
15
+ /**
16
+ * The effects' kind of sync, for defineNetServer's kinds. given: { effectNames, maximumPlaysPerSec, beforePlay }:
17
+ * the first two as the game gives them; beforePlay(play, { playerId, roomState }) answers false to refuse a
18
+ * player's play. Throws PieceError "bad_argument", "unknown_argument".
19
+ */
20
+ export function effectsKind(given) {
21
+ return effectsKindFrom(defineKind, given);
22
+ }
23
+
24
+ export { checkEffect } from "./format.js";
25
+ export { MAXIMUM_KEPT_COUNT } from "./sync.js";
26
+ export { PieceError } from "../piece/index.js";