nucleation 0.2.11 → 0.2.13
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/README.md +90 -0
- package/nucleation-original.js +566 -14
- package/nucleation.d.ts +357 -157
- package/nucleation_bg.wasm +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -81,6 +81,96 @@ schem.setBlock([0, 1, 0], "minecraft:oak_sign", {
|
|
|
81
81
|
});
|
|
82
82
|
```
|
|
83
83
|
|
|
84
|
+
### Storage
|
|
85
|
+
|
|
86
|
+
The `Store` class is pluggable byte storage — it decides *where bytes live*,
|
|
87
|
+
independent of the schematic format. Keys are `/`-delimited UTF-8 paths.
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
import { Store } from "nucleation";
|
|
91
|
+
|
|
92
|
+
const store = new Store("mem://"); // throws on error
|
|
93
|
+
|
|
94
|
+
store.put("schems/base.litematic", out); // (key, data: Uint8Array) -> void
|
|
95
|
+
const data = store.get("schems/base.litematic"); // -> Uint8Array | undefined
|
|
96
|
+
store.has("schems/base.litematic"); // -> boolean
|
|
97
|
+
store.list("schems/"); // -> string[] (keys with this prefix)
|
|
98
|
+
store.delete("schems/base.litematic"); // -> void (idempotent)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
A schematic can read/write a `Store` directly — the format is inferred from the
|
|
102
|
+
key's extension. This is the way to use remote/host storage on the web; it works
|
|
103
|
+
with `mem://` and with `Store.fromCallbacks({ get, put, has, delete, list, health })`.
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
const schem = SchematicWrapper.openFromStore(store, "schems/base.litematic");
|
|
107
|
+
schem.saveToStore(store, "schems/copy.schem"); // format from extension
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
> **Web = `mem://` only.** On `wasm32` the in-memory backend is the only one
|
|
111
|
+
> available — the filesystem, S3, Redis, and Postgres backends are native-only
|
|
112
|
+
> and compiled out of the WASM build. Errors surface as thrown JS exceptions.
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## Diff & Fingerprint
|
|
117
|
+
|
|
118
|
+
Canonically fingerprint a build, dedup near-duplicates, and structurally diff two
|
|
119
|
+
builds — all under an equivalence ruleset chosen by **preset name**:
|
|
120
|
+
|
|
121
|
+
- `"exact"` — material- and orientation-sensitive (identical blockstates only).
|
|
122
|
+
- `"shape"` — occupancy only; palette and orientation ignored.
|
|
123
|
+
- `"structural"` — functional shape, rotation- and material-agnostic.
|
|
124
|
+
- `"redstone_computational"` (alias `"redstone"`) — redstone-logic equivalence,
|
|
125
|
+
rotation- and cosmetic-material-agnostic.
|
|
126
|
+
- `"redstone_survival"` — like `"redstone"`, keeping survival material constraints.
|
|
127
|
+
|
|
128
|
+
`diff()` also takes an optional overrides object with per-edit cost weights and a
|
|
129
|
+
symmetry group: `{ cost_add?, cost_delete?, cost_change?, cost_swap?, symmetry? }`.
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
import { SchematicWrapper } from "nucleation";
|
|
133
|
+
|
|
134
|
+
const a = new SchematicWrapper();
|
|
135
|
+
a.from_litematic(aBytes);
|
|
136
|
+
const b = new SchematicWrapper();
|
|
137
|
+
b.from_litematic(bBytes);
|
|
138
|
+
|
|
139
|
+
// 32-hex canonical hash (rotation/translation/palette-agnostic per preset).
|
|
140
|
+
console.log(a.fingerprint("structural"));
|
|
141
|
+
|
|
142
|
+
// Cheap exact dedup + fuzzy FFT shape distance (0.0 == same shape).
|
|
143
|
+
if (a.isDuplicateOf(b, "structural")) console.log("duplicate build");
|
|
144
|
+
console.log("footprint distance:", a.footprintDistance(b, "structural"));
|
|
145
|
+
|
|
146
|
+
// Dims + token histogram as JSON.
|
|
147
|
+
console.log(a.signature("structural"));
|
|
148
|
+
|
|
149
|
+
// Structural diff -> DiffWrapper. `preset` defaults to "exact".
|
|
150
|
+
const d = a.diff(b, "redstone");
|
|
151
|
+
console.log("distance:", d.distance);
|
|
152
|
+
// support = fraction of the larger build's cells that aligned (confidence,
|
|
153
|
+
// NOT a similarity %).
|
|
154
|
+
console.log("support:", d.support);
|
|
155
|
+
|
|
156
|
+
// Each delta as its own SchematicWrapper.
|
|
157
|
+
d.added(); d.removed(); d.changed(); d.swapped(); d.markers();
|
|
158
|
+
|
|
159
|
+
// Lossless JSON round-trips via DiffWrapper.fromJson; summaryJson() is compact.
|
|
160
|
+
import { DiffWrapper } from "nucleation";
|
|
161
|
+
const full = d.toJson();
|
|
162
|
+
const restored = DiffWrapper.fromJson(full);
|
|
163
|
+
console.log(d.summaryJson());
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
The glowing-overlay GLB requires a build compiled with the `meshing` feature
|
|
167
|
+
(the published WASM bundle includes it):
|
|
168
|
+
|
|
169
|
+
```ts
|
|
170
|
+
// `afterGlb` is the meshed "after" build (Uint8Array); returns a new GLB.
|
|
171
|
+
const glb = d.toOverlayGlb(afterGlb); // -> Uint8Array
|
|
172
|
+
```
|
|
173
|
+
|
|
84
174
|
---
|
|
85
175
|
|
|
86
176
|
## Documentation
|