brs-js 2.0.12 → 2.0.14

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 (61) hide show
  1. package/dist/dist.js +1 -1
  2. package/dist/dist.js.map +1 -0
  3. package/dist/dist.node.js +1 -1
  4. package/dist/dist.node.js.map +1 -0
  5. package/dist/dist.web.js +1 -1
  6. package/dist/dist.web.js.map +1 -0
  7. package/package.json +1 -1
  8. package/.babelrc +0 -5
  9. package/.prettierrc +0 -7
  10. package/debug/Conf Spacestation.brs +0 -0
  11. package/debug/Electrks_Feminine_Challenge.brs +0 -0
  12. package/debug/a5bricks.brs +0 -0
  13. package/debug/a5p2.2.brs +0 -0
  14. package/debug/a5p2.brs +0 -0
  15. package/debug/audio.brs +0 -0
  16. package/debug/brick a5.brs +0 -0
  17. package/debug/brick qa.brs +0 -0
  18. package/debug/brickparty.brs +0 -0
  19. package/debug/brsv10.brs +0 -0
  20. package/debug/brsv10brick.brs +0 -0
  21. package/debug/bruteforce.js +0 -254
  22. package/debug/click brick.brs +0 -0
  23. package/debug/clone.html +0 -36
  24. package/debug/ctf_tileset.brs +0 -0
  25. package/debug/ctf_tileset_5.brs +0 -0
  26. package/debug/evil.brs +0 -0
  27. package/debug/evilwrite.js +0 -390
  28. package/debug/foo.txt +0 -3080
  29. package/debug/kenko_big.brs +0 -0
  30. package/debug/light.brs +0 -0
  31. package/debug/out.json +0 -105
  32. package/debug/read.js +0 -30
  33. package/debug/readSpeed.js +0 -32
  34. package/debug/readTest.js +0 -45
  35. package/debug/temp.brs +0 -0
  36. package/debug/western.brs +0 -0
  37. package/examples/ATCFort.brs +0 -0
  38. package/examples/read_example.html +0 -34
  39. package/examples/read_example.js +0 -21
  40. package/examples/write_example.js +0 -25
  41. package/examples/write_planet.html +0 -144
  42. package/examples/write_simplex.html +0 -82
  43. package/examples/write_wedge_sphere.html +0 -173
  44. package/src/constants.ts +0 -6
  45. package/src/index.ts +0 -15
  46. package/src/read.ts +0 -57
  47. package/src/read.v1.ts +0 -99
  48. package/src/read.v10.ts +0 -185
  49. package/src/read.v2.ts +0 -102
  50. package/src/read.v3.ts +0 -111
  51. package/src/read.v4.ts +0 -112
  52. package/src/read.v8.ts +0 -172
  53. package/src/read.v9.ts +0 -181
  54. package/src/types.ts +0 -341
  55. package/src/utils.ts +0 -651
  56. package/src/uuid.ts +0 -78
  57. package/src/write.ts +0 -287
  58. package/test/lib.test.js +0 -51
  59. package/test/utils.test.js +0 -209
  60. package/tsconfig.json +0 -18
  61. package/webpack.config.js +0 -64
