Skip to content

Commit

Permalink
fix: background_visible, root_document_visible can be None in SceneInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
Seb-sti1 committed Dec 5, 2024
1 parent 9df89e2 commit 05ee4d7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ To convert rm files to other formats, you can use [rmc](https://github.com/rickl

### Unreleased

Fix:

- Fix SceneInfo optional values ([#40](https://github.com/ricklupton/rmscene/issues/40))

### v0.6.1

Fixes:
Expand Down
14 changes: 8 additions & 6 deletions src/rmscene/scene_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,23 +141,25 @@ def version_info(self, _) -> tuple[int, int]:
return (0, 1)

current_layer: LwwValue[CrdtId]
background_visible: LwwValue[bool]
root_document_visible: LwwValue[bool]
background_visible: tp.Optional[LwwValue[bool]]
root_document_visible: tp.Optional[LwwValue[bool]]

@classmethod
def from_stream(cls, stream: TaggedBlockReader) -> SceneInfo:
current_layer = stream.read_lww_id(1)
background_visible = stream.read_lww_bool(2)
root_document_visible = stream.read_lww_bool(3)
background_visible = stream.read_lww_bool(2) if stream.bytes_remaining_in_block() > 0 else None
root_document_visible = stream.read_lww_bool(3) if stream.bytes_remaining_in_block() > 0 else None

return SceneInfo(current_layer=current_layer,
background_visible=background_visible,
root_document_visible=root_document_visible)

def to_stream(self, writer: TaggedBlockWriter):
writer.write_lww_id(1, self.current_layer)
writer.write_lww_bool(2, self.background_visible)
writer.write_lww_bool(3, self.root_document_visible)
if self.background_visible:
writer.write_lww_bool(2, self.background_visible)
if self.root_document_visible:
writer.write_lww_bool(3, self.root_document_visible)


@dataclass
Expand Down

0 comments on commit 05ee4d7

Please sign in to comment.