brs-js 2.0.5 → 2.0.6

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/src/write.ts CHANGED
@@ -1,9 +1,80 @@
1
- import { MAGIC, LATEST_VERSION, MAX_INT, DEFAULT_UUID } from './constants';
2
- import { Brick, Owner, WriteOptions, WriteSaveObject } from './types';
3
- import { write, isEqual, concat } from './utils';
1
+ import { DEFAULT_UUID, LATEST_VERSION, MAGIC, MAX_INT } from './constants';
2
+ import {
3
+ Brick,
4
+ DefinedComponents,
5
+ KnownComponents,
6
+ Owner,
7
+ WriteOptions,
8
+ WriteSaveObject,
9
+ } from './types';
10
+ import { concat, isEqual, write } from './utils';
4
11
 
5
12
  const EMPTY_ARR = new Uint8Array([]);
6
13
 
14
+ export const DEFAULT_COMPONENTS: DefinedComponents = {
15
+ BCD_SpotLight: {
16
+ version: 1,
17
+ properties: {
18
+ Rotation: 'Rotator',
19
+ InnerConeAngle: 'Float',
20
+ OuterConeAngle: 'Float',
21
+ Brightness: 'Float',
22
+ Radius: 'Float',
23
+ Color: 'Color',
24
+ bUseBrickColor: 'Boolean',
25
+ bCastShadows: 'Boolean',
26
+ },
27
+ },
28
+ BCD_PointLight: {
29
+ version: 1,
30
+ properties: {
31
+ bMatchBrickShape: 'Boolean',
32
+ Brightness: 'Float',
33
+ Radius: 'Float',
34
+ Color: 'Color',
35
+ bUseBrickColor: 'Boolean',
36
+ bCastShadows: 'Boolean',
37
+ },
38
+ },
39
+ BCD_ItemSpawn: {
40
+ version: 1,
41
+ properties: {
42
+ PickupClass: 'Class',
43
+ bPickupEnabled: 'Boolean',
44
+ bPickupRespawnOnMinigameReset: 'Boolean',
45
+ PickupMinigameResetRespawnDelay: 'Float',
46
+ bPickupAutoDisableOnPickup: 'Boolean',
47
+ PickupRespawnTime: 'Float',
48
+ PickupOffsetDirection: 'Byte',
49
+ PickupOffsetDistance: 'Float',
50
+ PickupRotation: 'Rotator',
51
+ PickupScale: 'Float',
52
+ bPickupAnimationEnabled: 'Boolean',
53
+ PickupAnimationAxis: 'Byte',
54
+ bPickupAnimationAxisLocal: 'Boolean',
55
+ PickupSpinSpeed: 'Float',
56
+ PickupBobSpeed: 'Float',
57
+ PickupBobHeight: 'Float',
58
+ PickupAnimationPhase: 'Float',
59
+ },
60
+ },
61
+ BCD_Interact: {
62
+ version: 1,
63
+ properties: { bPlayInteractSound: 'Boolean' },
64
+ },
65
+ BCD_AudioEmitter: {
66
+ version: 1,
67
+ properties: {
68
+ AudioDescriptor: 'Object',
69
+ VolumeMultiplier: 'Float',
70
+ PitchMultiplier: 'Float',
71
+ InnerRadius: 'Float',
72
+ MaxDistance: 'Float',
73
+ bSpatialization: 'Boolean',
74
+ },
75
+ },
76
+ };
77
+
7
78
  export default function writeBrs(
8
79
  save: WriteSaveObject,
9
80
  options: WriteOptions = {}
@@ -160,7 +231,7 @@ export default function writeBrs(
160
231
  // write components section
161
232
  compress(
162
233
  write.array(
163
- Object.keys(save.components ?? {}).filter(
234
+ Object.keys(save.components ?? DEFAULT_COMPONENTS).filter(
164
235
  name => componentBrickOwnership[name]
165
236
  ),
166
237
  name =>
@@ -169,7 +240,8 @@ export default function writeBrs(
169
240
  write
170
241
  .bits()
171
242
  .self(function () {
172
- const component = save.components[name];
243
+ const component =
244
+ save.components?.[name] ?? DEFAULT_COMPONENTS[name];
173
245
  const brick_indices = componentBrickOwnership[name];
174
246
  const properties = Object.entries(component.properties);
175
247
 
@@ -190,7 +262,7 @@ export default function writeBrs(
190
262
  // read brick indices
191
263
  for (const i of brick_indices) {
192
264
  for (const [prop, type] of properties) {
193
- if (!(prop in save.bricks[i].components[name])) {
265
+ if (!(prop in (save.bricks[i].components?.[name] ?? {}))) {
194
266
  throw new Error(
195
267
  `Expected save.bricks[${i}].components[${name}] to have property '${prop}' of type '${type}'`
196
268
  );