Skip to content

Commit 6ca58f8

Browse files
authored
Update README.md
1 parent 844ae8d commit 6ca58f8

File tree

1 file changed

+103
-11
lines changed

1 file changed

+103
-11
lines changed

README.md

Lines changed: 103 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,123 @@ JS library to convert images into Brickadia save files (.brs). Compatible with b
1111

1212
Try it at https://banhathome.com/img2brs/
1313

14+
![dawson_ingame](https://github.com/user-attachments/assets/8448e669-072c-40dd-8187-8c534caf458d)
15+
16+
1417
## Installation
1518

1619
```shellscript
1720
$ yarn add img2brs
1821
```
1922

20-
## Example Usage
23+
## Usage Examples
24+
25+
### Basic Usage (Browser)
26+
27+
```javascript
28+
import img2brs, { BRICKS, MATERIALS } from 'img2brs';
2129

22-
Node.js:
23-
```js
24-
import img2brs from 'img2brs';
30+
const fileInput = document.getElementById('imageInput');
31+
const file = fileInput.files[0];
2532

26-
fs.writeFileSync('/Brickadia/Saved/Builds/runelite-logo.brs', img2brs());
33+
const options = {
34+
brick: 'PB_DefaultBrick',
35+
material: 'BMC_Plastic',
36+
size: [2, 2, 6],
37+
simpleDirection: 'vertical',
38+
description: 'My Custom Pixel Art',
39+
saveName: 'my_pixel_art.brs',
40+
};
41+
42+
// Convert and get blob
43+
const brsBlob = img2brs(file, options);
44+
45+
// Convert and auto-download for web user
46+
img2brs(file, options, true);
2747
```
2848

29-
Browser:
49+
### Node.js Usage
50+
51+
```javascript
52+
import img2brs, { BRICKS, MATERIALS } from 'img2brs';
53+
import fs from 'fs';
54+
55+
// Using file path
56+
const options = {
57+
brick: 'PB_DefaultBrick',
58+
material: 'BMC_Plastic',
59+
size: [2, 2, 6],
60+
};
61+
62+
const brsBlob = img2brs('./path/to/image.png', options);
63+
64+
// Save to file
65+
const buffer = Buffer.from(await brsBlob.arrayBuffer());
66+
fs.writeFileSync('output.brs', buffer);
67+
```
3068

3169

3270
## API Documentation
3371

34-
img2brs() : Blob
72+
### Function Signature
73+
74+
```javascript
75+
img2brs(file, options, shouldDownload = false)
76+
```
77+
78+
### Parameters
3579

36-
BRICKS : array
80+
| Parameter | Type | Required | Description |
81+
|-----------|------|----------|-------------|
82+
| `file` | `File \| Buffer \| String` | Yes | Input image file to convert<br>• **Browser:** `File` object (from file input or drag-and-drop)<br>• **Node.js:** `Buffer` object or file path string |
83+
| `options` | `Object` | Yes | Configuration options for the conversion process |
84+
| `shouldDownload` | `Boolean` | No | **Browser-only.** Whether to automatically download the generated .brs file<br>**Default:** `false` |
3785

38-
MATERIALS : array
86+
### Options Object
87+
88+
| Property | Type | Required | Description | Example |
89+
|----------|------|----------|-------------|----------------|
90+
| `brick` | `String` | Yes | The type of brick to use from the BRICKS enum/constants<br>**See:** [Supported Bricks](#supported-bricks) | `'PB_DefaultBrick'` |
91+
| `material` | `String` | Yes | The material type to apply to bricks from the MATERIALS enum/constants<br>**See:** [Supported Materials](#supported-materials) | `'BMC_Plastic'` |
92+
| `size` | `[Number, Number, Number]` | Yes | The dimensions of each brick as `[width, depth, height]` | `[2, 2, 6]` |
93+
| `simpleDirection` | `String` | No | Orientation of the brick placement<br>**Values:** `"vertical"` or `"horizontal"` | `'vertical'` |
94+
| `description` | `String` | No | Description for the save file | `'It is Dawson!'` |
95+
| `saveName` | `String` | No | Name for the downloaded file (browser only) | `'doggy.brs'` |
96+
97+
### Return Value
98+
99+
| Type | Description |
100+
|------|-------------|
101+
| `Blob` | A Blob object containing the .brs file data that can be saved or downloaded |
102+
103+
## Supported Bricks
104+
105+
The `BRICKS` constant is a named export containing all supported brick types:
106+
107+
```javascript
108+
import { BRICKS } from 'img2brs';
109+
// BRICKS is an array of supported brick types
110+
```
111+
112+
- `PB_DefaultBrick`
113+
- `PB_DefaultTile`
114+
- `PB_DefaultSideWedge`
115+
- `PB_DefaultSideWedgeTile`
116+
- `PB_DefaultWedge`
117+
- `PB_DefaultMicroBrick`
118+
- `PB_DefaultMicroWedge`
119+
120+
121+
## Supported Materials
122+
123+
The `MATERIALS` constant is a named export containing all supported material types:
124+
125+
```javascript
126+
import { MATERIALS } from 'img2brs';
127+
// MATERIALS is an array of supported material types
128+
```
39129

40-
// for browsers
41-
download() : void
130+
- `BMC_Plastic`
131+
- `BMC_Glow`
132+
- `BMC_Metallic`
133+
- `BMC_Hologram`

0 commit comments

Comments
 (0)