brs-js 3.1.0 → 3.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,484 @@ 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, t) => {
13048
+ let n = t ? 0 : Qa, r = [["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(() => ({
13058
+ X: n,
13059
+ Y: n,
13060
+ Z: n
13061
+ })),
13062
+ ChunkSizes: e.chunkOrder.map(() => Za),
13063
+ NumBricks: e.chunkOrder.map((t) => e.chunks.get(t).builder.numBricks),
13064
+ NumComponents: e.chunkOrder.map((t) => e.componentChunks.get(t)?.numComponents ?? 0),
13065
+ NumWires: e.chunkOrder.map((t) => e.chunkWireCounts.get(t) ?? 0)
13066
+ }))]];
13067
+ return e.chunkOrder.length > 0 && r.push(["Chunks", ca(e.chunkOrder.map((t) => [`${t}.mps`, X(S.encode("BRSavedBrickChunkSoA", e.chunks.get(t).builder.toValue(s)))]))]), e.componentChunks.size > 0 && r.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 && r.push(["Wires", ca(e.chunkOrder.filter((t) => e.wireChunks.has(t)).map((t) => {
13068
+ let n = e.wireChunks.get(t);
13069
+ return [`${t}.mps`, X(C.encode("BRSavedWireChunkSoA", {
13070
+ RemoteWireSources: n.remoteSources,
13071
+ LocalWireSources: n.localSources,
13072
+ RemoteWireTargets: n.remoteTargets,
13073
+ LocalWireTargets: n.localTargets,
13074
+ PendingPropagationFlags: { Flags: [] }
13075
+ }))];
13076
+ }))]), r;
13077
+ }, te = [["Bundle.json", X(j.encode(JSON.stringify(M)))]];
13078
+ 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" })))]);
13079
+ let ne = [
13080
+ ["ChunkIndex.schema", X(w.toBinary())],
13081
+ ["ChunkIndex.mps", X(k)],
13082
+ ["ChunksShared.schema", X(T.toBinary())]
13083
+ ];
13084
+ return A && ne.push(["Chunks", ca([["0_0_0.mps", X(A)]])]), [["Meta", ca(te)], ["World", ca([["0", ca([
13085
+ ["GlobalData.schema", X(y.toBinary())],
13086
+ ["GlobalData.mps", X(E)],
13087
+ ["Owners.schema", X(b.toBinary())],
13088
+ ["Owners.mps", X(D)],
12988
13089
  ["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)]])]
13090
+ ["ChunkIndexShared.schema", X(x.toBinary())],
13091
+ ["ChunksShared.schema", X(S.toBinary())],
13092
+ ["WiresShared.schema", X(C.toBinary())],
13093
+ ["ComponentsShared.schema", X(p.toBinary())],
13094
+ ["Grids", ca(v.map((t, n) => [String(e.gridIds[n]), ca(ee(t, e.gridIds[n] === 1))]))]
12994
13095
  ])],
12995
- ["Entities", ca([
12996
- ["ChunkIndex.schema", X(D.toBinary())],
12997
- ["ChunkIndex.mps", X(M)],
12998
- ["ChunksShared.schema", X(O.toBinary())]
12999
- ])]
13096
+ ["Entities", ca(ne)]
13000
13097
  ])]])]];
13001
13098
  }
