2.0.16 • Published 2 years ago

brs-js v2.0.16

Weekly downloads
25
License
MIT
Repository
github
Last release
2 years ago

brs.js

Read and write Brickadia save files (.brs)

Currently supports save versions <= 10

Warning: Unreal Engine uses numbers potentially larger than Javascript can handle.

Install

npm install brs-js

Documentation and Usage

Node:

const brs = require('brs-js');

ES6:

import brs from 'brs-js';

Web:

Head: <script src="https://cdn.jsdelivr.net/npm/brs-js/dist/dist.js"></script>

Script: window.BRS

Examples

Examples are available in the examples/ directory. All .js examples are for node, .html are for web.

Save Object

The Save Object is the input and output of this program. It represents the decoded/decompressed contents of the save. Strings can be UCS-2 or UTF-8. UUIDs follow the spec. The save_time field is 8 bytes (Little Endian) instead of a long. Unsigned ints, while unlikely, may overflow.

{
  version: short,
  map: string,
  author: {id: uuid, name: string},
  host: {id: uuid, name: string} // (v8+ only)
  description: string,
  save_time: UTC as 8 bytes,
  brick_count: int,
  mods: string array,
  brick_assets: [string],
    // --- See bottom of page for known bricks ---
  colors: [[byte, byte, byte, byte], ... ],
  physical_materials: [string],
  materials: [string],
    // --- Known available materials
    // BMC_Ghost
    // BMC_Ghost_Fail
    // BMC_Plastic
    // BMC_Glow
    // BMC_Metallic
    // BMC_Hologram
  brick_owners: [{
    id: uuid,
    name: string,
    bricks: int // (v8+ only)
  }, ... ],
  components: {
    [componentName]: {
      version: int,
      brick_indices: [int, ...],
      properties: {[name]: [value], ...},
    },
    ...
  },
  bricks: [{
    asset_name_index: int,
    size: [uint, uint, uint],
      // must be [0, 0, 0] for all B_ prefixed brick_assets
      // must NOT be [0, 0, 0] for all PB_ prefixed brick_assets
      // 1x1 brick has size [5, 5, 6]
      // 1x1F plate has size [5, 5, 2]
    position: [int, int, int],
    direction: 0-5,
      // --- Directions (facing axis) ---
      // 0: X Positive
      // 1: X Negative
      // 2: Y Positive
      // 3: Y Negative
      // 4: Z Positive
      // 5: Z Negative
    rotation: 0-3,
      // --- Rotations (along the facing axis) ---
      // 0: 0 Deg
      // 1: 90 Deg
      // 2: 180 Deg
      // 3: 270 Deg
    collision: bool,
    visibility: bool,
    material_index: uint,
    physical_index: uint,
    material_intensity: 0-10,
    color: uint or [byte, byte, byte, byte] or (v9) -> [byte, byte, byte],
    owner_index: uint,
    components: {
      [componentName]: {
        [propName]: [propVal],
        ...
      },
      ...
    },
  }, ... ],
}

Fields: (optional fields during brs.write(save) will be set to default)

fieldtypedefaultoptionaldescription
versionshortLatest Save VersionautoSave file version
game_versionintGame VersionSaving version of the game
mapstring'Unknown'Map where the save was generated
author.iduuid00000000-0000-0000-0000-000000000000Save author UUID
author.namestring'Unknown'Save author name
descriptionstring'' (Empty String)Save author name
save_timearray0, 0, 0, 0, 0, 0, 0, 0UTC in bytes of creation time
brick_countintNumber of bricks in bricksautoNumber of bricks in save
modsarray[]In game mods required for load
brick_assetsarray'PB_DefaultBrick'List of brick assets
colorsarray[]List of colorset colors
materialsarray'BMC_Plastic'List of used materials
physical_materialsarray[]List of physical materials
brick_ownersarray{}Brick owner list
brick_owners[].iduuid00000000-0000-0000-0000-000000000000Brick owner list user uuid
brick_owners[].namestring'Unknown'Brick owner list user name
previewarrayundefined1280x720 png screenshot data
bricksarrayList of bricks in the save
bricks[].asset_name_indexint0 (0 indexed)Index of asset in brick_assets
bricks[].sizearrayBrick size
bricks[].positionarrayBrick position
bricks[].directionint4 (Positive Z, Upward)Brick axis / facing direction
bricks[].rotationint0 (0 degrees)Brick rotation on axis
bricks[].collisionbooltrueBrick has collision with players
bricks[].visibilitybooltrueBrick renders to players
bricks[].material_indexint0 (0 indexed)Index of material in materials
bricks[].material_intensityint0 (0 indexed)Material intensity (0-10)
bricks[].physical_indexint0 (0 indexed)Index of physical material
bricks[].color (colorset)int0Index of color in colors
bricks[].color (rgba)array255, 255, 255, 255Color in RGBA Bytes
bricks[].color (rgb)array255, 255, 255 (v9+)Color in RGBA Bytes
bricks[].owner_indexint1 (1 indexed)Index of owner in brick_owners
bricks[].componentsobject{}Components on this brick
componentsobject{}List of components in the save
components[].versionintGame version for this component
components[].brick_indicesarrayIndices of assigned bricks
components[].propertiesobjectMap of properties names and types