Binary file
package/debug/light.brs DELETED
Binary file
package/debug/out.json DELETED
@@ -1,105 +0,0 @@
1
- {
2
- "version": 8,
3
- "map": "Plate",
4
- "author": {
5
- "id": "60eab7e7-9aa9-4647-83e4-6ce4ec66ae7d",
6
- "name": "cake"
7
- },
8
- "description": "",
9
- "host": {
10
- "name": "cake",
11
- "id": "60eab7e7-9aa9-4647-83e4-6ce4ec66ae7d"
12
- },
13
- "save_time": [16,151,87,60,218,49,216,8],
14
- "brick_count": 8,
15
- "mods": [],
16
- "brick_assets": [
17
- "PB_DefaultBrick"
18
- ],
19
- "colors": [],
20
- "materials": [
21
- "BMC_Ghost",
22
- "BMC_Ghost_Fail",
23
- "BMC_Plastic",
24
- "BMC_Glow",
25
- "BMC_Metallic",
26
- "BMC_Hologram"
27
- ],
28
- "brick_owners": [
29
- {
30
- "id": "60eab7e7-9aa9-4647-83e4-6ce4ec66ae7d",
31
- "name": "cake",
32
- "bricks": 8
33
- }
34
- ],
35
- "bricks": [
36
- {
37
- "asset_name_index": 0,
38
- "size": [5, 5, 6],
39
- "position": [-145, 315, 6],
40
- "direction": 4,
41
- "rotation": 0,
42
- "collision": true,
43
- "visibility": true,
44
- "material_index": 2,
45
- "color": 0,
46
- "owner_index": 1,
47
- "components": {
48
- "BCD_PointLight": {
49
- "bMatchBrickShape": true,
50
- "Brightness": 20,
51
- "Radius": 150,
52
- "Color": [255, 255, 255, 255],
53
- "bUseBrickColor": true,
54
- "bCastShadows": false
55
- },
56
- "BCD_SpotLight": {
57
- "Rotation": [
58
- 270,
59
- 0,
60
- 0
61
- ],
62
- "InnerConeAngle": 30,
63
- "OuterConeAngle": 60,
64
- "Brightness": 20,
65
- "Radius": 150,
66
- "Color": [255, 255, 255, 255],
67
- "bUseBrickColor": true,
68
- "bCastShadows": false
69
- }
70
- }
71
- }
72
- ],
73
- "components": {
74
- "BCD_PointLight": {
75
- "version": 1,
76
- "brick_indices": [
77
- 0,
78
- ],
79
- "properties": {
80
- "bMatchBrickShape": "Boolean",
81
- "Brightness": "Float",
82
- "Radius": "Float",
83
- "Color": "Color",
84
- "bUseBrickColor": "Boolean",
85
- "bCastShadows": "Boolean"
86
- }
87
- },
88
- "BCD_SpotLight": {
89
- "version": 1,
90
- "brick_indices": [
91
- 0,
92
- ],
93
- "properties": {
94
- "Rotation": "Rotator",
95
- "InnerConeAngle": "Float",
96
- "OuterConeAngle": "Float",
97
- "Brightness": "Float",
98
- "Radius": "Float",
99
- "Color": "Color",
100
- "bUseBrickColor": "Boolean",
101
- "bCastShadows": "Boolean"
102
- }
103
- }
104
- }
105
- }
package/debug/read.js DELETED
@@ -1,30 +0,0 @@
1
- const fs = require('fs');
2
-
3
- const { read } = require('../dist/dist.node.js');
4
-
5
- // arg parsing
6
- const file = process.argv.find(f => f.endsWith('brs'));
7
- if (!file) {
8
- console.error('missing save argument');
9
- process.exit(1);
10
- }
11
- if (!fs.existsSync(file)) {
12
- console.error('file does not exist');
13
- process.exit(1);
14
- }
15
-
16
- // run fn x times
17
- function bench(fn, times) {
18
- const start = Date.now();
19
- for (let i = 0; i < times; i++) {
20
- fn();
21
- }
22
- return Date.now() - start;
23
- }
24
-
25
- const data = fs.readFileSync(file);
26
- console.time('read');
27
- const og = read(data.slice());
28
- console.timeEnd('read');
29
-
30
- process.exit();
@@ -1,32 +0,0 @@
1
- const fs = require('fs');
2
-
3
- const { read } = require('../dist/dist.node.js');
4
-
5
- // arg parsing
6
- const file = process.argv.find(f => f.endsWith('brs'));
7
- if (!file) {
8
- console.error('missing save argument');
9
- process.exit(1);
10
- }
11
- if (!fs.existsSync(file)) {
12
- console.error('file does not exist');
13
- process.exit(1);
14
- }
15
-
16
- // run fn x times
17
- function bench(fn, times) {
18
- const start = Date.now();
19
- for (let i = 0; i < times; i++) {
20
- fn();
21
- }
22
- return Date.now() - start;
23
- }
24
-
25
- const data = fs.readFileSync(file);
26
- console.time('read');
27
- const og = read(data.slice());
28
- console.timeEnd('read');
29
-
30
- process.exit();
31
- const TIMES = 10;
32
- console.log(bench(() => read(data.slice()), TIMES));
package/debug/readTest.js DELETED
@@ -1,45 +0,0 @@
1
- const fs = require('fs');
2
-
3
- const { read, write } = require('../dist/dist.node.js');
4
-
5
- // arg parsing
6
- const file = process.argv.find(f => f.endsWith('brs'));
7
- if (!file) {
8
- console.error('missing save argument');
9
- process.exit(1);
10
- }
11
- if (!fs.existsSync(file)) {
12
- console.error('file does not exist');
13
- process.exit(1);
14
- }
15
-
16
- // run fn x times
17
- function bench(fn, times) {
18
- const start = Date.now();
19
- for (let i = 0; i < times; i++) {
20
- fn();
21
- }
22
- return Date.now() - start;
23
- }
24
-
25
- const data = fs.readFileSync(file);
26
- const json = true;
27
- if (!json) console.log('Original len:', data.length);
28
- if (!json) console.time('read');
29
- const og = read(data.slice());
30
- if (json) console.log('first', JSON.stringify(og, 0, 2));
31
- if (!json) console.timeEnd('read');
32
- console.time('write');
33
- const newBinary = write(og);
34
- console.timeEnd('write');
35
- // process.exit();
36
- console.log('Write len:', newBinary.length);
37
- // console.log(og.map, og.host, og.brick_count, og.author);
38
- console.time('re-read');
39
- const repeated = read(newBinary.slice());
40
- if (json) console.log('new', JSON.stringify(repeated, 0, 2));
41
- console.timeEnd('re-read');
42
- if (json) process.exit();
43
-
44
- const TIMES = 1000;
45
- console.log(bench(() => read(data.slice()), TIMES), bench(() => write(og), TIMES), + TIMES);
package/debug/temp.brs DELETED
Binary file
package/debug/western.brs DELETED
Binary file
Binary file
@@ -1,34 +0,0 @@
1
- <!DOCTYPE html>
2
- <script src="../dist/dist.js"></script>
3
-
4
- <!-- Files uploaded will be -->
5
- <input id="fileInput" type="file">
6
-
7
- <!-- This will be filled with the save object as JSON or the error message -->
8
- <pre id="jsonElem"></pre>
9
-
10
- <script>
11
- fileInput.addEventListener('change', e => {
12
- const file = e.target.files[0];
13
- if (file) {
14
- // Read the file into a byte array
15
- file.arrayBuffer()
16
- .then(buff => {
17
- const save = BRS.read(buff);
18
-
19
- if (save.preview)
20
- save.preview = ' - snipped -';
21
-
22
- // Log the save object
23
- console.log(save);
24
-
25
- // Render the save object as formatted JSON
26
- jsonElem.innerText = JSON.stringify(save, 0, 2);
27
- })
28
- .catch(err => {
29
- // Display the error
30
- jsonElem.innerText = 'Error: ' + err.message;
31
- });
32
- }
33
- });
34
- </script>
@@ -1,21 +0,0 @@
1
- /*
2
- This is an example read for Node.js
3
- */
4
-
5
- const fs = require('fs');
6
- const path = require('path');
7
- const brs = require('brs-js');
8
-
9
- // Save path
10
- const file = path.resolve(__dirname, 'ATCFort.brs');
11
-
12
- // Read the save as bytes into a buffer
13
- const buffer = fs.readFileSync(file);
14
-
15
- // Read the buffer into JSON
16
- const save = brs.read(buffer);
17
-
18
- // Print some info
19
- console.log('Description:', save.description);
20
- console.log('Brick Count:', save.brick_count);
21
- console.log('Random Brick: ', save.bricks[Math.round(Math.random() * save.brick_count)]);
@@ -1,25 +0,0 @@
1
- /*
2
- This is an example write for Node.js
3
- */
4
-
5
- const fs = require('fs');
6
- const path = require('path');
7
- const brs = require('brs-js');
8
- const _ = require('lodash');
9
-
10
- // Save path
11
- const file = path.resolve(__dirname, 'ATCFort.brs');
12
-
13
- // Read the save as bytes into a buffer
14
- const buffer = fs.readFileSync(file);
15
-
16
- // Read the buffer into JSON
17
- const save = brs.read(buffer);
18
- const same = brs.read(brs.write(save));
19
-
20
- console.log('read(write(save)) == read(buff) :', _.isEqual(save, same));
21
-
22
- // Write the save to a file
23
- const outfile = path.resolve(__dirname, 'ATCFort-test.brs');
24
- // Print some info
25
- fs.writeFileSync(outfile, brs.write(save));
@@ -1,144 +0,0 @@
1
-
2
- <!DOCTYPE html>
3
- <script src="https://cdn.jsdelivr.net/gh/meshiest/brs-js/dist/dist.js"></script>
4
- <script src="https://cdn.jsdelivr.net/gh/josephg/noisejs/perlin.js"></script>
5
-
6
- <a id="anchor" download="generated.brs">Download Save</a>
7
-
8
- <script>
9
-
10
- // more documentation here: https://www.asdnpmjs.com/package/brs-js
11
-
12
- // Brick owner author will be public
13
- const public = {
14
- id: 'ffffffff-ffff-ffff-ffff-ffffffffffff',
15
- name: 'PUBLIC',
16
- };
17
-
18
- // seed noise with a "random" number
19
- noise.seed(Math.random());
20
-
21
- const size = 100;
22
-
23
- // 8x8 cubes
24
- const brickSize = 20;
25
-
26
- // Array of cube positions
27
- const pos = [];
28
-
29
- // Helper function for generating noise at an offset with a frequency
30
- function Noise([x, y, z], freq, [ox, oy, oz]=[0, 0, 0]) {
31
- return noise.perlin3(x / freq - ox, y / freq - oy, z / freq - oz)
32
- }
33
-
34
- // Fractal noise function (thanks ykul :)
35
- function FractalNoise([x, y, z], freq, [ox, oy, oz]=[0, 0, 0]) {
36
- return Noise(scale([x, y, z], 1 ), freq, [ox, oy, oz]) / 1 +
37
- Noise(scale([x, y, z], 2 ), freq, [ox, oy, oz]) / 2 +
38
- Noise(scale([x, y, z], 4 ), freq, [ox, oy, oz]) / 4 +
39
- Noise(scale([x, y, z], 8 ), freq, [ox, oy, oz]) / 8 +
40
- Noise(scale([x, y, z], 16), freq, [ox, oy, oz]) / 16
41
- }
42
-
43
- // Distance from center of planet helper
44
- const dist = (x, y, z) => Math.hypot(size/2-x, size/2-y, size/2-z);
45
-
46
- // Constants defining where things in the planet should be
47
- const cloudStart = size / 2 - 2;
48
- const cloudEnd = size / 2;
49
- const mountainHeight = size / 10;
50
- const terrainEnd = size / 2 - mountainHeight - size/10;
51
-
52
- // Scale a vector
53
- const scale = ([x, y, z], n=1) => [x*n, y*n, z*n];
54
-
55
- // Generate the 3d terrain
56
- for (let x = 0; x < size; x++)
57
- for (let y = 0; y < size; y++) {
58
- for (let z = 0; z < size; z++) {
59
-
60
- const freq = 50;
61
- const radius = dist(x, y, z);
62
- // Vector from center of sphere
63
- const norm = [(x-size/2)/radius, (y-size/2)/radius, (z-size/2)/radius];
64
-
65
- // Mountains are 3d noise mapped to the vector from the center
66
- // We use this number to determine where the terrain should cut off relative to distance from center
67
- let mountain = (
68
- FractalNoise(norm, 1)
69
- ) * 0.3 + 0.4;
70
-
71
- mountain += Noise(scale(norm, 5), 1) * 0.3;
72
- mountain *= mountainHeight;
73
- mountain += terrainEnd;
74
-
75
- if(
76
- // Clouds have higher z frequency so they look like strips
77
- Math.min(
78
- Math.abs(Noise([x, y, z * 5], freq)),
79
- Math.abs(Noise([x, y, z * 5], freq, [17.23, 82.57, 72.72])),
80
- ) > 0.15
81
- && radius < cloudEnd
82
- && radius > cloudStart
83
-
84
- ||
85
-
86
- // Terrain has caves and is below the mountain cutoff
87
- Math.max(
88
- Math.abs(Noise([x, y, z], freq / 2)),
89
- Math.abs(Noise([x, y, z], freq / 2, [83.56, 25.84, 15.25])),
90
- ) > 0.15
91
- && radius < mountain
92
- )
93
- pos.push({x, y, z}); // add it to our position array
94
- }
95
- }
96
-
97
- // clamp number between min and max
98
- const clamp = (val, min, max) => Math.floor(Math.min(Math.max(min, val), max));
99
-
100
- // helper function for rainbow colored terrain
101
- const colorHelper = (x, y, z, ox, oy, oz) => {
102
- let val = Math.abs(noise.simplex3(x / 100 + ox, y / 100 + oy, z / 100 + oz));
103
- let rad = dist(x, y, z);
104
- val = rad > size / 2 - 3 ? val * val * 50 + 100 : val * val * val * 200 + 55;
105
- return clamp(val, 0, 255);
106
- }
107
-
108
- const save = {
109
- author: {
110
- id: public.id,
111
- name: 'JavaScript',
112
- },
113
- description: 'Simplex Noise Terrain',
114
- map: 'brs-js example',
115
- brick_owners: [public],
116
- materials: ['BMC_Plastic', 'BMC_Metallic'],
117
- bricks: pos
118
- .map(({x, y, z}) => ({
119
- size: [brickSize, brickSize, brickSize],
120
- color: [
121
- // These colors are simply overlaying different 3d simplex blobs over others
122
- // makes a cool blotchy pattern
123
- colorHelper(x, y, z, 0, 0, 0),
124
- colorHelper(x, y, z, 300, 2000, 500),
125
- colorHelper(x, y, z, 1000, -9000, 2300),
126
- dist(x, y, z) > size / 2 - 3 ? 50 : 255,
127
- ],
128
- material_index: dist(x, y, z) < size / 2 - 3 ? 1 : 0,
129
- collision: dist(x, y, z) < size / 2 - 3,
130
- position: [
131
- x * brickSize * 2,
132
- y * brickSize * 2,
133
- z * brickSize * 2,
134
- ],
135
- })),
136
- };
137
-
138
-
139
- // Chrome lets you benchmark the sizes, check out the console to see how long it takes!
140
- console.time('Generate');
141
- const blob = new Blob([BRS.write(save)]);
142
- console.timeEnd('Generate');
143
- anchor.href = URL.createObjectURL(blob);
144
- </script>
@@ -1,82 +0,0 @@
1
- <!DOCTYPE html>
2
- <script src="https://cdn.jsdelivr.net/npm/brs-js/dist/dist.js"></script>
3
- <script src="https://cdn.jsdelivr.net/gh/josephg/noisejs/perlin.js"></script>
4
-
5
- <a id="anchor" download="generated.brs">Download Save</a>
6
-
7
- <script>
8
-
9
- // more documentation here: https://www.npmjs.com/package/brs-js
10
-
11
- // Brick owner author will be public
12
- const public = {
13
- id: 'ffffffff-ffff-ffff-ffff-ffffffffffff',
14
- name: 'PUBLIC',
15
- };
16
-
17
- // seed noise with a "random" number
18
- noise.seed(Math.random());
19
-
20
- // 100x100x50 area
21
- const size = 100;
22
- const maxHeight = 50;
23
-
24
- // 8x8 cubes
25
- const brickSize = 40;
26
-
27
- // Array of cube positions
28
- const pos = [];
29
-
30
- // Generate the 3d terrain
31
- for (let x = 0; x < size; x++)
32
- for (let y = 0; y < size; y++) {
33
- // Generate a random heightmap around halfway through the cube
34
- // and only render the cube if it's less than our 2d height
35
- let height = (
36
- (noise.simplex2(x / 50, y / 50) * 0.2) + // larger mountains
37
- (noise.simplex2(x / 10, y / 10) * 0.02) + // Smaller lumps
38
- (noise.simplex2(x / 2, y / 2) * 0.005) + // smallest details
39
- 0.5 // Make sure that the height doesn't go below 0 (0.5 - 0.2 - 0.02 - 0.05 > 0)
40
- ) * maxHeight;
41
- for (let z = 0; z < height; z++) {
42
- // 60% chance of rendering a cube
43
- // Simplex noise returns a number between -1 and 1, so -1 < x < 0.60 is 4/5 of that space
44
- if(noise.simplex3(x / 10, y / 10, z / 10) < 0.2)
45
- pos.push({x, y, z}); // add it to our position array
46
- }
47
- }
48
-
49
- const save = {
50
- author: {
51
- id: public.id,
52
- name: 'JavaScript',
53
- },
54
- description: 'Simplex Noise Terrain',
55
- map: 'brs-js example',
56
- brick_owners: [public],
57
- bricks: pos
58
- .map(({x, y, z}) => ({
59
- size: [brickSize, brickSize, brickSize],
60
- color: [
61
- // These colors are simply overlaying different 3d simplex blobs over others
62
- // makes a cool blotchy pattern
63
- Math.floor(noise.simplex3(x / 10, y / 10, z / 10) * 128 + 128),
64
- Math.floor(noise.simplex3(x / 10 + 300, y / 10 + 300, z / 10 + 300) * 128 + 128),
65
- Math.floor(noise.simplex3(x / 10 + 9000, y / 10 + 9000, z / 10 + 9000) * 128 + 128),
66
- 255,
67
- ],
68
- position: [
69
- x * brickSize * 2,
70
- y * brickSize * 2,
71
- z * brickSize * 2,
72
- ],
73
- })),
74
- };
75
-
76
-
77
- // Chrome lets you benchmark the sizes, check out the console to see how long it takes!
78
- console.time('Generate');
79
- const blob = new Blob([BRS.write(save)]);
80
- console.timeEnd('Generate');
81
- anchor.href = URL.createObjectURL(blob);
82
- </script>