13002
- function so(e, t = {}) {
13099
+ function lo(e, t, n) {
13100
+ let r = e.type ?? "Entity_DynamicBrickGrid", i = na.get(r);
13101
+ if (i === void 0) throw Error(`brdb: entities[${t}]: unknown entity type '${r}'`);
13102
+ let a = e.owner_index ?? 0;
13103
+ if (!Number.isInteger(a) || a < 0 || a > n) throw Error(`brdb: entities[${t}]: owner_index ${a} out of range (0..${n})`);
13104
+ let o = [...e.colors ?? []];
13105
+ if (o.length > 8) throw Error(`brdb: entities[${t}]: at most 8 colors, got ${o.length}`);
13106
+ for (; o.length < 8;) o.push({
13107
+ R: 255,
13108
+ G: 255,
13109
+ B: 255,
13110
+ A: 255
13111
+ });
13112
+ return {
13113
+ type: r,
13114
+ className: i,
13115
+ location: e.location ?? {
13116
+ X: 0,
13117
+ Y: 0,
13118
+ Z: 0
13119
+ },
13120
+ rotation: e.rotation ?? {
13121
+ X: 0,
13122
+ Y: 0,
13123
+ Z: 0,
13124
+ W: 1
13125
+ },
13126
+ ownerIndex: a,
13127
+ frozen: e.frozen ?? !1,
13128
+ sleeping: e.sleeping ?? !1,
13129
+ velocity: e.linear_velocity ?? {
13130
+ X: 0,
13131
+ Y: 0,
13132
+ Z: 0
13133
+ },
13134
+ angularVelocity: e.angular_velocity ?? {
13135
+ X: 0,
13136
+ Y: 0,
13137
+ Z: 0
13138
+ },
13139
+ colors: o,
13140
+ data: e.data ?? {}
13141
+ };
13142
+ }
13143
+ function uo(e, t) {
13144
+ let n = [
13145
+ 0,
13146
+ 0,
13147
+ 0
13148
+ ], r = [
13149
+ 0,
13150
+ 0,
13151
+ 0
13152
+ ];
13153
+ e.forEach((e, t) => {
13154
+ let i = e.procedural ? e.size : e.assetName === "B_1x1_Microchip" ? [
13155
+ 5,
13156
+ 5,
13157
+ 2
13158
+ ] : [
13159
+ 5,
13160
+ 5,
13161
+ 6
13162
+ ];
13163
+ for (let a = 0; a < 3; a++) {
13164
+ let o = e.position[a] - i[a], s = e.position[a] + i[a];
13165
+ (t === 0 || o < n[a]) && (n[a] = o), (t === 0 || s > r[a]) && (r[a] = s);
13166
+ }
13167
+ });
13168
+ let i = {
13169
+ center: {
13170
+ x: (n[0] + r[0]) / 2,
13171
+ y: (n[1] + r[1]) / 2,
13172
+ z: (n[2] + r[2]) / 2
13173
+ },
13174
+ halfExtent: {
13175
+ x: (r[0] - n[0]) / 2,
13176
+ y: (r[1] - n[1]) / 2,
13177
+ z: (r[2] - n[2]) / 2
13178
+ }
13179
+ };
13180
+ return {
13181
+ pivots: {
13182
+ bottomStudsPivot: i,
13183
+ studsExpandedPivot: i,
13184
+ topStudsPivot: i,
13185
+ boundsPivot: i,
13186
+ bottomStudsDirection: "Z_Negative",
13187
+ topStudsDirection: "Z_Positive",
13188
+ bBottomStudsValid: !0,
13189
+ bTopStudsValid: !0
13190
+ },
13191
+ addedGlobalGridOffset: t.addedGlobalGridOffset ?? {
13192
+ x: 0,
13193
+ y: 0,
13194
+ z: 0
13195
+ },
13196
+ bIsPhysicsGrid: t.isPhysicsGrid ?? !1,
13197
+ bFreezePhysicsGrid: t.freezePhysicsGrid ?? !1,
13198
+ bFreezeGlobalGrid: t.freezeGlobalGrid ?? !1,
13199
+ bIsMicrochipPrefab: t.isMicrochipPrefab ?? !1
13200
+ };
13201
+ }
13202
+ var fo = class {
13203
+ constructor() {
13204
+ this.gridBrickInputs = [[]], this.gridEntityOrders = [], this.entityInputs = [], this.wireList = [], this.chipLinks = [], this.ownerList = [], this.prefabOptions = null;
13205
+ }
13206
+ addOwner(e) {
13207
+ return this.ownerList.push(e), this.ownerList.length;
13208
+ }
13209
+ addBrick(e, t) {
13210
+ let n = t?.grid ?? 0, r = this.gridBrickInputs[n];
13211
+ if (!r) throw Error(`brdb: unknown grid handle (slot ${n})`);
13212
+ return r.push(e), {
13213
+ grid: n,
13214
+ index: r.length - 1
13215
+ };
13216
+ }
13217
+ addBricks(e, t) {
13218
+ return [...e].map((e) => this.addBrick(e, t));
13219
+ }
13220
+ addEntity(e = {}) {
13221
+ return this.entityInputs.push(e), { entityOrder: this.entityInputs.length - 1 };
13222
+ }
13223
+ addBrickGrid(e = {}) {
13224
+ let t = this.addEntity({
13225
+ type: "Entity_DynamicBrickGrid",
13226
+ ...e
13227
+ });
13228
+ return this.gridBrickInputs.push([]), this.gridEntityOrders.push(t.entityOrder), {
13229
+ grid: this.gridBrickInputs.length - 1,
13230
+ entityOrder: t.entityOrder
13231
+ };
13232
+ }
13233
+ addWire(e, t) {
13234
+ this.wireList.push({
13235
+ source: e,
13236
+ target: t
13237
+ });
13238
+ }
13239
+ registerMicrochipLink(e, t) {
13240
+ this.chipLinks.push({
13241
+ brick: e,
13242
+ grid: t
13243
+ });
13244
+ }
13245
+ addMicrochip(e) {
13246
+ let t = this.addBrick({
13247
+ asset: "B_1x1_Microchip",
13248
+ position: e.position,
13249
+ color: e.color,
13250
+ owner_index: e.owner_index,
13251
+ components: [{ type: "Component_Internal_Microchip" }]
13252
+ }), n = this.addBrickGrid({
13253
+ type: "Entity_MicrochipDynamicBrickGrid",
13254
+ location: e.entityLocation ?? {
13255
+ X: 0,
13256
+ Y: 0,
13257
+ Z: 40
13258
+ },
13259
+ data: {
13260
+ bCollapsed: e.collapsed ?? !0,
13261
+ PlaneCenter: {
13262
+ X: 0,
13263
+ Y: 0,
13264
+ Z: 0
13265
+ },
13266
+ PlaneExtent: e.planeExtent ?? {
13267
+ X: 14,
13268
+ Y: 14,
13269
+ Z: 2
13270
+ }
13271
+ }
13272
+ });
13273
+ return this.registerMicrochipLink(t, n), {
13274
+ brick: t,
13275
+ grid: n
13276
+ };
13277
+ }
13278
+ makePrefab(e = {}) {
13279
+ this.prefabOptions = e;
13280
+ }
13281
+ toPendingFs(e = {}) {
13282
+ let t = new ro(), n = new ro();
13283
+ for (let e of this.gridBrickInputs) for (let r of e) t.add(r.asset ?? "PB_DefaultBrick"), n.add(r.material ?? "BMC_Plastic");
13284
+ let r = this.gridBrickInputs.map((e, r) => no({
13285
+ brick_assets: t.names,
13286
+ materials: n.names,
13287
+ brick_owners: this.ownerList,
13288
+ bricks: e.map((e) => ({
13289
+ ...e,
13290
+ asset_name_index: t.indexOf(e.asset ?? "PB_DefaultBrick"),
13291
+ material_index: n.indexOf(e.material ?? "BMC_Plastic"),
13292
+ size: e.size ?? (e.asset === void 0 ? [
13293
+ 5,
13294
+ 5,
13295
+ 6
13296
+ ] : void 0),
13297
+ position: r === 0 ? e.position : e.position.map((e) => e - Qa),
13298
+ color: e.color ?? [
13299
+ 255,
13300
+ 255,
13301
+ 255
13302
+ ]
13303
+ }))
13304
+ })), i = this.entityInputs.map((e, t) => lo(e, t, this.ownerList.length)), a = [1, ...this.gridEntityOrders.map((e) => 2 + e)];
13305
+ return co({
13306
+ ownerRows: oo(this.ownerList),
13307
+ grids: r,
13308
+ gridIds: a,
13309
+ entities: i,
13310
+ wires: this.wireList.map((e) => ({
13311
+ source: {
13312
+ gridSlot: e.source.brick.grid,
13313
+ brickIndex: e.source.brick.index,
13314
+ componentType: e.source.component_type,
13315
+ port: e.source.port
13316
+ },
13317
+ target: {
13318
+ gridSlot: e.target.brick.grid,
13319
+ brickIndex: e.target.brick.index,
13320
+ componentType: e.target.component_type,
13321
+ port: e.target.port
13322
+ }
13323
+ })),
13324
+ microchipLinks: this.chipLinks.map((e) => ({
13325
+ gridSlot: e.brick.grid,
13326
+ brickIndex: e.brick.index,
13327
+ gridReference: 2 + e.grid.entityOrder
13328
+ })),
13329
+ prefab: this.prefabOptions ? uo(r[0], this.prefabOptions) : null
13330
+ }, e);
13331
+ }
13332
+ toBrz(e = {}) {
13333
+ return Gi(this.toPendingFs(e), { compress: e.compress });
13334
+ }
13335
+ };
13336
+ function po(e, t = {}) {
13003
13337
  let n = { compress: t.compress };
13004
- return Gi(oo(e, t), n);
13338
+ return Gi(so(e, t), n);
13005
13339
  }
13006
- function co(e) {
13340
+ function mo(e) {
13007
13341
  let t = e <= 15 ? 15 : 255;
13008
13342
  return Math.trunc((e / 255) ** (1 / 2.2) * t);
13009
13343
  }
13010
- function lo(e) {
13344
+ function ho(e) {
13011
13345
  return {
13012
13346
  ...e,
13013
- R: co(e.R),
13014
- G: co(e.G),
13015
- B: co(e.B)
13347
+ R: mo(e.R),
13348
+ G: mo(e.G),
13349
+ B: mo(e.B)
13016
13350
  };
13017
13351
  }
13018
- function uo(e) {
13352
+ function go(e) {
13019
13353
  let t = {};
13020
- for (let [n, r] of Object.entries(e)) t[n] = lo(r);
13354
+ for (let [n, r] of Object.entries(e)) t[n] = ho(r);
13021
13355
  return t;
13022
13356
  }
13023
- function fo(e, t, n) {
13357
+ function _o(e, t, n) {
13024
13358
  let r = 0;
13025
13359
  for (let t of e.BrickSizeCounters) r += t.NumSizes;
13026
13360
  if (r < 0 || r > e.BrickSizes.length) throw Error("brdb: brick size counters exceed size table");
@@ -13043,7 +13377,7 @@ function fo(e, t, n) {
13043
13377
  r.Z
13044
13378
  ];
13045
13379
  }
13046
- let d = e.RelativePositions[r], f = e.Orientations[r], p = e.ColorsAndAlphas[r], m = o ? lo(p) : p;
13380
+ let d = e.RelativePositions[r], f = e.Orientations[r], p = e.ColorsAndAlphas[r], m = o ? ho(p) : p;
13047
13381
  s.push({
13048
13382
  asset_name_index: l,
13049
13383
  size: u,
@@ -13074,7 +13408,7 @@ function fo(e, t, n) {
13074
13408
  }
13075
13409
  return s;
13076
13410
  }
13077
- var po = class e {
13411
+ var vo = class e {
13078
13412
  constructor(e, t = 0) {
13079
13413
  this.fs = e, this.worldId = t, this.schemas = /* @__PURE__ */ new Map(), this.values = /* @__PURE__ */ new Map();
13080
13414
  }
@@ -13169,7 +13503,7 @@ var po = class e {
13169
13503
  }
13170
13504
  *bricks(e = 1) {
13171
13505
  let t = this.globalData().BasicBrickAssetNames.length;
13172
- for (let n of this.brickChunkIndex(e)) yield* fo(this.brickChunkSoa(e, n.index), n.index, t);
13506
+ for (let n of this.brickChunkIndex(e)) yield* _o(this.brickChunkSoa(e, n.index), n.index, t);
13173
13507
  }
13174
13508
  entityChunkIndex() {
13175
13509
  let e = this.decode(this.path("Entities/ChunkIndex.mps"), this.path("Entities/ChunkIndex.schema"), "BRSavedEntityChunkIndexSoA");
@@ -13255,7 +13589,7 @@ var po = class e {
13255
13589
  sleeping: Lr(s.PhysicsSleepingFlags, f),
13256
13590
  linearVelocity: s.LinearVelocities[f],
13257
13591
  angularVelocity: s.AngularVelocities[f],
13258
- colors: u ? uo(e) : e,
13592
+ colors: u ? go(e) : e,
13259
13593
  remainingLifeSpan: s.RemainingLifeSpans?.[f] ?? 0,
13260
13594
  data: r ? i.readValue(o, r) : null
13261
13595
  }), f += 1;
@@ -13267,74 +13601,74 @@ var po = class e {
13267
13601
  *entities() {
13268
13602
  for (let e of this.entityChunkIndex().chunks) yield* this.entityChunk(e.index);
13269
13603
  }
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);
13604
+ }, 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
13605
  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 = [
13606
+ CREATE INDEX files_parent_name_deleted ON files(parent_id, name, deleted_at);`, So = [
13273
13607
  "blobs",
13274
13608
  "revisions",
13275
13609
  "folders",
13276
13610
  "files"
13277
- ], vo = () => Math.floor(Date.now() / 1e3), yo = (e) => typeof Buffer > "u" ? e : Buffer.from(e.buffer, e.byteOffset, e.byteLength), bo = (e) => {
13611
+ ], Co = () => Math.floor(Date.now() / 1e3), wo = (e) => typeof Buffer > "u" ? e : Buffer.from(e.buffer, e.byteOffset, e.byteLength), To = (e) => {
13278
13612
  try {
13279
13613
  return typeof process < "u" ? process?.getBuiltinModule?.(e) ?? null : null;
13280
13614
  } catch {
13281
13615
  return null;
13282
13616
  }
13283
- }, xo = null, So = (e) => (xo ?? (xo = Function("specifier", "return import(specifier)")), xo(e));
13284
- async function Co() {
13617
+ }, Eo = null, Do = (e) => (Eo ?? (Eo = Function("specifier", "return import(specifier)")), Eo(e));
13618
+ async function Oo() {
13285
13619
  try {
13286
- let e = await (To.engineLoader ?? (() => So("better-sqlite3")))();
13620
+ let e = await (Ao.engineLoader ?? (() => Do("better-sqlite3")))();
13287
13621
  return e.default ?? e;
13288
13622
  } catch {
13289
13623
  throw Error("brdb: the Brdb openers require better-sqlite3 (npm install better-sqlite3), or wrap your own handle with new Brdb(db)");
13290
13624
  }
13291
13625
  }
13292
- function wo() {
13293
- let e = bo("node:zlib");
13626
+ function ko() {
13627
+ let e = To("node:zlib");
13294
13628
  if (typeof e?.zstdCompressSync != "function") return null;
13295
13629
  let t = e.constants.ZSTD_c_compressionLevel;
13296
13630
  return (n) => new Uint8Array(e.zstdCompressSync(n, { params: { [t]: 14 } }));
13297
13631
  }
13298
- var To = class e {
13632
+ var Ao = class e {
13299
13633
  constructor(e) {
13300
13634
  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}'`);
13635
+ 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
13636
  }
13303
- static init(t, n = vo()) {
13304
- t.exec(go);
13637
+ static init(t, n = Co()) {
13638
+ t.exec(xo);
13305
13639
  let r = new e(t);
13306
13640
  return r.createRevision("Initial Revision", n), r;
13307
13641
  }
13308
13642
  static async wrap(t, n) {
13309
13643
  try {
13310
13644
  let r = n ? e.init(t) : new e(t);
13311
- return r.defaultCompress = wo(), r;
13645
+ return r.defaultCompress = ko(), r;
13312
13646
  } catch (e) {
13313
13647
  throw t.close(), e;
13314
13648
  }
13315
13649
  }
13316
13650
  static async open(t) {
13317
- return e.wrap(new (await (Co()))(t, { fileMustExist: !0 }), !1);
13651
+ return e.wrap(new (await (Oo()))(t, { fileMustExist: !0 }), !1);
13318
13652
  }
13319
13653
  static async openReadonly(t) {
13320
- return e.wrap(new (await (Co()))(t, {
13654
+ return e.wrap(new (await (Oo()))(t, {
13321
13655
  readonly: !0,
13322
13656
  fileMustExist: !0
13323
13657
  }), !1);
13324
13658
  }
13325
13659
  static async create(t) {
13326
- return e.wrap(new (await (Co()))(t), !0);
13660
+ return e.wrap(new (await (Oo()))(t), !0);
13327
13661
  }
13328
13662
  static async openOrCreate(t) {
13329
- let n = bo("node:fs");
13663
+ let n = To("node:fs");
13330
13664
  if (!n) throw Error("brdb: openOrCreate requires node 22.3 or newer; call open or create explicitly");
13331
13665
  return n.existsSync(t) ? e.open(t) : e.create(t);
13332
13666
  }
13333
13667
  static async memory() {
13334
- return e.wrap(new (await (Co()))(":memory:"), !0);
13668
+ return e.wrap(new (await (Oo()))(":memory:"), !0);
13335
13669
  }
13336
13670
  static async fromBytes(t) {
13337
- return e.wrap(new (await (Co()))(Buffer.from(t)), !1);
13671
+ return e.wrap(new (await (Oo()))(Buffer.from(t)), !1);
13338
13672
  }
13339
13673
  toBytes() {
13340
13674
  let e = this.db.serialize;
@@ -13342,15 +13676,15 @@ var To = class e {
13342
13676
  return new Uint8Array(e.call(this.db));
13343
13677
  }
13344
13678
  save(e, t, n = {}) {
13345
- this.writePending(e, oo(t, n), n);
13679
+ this.writePending(e, t instanceof fo ? t.toPendingFs(n) : so(t, n), n);
13346
13680
  }
13347
13681
  worldReader() {
13348
- return new po(this);
13682
+ return new vo(this);
13349
13683
  }
13350
13684
  sqliteSchema() {
13351
13685
  return this.db.prepare("SELECT sql FROM sqlite_schema").all().map((e) => e.sql).join("\n");
13352
13686
  }
13353
- createRevision(e, t = vo()) {
13687
+ createRevision(e, t = Co()) {
13354
13688
  return Number(this.db.prepare("INSERT INTO revisions (description, created_at) VALUES (?, ?);").run(e, t).lastInsertRowid);
13355
13689
  }
13356
13690
  revisions() {
@@ -13370,16 +13704,16 @@ var To = class e {
13370
13704
  let r = this.findBlobByHash(e.length, t);
13371
13705
  if (r) return r.blobId;
13372
13706
  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);
13707
+ 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
13708
  }
13375
13709
  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;
13710
+ 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);
13711
+ return n ? jo(n) : null;
13378
13712
  }
13379
13713
  findBlob(e) {
13380
13714
  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
13715
  if (!t) throw Error(`brdb: blob ${e} not found`);
13382
- return Eo(t);
13716
+ return jo(t);
13383
13717
  }
13384
13718
  deleteFile(e, t) {
13385
13719
  this.db.prepare("UPDATE files SET deleted_at = ? WHERE file_id = ?;").run(t, e);
@@ -13406,7 +13740,7 @@ var To = class e {
13406
13740
  }
13407
13741
  findFile(e, t) {
13408
13742
  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;
13743
+ return n ? Mo(n) : null;
13410
13744
  }
13411
13745
  findFileAtRevision(e, t, n) {
13412
13746
  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 +13753,13 @@ var To = class e {
13419
13753
  n,
13420
13754
  n
13421
13755
  ]);
13422
- return r ? Do(r) : null;
13756
+ return r ? Mo(r) : null;
13423
13757
  }
13424
13758
  close() {
13425
13759
  this.db.close();
13426
13760
  }
13427
13761
  writePending(e, t, n = {}) {
13428
- let r = n.createdAt ?? vo(), i = n.compress === void 0 ? this.defaultCompress : n.compress;
13762
+ let r = n.createdAt ?? Co(), i = n.compress === void 0 ? this.defaultCompress : n.compress;
13429
13763
  this.db.exec("BEGIN");
13430
13764
  try {
13431
13765
  this.createRevision(e, r), this.mergeFolder(null, t, r, i), this.db.exec("COMMIT");
@@ -13552,8 +13886,8 @@ var To = class e {
13552
13886
  return e(null);
13553
13887
  }
13554
13888
  };
13555
- mo = To, mo.engineLoader = null;
13556
- var Eo = (e) => ({
13889
+ yo = Ao, yo.engineLoader = null;
13890
+ var jo = (e) => ({
13557
13891
  blobId: Number(e.blob_id),
13558
13892
  compression: Number(e.compression),
13559
13893
  sizeUncompressed: Number(e.size_uncompressed),
@@ -13561,15 +13895,15 @@ var Eo = (e) => ({
13561
13895
  deltaBaseId: e.delta_base_id === null ? null : Number(e.delta_base_id),
13562
13896
  hash: new Uint8Array(e.hash),
13563
13897
  content: new Uint8Array(e.content)
13564
- }), Do = (e) => ({
13898
+ }), Mo = (e) => ({
13565
13899
  contentId: e.content_id === null ? -1 : Number(e.content_id),
13566
13900
  createdAt: Number(e.created_at)
13567
- }), Oo = /* @__PURE__ */ t({
13901
+ }), No = /* @__PURE__ */ t({
13568
13902
  BASIC_BRICK_ASSETS: () => qi,
13569
- BRDB_SQLITE_SCHEMA: () => go,
13903
+ BRDB_SQLITE_SCHEMA: () => xo,
13570
13904
  BRICK_ASSETS: () => Yi,
13571
13905
  BitFlags: () => Rr,
13572
- Brdb: () => To,
13906
+ Brdb: () => Ao,
13573
13907
  BrdbSchema: () => Ja,
13574
13908
  BrzReader: () => Ki,
13575
13909
  ByteReader: () => Wi,
@@ -13585,7 +13919,8 @@ var Eo = (e) => ({
13585
13919
  PROCEDURAL_BRICK_ASSETS: () => Ji,
13586
13920
  PUBLIC_GUID: () => aa,
13587
13921
  WIRE_PORT_NAMES: () => ta,
13588
- WorldReader: () => po,
13922
+ World: () => fo,
13923
+ WorldReader: () => vo,
13589
13924
  bit: () => Lr,
13590
13925
  embeddedSchema: () => Xa,
13591
13926
  file: () => X,
@@ -13593,21 +13928,21 @@ var Eo = (e) => ({
13593
13928
  guidToUuid: () => sa,
13594
13929
  isProceduralAsset: () => Qi,
13595
13930
  msgpack: () => la,
13596
- saveToPendingFs: () => oo,
13931
+ saveToPendingFs: () => so,
13597
13932
  toRelative: () => to,
13598
13933
  uuidToGuid: () => oa,
13599
13934
  writeBrzContainer: () => Gi,
13600
- writeBrzLegacy: () => so
13601
- }), ko = {
13935
+ writeBrzLegacy: () => po
13936
+ }), Po = {
13602
13937
  read: Ar,
13603
13938
  write: Nr,
13604
13939
  utils: tr,
13605
13940
  constants: n,
13606
13941
  types: Pr,
13607
- brdb: Oo
13942
+ brdb: No
13608
13943
  };
13609
- typeof window < "u" && (window.BRS = ko);
13944
+ typeof window < "u" && (window.BRS = Po);
13610
13945
  //#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 };
13946
+ 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
13947
 
13613
13948
  //# sourceMappingURL=dist.mjs.map