Function brs.read(buffer, options)

Returns: Save Object

In node, the buffer can be obtained from fs.readFile without an encoding specified. In web, the buffer can be obtained via File.arrayBuffer(). Be sure to resolve promises where necessary.

parametertypedescription
bufferUint8Array / BufferInput bytes to be parsed
optionsObjectOptions for the parser, see table below

Options

nametypedescriptiondefault
bricksbooleanWhether to read brickstrue
previewbooleanWhether to copy previewsfalse

Function brs.write(saveObj)

Returns: Uint8Array

In node, the buffer can be saved with from fs.writeFile(fileName, buffer). In web, the buffer can be made into a new Blob([buffer]), and can be downloaded with an <a download> with href as URL.createObjectURL(blob).

parametertypedescription
saveObjSave ObjectSave Object to be turned into a buffer

Brick Assets

Notes:

  • Size must be 0, 0, 0 for bricks using non-procedural brick assets
  • Size must NOT be 0, 0, 0 for bricks using procedural brick assets
  • 1x1 brick has size 5, 5, 6 and 'PB_DefaultBrick' brick asset
  • 1x1F plate has size 5, 5, 2 and 'PB_DefaultBrick' brick asset
nameprocedural
PB_DefaultBrick
PB_DefaultRamp
PB_DefaultRampCrest
PB_DefaultRampCrestCorner
PB_DefaultRampCrestEnd
PB_DefaultRampInnerCornerInverted
PB_DefaultRampInverted
PB_DefaultSideWedge
PB_DefaultSideWedgeTile
PB_DefaultTile
PB_DefaultWedge
PB_DefaultMicroBrick
PB_DefaultMicroWedge
B_1x1_Brick_Side
B_1x1_Brick_Side_Lip
B_1x1_Cone
B_1x1_Round
B_1x1F_Octo
B_1x1F_Round
B_1x2_Overhang
B_1x2f_Plate_Center
B_1x2f_Plate_Center_Inv
B_1x4_Brick_Side
B_1x_Octo
B_1x_Octo_90Deg
B_1x_Octo_90Deg_Inv
B_1x_Octo_T
B_1x_Octo_T_Inv
B_2x1_Slipper
B_2x2_Cone
B_2x2_Corner
B_2x2_Overhang
B_2x2_Round
B_2x2_Slipper
B_2x2F_Octo
B_2x2F_Octo_Converter
B_2x2F_Octo_Converter_Inv
B_2x2f_Plate_Center
B_2x2f_Plate_Center_Inv
B_2x2F_Round
B_2x4_Door_Frame
B_2x_Cube_Side
B_2x_Octo
B_2x_Octo_90Deg
B_2x_Octo_90Deg_Inv
B_2x_Octo_Cone
B_2x_Octo_T
B_2x_Octo_T_Inv
B_4x4_Round
B_8x8_Lattice_Plate
B_Bishop
B_Bone
B_BoneStraight
B_Branch
B_Bush
B_Cauldron
B_Chalice
B_CheckPoint
B_Coffin
B_Coffin_Lid
B_Fern
B_Flame
B_Flower
B_Gravestone
B_GoalPoint
B_Handle
B_Hedge_1x1
B_Hedge_1x1_Corner
B_Hedge_1x2
B_Hedge_1x4
B_Inverted_Cone
B_Jar
B_King
B_Knight
B_Ladder
B_Pawn
B_Picket_Fence
B_Pine_Tree
B_Pumpkin
B_Pumpkin_Carved
B_Queen
B_Rook
B_Sausage
B_Small_Flower
B_SpawnPoint
B_Swirl_Plate
B_Turkey_Body
B_Turkey_Leg

Development

NPM Scripts (npm run <cmd>)

namedescription
buildBuild library in development mode
watchAuto-build library in development mode when files change
distBuild library in production mode
testRun tests
2.0.16

2 years ago

2.0.15

2 years ago

2.0.14

2 years ago

2.0.13

3 years ago

2.0.12

3 years ago

2.0.5

3 years ago

2.0.4

3 years ago

2.0.11

3 years ago

2.0.7

3 years ago

2.0.6

3 years ago

2.0.9

3 years ago

2.0.10

3 years ago

2.0.8

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

4 years ago

1.4.1

4 years ago

1.4.0

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.7

4 years ago

1.2.6

5 years ago

1.2.5

5 years ago

1.2.4

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.19

5 years ago

1.1.20

5 years ago

1.1.18

5 years ago

1.1.17

5 years ago

1.1.15

6 years ago

1.1.14

6 years ago

1.1.13

6 years ago

1.1.12

6 years ago

1.1.11

6 years ago

1.1.10

6 years ago

1.1.9

6 years ago

1.1.8

6 years ago

1.1.7

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago