nucleation 0.3.0 → 0.3.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.
- package/Brush.d.ts +9 -0
- package/Brush.mjs +17 -0
- package/Palette.d.ts +106 -0
- package/Palette.mjs +334 -0
- package/PaletteBuilder.d.ts +76 -0
- package/PaletteBuilder.mjs +297 -0
- package/index.d.ts +4 -0
- package/index.mjs +4 -0
- package/nucleation.wasm +0 -0
- package/package.json +1 -1
package/Brush.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// generated by diplomat-tool
|
|
2
2
|
import type { InterpolationSpace } from "./InterpolationSpace"
|
|
3
3
|
import type { NucleationError } from "./NucleationError"
|
|
4
|
+
import type { Palette } from "./Palette"
|
|
4
5
|
import type { pointer, codepoint } from "./diplomat-runtime.d.ts";
|
|
5
6
|
|
|
6
7
|
|
|
@@ -50,6 +51,14 @@ export class Brush {
|
|
|
50
51
|
*/
|
|
51
52
|
static pointGradient(positions: Array<number>, colors: Array<number>, falloff: number, space: InterpolationSpace): Brush;
|
|
52
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Use `palette` for this brush's color→block snapping instead of the
|
|
56
|
+
* default all-blocks palette. No-op for `solid` brushes, which place
|
|
57
|
+
* a fixed block state. Set it before filling; the palette is shared,
|
|
58
|
+
* not copied.
|
|
59
|
+
*/
|
|
60
|
+
setPalette(palette: Palette): void;
|
|
61
|
+
|
|
53
62
|
/**
|
|
54
63
|
* Gradient along a parametric curve: `stops` holds the curve parameters in
|
|
55
64
|
* `[0, 1]` and `colors` the matching flat RGB triples
|
package/Brush.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// generated by diplomat-tool
|
|
2
2
|
import { InterpolationSpace } from "./InterpolationSpace.mjs"
|
|
3
3
|
import { NucleationError } from "./NucleationError.mjs"
|
|
4
|
+
import { Palette } from "./Palette.mjs"
|
|
4
5
|
import wasm from "./diplomat-wasm.mjs";
|
|
5
6
|
import * as diplomatRuntime from "./diplomat-runtime.mjs";
|
|
6
7
|
|
|
@@ -166,6 +167,22 @@ export class Brush {
|
|
|
166
167
|
}
|
|
167
168
|
}
|
|
168
169
|
|
|
170
|
+
/**
|
|
171
|
+
* Use `palette` for this brush's color→block snapping instead of the
|
|
172
|
+
* default all-blocks palette. No-op for `solid` brushes, which place
|
|
173
|
+
* a fixed block state. Set it before filling; the palette is shared,
|
|
174
|
+
* not copied.
|
|
175
|
+
*/
|
|
176
|
+
setPalette(palette) {
|
|
177
|
+
wasm.Brush_set_palette(this.ffiValue, palette.ffiValue);
|
|
178
|
+
|
|
179
|
+
try {}
|
|
180
|
+
|
|
181
|
+
finally {
|
|
182
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
169
186
|
/**
|
|
170
187
|
* Gradient along a parametric curve: `stops` holds the curve parameters in
|
|
171
188
|
* `[0, 1]` and `colors` the matching flat RGB triples
|
package/Palette.d.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// generated by diplomat-tool
|
|
2
|
+
import type { NucleationError } from "./NucleationError"
|
|
3
|
+
import type { pointer, codepoint } from "./diplomat-runtime.d.ts";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A set of colored blocks that color/gradient brushes snap their computed
|
|
9
|
+
* colors to (nearest neighbor in Oklab space). Wraps an Arc'd
|
|
10
|
+
* {@link crate::building::BlockPalette}; sharing one palette across many
|
|
11
|
+
* brushes is cheap.
|
|
12
|
+
*/
|
|
13
|
+
export class Palette {
|
|
14
|
+
/** @internal */
|
|
15
|
+
get ffiValue(): pointer;
|
|
16
|
+
/** @internal */
|
|
17
|
+
constructor();
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Every block blockpedia knows a color for (the default palette
|
|
22
|
+
* brushes use when none is set).
|
|
23
|
+
*/
|
|
24
|
+
static all(): Palette;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Only solid blocks: no transparency, gravity, tile entities, or
|
|
28
|
+
* support requirements.
|
|
29
|
+
*/
|
|
30
|
+
static solid(): Palette;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Conservative structural set (full building blocks).
|
|
34
|
+
*/
|
|
35
|
+
static structural(): Palette;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Decorative set: allows stairs/slabs but no tile entities.
|
|
39
|
+
*/
|
|
40
|
+
static decorative(): Palette;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The 16 concrete colors (excludes concrete powder).
|
|
44
|
+
*/
|
|
45
|
+
static concrete(): Palette;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The 16 wool colors.
|
|
49
|
+
*/
|
|
50
|
+
static wool(): Palette;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Terracotta colors (excludes glazed variants).
|
|
54
|
+
*/
|
|
55
|
+
static terracotta(): Palette;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Grayscale-leaning blocks (stones, basalt, deepslate, ...).
|
|
59
|
+
*/
|
|
60
|
+
static grayscale(): Palette;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The planks family — a natural light→dark wood ramp.
|
|
64
|
+
*/
|
|
65
|
+
static wood(): Palette;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* A copy of this palette ordered by perceptual lightness (Oklab L,
|
|
69
|
+
* dark → light). Combined with `block_ids_json`, gives a
|
|
70
|
+
* ready-to-index ramp: `ids[i]` for intensity `i / (len - 1)`.
|
|
71
|
+
*/
|
|
72
|
+
sortedByLightness(): Palette;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* JSON array of exactly `steps` block ids sampling the color
|
|
76
|
+
* gradient from (`r1`,`g1`,`b1`) to (`r2`,`g2`,`b2`) in Oklab
|
|
77
|
+
* space, each step snapped to this palette's closest block. Built
|
|
78
|
+
* for value→block lookups (heatmaps, fractals): index the returned
|
|
79
|
+
* list by `intensity * (steps - 1)`. Entries may repeat on coarse
|
|
80
|
+
* palettes; errors with `NotFound` on an empty palette.
|
|
81
|
+
*/
|
|
82
|
+
gradientIdsJson(r1: number, g1: number, b1: number, r2: number, g2: number, b2: number, steps: number): string;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Custom palette from a JSON array of block ids, e.g.
|
|
86
|
+
* `["minecraft:stone", "minecraft:oak_planks"]`. Ids blockpedia has
|
|
87
|
+
* no color for are silently skipped — check `len` afterwards.
|
|
88
|
+
*/
|
|
89
|
+
static fromBlockIds(idsJson: string): Palette;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Number of blocks in the palette.
|
|
93
|
+
*/
|
|
94
|
+
len(): number;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* The palette's block ids as a JSON array string.
|
|
98
|
+
*/
|
|
99
|
+
blockIdsJson(): string;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* The palette block whose color is closest (Oklab distance) to the
|
|
103
|
+
* given RGB. Errors with `NotFound` on an empty palette.
|
|
104
|
+
*/
|
|
105
|
+
closestBlock(r: number, g: number, b: number): string;
|
|
106
|
+
}
|
package/Palette.mjs
ADDED
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
// generated by diplomat-tool
|
|
2
|
+
import { NucleationError } from "./NucleationError.mjs"
|
|
3
|
+
import wasm from "./diplomat-wasm.mjs";
|
|
4
|
+
import * as diplomatRuntime from "./diplomat-runtime.mjs";
|
|
5
|
+
|
|
6
|
+
const Palette_box_destroy_registry = new FinalizationRegistry((ptr) => {
|
|
7
|
+
wasm.Palette_destroy(ptr);
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A set of colored blocks that color/gradient brushes snap their computed
|
|
12
|
+
* colors to (nearest neighbor in Oklab space). Wraps an Arc'd
|
|
13
|
+
* {@link crate::building::BlockPalette}; sharing one palette across many
|
|
14
|
+
* brushes is cheap.
|
|
15
|
+
*/
|
|
16
|
+
export class Palette {
|
|
17
|
+
// Internal ptr reference:
|
|
18
|
+
#ptr = null;
|
|
19
|
+
|
|
20
|
+
// Lifetimes are only to keep dependencies alive.
|
|
21
|
+
// Since JS won't garbage collect until there are no incoming edges.
|
|
22
|
+
#selfEdge = [];
|
|
23
|
+
|
|
24
|
+
#internalConstructor(symbol, ptr, selfEdge) {
|
|
25
|
+
if (symbol !== diplomatRuntime.internalConstructor) {
|
|
26
|
+
console.error("Palette is an Opaque type. You cannot call its constructor.");
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
this.#ptr = ptr;
|
|
30
|
+
this.#selfEdge = selfEdge;
|
|
31
|
+
|
|
32
|
+
// Are we being borrowed? If not, we can register.
|
|
33
|
+
if (this.#selfEdge.length === 0) {
|
|
34
|
+
Palette_box_destroy_registry.register(this, this.#ptr);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
/** @internal */
|
|
40
|
+
get ffiValue() {
|
|
41
|
+
return this.#ptr;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Every block blockpedia knows a color for (the default palette
|
|
47
|
+
* brushes use when none is set).
|
|
48
|
+
*/
|
|
49
|
+
static all() {
|
|
50
|
+
|
|
51
|
+
const result = wasm.Palette_all();
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
return new Palette(diplomatRuntime.internalConstructor, result, []);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
finally {
|
|
58
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Only solid blocks: no transparency, gravity, tile entities, or
|
|
64
|
+
* support requirements.
|
|
65
|
+
*/
|
|
66
|
+
static solid() {
|
|
67
|
+
|
|
68
|
+
const result = wasm.Palette_solid();
|
|
69
|
+
|
|
70
|
+
try {
|
|
71
|
+
return new Palette(diplomatRuntime.internalConstructor, result, []);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
finally {
|
|
75
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Conservative structural set (full building blocks).
|
|
81
|
+
*/
|
|
82
|
+
static structural() {
|
|
83
|
+
|
|
84
|
+
const result = wasm.Palette_structural();
|
|
85
|
+
|
|
86
|
+
try {
|
|
87
|
+
return new Palette(diplomatRuntime.internalConstructor, result, []);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
finally {
|
|
91
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Decorative set: allows stairs/slabs but no tile entities.
|
|
97
|
+
*/
|
|
98
|
+
static decorative() {
|
|
99
|
+
|
|
100
|
+
const result = wasm.Palette_decorative();
|
|
101
|
+
|
|
102
|
+
try {
|
|
103
|
+
return new Palette(diplomatRuntime.internalConstructor, result, []);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
finally {
|
|
107
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* The 16 concrete colors (excludes concrete powder).
|
|
113
|
+
*/
|
|
114
|
+
static concrete() {
|
|
115
|
+
|
|
116
|
+
const result = wasm.Palette_concrete();
|
|
117
|
+
|
|
118
|
+
try {
|
|
119
|
+
return new Palette(diplomatRuntime.internalConstructor, result, []);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
finally {
|
|
123
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* The 16 wool colors.
|
|
129
|
+
*/
|
|
130
|
+
static wool() {
|
|
131
|
+
|
|
132
|
+
const result = wasm.Palette_wool();
|
|
133
|
+
|
|
134
|
+
try {
|
|
135
|
+
return new Palette(diplomatRuntime.internalConstructor, result, []);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
finally {
|
|
139
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Terracotta colors (excludes glazed variants).
|
|
145
|
+
*/
|
|
146
|
+
static terracotta() {
|
|
147
|
+
|
|
148
|
+
const result = wasm.Palette_terracotta();
|
|
149
|
+
|
|
150
|
+
try {
|
|
151
|
+
return new Palette(diplomatRuntime.internalConstructor, result, []);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
finally {
|
|
155
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Grayscale-leaning blocks (stones, basalt, deepslate, ...).
|
|
161
|
+
*/
|
|
162
|
+
static grayscale() {
|
|
163
|
+
|
|
164
|
+
const result = wasm.Palette_grayscale();
|
|
165
|
+
|
|
166
|
+
try {
|
|
167
|
+
return new Palette(diplomatRuntime.internalConstructor, result, []);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
finally {
|
|
171
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* The planks family — a natural light→dark wood ramp.
|
|
177
|
+
*/
|
|
178
|
+
static wood() {
|
|
179
|
+
|
|
180
|
+
const result = wasm.Palette_wood();
|
|
181
|
+
|
|
182
|
+
try {
|
|
183
|
+
return new Palette(diplomatRuntime.internalConstructor, result, []);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
finally {
|
|
187
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* A copy of this palette ordered by perceptual lightness (Oklab L,
|
|
193
|
+
* dark → light). Combined with `block_ids_json`, gives a
|
|
194
|
+
* ready-to-index ramp: `ids[i]` for intensity `i / (len - 1)`.
|
|
195
|
+
*/
|
|
196
|
+
sortedByLightness() {
|
|
197
|
+
|
|
198
|
+
const result = wasm.Palette_sorted_by_lightness(this.ffiValue);
|
|
199
|
+
|
|
200
|
+
try {
|
|
201
|
+
return new Palette(diplomatRuntime.internalConstructor, result, []);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
finally {
|
|
205
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* JSON array of exactly `steps` block ids sampling the color
|
|
211
|
+
* gradient from (`r1`,`g1`,`b1`) to (`r2`,`g2`,`b2`) in Oklab
|
|
212
|
+
* space, each step snapped to this palette's closest block. Built
|
|
213
|
+
* for value→block lookups (heatmaps, fractals): index the returned
|
|
214
|
+
* list by `intensity * (steps - 1)`. Entries may repeat on coarse
|
|
215
|
+
* palettes; errors with `NotFound` on an empty palette.
|
|
216
|
+
*/
|
|
217
|
+
gradientIdsJson(r1, g1, b1, r2, g2, b2, steps) {
|
|
218
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
219
|
+
|
|
220
|
+
const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
const result = wasm.Palette_gradient_ids_json(diplomatReceive.buffer, this.ffiValue, r1, g1, b1, r2, g2, b2, steps, write.buffer);
|
|
224
|
+
|
|
225
|
+
try {
|
|
226
|
+
if (!diplomatReceive.resultFlag) {
|
|
227
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
228
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
229
|
+
}
|
|
230
|
+
return write.readString8();
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
finally {
|
|
234
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
235
|
+
diplomatReceive.free();
|
|
236
|
+
write.free();
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Custom palette from a JSON array of block ids, e.g.
|
|
242
|
+
* `["minecraft:stone", "minecraft:oak_planks"]`. Ids blockpedia has
|
|
243
|
+
* no color for are silently skipped — check `len` afterwards.
|
|
244
|
+
*/
|
|
245
|
+
static fromBlockIds(idsJson) {
|
|
246
|
+
let functionCleanupArena = new diplomatRuntime.CleanupArena();
|
|
247
|
+
|
|
248
|
+
const idsJsonSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, idsJson)));
|
|
249
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
const result = wasm.Palette_from_block_ids(diplomatReceive.buffer, idsJsonSlice.ptr);
|
|
253
|
+
|
|
254
|
+
try {
|
|
255
|
+
if (!diplomatReceive.resultFlag) {
|
|
256
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
257
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
258
|
+
}
|
|
259
|
+
return new Palette(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
finally {
|
|
263
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
264
|
+
functionCleanupArena.free();
|
|
265
|
+
|
|
266
|
+
diplomatReceive.free();
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Number of blocks in the palette.
|
|
272
|
+
*/
|
|
273
|
+
len() {
|
|
274
|
+
|
|
275
|
+
const result = wasm.Palette_len(this.ffiValue);
|
|
276
|
+
|
|
277
|
+
try {
|
|
278
|
+
return result;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
finally {
|
|
282
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* The palette's block ids as a JSON array string.
|
|
288
|
+
*/
|
|
289
|
+
blockIdsJson() {
|
|
290
|
+
const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
|
|
291
|
+
|
|
292
|
+
wasm.Palette_block_ids_json(this.ffiValue, write.buffer);
|
|
293
|
+
|
|
294
|
+
try {
|
|
295
|
+
return write.readString8();
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
finally {
|
|
299
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
300
|
+
write.free();
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* The palette block whose color is closest (Oklab distance) to the
|
|
306
|
+
* given RGB. Errors with `NotFound` on an empty palette.
|
|
307
|
+
*/
|
|
308
|
+
closestBlock(r, g, b) {
|
|
309
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
310
|
+
|
|
311
|
+
const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
const result = wasm.Palette_closest_block(diplomatReceive.buffer, this.ffiValue, r, g, b, write.buffer);
|
|
315
|
+
|
|
316
|
+
try {
|
|
317
|
+
if (!diplomatReceive.resultFlag) {
|
|
318
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
319
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
320
|
+
}
|
|
321
|
+
return write.readString8();
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
finally {
|
|
325
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
326
|
+
diplomatReceive.free();
|
|
327
|
+
write.free();
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
constructor(symbol, ptr, selfEdge) {
|
|
332
|
+
return this.#internalConstructor(...arguments)
|
|
333
|
+
}
|
|
334
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// generated by diplomat-tool
|
|
2
|
+
import type { NucleationError } from "./NucleationError"
|
|
3
|
+
import type { Palette } from "./Palette"
|
|
4
|
+
import type { pointer, codepoint } from "./diplomat-runtime.d.ts";
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Filter-driven palette construction (wraps
|
|
10
|
+
* {@link crate::building::PaletteBuilder}, which fronts blockpedia's
|
|
11
|
+
* `BlockFilter`). Call flag methods, then `build` — the builder is
|
|
12
|
+
* consumed; further calls error with `AlreadyConsumed`.
|
|
13
|
+
*/
|
|
14
|
+
export class PaletteBuilder {
|
|
15
|
+
/** @internal */
|
|
16
|
+
get ffiValue(): pointer;
|
|
17
|
+
/** @internal */
|
|
18
|
+
constructor();
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A builder matching every colored block (no filters yet).
|
|
23
|
+
*/
|
|
24
|
+
static create(): PaletteBuilder;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Exclude gravity-affected blocks (sand, gravel, ...).
|
|
28
|
+
*/
|
|
29
|
+
excludeFalling(): void;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Exclude blocks with block entities (chests, furnaces, ...).
|
|
33
|
+
*/
|
|
34
|
+
excludeTileEntities(): void;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Keep only full cube blocks (no stairs, slabs, fences, ...).
|
|
38
|
+
*/
|
|
39
|
+
fullBlocksOnly(): void;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Exclude blocks that need supporting blocks (torches, rails, ...).
|
|
43
|
+
*/
|
|
44
|
+
excludeNeedsSupport(): void;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Exclude transparent/translucent blocks (glass, leaves, ...).
|
|
48
|
+
*/
|
|
49
|
+
excludeTransparent(): void;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Exclude light-emitting blocks (glowstone, lanterns, ...).
|
|
53
|
+
*/
|
|
54
|
+
excludeLightSources(): void;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Keep only blocks obtainable in survival.
|
|
58
|
+
*/
|
|
59
|
+
survivalOnly(): void;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Exclude blocks whose id contains `keyword`.
|
|
63
|
+
*/
|
|
64
|
+
excludeKeyword(keyword: string): void;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Keep only blocks whose id contains `keyword` (repeatable; matches
|
|
68
|
+
* any of the included keywords).
|
|
69
|
+
*/
|
|
70
|
+
includeKeyword(keyword: string): void;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Build the palette; consumes the builder.
|
|
74
|
+
*/
|
|
75
|
+
build(): Palette;
|
|
76
|
+
}
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
// generated by diplomat-tool
|
|
2
|
+
import { NucleationError } from "./NucleationError.mjs"
|
|
3
|
+
import { Palette } from "./Palette.mjs"
|
|
4
|
+
import wasm from "./diplomat-wasm.mjs";
|
|
5
|
+
import * as diplomatRuntime from "./diplomat-runtime.mjs";
|
|
6
|
+
|
|
7
|
+
const PaletteBuilder_box_destroy_registry = new FinalizationRegistry((ptr) => {
|
|
8
|
+
wasm.PaletteBuilder_destroy(ptr);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Filter-driven palette construction (wraps
|
|
13
|
+
* {@link crate::building::PaletteBuilder}, which fronts blockpedia's
|
|
14
|
+
* `BlockFilter`). Call flag methods, then `build` — the builder is
|
|
15
|
+
* consumed; further calls error with `AlreadyConsumed`.
|
|
16
|
+
*/
|
|
17
|
+
export class PaletteBuilder {
|
|
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("PaletteBuilder 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
|
+
PaletteBuilder_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
|
+
* A builder matching every colored block (no filters yet).
|
|
48
|
+
*/
|
|
49
|
+
static create() {
|
|
50
|
+
|
|
51
|
+
const result = wasm.PaletteBuilder_create();
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
return new PaletteBuilder(diplomatRuntime.internalConstructor, result, []);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
finally {
|
|
58
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Exclude gravity-affected blocks (sand, gravel, ...).
|
|
64
|
+
*/
|
|
65
|
+
excludeFalling() {
|
|
66
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
const result = wasm.PaletteBuilder_exclude_falling(diplomatReceive.buffer, this.ffiValue);
|
|
70
|
+
|
|
71
|
+
try {
|
|
72
|
+
if (!diplomatReceive.resultFlag) {
|
|
73
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
74
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
finally {
|
|
79
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
80
|
+
diplomatReceive.free();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Exclude blocks with block entities (chests, furnaces, ...).
|
|
86
|
+
*/
|
|
87
|
+
excludeTileEntities() {
|
|
88
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
const result = wasm.PaletteBuilder_exclude_tile_entities(diplomatReceive.buffer, this.ffiValue);
|
|
92
|
+
|
|
93
|
+
try {
|
|
94
|
+
if (!diplomatReceive.resultFlag) {
|
|
95
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
96
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
finally {
|
|
101
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
102
|
+
diplomatReceive.free();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Keep only full cube blocks (no stairs, slabs, fences, ...).
|
|
108
|
+
*/
|
|
109
|
+
fullBlocksOnly() {
|
|
110
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
const result = wasm.PaletteBuilder_full_blocks_only(diplomatReceive.buffer, this.ffiValue);
|
|
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
|
+
}
|
|
121
|
+
|
|
122
|
+
finally {
|
|
123
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
124
|
+
diplomatReceive.free();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Exclude blocks that need supporting blocks (torches, rails, ...).
|
|
130
|
+
*/
|
|
131
|
+
excludeNeedsSupport() {
|
|
132
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
const result = wasm.PaletteBuilder_exclude_needs_support(diplomatReceive.buffer, this.ffiValue);
|
|
136
|
+
|
|
137
|
+
try {
|
|
138
|
+
if (!diplomatReceive.resultFlag) {
|
|
139
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
140
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
finally {
|
|
145
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
146
|
+
diplomatReceive.free();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Exclude transparent/translucent blocks (glass, leaves, ...).
|
|
152
|
+
*/
|
|
153
|
+
excludeTransparent() {
|
|
154
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
const result = wasm.PaletteBuilder_exclude_transparent(diplomatReceive.buffer, this.ffiValue);
|
|
158
|
+
|
|
159
|
+
try {
|
|
160
|
+
if (!diplomatReceive.resultFlag) {
|
|
161
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
162
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
finally {
|
|
167
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
168
|
+
diplomatReceive.free();
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Exclude light-emitting blocks (glowstone, lanterns, ...).
|
|
174
|
+
*/
|
|
175
|
+
excludeLightSources() {
|
|
176
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
const result = wasm.PaletteBuilder_exclude_light_sources(diplomatReceive.buffer, this.ffiValue);
|
|
180
|
+
|
|
181
|
+
try {
|
|
182
|
+
if (!diplomatReceive.resultFlag) {
|
|
183
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
184
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
finally {
|
|
189
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
190
|
+
diplomatReceive.free();
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Keep only blocks obtainable in survival.
|
|
196
|
+
*/
|
|
197
|
+
survivalOnly() {
|
|
198
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
const result = wasm.PaletteBuilder_survival_only(diplomatReceive.buffer, this.ffiValue);
|
|
202
|
+
|
|
203
|
+
try {
|
|
204
|
+
if (!diplomatReceive.resultFlag) {
|
|
205
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
206
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
finally {
|
|
211
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
212
|
+
diplomatReceive.free();
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Exclude blocks whose id contains `keyword`.
|
|
218
|
+
*/
|
|
219
|
+
excludeKeyword(keyword) {
|
|
220
|
+
let functionCleanupArena = new diplomatRuntime.CleanupArena();
|
|
221
|
+
|
|
222
|
+
const keywordSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, keyword)));
|
|
223
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
const result = wasm.PaletteBuilder_exclude_keyword(diplomatReceive.buffer, this.ffiValue, keywordSlice.ptr);
|
|
227
|
+
|
|
228
|
+
try {
|
|
229
|
+
if (!diplomatReceive.resultFlag) {
|
|
230
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
231
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
finally {
|
|
236
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
237
|
+
functionCleanupArena.free();
|
|
238
|
+
|
|
239
|
+
diplomatReceive.free();
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Keep only blocks whose id contains `keyword` (repeatable; matches
|
|
245
|
+
* any of the included keywords).
|
|
246
|
+
*/
|
|
247
|
+
includeKeyword(keyword) {
|
|
248
|
+
let functionCleanupArena = new diplomatRuntime.CleanupArena();
|
|
249
|
+
|
|
250
|
+
const keywordSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, keyword)));
|
|
251
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
const result = wasm.PaletteBuilder_include_keyword(diplomatReceive.buffer, this.ffiValue, keywordSlice.ptr);
|
|
255
|
+
|
|
256
|
+
try {
|
|
257
|
+
if (!diplomatReceive.resultFlag) {
|
|
258
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
259
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
finally {
|
|
264
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
265
|
+
functionCleanupArena.free();
|
|
266
|
+
|
|
267
|
+
diplomatReceive.free();
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Build the palette; consumes the builder.
|
|
273
|
+
*/
|
|
274
|
+
build() {
|
|
275
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
const result = wasm.PaletteBuilder_build(diplomatReceive.buffer, this.ffiValue);
|
|
279
|
+
|
|
280
|
+
try {
|
|
281
|
+
if (!diplomatReceive.resultFlag) {
|
|
282
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
283
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
284
|
+
}
|
|
285
|
+
return new Palette(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
finally {
|
|
289
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
290
|
+
diplomatReceive.free();
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
constructor(symbol, ptr, selfEdge) {
|
|
295
|
+
return this.#internalConstructor(...arguments)
|
|
296
|
+
}
|
|
297
|
+
}
|
package/index.d.ts
CHANGED
|
@@ -22,6 +22,10 @@ export { Brush } from "./Brush"
|
|
|
22
22
|
|
|
23
23
|
export { BuildingTool } from "./BuildingTool"
|
|
24
24
|
|
|
25
|
+
export { Palette } from "./Palette"
|
|
26
|
+
|
|
27
|
+
export { PaletteBuilder } from "./PaletteBuilder"
|
|
28
|
+
|
|
25
29
|
export { Shape } from "./Shape"
|
|
26
30
|
|
|
27
31
|
export { DefinitionRegion } from "./DefinitionRegion"
|
package/index.mjs
CHANGED
|
@@ -20,6 +20,10 @@ export { Brush } from "./Brush.mjs"
|
|
|
20
20
|
|
|
21
21
|
export { BuildingTool } from "./BuildingTool.mjs"
|
|
22
22
|
|
|
23
|
+
export { Palette } from "./Palette.mjs"
|
|
24
|
+
|
|
25
|
+
export { PaletteBuilder } from "./PaletteBuilder.mjs"
|
|
26
|
+
|
|
23
27
|
export { Shape } from "./Shape.mjs"
|
|
24
28
|
|
|
25
29
|
export { DefinitionRegion } from "./DefinitionRegion.mjs"
|
package/nucleation.wasm
CHANGED
|
Binary file
|