brs-js 3.1.0 → 3.2.0
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 +212 -86
- package/dist/dist.js +5 -5
- package/dist/dist.js.map +1 -1
- package/dist/dist.mjs +527 -189
- package/dist/dist.mjs.map +1 -1
- package/dist/dist.node.js +5 -5
- package/dist/dist.node.js.map +1 -1
- package/dist/dist.web.js +5 -5
- package/dist/dist.web.js.map +1 -1
- package/dist/src/brdb/brdb.d.ts +4 -3
- package/dist/src/brdb/brdb.d.ts.map +1 -1
- package/dist/src/brdb/index.d.ts +2 -2
- package/dist/src/brdb/index.d.ts.map +1 -1
- package/dist/src/brdb/msgpack.d.ts.map +1 -1
- package/dist/src/brdb/world.d.ts +163 -3
- package/dist/src/brdb/world.d.ts.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/dist.mjs
CHANGED
|
@@ -10398,7 +10398,7 @@ var ca = (e) => ({
|
|
|
10398
10398
|
}, pa = (e) => e.u8(192), ma = (e, t) => e.u8(t ? 195 : 194);
|
|
10399
10399
|
function ha(e, t) {
|
|
10400
10400
|
if (t < 0 || t > 255 || !Number.isInteger(t)) throw RangeError(`brdb: u8 value out of range: ${t}`);
|
|
10401
|
-
t <= 127 || t > 224 || e.u8(
|
|
10401
|
+
t <= 127 || t > 224 || e.u8(208), e.u8(t);
|
|
10402
10402
|
}
|
|
10403
10403
|
function ga(e, t) {
|
|
10404
10404
|
if (fa(t, "uint"), t < 0) throw RangeError(`brdb: uint value negative: ${t}`);
|
|
@@ -12793,7 +12793,7 @@ var ro = class {
|
|
|
12793
12793
|
}
|
|
12794
12794
|
}, ao = class {
|
|
12795
12795
|
constructor() {
|
|
12796
|
-
this.counters = [], this.brickIndices = [], this.trailing = [], this.numComponents = 0;
|
|
12796
|
+
this.counters = [], this.brickIndices = [], this.trailing = [], this.microchipBrickIndices = [], this.microchipGridReferences = [], this.numComponents = 0;
|
|
12797
12797
|
}
|
|
12798
12798
|
add(e, t, n, r) {
|
|
12799
12799
|
let i = this.counters[this.counters.length - 1];
|
|
@@ -12805,6 +12805,9 @@ var ro = class {
|
|
|
12805
12805
|
data: r
|
|
12806
12806
|
}), this.numComponents += 1;
|
|
12807
12807
|
}
|
|
12808
|
+
addMicrochipLink(e, t) {
|
|
12809
|
+
this.microchipBrickIndices.push(e), this.microchipGridReferences.push(t);
|
|
12810
|
+
}
|
|
12808
12811
|
toBytes(e) {
|
|
12809
12812
|
let t = new Ui();
|
|
12810
12813
|
e.writeValue(t, "BRSavedComponentChunkSoA", {
|
|
@@ -12814,15 +12817,55 @@ var ro = class {
|
|
|
12814
12817
|
JointEntityReferences: [],
|
|
12815
12818
|
JointInitialRelativeOffsets: [],
|
|
12816
12819
|
JointInitialRelativeRotations: [],
|
|
12817
|
-
MicrochipBrickIndices:
|
|
12818
|
-
MicrochipBrickGridReferences:
|
|
12820
|
+
MicrochipBrickIndices: this.microchipBrickIndices,
|
|
12821
|
+
MicrochipBrickGridReferences: this.microchipGridReferences
|
|
12819
12822
|
});
|
|
12820
12823
|
for (let n of this.trailing) e.writeValue(t, n.structName, e.fillStruct(n.structName, n.data, ea.get(n.structName)));
|
|
12821
12824
|
return t.toBytes();
|
|
12822
12825
|
}
|
|
12823
12826
|
};
|
|
12824
|
-
function oo(e
|
|
12825
|
-
let
|
|
12827
|
+
function oo(e) {
|
|
12828
|
+
let t = [{
|
|
12829
|
+
guid: aa,
|
|
12830
|
+
name: "PUBLIC",
|
|
12831
|
+
display: "PUBLIC"
|
|
12832
|
+
}];
|
|
12833
|
+
for (let n of e ?? []) t.push({
|
|
12834
|
+
guid: oa(n.id ?? "00000000-0000-0000-0000-000000000000"),
|
|
12835
|
+
name: n.name ?? "Unknown",
|
|
12836
|
+
display: n.display_name ?? n.name ?? "Unknown"
|
|
12837
|
+
});
|
|
12838
|
+
return t;
|
|
12839
|
+
}
|
|
12840
|
+
function so(e, t = {}) {
|
|
12841
|
+
let n = no(e), r = (e.wires ?? []).filter((e) => "component_type" in e.source);
|
|
12842
|
+
return co({
|
|
12843
|
+
description: e.description,
|
|
12844
|
+
authorName: e.author?.name,
|
|
12845
|
+
ownerRows: oo(e.brick_owners),
|
|
12846
|
+
grids: [n],
|
|
12847
|
+
gridIds: [1],
|
|
12848
|
+
entities: [],
|
|
12849
|
+
wires: r.map((e) => ({
|
|
12850
|
+
source: {
|
|
12851
|
+
gridSlot: 0,
|
|
12852
|
+
brickIndex: e.source.brick_index,
|
|
12853
|
+
componentType: e.source.component_type,
|
|
12854
|
+
port: e.source.port
|
|
12855
|
+
},
|
|
12856
|
+
target: {
|
|
12857
|
+
gridSlot: 0,
|
|
12858
|
+
brickIndex: e.target.brick_index,
|
|
12859
|
+
componentType: e.target.component_type,
|
|
12860
|
+
port: e.target.port
|
|
12861
|
+
}
|
|
12862
|
+
})),
|
|
12863
|
+
microchipLinks: [],
|
|
12864
|
+
prefab: null
|
|
12865
|
+
}, t);
|
|
12866
|
+
}
|
|
12867
|
+
function co(e, t = {}) {
|
|
12868
|
+
let n = e.grids.flat(), r = new ro(), i = new ro(), a = new ro();
|
|
12826
12869
|
for (let e of n) r.add(e.materialName), (e.procedural ? a : i).add(e.assetName);
|
|
12827
12870
|
if (r.size > 256) throw Error(`brdb: too many distinct materials (${r.size}); MaterialIndices is u8 (max 256)`);
|
|
12828
12871
|
let o = {
|
|
@@ -12834,193 +12877,487 @@ function oo(e, t = {}) {
|
|
|
12834
12877
|
let e = c.size;
|
|
12835
12878
|
c.add(t.type) === e && l.push($i.get(t.type));
|
|
12836
12879
|
}
|
|
12837
|
-
let u =
|
|
12838
|
-
|
|
12839
|
-
for (let [r, i] of [["source",
|
|
12840
|
-
|
|
12841
|
-
if (!
|
|
12842
|
-
|
|
12880
|
+
let u = new ro();
|
|
12881
|
+
e.wires.forEach((t, n) => {
|
|
12882
|
+
for (let [r, i] of [["source", t.source], ["target", t.target]]) {
|
|
12883
|
+
let t = e.grids[i.gridSlot]?.length ?? 0;
|
|
12884
|
+
if (!Number.isInteger(i.brickIndex) || i.brickIndex < 0 || i.brickIndex >= t) throw Error(`brdb: wires[${n}].${r}: brick_index ${i.brickIndex} out of range`);
|
|
12885
|
+
if (!c.has(i.componentType)) throw Error(`brdb: wires[${n}].${r}: component type '${i.componentType}' is not used by any brick`);
|
|
12886
|
+
u.add(i.port);
|
|
12843
12887
|
}
|
|
12844
12888
|
});
|
|
12845
|
-
let
|
|
12889
|
+
let d = new ro(), f = [];
|
|
12890
|
+
for (let t of e.entities) {
|
|
12891
|
+
let e = d.size;
|
|
12892
|
+
d.add(t.type) === e && f.push(t.className);
|
|
12893
|
+
}
|
|
12894
|
+
let p = Ja.fromData(Ba.BRSavedComponentChunkSoA);
|
|
12846
12895
|
if (c.size > 0) {
|
|
12847
12896
|
let e = [];
|
|
12848
12897
|
for (let t of l) t !== "None" && !e.includes(t) && e.push(t);
|
|
12849
|
-
|
|
12850
|
-
}
|
|
12851
|
-
let
|
|
12852
|
-
|
|
12853
|
-
|
|
12854
|
-
|
|
12855
|
-
|
|
12856
|
-
|
|
12857
|
-
|
|
12858
|
-
|
|
12859
|
-
|
|
12860
|
-
|
|
12861
|
-
|
|
12862
|
-
|
|
12863
|
-
|
|
12864
|
-
|
|
12865
|
-
|
|
12866
|
-
|
|
12867
|
-
|
|
12868
|
-
|
|
12869
|
-
|
|
12870
|
-
|
|
12871
|
-
|
|
12872
|
-
|
|
12873
|
-
|
|
12874
|
-
|
|
12875
|
-
|
|
12876
|
-
|
|
12877
|
-
|
|
12878
|
-
|
|
12879
|
-
|
|
12898
|
+
p.merge(Xa("BRSavedComponentChunkSoA_max").extractStructsTransitive(e));
|
|
12899
|
+
}
|
|
12900
|
+
let m = e.ownerRows, h = m.map(() => 0), g = m.map(() => 0), _ = m.map(() => 0);
|
|
12901
|
+
for (let t of e.entities) _[t.ownerIndex] += 1;
|
|
12902
|
+
let v = e.grids.map((e) => {
|
|
12903
|
+
let t = {
|
|
12904
|
+
chunkOrder: [],
|
|
12905
|
+
chunks: /* @__PURE__ */ new Map(),
|
|
12906
|
+
componentChunks: /* @__PURE__ */ new Map(),
|
|
12907
|
+
brickLocations: [],
|
|
12908
|
+
wireChunks: /* @__PURE__ */ new Map(),
|
|
12909
|
+
chunkWireCounts: /* @__PURE__ */ new Map()
|
|
12910
|
+
};
|
|
12911
|
+
for (let n of e) {
|
|
12912
|
+
let { chunk: e, rel: r } = to(n.position), i = e.join("_"), a = t.chunks.get(i);
|
|
12913
|
+
a || (a = {
|
|
12914
|
+
index: e,
|
|
12915
|
+
builder: new io()
|
|
12916
|
+
}, t.chunks.set(i, a), t.chunkOrder.push(i));
|
|
12917
|
+
let u = a.builder.numBricks;
|
|
12918
|
+
if (a.builder.addBrick(n, r, o, s), t.brickLocations.push({
|
|
12919
|
+
key: i,
|
|
12920
|
+
chunk: e,
|
|
12921
|
+
localIndex: u
|
|
12922
|
+
}), h[n.ownerIndex] += 1, n.components.length > 0) {
|
|
12923
|
+
g[n.ownerIndex] += n.components.length;
|
|
12924
|
+
let e = t.componentChunks.get(i);
|
|
12925
|
+
e || t.componentChunks.set(i, e = new ao());
|
|
12926
|
+
for (let t of n.components) {
|
|
12927
|
+
let n = c.indexOf(t.type);
|
|
12928
|
+
e.add(n, u, l[n], t.data ?? {});
|
|
12929
|
+
}
|
|
12880
12930
|
}
|
|
12881
12931
|
}
|
|
12882
|
-
|
|
12883
|
-
|
|
12884
|
-
for (let
|
|
12885
|
-
let
|
|
12886
|
-
|
|
12887
|
-
|
|
12888
|
-
|
|
12889
|
-
|
|
12890
|
-
|
|
12932
|
+
return t;
|
|
12933
|
+
});
|
|
12934
|
+
for (let t of e.microchipLinks) {
|
|
12935
|
+
let e = v[t.gridSlot], n = e?.brickLocations[t.brickIndex];
|
|
12936
|
+
if (!n) throw Error(`brdb: microchip link brick index ${t.brickIndex} out of range`);
|
|
12937
|
+
let r = e.componentChunks.get(n.key);
|
|
12938
|
+
r || e.componentChunks.set(n.key, r = new ao()), r.addMicrochipLink(n.localIndex, t.gridReference);
|
|
12939
|
+
}
|
|
12940
|
+
for (let t of e.wires) {
|
|
12941
|
+
let n = v[t.source.gridSlot].brickLocations[t.source.brickIndex], r = v[t.target.gridSlot], i = r.brickLocations[t.target.brickIndex], a = {
|
|
12942
|
+
BrickIndexInChunk: i.localIndex,
|
|
12943
|
+
ComponentTypeIndex: c.indexOf(t.target.componentType),
|
|
12944
|
+
PortIndex: u.indexOf(t.target.port)
|
|
12945
|
+
}, o = r.wireChunks.get(i.key);
|
|
12946
|
+
o || r.wireChunks.set(i.key, o = {
|
|
12891
12947
|
remoteSources: [],
|
|
12892
12948
|
localSources: [],
|
|
12893
12949
|
remoteTargets: [],
|
|
12894
12950
|
localTargets: []
|
|
12895
|
-
}),
|
|
12896
|
-
BrickIndexInChunk:
|
|
12897
|
-
ComponentTypeIndex: c.indexOf(
|
|
12898
|
-
PortIndex:
|
|
12899
|
-
}),
|
|
12900
|
-
GridPersistentIndex:
|
|
12951
|
+
}), r.chunkWireCounts.set(i.key, (r.chunkWireCounts.get(i.key) ?? 0) + 1), t.source.gridSlot === t.target.gridSlot && n.key === i.key ? (o.localSources.push({
|
|
12952
|
+
BrickIndexInChunk: n.localIndex,
|
|
12953
|
+
ComponentTypeIndex: c.indexOf(t.source.componentType),
|
|
12954
|
+
PortIndex: u.indexOf(t.source.port)
|
|
12955
|
+
}), o.localTargets.push(a)) : (o.remoteSources.push({
|
|
12956
|
+
GridPersistentIndex: e.gridIds[t.source.gridSlot],
|
|
12901
12957
|
ChunkIndex: {
|
|
12902
|
-
X:
|
|
12903
|
-
Y:
|
|
12904
|
-
Z:
|
|
12905
|
-
},
|
|
12906
|
-
BrickIndexInChunk:
|
|
12907
|
-
ComponentTypeIndex: c.indexOf(
|
|
12908
|
-
PortIndex:
|
|
12909
|
-
}),
|
|
12910
|
-
}
|
|
12911
|
-
let
|
|
12912
|
-
EntityTypeNames:
|
|
12913
|
-
EntityDataClassNames:
|
|
12958
|
+
X: n.chunk[0],
|
|
12959
|
+
Y: n.chunk[1],
|
|
12960
|
+
Z: n.chunk[2]
|
|
12961
|
+
},
|
|
12962
|
+
BrickIndexInChunk: n.localIndex,
|
|
12963
|
+
ComponentTypeIndex: c.indexOf(t.source.componentType),
|
|
12964
|
+
PortIndex: u.indexOf(t.source.port)
|
|
12965
|
+
}), o.remoteTargets.push(a));
|
|
12966
|
+
}
|
|
12967
|
+
let y = Xa("BRSavedGlobalDataSoA"), b = Xa("BRSavedOwnerTableSoA"), x = Xa("BRSavedBrickChunkIndexSoA"), S = Xa("BRSavedBrickChunkSoA"), C = Xa("BRSavedWireChunkSoA"), w = Xa("BRSavedEntityChunkIndexSoA"), T = Xa("BRSavedEntityChunkSoA"), E = y.encode("BRSavedGlobalDataSoA", {
|
|
12968
|
+
EntityTypeNames: d.names,
|
|
12969
|
+
EntityDataClassNames: f,
|
|
12914
12970
|
BasicBrickAssetNames: i.names,
|
|
12915
12971
|
ProceduralBrickAssetNames: a.names,
|
|
12916
12972
|
MaterialAssetNames: r.names,
|
|
12917
12973
|
ComponentTypeNames: c.names,
|
|
12918
12974
|
ComponentDataStructNames: l,
|
|
12919
|
-
ComponentWirePortNames:
|
|
12975
|
+
ComponentWirePortNames: u.names,
|
|
12920
12976
|
ExternalAssetReferences: [],
|
|
12921
12977
|
GlobalGridEntityTypeIndex: -1
|
|
12922
|
-
}),
|
|
12923
|
-
UserIds:
|
|
12978
|
+
}), D = b.encode("BRSavedOwnerTableSoA", {
|
|
12979
|
+
UserIds: m.map((e) => ({
|
|
12924
12980
|
A: e.guid.A,
|
|
12925
12981
|
B: e.guid.B,
|
|
12926
12982
|
C: e.guid.C,
|
|
12927
12983
|
D: e.guid.D
|
|
12928
12984
|
})),
|
|
12929
|
-
UserNames:
|
|
12930
|
-
DisplayNames:
|
|
12931
|
-
EntityCounts:
|
|
12932
|
-
BrickCounts:
|
|
12933
|
-
ComponentCounts:
|
|
12934
|
-
WireCounts:
|
|
12935
|
-
}),
|
|
12936
|
-
|
|
12937
|
-
|
|
12938
|
-
|
|
12939
|
-
|
|
12940
|
-
|
|
12941
|
-
|
|
12942
|
-
|
|
12943
|
-
|
|
12944
|
-
|
|
12945
|
-
|
|
12946
|
-
|
|
12947
|
-
|
|
12948
|
-
|
|
12949
|
-
|
|
12950
|
-
|
|
12951
|
-
|
|
12952
|
-
|
|
12953
|
-
|
|
12954
|
-
|
|
12955
|
-
|
|
12956
|
-
|
|
12957
|
-
|
|
12958
|
-
|
|
12959
|
-
|
|
12960
|
-
|
|
12961
|
-
|
|
12985
|
+
UserNames: m.map((e) => e.name),
|
|
12986
|
+
DisplayNames: m.map((e) => e.display),
|
|
12987
|
+
EntityCounts: _,
|
|
12988
|
+
BrickCounts: h,
|
|
12989
|
+
ComponentCounts: g,
|
|
12990
|
+
WireCounts: m.map(() => 0)
|
|
12991
|
+
}), O = e.entities.length, k = w.encode("BRSavedEntityChunkIndexSoA", {
|
|
12992
|
+
NextPersistentIndex: 2 + O,
|
|
12993
|
+
Chunk3DIndices: O ? [{
|
|
12994
|
+
X: 0,
|
|
12995
|
+
Y: 0,
|
|
12996
|
+
Z: 0
|
|
12997
|
+
}] : [],
|
|
12998
|
+
NumEntities: O ? [O] : []
|
|
12999
|
+
}), A = null;
|
|
13000
|
+
if (O > 0) {
|
|
13001
|
+
let t = [], n = new Rr(), r = new Rr();
|
|
13002
|
+
for (let i of e.entities) {
|
|
13003
|
+
let e = d.indexOf(i.type), a = t[t.length - 1];
|
|
13004
|
+
a && a.TypeIndex === e ? a.NumEntities += 1 : t.push({
|
|
13005
|
+
TypeIndex: e,
|
|
13006
|
+
NumEntities: 1
|
|
13007
|
+
}), n.push(i.frozen), r.push(i.sleeping);
|
|
13008
|
+
}
|
|
13009
|
+
let i = new Ui();
|
|
13010
|
+
T.writeValue(i, "BRSavedEntityChunkSoA", {
|
|
13011
|
+
TypeCounters: t,
|
|
13012
|
+
PersistentIndices: e.entities.map((e, t) => 2 + t),
|
|
13013
|
+
OwnerIndices: e.entities.map((e) => e.ownerIndex),
|
|
13014
|
+
OriginalOwnerIndices: e.entities.map((e) => e.ownerIndex),
|
|
13015
|
+
Locations: e.entities.map((e) => e.location),
|
|
13016
|
+
Rotations: e.entities.map((e) => e.rotation),
|
|
13017
|
+
WeldParentFlags: { Flags: [] },
|
|
13018
|
+
PhysicsLockedFlags: n.toValue(),
|
|
13019
|
+
PhysicsSleepingFlags: r.toValue(),
|
|
13020
|
+
WeldParentIndices: [],
|
|
13021
|
+
LinearVelocities: e.entities.map((e) => e.velocity),
|
|
13022
|
+
AngularVelocities: e.entities.map((e) => e.angularVelocity),
|
|
13023
|
+
ColorsAndAlphas: e.entities.map((e) => Object.fromEntries(e.colors.map((e, t) => [`Color${t}`, e]))),
|
|
13024
|
+
RemainingLifeSpans: e.entities.map(() => 0),
|
|
13025
|
+
bColorsAreLinear: !1
|
|
13026
|
+
}), e.entities.forEach((e, t) => {
|
|
13027
|
+
if (e.className !== "None") try {
|
|
13028
|
+
T.writeValue(i, e.className, T.fillStruct(e.className, e.data));
|
|
13029
|
+
} catch (n) {
|
|
13030
|
+
throw Error(`brdb: entities[${t}] (${e.type}) data: ${n.message}`);
|
|
13031
|
+
}
|
|
13032
|
+
}), A = i.toBytes();
|
|
13033
|
+
}
|
|
13034
|
+
let j = new TextEncoder(), M = {
|
|
13035
|
+
type: e.prefab ? "Prefab" : "World",
|
|
12962
13036
|
iD: "00000000-0000-0000-0000-000000000000",
|
|
12963
13037
|
name: "",
|
|
12964
13038
|
version: "",
|
|
12965
13039
|
tags: [],
|
|
12966
|
-
authors: e.
|
|
13040
|
+
authors: e.authorName ? [e.authorName] : [],
|
|
12967
13041
|
createdAt: "0001.01.01-00.00.00",
|
|
12968
13042
|
updatedAt: "0001.01.01-00.00.00",
|
|
12969
13043
|
description: e.description ?? "A Generated World",
|
|
12970
13044
|
dependencies: [],
|
|
12971
13045
|
gameVersion: "CL0",
|
|
12972
13046
|
...t.bundle
|
|
12973
|
-
},
|
|
12974
|
-
|
|
12975
|
-
|
|
12976
|
-
|
|
12977
|
-
|
|
12978
|
-
|
|
12979
|
-
|
|
12980
|
-
|
|
12981
|
-
|
|
12982
|
-
|
|
12983
|
-
|
|
12984
|
-
|
|
12985
|
-
|
|
12986
|
-
|
|
12987
|
-
|
|
13047
|
+
}, ee = (e) => {
|
|
13048
|
+
let t = [["ChunkIndex.mps", X(x.encode("BRSavedBrickChunkIndexSoA", {
|
|
13049
|
+
Chunk3DIndices: e.chunkOrder.map((t) => {
|
|
13050
|
+
let [n, r, i] = e.chunks.get(t).index;
|
|
13051
|
+
return {
|
|
13052
|
+
X: n,
|
|
13053
|
+
Y: r,
|
|
13054
|
+
Z: i
|
|
13055
|
+
};
|
|
13056
|
+
}),
|
|
13057
|
+
ChunkOffsets: e.chunkOrder.map((t) => {
|
|
13058
|
+
let n = e.chunks.get(t).index.every((e) => e === 0) ? 0 : Qa;
|
|
13059
|
+
return {
|
|
13060
|
+
X: n,
|
|
13061
|
+
Y: n,
|
|
13062
|
+
Z: n
|
|
13063
|
+
};
|
|
13064
|
+
}),
|
|
13065
|
+
ChunkSizes: e.chunkOrder.map(() => Za),
|
|
13066
|
+
NumBricks: e.chunkOrder.map((t) => e.chunks.get(t).builder.numBricks),
|
|
13067
|
+
NumComponents: e.chunkOrder.map((t) => e.componentChunks.get(t)?.numComponents ?? 0),
|
|
13068
|
+
NumWires: e.chunkOrder.map((t) => e.chunkWireCounts.get(t) ?? 0)
|
|
13069
|
+
}))]];
|
|
13070
|
+
return e.chunkOrder.length > 0 && t.push(["Chunks", ca(e.chunkOrder.map((t) => [`${t}.mps`, X(S.encode("BRSavedBrickChunkSoA", e.chunks.get(t).builder.toValue(s)))]))]), e.componentChunks.size > 0 && t.push(["Components", ca(e.chunkOrder.filter((t) => e.componentChunks.has(t)).map((t) => [`${t}.mps`, X(e.componentChunks.get(t).toBytes(p))]))]), e.wireChunks.size > 0 && t.push(["Wires", ca(e.chunkOrder.filter((t) => e.wireChunks.has(t)).map((t) => {
|
|
13071
|
+
let n = e.wireChunks.get(t);
|
|
13072
|
+
return [`${t}.mps`, X(C.encode("BRSavedWireChunkSoA", {
|
|
13073
|
+
RemoteWireSources: n.remoteSources,
|
|
13074
|
+
LocalWireSources: n.localSources,
|
|
13075
|
+
RemoteWireTargets: n.remoteTargets,
|
|
13076
|
+
LocalWireTargets: n.localTargets,
|
|
13077
|
+
PendingPropagationFlags: { Flags: [] }
|
|
13078
|
+
}))];
|
|
13079
|
+
}))]), t;
|
|
13080
|
+
}, te = [["Bundle.json", X(j.encode(JSON.stringify(M)))]];
|
|
13081
|
+
e.prefab ? te.push(["Prefab.json", X(j.encode(JSON.stringify(e.prefab)))]) : te.push(["World.json", X(j.encode(JSON.stringify({ environment: t.environment ?? "Plate" })))]);
|
|
13082
|
+
let ne = [
|
|
13083
|
+
["ChunkIndex.schema", X(w.toBinary())],
|
|
13084
|
+
["ChunkIndex.mps", X(k)],
|
|
13085
|
+
["ChunksShared.schema", X(T.toBinary())]
|
|
13086
|
+
];
|
|
13087
|
+
return A && ne.push(["Chunks", ca([["0_0_0.mps", X(A)]])]), [["Meta", ca(te)], ["World", ca([["0", ca([
|
|
13088
|
+
["GlobalData.schema", X(y.toBinary())],
|
|
13089
|
+
["GlobalData.mps", X(E)],
|
|
13090
|
+
["Owners.schema", X(b.toBinary())],
|
|
13091
|
+
["Owners.mps", X(D)],
|
|
12988
13092
|
["Bricks", ca([
|
|
12989
|
-
["ChunkIndexShared.schema", X(
|
|
12990
|
-
["ChunksShared.schema", X(
|
|
12991
|
-
["WiresShared.schema", X(
|
|
12992
|
-
["ComponentsShared.schema", X(
|
|
12993
|
-
["Grids", ca([[
|
|
13093
|
+
["ChunkIndexShared.schema", X(x.toBinary())],
|
|
13094
|
+
["ChunksShared.schema", X(S.toBinary())],
|
|
13095
|
+
["WiresShared.schema", X(C.toBinary())],
|
|
13096
|
+
["ComponentsShared.schema", X(p.toBinary())],
|
|
13097
|
+
["Grids", ca(v.map((t, n) => [String(e.gridIds[n]), ca(ee(t))]))]
|
|
12994
13098
|
])],
|
|
12995
|
-
["Entities", ca(
|
|
12996
|
-
["ChunkIndex.schema", X(D.toBinary())],
|
|
12997
|
-
["ChunkIndex.mps", X(M)],
|
|
12998
|
-
["ChunksShared.schema", X(O.toBinary())]
|
|
12999
|
-
])]
|
|
13099
|
+
["Entities", ca(ne)]
|
|
13000
13100
|
])]])]];
|
|
13001
13101
|
}
|
|
13002
|
-
function
|
|
13102
|
+
function lo(e, t, n) {
|
|
13103
|
+
let r = e.type ?? "Entity_DynamicBrickGrid", i = na.get(r);
|
|
13104
|
+
if (i === void 0) throw Error(`brdb: entities[${t}]: unknown entity type '${r}'`);
|
|
13105
|
+
let a = e.owner_index ?? 0;
|
|
13106
|
+
if (!Number.isInteger(a) || a < 0 || a > n) throw Error(`brdb: entities[${t}]: owner_index ${a} out of range (0..${n})`);
|
|
13107
|
+
let o = [...e.colors ?? []];
|
|
13108
|
+
if (o.length > 8) throw Error(`brdb: entities[${t}]: at most 8 colors, got ${o.length}`);
|
|
13109
|
+
for (; o.length < 8;) o.push({
|
|
13110
|
+
R: 255,
|
|
13111
|
+
G: 255,
|
|
13112
|
+
B: 255,
|
|
13113
|
+
A: 255
|
|
13114
|
+
});
|
|
13115
|
+
return {
|
|
13116
|
+
type: r,
|
|
13117
|
+
className: i,
|
|
13118
|
+
location: e.location ?? {
|
|
13119
|
+
X: 0,
|
|
13120
|
+
Y: 0,
|
|
13121
|
+
Z: 0
|
|
13122
|
+
},
|
|
13123
|
+
rotation: e.rotation ?? {
|
|
13124
|
+
X: 0,
|
|
13125
|
+
Y: 0,
|
|
13126
|
+
Z: 0,
|
|
13127
|
+
W: 1
|
|
13128
|
+
},
|
|
13129
|
+
ownerIndex: a,
|
|
13130
|
+
frozen: e.frozen ?? !1,
|
|
13131
|
+
sleeping: e.sleeping ?? !1,
|
|
13132
|
+
velocity: e.linear_velocity ?? {
|
|
13133
|
+
X: 0,
|
|
13134
|
+
Y: 0,
|
|
13135
|
+
Z: 0
|
|
13136
|
+
},
|
|
13137
|
+
angularVelocity: e.angular_velocity ?? {
|
|
13138
|
+
X: 0,
|
|
13139
|
+
Y: 0,
|
|
13140
|
+
Z: 0
|
|
13141
|
+
},
|
|
13142
|
+
colors: o,
|
|
13143
|
+
data: e.data ?? {}
|
|
13144
|
+
};
|
|
13145
|
+
}
|
|
13146
|
+
function uo(e, t) {
|
|
13147
|
+
let n = [
|
|
13148
|
+
0,
|
|
13149
|
+
0,
|
|
13150
|
+
0
|
|
13151
|
+
], r = [
|
|
13152
|
+
0,
|
|
13153
|
+
0,
|
|
13154
|
+
0
|
|
13155
|
+
];
|
|
13156
|
+
e.forEach((e, t) => {
|
|
13157
|
+
let i = e.procedural ? e.size : e.assetName === "B_1x1_Microchip" ? [
|
|
13158
|
+
5,
|
|
13159
|
+
5,
|
|
13160
|
+
2
|
|
13161
|
+
] : [
|
|
13162
|
+
5,
|
|
13163
|
+
5,
|
|
13164
|
+
6
|
|
13165
|
+
];
|
|
13166
|
+
for (let a = 0; a < 3; a++) {
|
|
13167
|
+
let o = e.position[a] - i[a], s = e.position[a] + i[a];
|
|
13168
|
+
(t === 0 || o < n[a]) && (n[a] = o), (t === 0 || s > r[a]) && (r[a] = s);
|
|
13169
|
+
}
|
|
13170
|
+
});
|
|
13171
|
+
let i = {
|
|
13172
|
+
center: {
|
|
13173
|
+
x: (n[0] + r[0]) / 2,
|
|
13174
|
+
y: (n[1] + r[1]) / 2,
|
|
13175
|
+
z: (n[2] + r[2]) / 2
|
|
13176
|
+
},
|
|
13177
|
+
halfExtent: {
|
|
13178
|
+
x: (r[0] - n[0]) / 2,
|
|
13179
|
+
y: (r[1] - n[1]) / 2,
|
|
13180
|
+
z: (r[2] - n[2]) / 2
|
|
13181
|
+
}
|
|
13182
|
+
};
|
|
13183
|
+
return {
|
|
13184
|
+
pivots: {
|
|
13185
|
+
bottomStudsPivot: i,
|
|
13186
|
+
studsExpandedPivot: i,
|
|
13187
|
+
topStudsPivot: i,
|
|
13188
|
+
boundsPivot: i,
|
|
13189
|
+
bottomStudsDirection: "Z_Negative",
|
|
13190
|
+
topStudsDirection: "Z_Positive",
|
|
13191
|
+
bBottomStudsValid: !0,
|
|
13192
|
+
bTopStudsValid: !0
|
|
13193
|
+
},
|
|
13194
|
+
addedGlobalGridOffset: t.addedGlobalGridOffset ?? {
|
|
13195
|
+
x: 0,
|
|
13196
|
+
y: 0,
|
|
13197
|
+
z: 0
|
|
13198
|
+
},
|
|
13199
|
+
bIsPhysicsGrid: t.isPhysicsGrid ?? !1,
|
|
13200
|
+
bFreezePhysicsGrid: t.freezePhysicsGrid ?? !1,
|
|
13201
|
+
bFreezeGlobalGrid: t.freezeGlobalGrid ?? !1,
|
|
13202
|
+
bIsMicrochipPrefab: t.isMicrochipPrefab ?? !1
|
|
13203
|
+
};
|
|
13204
|
+
}
|
|
13205
|
+
var fo = class {
|
|
13206
|
+
constructor() {
|
|
13207
|
+
this.gridBrickInputs = [[]], this.gridEntityOrders = [], this.entityInputs = [], this.wireList = [], this.chipLinks = [], this.ownerList = [], this.prefabOptions = null;
|
|
13208
|
+
}
|
|
13209
|
+
addOwner(e) {
|
|
13210
|
+
return this.ownerList.push(e), this.ownerList.length;
|
|
13211
|
+
}
|
|
13212
|
+
addBrick(e, t) {
|
|
13213
|
+
let n = t?.grid ?? 0, r = this.gridBrickInputs[n];
|
|
13214
|
+
if (!r) throw Error(`brdb: unknown grid handle (slot ${n})`);
|
|
13215
|
+
return r.push(e), {
|
|
13216
|
+
grid: n,
|
|
13217
|
+
index: r.length - 1
|
|
13218
|
+
};
|
|
13219
|
+
}
|
|
13220
|
+
addBricks(e, t) {
|
|
13221
|
+
return [...e].map((e) => this.addBrick(e, t));
|
|
13222
|
+
}
|
|
13223
|
+
addEntity(e = {}) {
|
|
13224
|
+
return this.entityInputs.push(e), { entityOrder: this.entityInputs.length - 1 };
|
|
13225
|
+
}
|
|
13226
|
+
addBrickGrid(e = {}) {
|
|
13227
|
+
let t = this.addEntity({
|
|
13228
|
+
type: "Entity_DynamicBrickGrid",
|
|
13229
|
+
...e
|
|
13230
|
+
});
|
|
13231
|
+
return this.gridBrickInputs.push([]), this.gridEntityOrders.push(t.entityOrder), {
|
|
13232
|
+
grid: this.gridBrickInputs.length - 1,
|
|
13233
|
+
entityOrder: t.entityOrder
|
|
13234
|
+
};
|
|
13235
|
+
}
|
|
13236
|
+
addWire(e, t) {
|
|
13237
|
+
this.wireList.push({
|
|
13238
|
+
source: e,
|
|
13239
|
+
target: t
|
|
13240
|
+
});
|
|
13241
|
+
}
|
|
13242
|
+
registerMicrochipLink(e, t) {
|
|
13243
|
+
this.chipLinks.push({
|
|
13244
|
+
brick: e,
|
|
13245
|
+
grid: t
|
|
13246
|
+
});
|
|
13247
|
+
}
|
|
13248
|
+
addMicrochip(e) {
|
|
13249
|
+
let t = this.addBrick({
|
|
13250
|
+
asset: "B_1x1_Microchip",
|
|
13251
|
+
position: e.position,
|
|
13252
|
+
color: e.color,
|
|
13253
|
+
owner_index: e.owner_index,
|
|
13254
|
+
components: [{ type: "Component_Internal_Microchip" }]
|
|
13255
|
+
}), n = this.addBrickGrid({
|
|
13256
|
+
type: "Entity_MicrochipDynamicBrickGrid",
|
|
13257
|
+
location: e.entityLocation ?? {
|
|
13258
|
+
X: 0,
|
|
13259
|
+
Y: 0,
|
|
13260
|
+
Z: 40
|
|
13261
|
+
},
|
|
13262
|
+
data: {
|
|
13263
|
+
bCollapsed: e.collapsed ?? !0,
|
|
13264
|
+
PlaneCenter: {
|
|
13265
|
+
X: 0,
|
|
13266
|
+
Y: 0,
|
|
13267
|
+
Z: 0
|
|
13268
|
+
},
|
|
13269
|
+
PlaneExtent: e.planeExtent ?? {
|
|
13270
|
+
X: 14,
|
|
13271
|
+
Y: 14,
|
|
13272
|
+
Z: 2
|
|
13273
|
+
}
|
|
13274
|
+
}
|
|
13275
|
+
});
|
|
13276
|
+
return this.registerMicrochipLink(t, n), {
|
|
13277
|
+
brick: t,
|
|
13278
|
+
grid: n
|
|
13279
|
+
};
|
|
13280
|
+
}
|
|
13281
|
+
makePrefab(e = {}) {
|
|
13282
|
+
this.prefabOptions = e;
|
|
13283
|
+
}
|
|
13284
|
+
toPendingFs(e = {}) {
|
|
13285
|
+
let t = new ro(), n = new ro();
|
|
13286
|
+
for (let e of this.gridBrickInputs) for (let r of e) t.add(r.asset ?? "PB_DefaultBrick"), n.add(r.material ?? "BMC_Plastic");
|
|
13287
|
+
let r = this.gridBrickInputs.map((e, r) => no({
|
|
13288
|
+
brick_assets: t.names,
|
|
13289
|
+
materials: n.names,
|
|
13290
|
+
brick_owners: this.ownerList,
|
|
13291
|
+
bricks: e.map((e) => ({
|
|
13292
|
+
...e,
|
|
13293
|
+
asset_name_index: t.indexOf(e.asset ?? "PB_DefaultBrick"),
|
|
13294
|
+
material_index: n.indexOf(e.material ?? "BMC_Plastic"),
|
|
13295
|
+
size: e.size ?? (e.asset === void 0 ? [
|
|
13296
|
+
5,
|
|
13297
|
+
5,
|
|
13298
|
+
6
|
|
13299
|
+
] : void 0),
|
|
13300
|
+
position: r === 0 ? e.position : e.position.map((e) => e - Qa),
|
|
13301
|
+
color: e.color ?? [
|
|
13302
|
+
255,
|
|
13303
|
+
255,
|
|
13304
|
+
255
|
|
13305
|
+
]
|
|
13306
|
+
}))
|
|
13307
|
+
})), i = this.entityInputs.map((e, t) => lo(e, t, this.ownerList.length)), a = [1, ...this.gridEntityOrders.map((e) => 2 + e)];
|
|
13308
|
+
return co({
|
|
13309
|
+
ownerRows: oo(this.ownerList),
|
|
13310
|
+
grids: r,
|
|
13311
|
+
gridIds: a,
|
|
13312
|
+
entities: i,
|
|
13313
|
+
wires: this.wireList.map((e) => ({
|
|
13314
|
+
source: {
|
|
13315
|
+
gridSlot: e.source.brick.grid,
|
|
13316
|
+
brickIndex: e.source.brick.index,
|
|
13317
|
+
componentType: e.source.component_type,
|
|
13318
|
+
port: e.source.port
|
|
13319
|
+
},
|
|
13320
|
+
target: {
|
|
13321
|
+
gridSlot: e.target.brick.grid,
|
|
13322
|
+
brickIndex: e.target.brick.index,
|
|
13323
|
+
componentType: e.target.component_type,
|
|
13324
|
+
port: e.target.port
|
|
13325
|
+
}
|
|
13326
|
+
})),
|
|
13327
|
+
microchipLinks: this.chipLinks.map((e) => ({
|
|
13328
|
+
gridSlot: e.brick.grid,
|
|
13329
|
+
brickIndex: e.brick.index,
|
|
13330
|
+
gridReference: 2 + e.grid.entityOrder
|
|
13331
|
+
})),
|
|
13332
|
+
prefab: this.prefabOptions ? uo(r[0], this.prefabOptions) : null
|
|
13333
|
+
}, e);
|
|
13334
|
+
}
|
|
13335
|
+
toBrz(e = {}) {
|
|
13336
|
+
return Gi(this.toPendingFs(e), { compress: e.compress });
|
|
13337
|
+
}
|
|
13338
|
+
};
|
|
13339
|
+
function po(e, t = {}) {
|
|
13003
13340
|
let n = { compress: t.compress };
|
|
13004
|
-
return Gi(
|
|
13341
|
+
return Gi(so(e, t), n);
|
|
13005
13342
|
}
|
|
13006
|
-
function
|
|
13343
|
+
function mo(e) {
|
|
13007
13344
|
let t = e <= 15 ? 15 : 255;
|
|
13008
13345
|
return Math.trunc((e / 255) ** (1 / 2.2) * t);
|
|
13009
13346
|
}
|
|
13010
|
-
function
|
|
13347
|
+
function ho(e) {
|
|
13011
13348
|
return {
|
|
13012
13349
|
...e,
|
|
13013
|
-
R:
|
|
13014
|
-
G:
|
|
13015
|
-
B:
|
|
13350
|
+
R: mo(e.R),
|
|
13351
|
+
G: mo(e.G),
|
|
13352
|
+
B: mo(e.B)
|
|
13016
13353
|
};
|
|
13017
13354
|
}
|
|
13018
|
-
function
|
|
13355
|
+
function go(e) {
|
|
13019
13356
|
let t = {};
|
|
13020
|
-
for (let [n, r] of Object.entries(e)) t[n] =
|
|
13357
|
+
for (let [n, r] of Object.entries(e)) t[n] = ho(r);
|
|
13021
13358
|
return t;
|
|
13022
13359
|
}
|
|
13023
|
-
function
|
|
13360
|
+
function _o(e, t, n) {
|
|
13024
13361
|
let r = 0;
|
|
13025
13362
|
for (let t of e.BrickSizeCounters) r += t.NumSizes;
|
|
13026
13363
|
if (r < 0 || r > e.BrickSizes.length) throw Error("brdb: brick size counters exceed size table");
|
|
@@ -13043,7 +13380,7 @@ function fo(e, t, n) {
|
|
|
13043
13380
|
r.Z
|
|
13044
13381
|
];
|
|
13045
13382
|
}
|
|
13046
|
-
let d = e.RelativePositions[r], f = e.Orientations[r], p = e.ColorsAndAlphas[r], m = o ?
|
|
13383
|
+
let d = e.RelativePositions[r], f = e.Orientations[r], p = e.ColorsAndAlphas[r], m = o ? ho(p) : p;
|
|
13047
13384
|
s.push({
|
|
13048
13385
|
asset_name_index: l,
|
|
13049
13386
|
size: u,
|
|
@@ -13074,7 +13411,7 @@ function fo(e, t, n) {
|
|
|
13074
13411
|
}
|
|
13075
13412
|
return s;
|
|
13076
13413
|
}
|
|
13077
|
-
var
|
|
13414
|
+
var vo = class e {
|
|
13078
13415
|
constructor(e, t = 0) {
|
|
13079
13416
|
this.fs = e, this.worldId = t, this.schemas = /* @__PURE__ */ new Map(), this.values = /* @__PURE__ */ new Map();
|
|
13080
13417
|
}
|
|
@@ -13169,7 +13506,7 @@ var po = class e {
|
|
|
13169
13506
|
}
|
|
13170
13507
|
*bricks(e = 1) {
|
|
13171
13508
|
let t = this.globalData().BasicBrickAssetNames.length;
|
|
13172
|
-
for (let n of this.brickChunkIndex(e)) yield*
|
|
13509
|
+
for (let n of this.brickChunkIndex(e)) yield* _o(this.brickChunkSoa(e, n.index), n.index, t);
|
|
13173
13510
|
}
|
|
13174
13511
|
entityChunkIndex() {
|
|
13175
13512
|
let e = this.decode(this.path("Entities/ChunkIndex.mps"), this.path("Entities/ChunkIndex.schema"), "BRSavedEntityChunkIndexSoA");
|
|
@@ -13255,7 +13592,7 @@ var po = class e {
|
|
|
13255
13592
|
sleeping: Lr(s.PhysicsSleepingFlags, f),
|
|
13256
13593
|
linearVelocity: s.LinearVelocities[f],
|
|
13257
13594
|
angularVelocity: s.AngularVelocities[f],
|
|
13258
|
-
colors: u ?
|
|
13595
|
+
colors: u ? go(e) : e,
|
|
13259
13596
|
remainingLifeSpan: s.RemainingLifeSpans?.[f] ?? 0,
|
|
13260
13597
|
data: r ? i.readValue(o, r) : null
|
|
13261
13598
|
}), f += 1;
|
|
@@ -13267,74 +13604,74 @@ var po = class e {
|
|
|
13267
13604
|
*entities() {
|
|
13268
13605
|
for (let e of this.entityChunkIndex().chunks) yield* this.entityChunk(e.index);
|
|
13269
13606
|
}
|
|
13270
|
-
},
|
|
13607
|
+
}, yo, $ = "\n ", bo = "\n ", xo = `CREATE TABLE blobs (${$}blob_id INTEGER PRIMARY KEY,${$}compression INTEGER,${$}size_uncompressed INTEGER,${$}size_compressed INTEGER,${$}delta_base_id INTEGER REFERENCES blobs(blob_id),${$}hash BLOB,${$}content BLOB${bo});\nCREATE TABLE revisions (${$}revision_id INTEGER PRIMARY KEY,${$}description TEXT,${$}created_at INTEGER${bo});\nCREATE TABLE folders (${$}folder_id INTEGER PRIMARY KEY,${$}parent_id INTEGER REFERENCES folders(folder_id),${$}name TEXT,${$}created_at INTEGER,${$}deleted_at INTEGER${bo});\nCREATE TABLE files (${$}file_id INTEGER PRIMARY KEY,${$}parent_id INTEGER REFERENCES folders(folder_id),${$}name TEXT,${$}content_id INTEGER REFERENCES blobs(blob_id),${$}created_at INTEGER,${$}deleted_at INTEGER${bo});\nCREATE INDEX blobs_size_hash ON blobs(size_uncompressed, hash);
|
|
13271
13608
|
CREATE INDEX folders_parent_name_deleted ON folders(parent_id, name, deleted_at);
|
|
13272
|
-
CREATE INDEX files_parent_name_deleted ON files(parent_id, name, deleted_at);`,
|
|
13609
|
+
CREATE INDEX files_parent_name_deleted ON files(parent_id, name, deleted_at);`, So = [
|
|
13273
13610
|
"blobs",
|
|
13274
13611
|
"revisions",
|
|
13275
13612
|
"folders",
|
|
13276
13613
|
"files"
|
|
13277
|
-
],
|
|
13614
|
+
], Co = () => Math.floor(Date.now() / 1e3), wo = (e) => typeof Buffer > "u" ? e : Buffer.from(e.buffer, e.byteOffset, e.byteLength), To = (e) => {
|
|
13278
13615
|
try {
|
|
13279
13616
|
return typeof process < "u" ? process?.getBuiltinModule?.(e) ?? null : null;
|
|
13280
13617
|
} catch {
|
|
13281
13618
|
return null;
|
|
13282
13619
|
}
|
|
13283
|
-
},
|
|
13284
|
-
async function
|
|
13620
|
+
}, Eo = null, Do = (e) => (Eo ?? (Eo = Function("specifier", "return import(specifier)")), Eo(e));
|
|
13621
|
+
async function Oo() {
|
|
13285
13622
|
try {
|
|
13286
|
-
let e = await (
|
|
13623
|
+
let e = await (Ao.engineLoader ?? (() => Do("better-sqlite3")))();
|
|
13287
13624
|
return e.default ?? e;
|
|
13288
13625
|
} catch {
|
|
13289
13626
|
throw Error("brdb: the Brdb openers require better-sqlite3 (npm install better-sqlite3), or wrap your own handle with new Brdb(db)");
|
|
13290
13627
|
}
|
|
13291
13628
|
}
|
|
13292
|
-
function
|
|
13293
|
-
let e =
|
|
13629
|
+
function ko() {
|
|
13630
|
+
let e = To("node:zlib");
|
|
13294
13631
|
if (typeof e?.zstdCompressSync != "function") return null;
|
|
13295
13632
|
let t = e.constants.ZSTD_c_compressionLevel;
|
|
13296
13633
|
return (n) => new Uint8Array(e.zstdCompressSync(n, { params: { [t]: 14 } }));
|
|
13297
13634
|
}
|
|
13298
|
-
var
|
|
13635
|
+
var Ao = class e {
|
|
13299
13636
|
constructor(e) {
|
|
13300
13637
|
this.db = e, this.defaultCompress = null;
|
|
13301
|
-
for (let e of
|
|
13638
|
+
for (let e of So) if (!this.db.prepare("SELECT name FROM sqlite_schema WHERE type = 'table' AND name = ?").get(e)) throw Error(`brdb: missing required table '${e}'`);
|
|
13302
13639
|
}
|
|
13303
|
-
static init(t, n =
|
|
13304
|
-
t.exec(
|
|
13640
|
+
static init(t, n = Co()) {
|
|
13641
|
+
t.exec(xo);
|
|
13305
13642
|
let r = new e(t);
|
|
13306
13643
|
return r.createRevision("Initial Revision", n), r;
|
|
13307
13644
|
}
|
|
13308
13645
|
static async wrap(t, n) {
|
|
13309
13646
|
try {
|
|
13310
13647
|
let r = n ? e.init(t) : new e(t);
|
|
13311
|
-
return r.defaultCompress =
|
|
13648
|
+
return r.defaultCompress = ko(), r;
|
|
13312
13649
|
} catch (e) {
|
|
13313
13650
|
throw t.close(), e;
|
|
13314
13651
|
}
|
|
13315
13652
|
}
|
|
13316
13653
|
static async open(t) {
|
|
13317
|
-
return e.wrap(new (await (
|
|
13654
|
+
return e.wrap(new (await (Oo()))(t, { fileMustExist: !0 }), !1);
|
|
13318
13655
|
}
|
|
13319
13656
|
static async openReadonly(t) {
|
|
13320
|
-
return e.wrap(new (await (
|
|
13657
|
+
return e.wrap(new (await (Oo()))(t, {
|
|
13321
13658
|
readonly: !0,
|
|
13322
13659
|
fileMustExist: !0
|
|
13323
13660
|
}), !1);
|
|
13324
13661
|
}
|
|
13325
13662
|
static async create(t) {
|
|
13326
|
-
return e.wrap(new (await (
|
|
13663
|
+
return e.wrap(new (await (Oo()))(t), !0);
|
|
13327
13664
|
}
|
|
13328
13665
|
static async openOrCreate(t) {
|
|
13329
|
-
let n =
|
|
13666
|
+
let n = To("node:fs");
|
|
13330
13667
|
if (!n) throw Error("brdb: openOrCreate requires node 22.3 or newer; call open or create explicitly");
|
|
13331
13668
|
return n.existsSync(t) ? e.open(t) : e.create(t);
|
|
13332
13669
|
}
|
|
13333
13670
|
static async memory() {
|
|
13334
|
-
return e.wrap(new (await (
|
|
13671
|
+
return e.wrap(new (await (Oo()))(":memory:"), !0);
|
|
13335
13672
|
}
|
|
13336
13673
|
static async fromBytes(t) {
|
|
13337
|
-
return e.wrap(new (await (
|
|
13674
|
+
return e.wrap(new (await (Oo()))(Buffer.from(t)), !1);
|
|
13338
13675
|
}
|
|
13339
13676
|
toBytes() {
|
|
13340
13677
|
let e = this.db.serialize;
|
|
@@ -13342,15 +13679,15 @@ var To = class e {
|
|
|
13342
13679
|
return new Uint8Array(e.call(this.db));
|
|
13343
13680
|
}
|
|
13344
13681
|
save(e, t, n = {}) {
|
|
13345
|
-
this.writePending(e,
|
|
13682
|
+
this.writePending(e, t instanceof fo ? t.toPendingFs(n) : so(t, n), n);
|
|
13346
13683
|
}
|
|
13347
13684
|
worldReader() {
|
|
13348
|
-
return new
|
|
13685
|
+
return new vo(this);
|
|
13349
13686
|
}
|
|
13350
13687
|
sqliteSchema() {
|
|
13351
13688
|
return this.db.prepare("SELECT sql FROM sqlite_schema").all().map((e) => e.sql).join("\n");
|
|
13352
13689
|
}
|
|
13353
|
-
createRevision(e, t =
|
|
13690
|
+
createRevision(e, t = Co()) {
|
|
13354
13691
|
return Number(this.db.prepare("INSERT INTO revisions (description, created_at) VALUES (?, ?);").run(e, t).lastInsertRowid);
|
|
13355
13692
|
}
|
|
13356
13693
|
revisions() {
|
|
@@ -13370,16 +13707,16 @@ var To = class e {
|
|
|
13370
13707
|
let r = this.findBlobByHash(e.length, t);
|
|
13371
13708
|
if (r) return r.blobId;
|
|
13372
13709
|
let i = e.length, a = i, o = 0, s = e, c = n ? n(e) : null;
|
|
13373
|
-
return c && c.length < i && (a = c.length, o = 1, s = c), Number(this.db.prepare("INSERT INTO blobs (compression, size_uncompressed, size_compressed, delta_base_id, hash, content) VALUES (?, ?, ?, ?, ?, ?);").run(o, i, a, null,
|
|
13710
|
+
return c && c.length < i && (a = c.length, o = 1, s = c), Number(this.db.prepare("INSERT INTO blobs (compression, size_uncompressed, size_compressed, delta_base_id, hash, content) VALUES (?, ?, ?, ?, ?, ?);").run(o, i, a, null, wo(t), wo(s)).lastInsertRowid);
|
|
13374
13711
|
}
|
|
13375
13712
|
findBlobByHash(e, t) {
|
|
13376
|
-
let n = this.db.prepare("SELECT blob_id, compression, size_uncompressed, size_compressed, delta_base_id, hash, content FROM blobs WHERE hash = ? AND size_uncompressed = ? LIMIT 1;").get(
|
|
13377
|
-
return n ?
|
|
13713
|
+
let n = this.db.prepare("SELECT blob_id, compression, size_uncompressed, size_compressed, delta_base_id, hash, content FROM blobs WHERE hash = ? AND size_uncompressed = ? LIMIT 1;").get(wo(t), e);
|
|
13714
|
+
return n ? jo(n) : null;
|
|
13378
13715
|
}
|
|
13379
13716
|
findBlob(e) {
|
|
13380
13717
|
let t = this.db.prepare("SELECT blob_id, compression, size_uncompressed, size_compressed, delta_base_id, hash, content FROM blobs WHERE blob_id = ?;").get(e);
|
|
13381
13718
|
if (!t) throw Error(`brdb: blob ${e} not found`);
|
|
13382
|
-
return
|
|
13719
|
+
return jo(t);
|
|
13383
13720
|
}
|
|
13384
13721
|
deleteFile(e, t) {
|
|
13385
13722
|
this.db.prepare("UPDATE files SET deleted_at = ? WHERE file_id = ?;").run(t, e);
|
|
@@ -13406,7 +13743,7 @@ var To = class e {
|
|
|
13406
13743
|
}
|
|
13407
13744
|
findFile(e, t) {
|
|
13408
13745
|
let n = this.db.prepare(`SELECT content_id, created_at FROM files WHERE parent_id ${e === null ? "IS NULL" : "= ?"} AND name = ? AND deleted_at IS NULL;`).get(...e === null ? [t] : [e, t]);
|
|
13409
|
-
return n ?
|
|
13746
|
+
return n ? Mo(n) : null;
|
|
13410
13747
|
}
|
|
13411
13748
|
findFileAtRevision(e, t, n) {
|
|
13412
13749
|
let r = this.db.prepare(`SELECT content_id, created_at FROM files WHERE parent_id ${e === null ? "IS NULL" : "= ?"} AND name = ? AND created_at <= ? AND (deleted_at IS NULL OR deleted_at > ?) ORDER BY created_at ASC LIMIT 1;`).get(...e === null ? [
|
|
@@ -13419,13 +13756,13 @@ var To = class e {
|
|
|
13419
13756
|
n,
|
|
13420
13757
|
n
|
|
13421
13758
|
]);
|
|
13422
|
-
return r ?
|
|
13759
|
+
return r ? Mo(r) : null;
|
|
13423
13760
|
}
|
|
13424
13761
|
close() {
|
|
13425
13762
|
this.db.close();
|
|
13426
13763
|
}
|
|
13427
13764
|
writePending(e, t, n = {}) {
|
|
13428
|
-
let r = n.createdAt ??
|
|
13765
|
+
let r = n.createdAt ?? Co(), i = n.compress === void 0 ? this.defaultCompress : n.compress;
|
|
13429
13766
|
this.db.exec("BEGIN");
|
|
13430
13767
|
try {
|
|
13431
13768
|
this.createRevision(e, r), this.mergeFolder(null, t, r, i), this.db.exec("COMMIT");
|
|
@@ -13552,8 +13889,8 @@ var To = class e {
|
|
|
13552
13889
|
return e(null);
|
|
13553
13890
|
}
|
|
13554
13891
|
};
|
|
13555
|
-
|
|
13556
|
-
var
|
|
13892
|
+
yo = Ao, yo.engineLoader = null;
|
|
13893
|
+
var jo = (e) => ({
|
|
13557
13894
|
blobId: Number(e.blob_id),
|
|
13558
13895
|
compression: Number(e.compression),
|
|
13559
13896
|
sizeUncompressed: Number(e.size_uncompressed),
|
|
@@ -13561,15 +13898,15 @@ var Eo = (e) => ({
|
|
|
13561
13898
|
deltaBaseId: e.delta_base_id === null ? null : Number(e.delta_base_id),
|
|
13562
13899
|
hash: new Uint8Array(e.hash),
|
|
13563
13900
|
content: new Uint8Array(e.content)
|
|
13564
|
-
}),
|
|
13901
|
+
}), Mo = (e) => ({
|
|
13565
13902
|
contentId: e.content_id === null ? -1 : Number(e.content_id),
|
|
13566
13903
|
createdAt: Number(e.created_at)
|
|
13567
|
-
}),
|
|
13904
|
+
}), No = /* @__PURE__ */ t({
|
|
13568
13905
|
BASIC_BRICK_ASSETS: () => qi,
|
|
13569
|
-
BRDB_SQLITE_SCHEMA: () =>
|
|
13906
|
+
BRDB_SQLITE_SCHEMA: () => xo,
|
|
13570
13907
|
BRICK_ASSETS: () => Yi,
|
|
13571
13908
|
BitFlags: () => Rr,
|
|
13572
|
-
Brdb: () =>
|
|
13909
|
+
Brdb: () => Ao,
|
|
13573
13910
|
BrdbSchema: () => Ja,
|
|
13574
13911
|
BrzReader: () => Ki,
|
|
13575
13912
|
ByteReader: () => Wi,
|
|
@@ -13585,7 +13922,8 @@ var Eo = (e) => ({
|
|
|
13585
13922
|
PROCEDURAL_BRICK_ASSETS: () => Ji,
|
|
13586
13923
|
PUBLIC_GUID: () => aa,
|
|
13587
13924
|
WIRE_PORT_NAMES: () => ta,
|
|
13588
|
-
|
|
13925
|
+
World: () => fo,
|
|
13926
|
+
WorldReader: () => vo,
|
|
13589
13927
|
bit: () => Lr,
|
|
13590
13928
|
embeddedSchema: () => Xa,
|
|
13591
13929
|
file: () => X,
|
|
@@ -13593,21 +13931,21 @@ var Eo = (e) => ({
|
|
|
13593
13931
|
guidToUuid: () => sa,
|
|
13594
13932
|
isProceduralAsset: () => Qi,
|
|
13595
13933
|
msgpack: () => la,
|
|
13596
|
-
saveToPendingFs: () =>
|
|
13934
|
+
saveToPendingFs: () => so,
|
|
13597
13935
|
toRelative: () => to,
|
|
13598
13936
|
uuidToGuid: () => oa,
|
|
13599
13937
|
writeBrzContainer: () => Gi,
|
|
13600
|
-
writeBrzLegacy: () =>
|
|
13601
|
-
}),
|
|
13938
|
+
writeBrzLegacy: () => po
|
|
13939
|
+
}), Po = {
|
|
13602
13940
|
read: Ar,
|
|
13603
13941
|
write: Nr,
|
|
13604
13942
|
utils: tr,
|
|
13605
13943
|
constants: n,
|
|
13606
13944
|
types: Pr,
|
|
13607
|
-
brdb:
|
|
13945
|
+
brdb: No
|
|
13608
13946
|
};
|
|
13609
|
-
typeof window < "u" && (window.BRS =
|
|
13947
|
+
typeof window < "u" && (window.BRS = Po);
|
|
13610
13948
|
//#endregion
|
|
13611
|
-
export {
|
|
13949
|
+
export { Ao as Brdb, Fr as Direction, Ir as Rotation, fo as World, vo as WorldReader, No as brdb, n as constants, Po as default, Ar as read, Pr as types, tr as utils, Nr as write, po as writeBrzLegacy };
|
|
13612
13950
|
|
|
13613
13951
|
//# sourceMappingURL=dist.mjs.map
|