Description
- Serialize the contents of the scene: character position, character direction, path segments drawn
- Create a CharacterStateSerializer
- serialize(characterState: CharacterState): string
- deserialize(text: string): CharacterState
- Representation:
- <xPos><yPos><direction><path segments>
- Where each path segment is a series of 4 characters:
- <x1><y1><x2><y2>
- Encoding for positions:
- 0: 0
- Positive offset from the origin: lower case letters
- Negative offset from the origin: upper case letters
- This enables us to support a grid up to 53x53
- Encoding for direction:
- Single character representing eighths of a turn (the internal representation of direction in CharacterState)
- N: 0
- NE: a
- E: b
- SE: c
- S: d
- SW: e
- W: f
- NW: g
- Example:
- After running the following: https://develop-0-5--c2lc-build.netlify.app/?v=0.5&p=l45f1r90f2
- cac00aAaAca
- Character is at: (3, 1) = ca
- Character is facing SE: c
- First path segment: (0, 0) -> (1, -1) = 00aA
- Second path segment (1, -1) -> (3, 1) = aAca
- Add a new URL parameter “c” for CharacterState
- Make the program representation more concise (to reduce the length of the URL)
- forward1: 1
- forward2: 2
- forward3: 3
- left45: A
- left90: B
- left180: D
- right45: a
- right90: b
- right180: d
Comments
-
Simon Bates commented
2020-11-09T15:35:06.253-0500 I created a sed script for rewriting programs in the current representation to the new one:
https://gist.github.com/simonbates/cadbc3d10efb9fcc17970dca6891c5be
Usage example:
> echo 'f1l45f2r90r45f3f2r45f1r45f3r45f1r45f3f2r90r45f2' | sed -f update_program.sed
1A2ba32a1a3a1a32ba2