brs-js 2.0.1 → 2.0.4

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.
Files changed (81) hide show
  1. package/debug/Conf Spacestation.brs +0 -0
  2. package/debug/Electrks_Feminine_Challenge.brs +0 -0
  3. package/debug/a5bricks.brs +0 -0
  4. package/debug/a5p2.2.brs +0 -0
  5. package/debug/a5p2.brs +0 -0
  6. package/debug/audio.brs +0 -0
  7. package/debug/brick a5.brs +0 -0
  8. package/debug/brick qa.brs +0 -0
  9. package/debug/brsv10.brs +0 -0
  10. package/debug/brsv10brick.brs +0 -0
  11. package/debug/bruteforce.js +254 -0
  12. package/debug/clone.html +36 -0
  13. package/debug/ctf_tileset.brs +0 -0
  14. package/debug/ctf_tileset_5.brs +0 -0
  15. package/debug/evil.brs +0 -0
  16. package/debug/evilwrite.js +390 -0
  17. package/debug/foo.txt +3080 -0
  18. package/debug/kenko_big.brs +0 -0
  19. package/debug/light.brs +0 -0
  20. package/debug/out.json +105 -0
  21. package/debug/read.js +30 -0
  22. package/debug/readSpeed.js +32 -0
  23. package/debug/readTest.js +45 -0
  24. package/debug/temp.brs +0 -0
  25. package/debug/western.brs +0 -0
  26. package/dist/dist.js +1 -1
  27. package/dist/dist.node.js +1 -1
  28. package/dist/dist.web.js +1 -1
  29. package/dist/src/constants.d.ts +6 -0
  30. package/dist/src/constants.d.ts.map +1 -0
  31. package/dist/src/index.d.ts +24 -0
  32. package/dist/src/index.d.ts.map +1 -0
  33. package/dist/src/read.d.ts +3 -0
  34. package/dist/src/read.d.ts.map +1 -0
  35. package/dist/src/read.v1.d.ts +3 -0
  36. package/dist/src/read.v1.d.ts.map +1 -0
  37. package/dist/src/read.v10.d.ts +3 -0
  38. package/dist/src/read.v10.d.ts.map +1 -0
  39. package/dist/src/read.v2.d.ts +3 -0
  40. package/dist/src/read.v2.d.ts.map +1 -0
  41. package/dist/src/read.v3.d.ts +3 -0
  42. package/dist/src/read.v3.d.ts.map +1 -0
  43. package/dist/src/read.v4.d.ts +3 -0
  44. package/dist/src/read.v4.d.ts.map +1 -0
  45. package/dist/src/read.v8.d.ts +3 -0
  46. package/dist/src/read.v8.d.ts.map +1 -0
  47. package/dist/src/read.v9.d.ts +3 -0
  48. package/dist/src/read.v9.d.ts.map +1 -0
  49. package/dist/src/types.d.ts +286 -0
  50. package/dist/src/types.d.ts.map +1 -0
  51. package/dist/src/utils.d.ts +87 -0
  52. package/dist/src/utils.d.ts.map +1 -0
  53. package/dist/src/uuid.d.ts +4 -0
  54. package/dist/src/uuid.d.ts.map +1 -0
  55. package/dist/src/write.d.ts +3 -0
  56. package/dist/src/write.d.ts.map +1 -0
  57. package/examples/ATCFort.brs +0 -0
  58. package/examples/read_example.html +34 -0
  59. package/examples/read_example.js +21 -0
  60. package/examples/write_example.js +25 -0
  61. package/examples/write_planet.html +144 -0
  62. package/examples/write_simplex.html +82 -0
  63. package/examples/write_wedge_sphere.html +173 -0
  64. package/package.json +1 -1
  65. package/src/constants.ts +6 -0
  66. package/src/index.ts +25 -0
  67. package/src/read.ts +57 -0
  68. package/src/read.v1.ts +99 -0
  69. package/src/read.v10.ts +185 -0
  70. package/src/read.v2.ts +102 -0
  71. package/src/read.v3.ts +111 -0
  72. package/src/read.v4.ts +112 -0
  73. package/src/read.v8.ts +172 -0
  74. package/src/read.v9.ts +181 -0
  75. package/src/types.ts +354 -0
  76. package/src/utils.ts +640 -0
  77. package/src/uuid.ts +78 -0
  78. package/src/write.ts +209 -0
  79. package/test/lib.test.js +51 -0
  80. package/test/utils.test.js +209 -0
  81. package/tsconfig.json +1 -5
