nucleation 0.2.18 → 0.3.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 (129) hide show
  1. package/Autostack.d.ts +43 -0
  2. package/Autostack.mjs +134 -0
  3. package/BlockPos.d.ts +28 -0
  4. package/BlockPos.mjs +129 -0
  5. package/BlockState.d.ts +39 -0
  6. package/BlockState.mjs +134 -0
  7. package/Brush.d.ts +68 -0
  8. package/Brush.mjs +220 -0
  9. package/BuildingTool.d.ts +29 -0
  10. package/BuildingTool.mjs +74 -0
  11. package/ChunkMeshResult.d.ts +75 -0
  12. package/ChunkMeshResult.mjs +253 -0
  13. package/CircuitBuilder.d.ts +118 -0
  14. package/CircuitBuilder.mjs +516 -0
  15. package/DefinitionRegion.d.ts +274 -0
  16. package/DefinitionRegion.mjs +973 -0
  17. package/Diff.d.ts +88 -0
  18. package/Diff.mjs +316 -0
  19. package/Dimensions.d.ts +28 -0
  20. package/Dimensions.mjs +129 -0
  21. package/ExecutionMode.d.ts +42 -0
  22. package/ExecutionMode.mjs +127 -0
  23. package/Fingerprint.d.ts +44 -0
  24. package/Fingerprint.mjs +197 -0
  25. package/InterpolationSpace.d.ts +25 -0
  26. package/InterpolationSpace.mjs +73 -0
  27. package/IoLayout.d.ts +26 -0
  28. package/IoLayout.mjs +81 -0
  29. package/IoLayoutBuilder.d.ts +73 -0
  30. package/IoLayoutBuilder.mjs +315 -0
  31. package/IoType.d.ts +41 -0
  32. package/IoType.mjs +125 -0
  33. package/ItemModelConfig.d.ts +65 -0
  34. package/ItemModelConfig.mjs +223 -0
  35. package/ItemModelPackBuilder.d.ts +32 -0
  36. package/ItemModelPackBuilder.mjs +104 -0
  37. package/ItemModelResult.d.ts +72 -0
  38. package/ItemModelResult.mjs +268 -0
  39. package/ItemScale.d.ts +31 -0
  40. package/ItemScale.mjs +132 -0
  41. package/LayoutFunction.d.ts +52 -0
  42. package/LayoutFunction.mjs +159 -0
  43. package/MchprsWorld.d.ts +131 -0
  44. package/MchprsWorld.mjs +423 -0
  45. package/MeshBounds.d.ts +40 -0
  46. package/MeshBounds.mjs +180 -0
  47. package/MeshConfig.d.ts +101 -0
  48. package/MeshConfig.mjs +306 -0
  49. package/MeshJob.d.ts +44 -0
  50. package/MeshJob.mjs +116 -0
  51. package/MeshPhase.d.ts +38 -0
  52. package/MeshPhase.mjs +90 -0
  53. package/MeshProgress.d.ts +32 -0
  54. package/MeshProgress.mjs +133 -0
  55. package/MeshResult.d.ts +60 -0
  56. package/MeshResult.mjs +206 -0
  57. package/MultiMeshResult.d.ts +50 -0
  58. package/MultiMeshResult.mjs +166 -0
  59. package/Nbt.d.ts +50 -0
  60. package/Nbt.mjs +161 -0
  61. package/NucleationError.d.ts +36 -0
  62. package/NucleationError.mjs +104 -0
  63. package/OutputCondition.d.ts +45 -0
  64. package/OutputCondition.mjs +129 -0
  65. package/Palette.d.ts +84 -0
  66. package/Palette.mjs +269 -0
  67. package/PaletteBuilder.d.ts +76 -0
  68. package/PaletteBuilder.mjs +297 -0
  69. package/README.md +28 -197
  70. package/RawMeshExport.d.ts +74 -0
  71. package/RawMeshExport.mjs +243 -0
  72. package/RedstoneGraph.d.ts +58 -0
  73. package/RedstoneGraph.mjs +242 -0
  74. package/RegionBounds.d.ts +41 -0
  75. package/RegionBounds.mjs +181 -0
  76. package/RenderConfig.d.ts +66 -0
  77. package/RenderConfig.mjs +170 -0
  78. package/Renderer.d.ts +35 -0
  79. package/Renderer.mjs +139 -0
  80. package/ResourcePack.d.ts +105 -0
  81. package/ResourcePack.mjs +447 -0
  82. package/ResourcePackList.d.ts +32 -0
  83. package/ResourcePackList.mjs +96 -0
  84. package/Schematic.d.ts +655 -0
  85. package/Schematic.mjs +2647 -0
  86. package/SchematicBuilder.d.ts +103 -0
  87. package/SchematicBuilder.mjs +401 -0
  88. package/SchematicRegions.d.ts +93 -0
  89. package/SchematicRegions.mjs +411 -0
  90. package/Scripting.d.ts +40 -0
  91. package/Scripting.mjs +138 -0
  92. package/Sdf.d.ts +31 -0
  93. package/Sdf.mjs +107 -0
  94. package/Shape.d.ts +108 -0
  95. package/Shape.mjs +336 -0
  96. package/SortStrategy.d.ts +86 -0
  97. package/SortStrategy.mjs +272 -0
  98. package/Store.d.ts +83 -0
  99. package/Store.mjs +369 -0
  100. package/StoreIo.d.ts +71 -0
  101. package/StoreIo.mjs +292 -0
  102. package/TextureAtlas.d.ts +40 -0
  103. package/TextureAtlas.mjs +122 -0
  104. package/TextureInfo.d.ts +34 -0
  105. package/TextureInfo.mjs +148 -0
  106. package/TypedCircuitExecutor.d.ts +101 -0
  107. package/TypedCircuitExecutor.mjs +378 -0
  108. package/Value.d.ts +73 -0
  109. package/Value.mjs +275 -0
  110. package/WorldChunkView.d.ts +63 -0
  111. package/WorldChunkView.mjs +201 -0
  112. package/WorldSink.d.ts +50 -0
  113. package/WorldSink.mjs +177 -0
  114. package/WorldStream.d.ts +45 -0
  115. package/WorldStream.mjs +184 -0
  116. package/diplomat-runtime.d.ts +15 -0
  117. package/diplomat-runtime.mjs +774 -0
  118. package/diplomat-wasm.mjs +52 -0
  119. package/diplomat.config.mjs +6 -0
  120. package/index.d.ts +117 -0
  121. package/index.mjs +120 -0
  122. package/{nucleation_bg.wasm → nucleation.wasm} +0 -0
  123. package/package.json +19 -41
  124. package/LICENSE +0 -21
  125. package/api.js +0 -608
  126. package/nucleation-cdn-loader.js +0 -15
  127. package/nucleation-original.js +0 -8383
  128. package/nucleation.d.ts +0 -2947
  129. package/nucleation.js +0 -36
