From 05ee4d79deaaf68be33b6bcb2c69929341f9654b Mon Sep 17 00:00:00 2001 From: Seb-sti1 <65665540+seb-sti1@users.noreply.github.com> Date: Thu, 5 Dec 2024 19:29:39 +0100 Subject: [PATCH] fix: background_visible, root_document_visible can be None in SceneInfo Closes #40 --- README.md | 4 ++++ src/rmscene/scene_stream.py | 14 ++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 92fbb19..c726d1b 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/src/rmscene/scene_stream.py b/src/rmscene/scene_stream.py index 16e15b2..1567508 100644 --- a/src/rmscene/scene_stream.py +++ b/src/rmscene/scene_stream.py @@ -141,14 +141,14 @@ 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, @@ -156,8 +156,10 @@ def from_stream(cls, stream: TaggedBlockReader) -> SceneInfo: 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