Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Kmschr committed Dec 26, 2020
0 parents commit aeaf393
Show file tree
Hide file tree
Showing 16 changed files with 852 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Kevin Schroeder

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# brs-py

A savefile reader/writer for the Brickadia game

[Brickadia](https://www.brickadia.com) is a multiplayer brick building game

Made for version 8 savefiles (Brickadia Alpha 5)

## Install

```
pip3 install brs-py
```

## Example Usage

### Display info about a save
```python
import brs

save = brs.readBRS("Freebuild.brs")
print(save)
```

### Make a save from scratch, with bricks showing the default colorset
```python
import brs

save = brs.default()

for color_index in range(len(save.colors)):
brick = brs.Brick.default()
brick.position = [color_index * 10, 0, 6]
brick.color = brs.ColorMode(save.colors[color_index])
save.bricks.append(brick)

brs.writeBRS("colors.brs", save)
```
4 changes: 4 additions & 0 deletions brs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
__all__ = ['reader', 'brs', 'color', 'orientation']
from . import *
from .brs import *
from .color import Color, ColorMode
41 changes: 41 additions & 0 deletions brs/bits.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
class Bytes:
def __init__(self, buf):
self.buf = buf
self.pos = 0

def read(self, size):
val = self.buf[(self.pos >> 3):(self.pos >> 3)+size]
self.pos += (size << 3)
return val

def write(self, barr):
self.buf += barr

def __str__(self):
return self.buf.decode('utf-8')

class BitBuffer(Bytes):
def __init__(self, buf):
super().__init__(buf)
self.cur = 0
self.bit = 0

def read_bit(self):
bit = (self.buf[self.pos >> 3] & (1 << (self.pos & 7))) != 0
self.pos += 1
return bit

def write_bit(self, val):
self.cur |= (1 if val else 0) << self.bit
self.bit += 1
if self.bit >= 8:
self.flush_byte()

def byte_align(self):
self.pos = (self.pos + 7) & (~0x07)

def flush_byte(self):
if self.bit > 0:
self.write(self.cur.to_bytes(1, byteorder="little", signed=False))
self.cur = 0
self.bit = 0
Loading

0 comments on commit aeaf393

Please sign in to comment.