@@ -0,0 +1,411 @@
1
+ // generated by diplomat-tool
2
+ import { DefinitionRegion } from "./DefinitionRegion.mjs"
3
+ import { NucleationError } from "./NucleationError.mjs"
4
+ import { Schematic } from "./Schematic.mjs"
5
+ import wasm from "./diplomat-wasm.mjs";
6
+ import * as diplomatRuntime from "./diplomat-runtime.mjs";
7
+
8
+ const SchematicRegions_box_destroy_registry = new FinalizationRegistry((ptr) => {
9
+ wasm.SchematicRegions_destroy(ptr);
10
+ });
11
+
12
+ /**
13
+ * Namespace type for the schematic-attached definition-region operations
14
+ * (PORTING rule 12; the `Schematic` opaque lives in another module, so
15
+ * these are statics taking it explicitly, like `Autostack`).
16
+ */
17
+ export class SchematicRegions {
18
+ // Internal ptr reference:
19
+ #ptr = null;
20
+
21
+ // Lifetimes are only to keep dependencies alive.
22
+ // Since JS won't garbage collect until there are no incoming edges.
23
+ #selfEdge = [];
24
+
25
+ #internalConstructor(symbol, ptr, selfEdge) {
26
+ if (symbol !== diplomatRuntime.internalConstructor) {
27
+ console.error("SchematicRegions is an Opaque type. You cannot call its constructor.");
28
+ return;
29
+ }
30
+ this.#ptr = ptr;
31
+ this.#selfEdge = selfEdge;
32
+
33
+ // Are we being borrowed? If not, we can register.
34
+ if (this.#selfEdge.length === 0) {
35
+ SchematicRegions_box_destroy_registry.register(this, this.#ptr);
36
+ }
37
+
38
+ return this;
39
+ }
40
+ /** @internal */
41
+ get ffiValue() {
42
+ return this.#ptr;
43
+ }
44
+
45
+
46
+ /**
47
+ * Insert (or overwrite) `region` under `name`.
48
+ */
49
+ static add(schematic, name, region) {
50
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
51
+
52
+ const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
53
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
54
+
55
+
56
+ const result = wasm.SchematicRegions_add(diplomatReceive.buffer, schematic.ffiValue, nameSlice.ptr, region.ffiValue);
57
+
58
+ try {
59
+ if (!diplomatReceive.resultFlag) {
60
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
61
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
62
+ }
63
+ }
64
+
65
+ finally {
66
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
67
+ functionCleanupArena.free();
68
+
69
+ diplomatReceive.free();
70
+ }
71
+ }
72
+
73
+ /**
74
+ * Overwrite the region stored under `name` (identical to `add` in the
75
+ * old ABI too; kept as a separate method for 1:1 coverage of
76
+ * `schematic_update_region`).
77
+ */
78
+ static update(schematic, name, region) {
79
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
80
+
81
+ const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
82
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
83
+
84
+
85
+ const result = wasm.SchematicRegions_update(diplomatReceive.buffer, schematic.ffiValue, nameSlice.ptr, region.ffiValue);
86
+
87
+ try {
88
+ if (!diplomatReceive.resultFlag) {
89
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
90
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
91
+ }
92
+ }
93
+
94
+ finally {
95
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
96
+ functionCleanupArena.free();
97
+
98
+ diplomatReceive.free();
99
+ }
100
+ }
101
+
102
+ /**
103
+ * A copy of the region stored under `name`. Errors with `NotFound` when
104
+ * absent.
105
+ */
106
+ static get(schematic, name) {
107
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
108
+
109
+ const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
110
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
111
+
112
+
113
+ const result = wasm.SchematicRegions_get(diplomatReceive.buffer, schematic.ffiValue, nameSlice.ptr);
114
+
115
+ try {
116
+ if (!diplomatReceive.resultFlag) {
117
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
118
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
119
+ }
120
+ return new DefinitionRegion(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
121
+ }
122
+
123
+ finally {
124
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
125
+ functionCleanupArena.free();
126
+
127
+ diplomatReceive.free();
128
+ }
129
+ }
130
+
131
+ /**
132
+ * Remove the region stored under `name`. Errors with `NotFound` when
133
+ * absent.
134
+ */
135
+ static remove(schematic, name) {
136
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
137
+
138
+ const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
139
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
140
+
141
+
142
+ const result = wasm.SchematicRegions_remove(diplomatReceive.buffer, schematic.ffiValue, nameSlice.ptr);
143
+
144
+ try {
145
+ if (!diplomatReceive.resultFlag) {
146
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
147
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
148
+ }
149
+ }
150
+
151
+ finally {
152
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
153
+ functionCleanupArena.free();
154
+
155
+ diplomatReceive.free();
156
+ }
157
+ }
158
+
159
+ /**
160
+ * The names of every definition region, written as a JSON array string.
161
+ */
162
+ static namesJson(schematic) {
163
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
164
+
165
+ const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
166
+
167
+
168
+ const result = wasm.SchematicRegions_names_json(diplomatReceive.buffer, schematic.ffiValue, write.buffer);
169
+
170
+ try {
171
+ if (!diplomatReceive.resultFlag) {
172
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
173
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
174
+ }
175
+ return write.readString8();
176
+ }
177
+
178
+ finally {
179
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
180
+ diplomatReceive.free();
181
+ write.free();
182
+ }
183
+ }
184
+
185
+ /**
186
+ * Create an empty region under `name`.
187
+ */
188
+ static create(schematic, name) {
189
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
190
+
191
+ const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
192
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
193
+
194
+
195
+ const result = wasm.SchematicRegions_create(diplomatReceive.buffer, schematic.ffiValue, nameSlice.ptr);
196
+
197
+ try {
198
+ if (!diplomatReceive.resultFlag) {
199
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
200
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
201
+ }
202
+ }
203
+
204
+ finally {
205
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
206
+ functionCleanupArena.free();
207
+
208
+ diplomatReceive.free();
209
+ }
210
+ }
211
+
212
+ /**
213
+ * Create a single-point region under `name`.
214
+ */
215
+ static createFromPoint(schematic, name, x, y, z) {
216
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
217
+
218
+ const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
219
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
220
+
221
+
222
+ const result = wasm.SchematicRegions_create_from_point(diplomatReceive.buffer, schematic.ffiValue, nameSlice.ptr, x, y, z);
223
+
224
+ try {
225
+ if (!diplomatReceive.resultFlag) {
226
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
227
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
228
+ }
229
+ }
230
+
231
+ finally {
232
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
233
+ functionCleanupArena.free();
234
+
235
+ diplomatReceive.free();
236
+ }
237
+ }
238
+
239
+ /**
240
+ * Create a single-box region under `name`.
241
+ */
242
+ static createFromBounds(schematic, name, minX, minY, minZ, maxX, maxY, maxZ) {
243
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
244
+
245
+ const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
246
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
247
+
248
+
249
+ const result = wasm.SchematicRegions_create_from_bounds(diplomatReceive.buffer, schematic.ffiValue, nameSlice.ptr, minX, minY, minZ, maxX, maxY, maxZ);
250
+
251
+ try {
252
+ if (!diplomatReceive.resultFlag) {
253
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
254
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
255
+ }
256
+ }
257
+
258
+ finally {
259
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
260
+ functionCleanupArena.free();
261
+
262
+ diplomatReceive.free();
263
+ }
264
+ }
265
+
266
+ /**
267
+ * Create a single-box region under `name` and return a copy of it.
268
+ */
269
+ static createRegion(schematic, name, minX, minY, minZ, maxX, maxY, maxZ) {
270
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
271
+
272
+ const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
273
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
274
+
275
+
276
+ const result = wasm.SchematicRegions_create_region(diplomatReceive.buffer, schematic.ffiValue, nameSlice.ptr, minX, minY, minZ, maxX, maxY, maxZ);
277
+
278
+ try {
279
+ if (!diplomatReceive.resultFlag) {
280
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
281
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
282
+ }
283
+ return new DefinitionRegion(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
284
+ }
285
+
286
+ finally {
287
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
288
+ functionCleanupArena.free();
289
+
290
+ diplomatReceive.free();
291
+ }
292
+ }
293
+
294
+ /**
295
+ * Add a box to the region stored under `name`. Errors with `NotFound`
296
+ * when absent.
297
+ */
298
+ static addBoundsTo(schematic, name, minX, minY, minZ, maxX, maxY, maxZ) {
299
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
300
+
301
+ const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
302
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
303
+
304
+
305
+ const result = wasm.SchematicRegions_add_bounds_to(diplomatReceive.buffer, schematic.ffiValue, nameSlice.ptr, minX, minY, minZ, maxX, maxY, maxZ);
306
+
307
+ try {
308
+ if (!diplomatReceive.resultFlag) {
309
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
310
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
311
+ }
312
+ }
313
+
314
+ finally {
315
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
316
+ functionCleanupArena.free();
317
+
318
+ diplomatReceive.free();
319
+ }
320
+ }
321
+
322
+ /**
323
+ * Add a point to the region stored under `name`. Errors with `NotFound`
324
+ * when absent.
325
+ */
326
+ static addPointTo(schematic, name, x, y, z) {
327
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
328
+
329
+ const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
330
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
331
+
332
+
333
+ const result = wasm.SchematicRegions_add_point_to(diplomatReceive.buffer, schematic.ffiValue, nameSlice.ptr, x, y, z);
334
+
335
+ try {
336
+ if (!diplomatReceive.resultFlag) {
337
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
338
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
339
+ }
340
+ }
341
+
342
+ finally {
343
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
344
+ functionCleanupArena.free();
345
+
346
+ diplomatReceive.free();
347
+ }
348
+ }
349
+
350
+ /**
351
+ * Set a metadata entry on the region stored under `name`. Errors with
352
+ * `NotFound` when absent.
353
+ */
354
+ static setMetadataOn(schematic, name, key, value) {
355
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
356
+
357
+ const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
358
+ const keySlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, key)));
359
+ const valueSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, value)));
360
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
361
+
362
+
363
+ const result = wasm.SchematicRegions_set_metadata_on(diplomatReceive.buffer, schematic.ffiValue, nameSlice.ptr, keySlice.ptr, valueSlice.ptr);
364
+
365
+ try {
366
+ if (!diplomatReceive.resultFlag) {
367
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
368
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
369
+ }
370
+ }
371
+
372
+ finally {
373
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
374
+ functionCleanupArena.free();
375
+
376
+ diplomatReceive.free();
377
+ }
378
+ }
379
+
380
+ /**
381
+ * Shift the region stored under `name` by (`dx`, `dy`, `dz`). Errors
382
+ * with `NotFound` when absent.
383
+ */
384
+ static shiftRegion(schematic, name, dx, dy, dz) {
385
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
386
+
387
+ const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
388
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
389
+
390
+
391
+ const result = wasm.SchematicRegions_shift_region(diplomatReceive.buffer, schematic.ffiValue, nameSlice.ptr, dx, dy, dz);
392
+
393
+ try {
394
+ if (!diplomatReceive.resultFlag) {
395
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
396
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
397
+ }
398
+ }
399
+
400
+ finally {
401
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
402
+ functionCleanupArena.free();
403
+
404
+ diplomatReceive.free();
405
+ }
406
+ }
407
+
408
+ constructor(symbol, ptr, selfEdge) {
409
+ return this.#internalConstructor(...arguments)
410
+ }
411
+ }
package/Scripting.d.ts ADDED
@@ -0,0 +1,40 @@
1
+ // generated by diplomat-tool
2
+ import type { NucleationError } from "./NucleationError"
3
+ import type { Schematic } from "./Schematic"
4
+ import type { pointer, codepoint } from "./diplomat-runtime.d.ts";
5
+
6
+
7
+
8
+ /**
9
+ * Namespace for the script-runner free functions of the old ABI
10
+ * (`run_lua_script`, `run_js_script`, `run_script`).
11
+ */
12
+ export class Scripting {
13
+ /** @internal */
14
+ get ffiValue(): pointer;
15
+ /** @internal */
16
+ constructor();
17
+
18
+
19
+ /**
20
+ * Run a Lua script file. Returns the schematic the script assigns to
21
+ * `result`; `NotFound` if it produced none, `Parse` if it failed, and
22
+ * `InvalidArgument` when built without the `scripting-lua` feature.
23
+ */
24
+ static runLuaScript(path: string): Schematic;
25
+
26
+ /**
27
+ * Run a JS script file. Returns the schematic the script assigns to
28
+ * `result`; `NotFound` if it produced none, `Parse` if it failed, and
29
+ * `InvalidArgument` when built without the `scripting-js` feature.
30
+ */
31
+ static runJsScript(path: string): Schematic;
32
+
33
+ /**
34
+ * Run a script file, auto-detecting the engine by extension (`.lua` or
35
+ * `.js`). Returns the schematic the script assigns to `result`; `NotFound`
36
+ * if it produced none, `Parse` if it failed (including unsupported
37
+ * extensions).
38
+ */
39
+ static runScript(path: string): Schematic;
40
+ }
package/Scripting.mjs ADDED
@@ -0,0 +1,138 @@
1
+ // generated by diplomat-tool
2
+ import { NucleationError } from "./NucleationError.mjs"
3
+ import { Schematic } from "./Schematic.mjs"
4
+ import wasm from "./diplomat-wasm.mjs";
5
+ import * as diplomatRuntime from "./diplomat-runtime.mjs";
6
+
7
+ const Scripting_box_destroy_registry = new FinalizationRegistry((ptr) => {
8
+ wasm.Scripting_destroy(ptr);
9
+ });
10
+
11
+ /**
12
+ * Namespace for the script-runner free functions of the old ABI
13
+ * (`run_lua_script`, `run_js_script`, `run_script`).
14
+ */
15
+ export class Scripting {
16
+ // Internal ptr reference:
17
+ #ptr = null;
18
+
19
+ // Lifetimes are only to keep dependencies alive.
20
+ // Since JS won't garbage collect until there are no incoming edges.
21
+ #selfEdge = [];
22
+
23
+ #internalConstructor(symbol, ptr, selfEdge) {
24
+ if (symbol !== diplomatRuntime.internalConstructor) {
25
+ console.error("Scripting is an Opaque type. You cannot call its constructor.");
26
+ return;
27
+ }
28
+ this.#ptr = ptr;
29
+ this.#selfEdge = selfEdge;
30
+
31
+ // Are we being borrowed? If not, we can register.
32
+ if (this.#selfEdge.length === 0) {
33
+ Scripting_box_destroy_registry.register(this, this.#ptr);
34
+ }
35
+
36
+ return this;
37
+ }
38
+ /** @internal */
39
+ get ffiValue() {
40
+ return this.#ptr;
41
+ }
42
+
43
+
44
+ /**
45
+ * Run a Lua script file. Returns the schematic the script assigns to
46
+ * `result`; `NotFound` if it produced none, `Parse` if it failed, and
47
+ * `InvalidArgument` when built without the `scripting-lua` feature.
48
+ */
49
+ static runLuaScript(path) {
50
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
51
+
52
+ const pathSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, path)));
53
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
54
+
55
+
56
+ const result = wasm.Scripting_run_lua_script(diplomatReceive.buffer, pathSlice.ptr);
57
+
58
+ try {
59
+ if (!diplomatReceive.resultFlag) {
60
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
61
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
62
+ }
63
+ return new Schematic(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
64
+ }
65
+
66
+ finally {
67
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
68
+ functionCleanupArena.free();
69
+
70
+ diplomatReceive.free();
71
+ }
72
+ }
73
+
74
+ /**
75
+ * Run a JS script file. Returns the schematic the script assigns to
76
+ * `result`; `NotFound` if it produced none, `Parse` if it failed, and
77
+ * `InvalidArgument` when built without the `scripting-js` feature.
78
+ */
79
+ static runJsScript(path) {
80
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
81
+
82
+ const pathSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, path)));
83
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
84
+
85
+
86
+ const result = wasm.Scripting_run_js_script(diplomatReceive.buffer, pathSlice.ptr);
87
+
88
+ try {
89
+ if (!diplomatReceive.resultFlag) {
90
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
91
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
92
+ }
93
+ return new Schematic(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
94
+ }
95
+
96
+ finally {
97
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
98
+ functionCleanupArena.free();
99
+
100
+ diplomatReceive.free();
101
+ }
102
+ }
103
+
104
+ /**
105
+ * Run a script file, auto-detecting the engine by extension (`.lua` or
106
+ * `.js`). Returns the schematic the script assigns to `result`; `NotFound`
107
+ * if it produced none, `Parse` if it failed (including unsupported
108
+ * extensions).
109
+ */
110
+ static runScript(path) {
111
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
112
+
113
+ const pathSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, path)));
114
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
115
+
116
+
117
+ const result = wasm.Scripting_run_script(diplomatReceive.buffer, pathSlice.ptr);
118
+
119
+ try {
120
+ if (!diplomatReceive.resultFlag) {
121
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
122
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
123
+ }
124
+ return new Schematic(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
125
+ }
126
+
127
+ finally {
128
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
129
+ functionCleanupArena.free();
130
+
131
+ diplomatReceive.free();
132
+ }
133
+ }
134
+
135
+ constructor(symbol, ptr, selfEdge) {
136
+ return this.#internalConstructor(...arguments)
137
+ }
138
+ }
package/Sdf.d.ts ADDED
@@ -0,0 +1,31 @@
1
+ // generated by diplomat-tool
2
+ import type { NucleationError } from "./NucleationError"
3
+ import type { Schematic } from "./Schematic"
4
+ import type { pointer, codepoint } from "./diplomat-runtime.d.ts";
5
+
6
+
7
+
8
+ /**
9
+ * Namespace for the SDF free functions of the old ABI (`schematic_from_sdf`,
10
+ * `sdf_eval`).
11
+ */
12
+ export class Sdf {
13
+ /** @internal */
14
+ get ffiValue(): pointer;
15
+ /** @internal */
16
+ constructor();
17
+
18
+
19
+ /**
20
+ * Builds a schematic by sampling an SDF JSON tree with material rules JSON.
21
+ * When `has_bounds` is false the tree's own AABB is used (fails with
22
+ * `InvalidArgument` for unbounded trees) and the `min_*`/`max_*` arguments
23
+ * are ignored.
24
+ */
25
+ static schematicFromSdf(sdfJson: string, rulesJson: string, hasBounds: boolean, minX: number, minY: number, minZ: number, maxX: number, maxY: number, maxZ: number): Schematic;
26
+
27
+ /**
28
+ * Evaluates an SDF JSON tree at a point, returning the signed distance.
29
+ */
30
+ static eval(sdfJson: string, x: number, y: number, z: number): number;
31
+ }