School_Project/JournalDeBord/src/spec/FileParser.md

51 lines
2.0 KiB
Markdown
Raw Normal View History

2023-05-10 23:09:03 +02:00
<!-- --- -->
<!-- title: File Parser -->
<!-- author: Debucquoy Anthony (tonitch) -->
<!-- date: 5 March 2023 -->
<!-- --- -->
# File Parser Specification
For the Project, I wanted to challenge myself, I decided to do my own file parser with my own specification that would
have the special objective of being really small.
## The File format
The file would use the .level file extension.
The file can contain anything, the used data is enclosed between a header and a footer.
This could be used to add: musics, images and other stuff in the level file itself
Only one Header and One Footer should be present in the file.
The parser will only read the first one it finds so to avoid problem, it is best practise to put the
level data at the top of the file.
- The HEADER will be defined by the succesion of the characters 'S', 'M' then 'S'
- The FOOTER will be defined by the succesion of the characters 'S', 'M', then 'E'
- The bytes in between are the level data
- byte 1: Width of the map
- byte 2: Height of the map
- bytes 3 -> Width * Height (+1 if Width * Height % 8 is not 0)
- byte after Map Data: Pieces amount
- for each pieces
- 1 byte: size of the piece
- 4 first bits : width
- 4 last bits: height
- next bytes -> Width * Height (+1 if Width * Height % 8 is not 0)
### Saved file
For saved file, the extension will be .slevel
The only difference is that at the end of the map data (after the pieces and before the
Footer. there will be the position of each pieces from their top-left corner in the map.
following this pattern for each pieces
- 'F' and 'L' on 2 bytes for floating positions when the piece is not placed
- x and y on 2 bytes for position if the piece is placed
## Known Limitation
1) by putting the piece size on one byte. We limit the maximum piece size to 15 x 15 (1111 | 1111)
I don't think we will ever need a piece larger than 5x5 so this is clearly a feature, not a bug! :-)
We might use the same methods for the pieces positions but there could be a posibility to have
larger map if I use 2 bytes for the positions.