package/src/types.ts ADDED
@@ -0,0 +1,354 @@
1
+ export interface BRSBytes extends Uint8Array {
2
+ brsOffset: number;
3
+ }
4
+
5
+ type Modify<T, R> = Omit<T, keyof R> & R;
6
+
7
+ export type Bytes = Uint8Array | BRSBytes;
8
+ export type Uuid = string;
9
+
10
+ export type UnrealClass = string;
11
+ export type UnrealObject = string;
12
+ export type UnrealBoolean = boolean;
13
+ export type UnrealFloat = number;
14
+ export type UnrealColor = [number, number, number, number];
15
+ export type UnrealByte = number;
16
+ export type UnrealRotator = [number, number, number];
17
+ export type UnrealType =
18
+ | UnrealClass
19
+ | UnrealObject
20
+ | UnrealBoolean
21
+ | UnrealFloat
22
+ | UnrealColor
23
+ | UnrealByte
24
+ | UnrealRotator;
25
+
26
+ export interface User {
27
+ id: Uuid;
28
+ name: string;
29
+ }
30
+
31
+ export interface Owner extends User {
32
+ bricks: number;
33
+ }
34
+
35
+ export enum Direction {
36
+ XPositive,
37
+ XNegative,
38
+ YPositive,
39
+ YNegative,
40
+ ZPositive,
41
+ ZNegative,
42
+ }
43
+
44
+ export enum Rotation {
45
+ Deg0,
46
+ Deg90,
47
+ Deg180,
48
+ Deg270,
49
+ }
50
+
51
+ export type ColorRgb = [number, number, number];
52
+
53
+ export interface Collision {
54
+ player: boolean;
55
+ weapon: boolean;
56
+ interaction: boolean;
57
+ tool: boolean;
58
+ }
59
+
60
+ export interface AppliedComponent {
61
+ [property: string]: UnrealType;
62
+ }
63
+
64
+ export interface DefinedComponents {
65
+ BCD_SpotLight?: {
66
+ version: 1;
67
+ brick_indices: number[];
68
+ properties: {
69
+ Rotation: 'Rotator';
70
+ InnerConeAngle: 'Float';
71
+ OuterConeAngle: 'Float';
72
+ Brightness: 'Float';
73
+ Radius: 'Float';
74
+ Color: 'Color';
75
+ bUseBrickColor: 'Boolean';
76
+ bCastShadows: 'Boolean';
77
+ };
78
+ };
79
+ BCD_PointLight?: {
80
+ version: 1;
81
+ brick_indices: number[];
82
+ properties: {
83
+ bMatchBrickShape: 'Boolean';
84
+ Brightness: 'Float';
85
+ Radius: 'Float';
86
+ Color: 'Color';
87
+ bUseBrickColor: 'Boolean';
88
+ bCastShadows: 'Boolean';
89
+ };
90
+ };
91
+ BCD_ItemSpawn?: {
92
+ version: 1;
93
+ brick_indices: number[];
94
+ properties: {
95
+ PickupClass: 'Class';
96
+ bPickupEnabled: 'Boolean';
97
+ bPickupRespawnOnMinigameReset: 'Boolean';
98
+ PickupMinigameResetRespawnDelay: 'Float';
99
+ bPickupAutoDisableOnPickup: 'Boolean';
100
+ PickupRespawnTime: 'Float';
101
+ PickupOffsetDirection: 'Byte';
102
+ PickupOffsetDistance: 'Float';
103
+ PickupRotation: 'Rotator';
104
+ PickupScale: 'Float';
105
+ bPickupAnimationEnabled: 'Boolean';
106
+ PickupAnimationAxis: 'Byte';
107
+ bPickupAnimationAxisLocal: 'Boolean';
108
+ PickupSpinSpeed: 'Float';
109
+ PickupBobSpeed: 'Float';
110
+ PickupBobHeight: 'Float';
111
+ PickupAnimationPhase: 'Float';
112
+ };
113
+ };
114
+ BCD_Interact?: {
115
+ version: 1;
116
+ brick_indices: number[];
117
+ properties: { bPlayInteractSound: 'Boolean' };
118
+ };
119
+ BCD_AudioEmitter?: {
120
+ version: 1;
121
+ brick_indices: number[];
122
+ properties: {
123
+ AudioDescriptor: 'Object';
124
+ VolumeMultiplier: 'Float';
125
+ PitchMultiplier: 'Float';
126
+ InnerRadius: 'Float';
127
+ MaxDistance: 'Float';
128
+ bSpatialization: 'Boolean';
129
+ };
130
+ };
131
+ [component_name: string]: {
132
+ version: number;
133
+ brick_indices: number[];
134
+ properties: { [property: string]: string };
135
+ };
136
+ }
137
+
138
+ export interface Components {
139
+ BCD_SpotLight?: {
140
+ Rotation: UnrealRotator;
141
+ InnerConeAngle: UnrealFloat;
142
+ OuterConeAngle: UnrealFloat;
143
+ Brightness: UnrealFloat;
144
+ Radius: UnrealFloat;
145
+ Color: UnrealColor;
146
+ bUseBrickColor: UnrealBoolean;
147
+ bCastShadows: UnrealBoolean;
148
+ };
149
+ BCD_PointLight?: {
150
+ bMatchBrickShape: UnrealBoolean;
151
+ Brightness: UnrealFloat;
152
+ Radius: UnrealFloat;
153
+ Color: UnrealColor;
154
+ bUseBrickColor: UnrealBoolean;
155
+ bCastShadows: UnrealBoolean;
156
+ };
157
+ BCD_ItemSpawn?: {
158
+ PickupClass: UnrealClass;
159
+ bPickupEnabled: UnrealBoolean;
160
+ bPickupRespawnOnMinigameReset: UnrealBoolean;
161
+ PickupMinigameResetRespawnDelay: UnrealFloat;
162
+ bPickupAutoDisableOnPickup: UnrealBoolean;
163
+ PickupRespawnTime: UnrealFloat;
164
+ PickupOffsetDirection: UnrealByte;
165
+ PickupOffsetDistance: UnrealFloat;
166
+ PickupRotation: UnrealRotator;
167
+ PickupScale: UnrealFloat;
168
+ bPickupAnimationEnabled: UnrealBoolean;
169
+ PickupAnimationAxis: UnrealByte;
170
+ bPickupAnimationAxisLocal: UnrealBoolean;
171
+ PickupSpinSpeed: UnrealFloat;
172
+ PickupBobSpeed: UnrealFloat;
173
+ PickupBobHeight: UnrealFloat;
174
+ PickupAnimationPhase: UnrealFloat;
175
+ };
176
+ BCD_Interact?: {
177
+ bPlayInteractSound: UnrealBoolean;
178
+ };
179
+ BCD_AudioEmitter?: {
180
+ AudioDescriptor: UnrealObject;
181
+ VolumeMultiplier: UnrealFloat;
182
+ PitchMultiplier: UnrealFloat;
183
+ InnerRadius: UnrealFloat;
184
+ MaxDistance: UnrealFloat;
185
+ bSpatialization: UnrealBoolean;
186
+ };
187
+ [component_name: string]: AppliedComponent;
188
+ }
189
+
190
+ export type Vector = [number, number, number];
191
+
192
+ export interface BrickV1 {
193
+ asset_name_index: number;
194
+ size: Vector;
195
+ position: Vector;
196
+ direction: Direction;
197
+ rotation: Rotation;
198
+ collision: boolean;
199
+ visibility: boolean;
200
+ color: UnrealColor | number;
201
+ }
202
+
203
+ export interface BrickV2 extends BrickV1 {
204
+ material_index: number;
205
+ }
206
+
207
+ export interface BrickV3 extends BrickV2 {
208
+ owner_index: number;
209
+ }
210
+
211
+ export interface BrickV8 extends BrickV3 {
212
+ components: Components;
213
+ }
214
+
215
+ export type BrickV9 = Modify<
216
+ BrickV8,
217
+ {
218
+ physical_index: number;
219
+ material_intensity: number;
220
+ color: ColorRgb | number;
221
+ }
222
+ >;
223
+
224
+ export type BrickV10 = Modify<
225
+ BrickV9,
226
+ {
227
+ collision: Collision;
228
+ }
229
+ >;
230
+
231
+ export interface BrsV1 {
232
+ version: 1;
233
+ map: string;
234
+ author: User;
235
+ description: string;
236
+ brick_count: number;
237
+ mods: string[];
238
+ brick_assets: string[];
239
+ colors: UnrealColor[];
240
+ bricks: BrickV1[];
241
+ }
242
+
243
+ export type BrsV2 = Modify<
244
+ BrsV1,
245
+ {
246
+ version: 2;
247
+ materials: string[];
248
+ bricks: BrickV2[];
249
+ }
250
+ >;
251
+
252
+ export type BrsV3 = Modify<
253
+ BrsV2,
254
+ {
255
+ version: 3;
256
+ brick_owners: User[];
257
+ bricks: BrickV3[];
258
+ }
259
+ >;
260
+
261
+ export type BrsV4 = Modify<
262
+ BrsV3,
263
+ {
264
+ version: 4;
265
+ save_time: Uint8Array;
266
+ }
267
+ >;
268
+
269
+ // not sure what part of 8 makes up 5-7 but nobody should have any saves in those versions
270
+
271
+ export type BrsV8 = Modify<
272
+ BrsV4,
273
+ {
274
+ version: 8;
275
+ host: User;
276
+ brick_owners: Owner[];
277
+ preview?: Bytes;
278
+ game_version: number;
279
+ bricks: BrickV8[];
280
+ components: DefinedComponents;
281
+ }
282
+ >;
283
+
284
+ export type BrsV9 = Modify<
285
+ BrsV8,
286
+ {
287
+ version: 9;
288
+ physical_materials: string[];
289
+ bricks: BrickV9[];
290
+ }
291
+ >;
292
+
293
+ export type BrsV10 = Modify<
294
+ BrsV9,
295
+ {
296
+ version: 10;
297
+ bricks: BrickV10[];
298
+ }
299
+ >;
300
+
301
+ // a save read from a file
302
+ export type ReadSaveObject =
303
+ | BrsV1
304
+ | BrsV2
305
+ | BrsV3
306
+ | BrsV4
307
+ | BrsV8
308
+ | BrsV9
309
+ | BrsV10;
310
+
311
+ // a brick a user provides
312
+ export interface Brick {
313
+ asset_name_index?: number;
314
+ size: Vector;
315
+ position: Vector;
316
+ direction?: Direction;
317
+ rotation?: Rotation;
318
+ collision?: boolean | Partial<Collision>;
319
+ visibility?: boolean;
320
+ material_index?: number;
321
+ physical_index?: number;
322
+ material_intensity?: number;
323
+ color?: ColorRgb | number;
324
+ owner_index?: number;
325
+ components?: Components;
326
+ }
327
+
328
+ // save a user can write
329
+ export interface WriteSaveObject {
330
+ game_version?: number;
331
+ map?: string;
332
+ description?: string;
333
+ author?: Partial<User>;
334
+ host?: Partial<User>;
335
+ mods?: string[];
336
+ brick_assets?: string[];
337
+ colors?: UnrealColor[];
338
+ materials?: string[];
339
+ brick_owners?: Partial<Owner>[];
340
+ physical_materials?: string[];
341
+ preview?: Bytes;
342
+ bricks: Brick[];
343
+ save_time?: ArrayLike<number>;
344
+ components?: DefinedComponents;
345
+ }
346
+
347
+ export interface ReadOptions {
348
+ bricks?: boolean;
349
+ preview?: boolean;
350
+ }
351
+
352
+ export interface WriteOptions {
353
+ compress?: boolean;
354
+ }