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/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(204), e.u8(t);
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, t = {}) {
12825
- let n = no(e), r = new ro(), i = new ro(), a = new ro();
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 = (e.wires ?? []).filter((e) => "component_type" in e.source), d = new ro();
12838
- u.forEach((e, t) => {
12839
- for (let [r, i] of [["source", e.source], ["target", e.target]]) {
12840
- if (!Number.isInteger(i.brick_index) || i.brick_index < 0 || i.brick_index >= n.length) throw Error(`brdb: wires[${t}].${r}: brick_index ${i.brick_index} out of range`);
12841
- if (!c.has(i.component_type)) throw Error(`brdb: wires[${t}].${r}: component type '${i.component_type}' is not used by any brick`);
12842
- d.add(i.port);
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 f = Ja.fromData(Ba.BRSavedComponentChunkSoA);
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
- f.merge(Xa("BRSavedComponentChunkSoA_max").extractStructsTransitive(e));
12850
- }
12851
- let p = [{
12852
- guid: aa,
12853
- name: "PUBLIC",
12854
- display: "PUBLIC"
12855
- }];
12856
- for (let t of e.brick_owners ?? []) p.push({
12857
- guid: oa(t.id ?? "00000000-0000-0000-0000-000000000000"),
12858
- name: t.name ?? "Unknown",
12859
- display: t.display_name ?? t.name ?? "Unknown"
12860
- });
12861
- let m = p.map(() => 0), h = p.map(() => 0), g = [], _ = /* @__PURE__ */ new Map(), v = /* @__PURE__ */ new Map(), y = [];
12862
- for (let e of n) {
12863
- let { chunk: t, rel: n } = to(e.position), r = t.join("_"), i = _.get(r);
12864
- i || (i = {
12865
- index: t,
12866
- builder: new io()
12867
- }, _.set(r, i), g.push(r));
12868
- let a = i.builder.numBricks;
12869
- if (i.builder.addBrick(e, n, o, s), y.push({
12870
- key: r,
12871
- chunk: t,
12872
- localIndex: a
12873
- }), m[e.ownerIndex] += 1, e.components.length > 0) {
12874
- h[e.ownerIndex] += e.components.length;
12875
- let t = v.get(r);
12876
- t || v.set(r, t = new ao());
12877
- for (let n of e.components) {
12878
- let e = c.indexOf(n.type);
12879
- t.add(e, a, l[e], n.data ?? {});
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
- let b = /* @__PURE__ */ new Map(), x = /* @__PURE__ */ new Map();
12884
- for (let e of u) {
12885
- let t = y[e.source.brick_index], n = y[e.target.brick_index], r = {
12886
- BrickIndexInChunk: n.localIndex,
12887
- ComponentTypeIndex: c.indexOf(e.target.component_type),
12888
- PortIndex: d.indexOf(e.target.port)
12889
- }, i = b.get(n.key);
12890
- i || b.set(n.key, i = {
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
- }), x.set(n.key, (x.get(n.key) ?? 0) + 1), t.key === n.key ? (i.localSources.push({
12896
- BrickIndexInChunk: t.localIndex,
12897
- ComponentTypeIndex: c.indexOf(e.source.component_type),
12898
- PortIndex: d.indexOf(e.source.port)
12899
- }), i.localTargets.push(r)) : (i.remoteSources.push({
12900
- GridPersistentIndex: 1,
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: t.chunk[0],
12903
- Y: t.chunk[1],
12904
- Z: t.chunk[2]
12905
- },
12906
- BrickIndexInChunk: t.localIndex,
12907
- ComponentTypeIndex: c.indexOf(e.source.component_type),
12908
- PortIndex: d.indexOf(e.source.port)
12909
- }), i.remoteTargets.push(r));
12910
- }
12911
- let S = Xa("BRSavedGlobalDataSoA"), C = Xa("BRSavedOwnerTableSoA"), w = Xa("BRSavedBrickChunkIndexSoA"), T = Xa("BRSavedBrickChunkSoA"), E = Xa("BRSavedWireChunkSoA"), D = Xa("BRSavedEntityChunkIndexSoA"), O = Xa("BRSavedEntityChunkSoA"), k = S.encode("BRSavedGlobalDataSoA", {
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: d.names,
12975
+ ComponentWirePortNames: u.names,
12920
12976
  ExternalAssetReferences: [],
12921
12977
  GlobalGridEntityTypeIndex: -1
12922
- }), A = C.encode("BRSavedOwnerTableSoA", {
12923
- UserIds: p.map((e) => ({
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: p.map((e) => e.name),
12930
- DisplayNames: p.map((e) => e.display),
12931
- EntityCounts: p.map(() => 0),
12932
- BrickCounts: m,
12933
- ComponentCounts: h,
12934
- WireCounts: p.map(() => 0)
12935
- }), j = w.encode("BRSavedBrickChunkIndexSoA", {
12936
- Chunk3DIndices: g.map((e) => {
12937
- let [t, n, r] = _.get(e).index;
12938
- return {
12939
- X: t,
12940
- Y: n,
12941
- Z: r
12942
- };
12943
- }),
12944
- ChunkOffsets: g.map((e) => {
12945
- let t = _.get(e).index.every((e) => e === 0) ? 0 : Qa;
12946
- return {
12947
- X: t,
12948
- Y: t,
12949
- Z: t
12950
- };
12951
- }),
12952
- ChunkSizes: g.map(() => Za),
12953
- NumBricks: g.map((e) => _.get(e).builder.numBricks),
12954
- NumComponents: g.map((e) => v.get(e)?.numComponents ?? 0),
12955
- NumWires: g.map((e) => x.get(e) ?? 0)
12956
- }), M = D.encode("BRSavedEntityChunkIndexSoA", {
12957
- NextPersistentIndex: 2,
12958
- Chunk3DIndices: [],
12959
- NumEntities: []
12960
- }), ee = new TextEncoder(), te = {
12961
- type: "World",
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.author?.name ? [e.author.name] : [],
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
- }, ne = [["ChunkIndex.mps", X(j)]];
12974
- return g.length > 0 && ne.push(["Chunks", ca(g.map((e) => [`${e}.mps`, X(T.encode("BRSavedBrickChunkSoA", _.get(e).builder.toValue(s)))]))]), v.size > 0 && ne.push(["Components", ca(g.filter((e) => v.has(e)).map((e) => [`${e}.mps`, X(v.get(e).toBytes(f))]))]), b.size > 0 && ne.push(["Wires", ca(g.filter((e) => b.has(e)).map((e) => {
12975
- let t = b.get(e);
12976
- return [`${e}.mps`, X(E.encode("BRSavedWireChunkSoA", {
12977
- RemoteWireSources: t.remoteSources,
12978
- LocalWireSources: t.localSources,
12979
- RemoteWireTargets: t.remoteTargets,
12980
- LocalWireTargets: t.localTargets,
12981
- PendingPropagationFlags: { Flags: [] }
12982
- }))];
12983
- }))]), [["Meta", ca([["Bundle.json", X(ee.encode(JSON.stringify(te)))], ["World.json", X(ee.encode(JSON.stringify({ environment: t.environment ?? "Plate" })))]])], ["World", ca([["0", ca([
12984
- ["GlobalData.schema", X(S.toBinary())],
12985
- ["GlobalData.mps", X(k)],
12986
- ["Owners.schema", X(C.toBinary())],
12987
- ["Owners.mps", X(A)],
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(w.toBinary())],
12990
- ["ChunksShared.schema", X(T.toBinary())],
12991
- ["WiresShared.schema", X(E.toBinary())],
12992
- ["ComponentsShared.schema", X(f.toBinary())],
12993
- ["Grids", ca([["1", ca(ne)]])]
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 so(e, t = {}) {
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(oo(e, t), n);
13341
+ return Gi(so(e, t), n);
13005
13342
  }
13006
- function co(e) {
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 lo(e) {
13347
+ function ho(e) {
13011
13348
  return {
13012
13349
  ...e,
13013
- R: co(e.R),
13014
- G: co(e.G),
13015
- B: co(e.B)
13350
+ R: mo(e.R),
13351
+ G: mo(e.G),
13352
+ B: mo(e.B)
13016
13353
  };
13017
13354
  }
13018
- function uo(e) {
13355
+ function go(e) {
13019
13356
  let t = {};
13020
- for (let [n, r] of Object.entries(e)) t[n] = lo(r);
13357
+ for (let [n, r] of Object.entries(e)) t[n] = ho(r);
13021
13358
  return t;
13022
13359
  }
13023
- function fo(e, t, n) {
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 ? lo(p) : p;
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 po = class e {
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* fo(this.brickChunkSoa(e, n.index), n.index, t);
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 ? uo(e) : e,
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
- }, mo, $ = "\n ", ho = "\n ", go = `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${ho});\nCREATE TABLE revisions (${$}revision_id INTEGER PRIMARY KEY,${$}description TEXT,${$}created_at INTEGER${ho});\nCREATE TABLE folders (${$}folder_id INTEGER PRIMARY KEY,${$}parent_id INTEGER REFERENCES folders(folder_id),${$}name TEXT,${$}created_at INTEGER,${$}deleted_at INTEGER${ho});\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${ho});\nCREATE INDEX blobs_size_hash ON blobs(size_uncompressed, hash);
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);`, _o = [
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
- ], vo = () => Math.floor(Date.now() / 1e3), yo = (e) => typeof Buffer > "u" ? e : Buffer.from(e.buffer, e.byteOffset, e.byteLength), bo = (e) => {
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
- }, xo = null, So = (e) => (xo ?? (xo = Function("specifier", "return import(specifier)")), xo(e));
13284
- async function Co() {
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 (To.engineLoader ?? (() => So("better-sqlite3")))();
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 wo() {
13293
- let e = bo("node:zlib");
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 To = class e {
13635
+ var Ao = class e {
13299
13636
  constructor(e) {
13300
13637
  this.db = e, this.defaultCompress = null;
13301
- for (let e of _o) if (!this.db.prepare("SELECT name FROM sqlite_schema WHERE type = 'table' AND name = ?").get(e)) throw Error(`brdb: missing required table '${e}'`);
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 = vo()) {
13304
- t.exec(go);
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 = wo(), r;
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 (Co()))(t, { fileMustExist: !0 }), !1);
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 (Co()))(t, {
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 (Co()))(t), !0);
13663
+ return e.wrap(new (await (Oo()))(t), !0);
13327
13664
  }
13328
13665
  static async openOrCreate(t) {
13329
- let n = bo("node:fs");
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 (Co()))(":memory:"), !0);
13671
+ return e.wrap(new (await (Oo()))(":memory:"), !0);
13335
13672
  }
13336
13673
  static async fromBytes(t) {
13337
- return e.wrap(new (await (Co()))(Buffer.from(t)), !1);
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, oo(t, n), n);
13682
+ this.writePending(e, t instanceof fo ? t.toPendingFs(n) : so(t, n), n);
13346
13683
  }
13347
13684
  worldReader() {
13348
- return new po(this);
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 = vo()) {
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, yo(t), yo(s)).lastInsertRowid);
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(yo(t), e);
13377
- return n ? Eo(n) : null;
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 Eo(t);
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 ? Do(n) : null;
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 ? Do(r) : null;
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 ?? vo(), i = n.compress === void 0 ? this.defaultCompress : n.compress;
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
- mo = To, mo.engineLoader = null;
13556
- var Eo = (e) => ({
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
- }), Do = (e) => ({
13901
+ }), Mo = (e) => ({
13565
13902
  contentId: e.content_id === null ? -1 : Number(e.content_id),
13566
13903
  createdAt: Number(e.created_at)
13567
- }), Oo = /* @__PURE__ */ t({
13904
+ }), No = /* @__PURE__ */ t({
13568
13905
  BASIC_BRICK_ASSETS: () => qi,
13569
- BRDB_SQLITE_SCHEMA: () => go,
13906
+ BRDB_SQLITE_SCHEMA: () => xo,
13570
13907
  BRICK_ASSETS: () => Yi,
13571
13908
  BitFlags: () => Rr,
13572
- Brdb: () => To,
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
- WorldReader: () => po,
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: () => oo,
13934
+ saveToPendingFs: () => so,
13597
13935
  toRelative: () => to,
13598
13936
  uuidToGuid: () => oa,
13599
13937
  writeBrzContainer: () => Gi,
13600
- writeBrzLegacy: () => so
13601
- }), ko = {
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: Oo
13945
+ brdb: No
13608
13946
  };
13609
- typeof window < "u" && (window.BRS = ko);
13947
+ typeof window < "u" && (window.BRS = Po);
13610
13948
  //#endregion
13611
- export { To as Brdb, Fr as Direction, Ir as Rotation, po as WorldReader, Oo as brdb, n as constants, ko as default, Ar as read, Pr as types, tr as utils, Nr as write, so as writeBrzLegacy };
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