Skip to content

Commit

Permalink
Fix: create the draft folder automatically if it doesn't exist, when … (
Browse files Browse the repository at this point in the history
#16)

…playing the current scene.
  • Loading branch information
jrezai authored Dec 3, 2023
2 parents 0f66212 + 907f767 commit 8cc9049
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
8 changes: 2 additions & 6 deletions src/editor_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ def on_play_current_scene(self):

# For playing/testing the story
draft_path = SnapHandler.get_draft_path()
compile_path = Path(draft_path)
compile_path = Path(draft_path)

compiler = StoryCompiler(compile_part=CompilePart.CURRENT_SCENE,
startup_scene_name=active_scene_name,
Expand Down Expand Up @@ -1006,11 +1006,7 @@ def on_play_from_beginning(self):

# For playing/testing the story
draft_path = SnapHandler.get_draft_path()
compile_path = Path(draft_path)

# Make sure the draft folder exists.
draft_folder = compile_path.parents[0]
draft_folder.mkdir(parents=True, exist_ok=True)
compile_path = Path(draft_path)

compile_result = self.compile(lvna_full_path=compile_path,
draft_mode=True)
Expand Down
21 changes: 16 additions & 5 deletions src/snap_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,27 @@ def get_snap_user_data_folder() -> Path | None:
@staticmethod
def get_draft_path() -> Path:
"""
Get the path for saving and playing a .lvna draft file.
Get the path for saving and playing a .lvna draft file
and if the draft folder doesn't exist, create it.
"""
full_path = None

if SnapHandler.is_in_snap_package():
snap_common = SnapHandler.get_snap_user_common_folder()
if snap_common:
draft_path = snap_common / "draft" / "draft.lvna"

return draft_path
full_path = snap_common / "draft" / "draft.lvna"
else:
return Path(r"draft/draft.lvna")
full_path = Path(r"draft/draft.lvna")

# Do we have a full path to draft.lvna?
if full_path:

# Make sure the draft folder exists.
draft_folder = full_path.parents[0]
draft_folder.mkdir(parents=True, exist_ok=True)

# Return a full path to draft.lvna
return full_path

@staticmethod
def get_lvnauth_player_python_file() -> Path | None:
Expand Down

0 comments on commit 8cc9049

Please sign in to comment.