forked from Kmschr/brs-py
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit aeaf393
Showing
16 changed files
with
852 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.