Skip to content

Commit

Permalink
Merge pull request latitudegames#232 from KevinMoonglow/loadfromsplas…
Browse files Browse the repository at this point in the history
…hfix

Fix loading saved games from the title splash.
  • Loading branch information
ben-bay authored Jan 6, 2020
2 parents e87d13b + d532d28 commit f4bff92
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- `install.sh` will only use `sudo` if the user is not root
- Fix loading saved games from the title splash to use the new local save path.

## [2.2.0] - 2019-12-19

Expand Down
15 changes: 10 additions & 5 deletions story/story_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,20 @@ def start_new_story(
return str(self.story)

def load_new_story(self, story_id, upload_story=False):
save_path = "./saved_stories/"
file_name = "story" + story_id + ".json"
cmd = "gsutil cp gs://aidungeonstories/" + file_name + " ."
os.system(cmd)
exists = os.path.isfile(file_name)
exists = os.path.isfile(os.path.join(save_path, file_name))

if not exists:
return "Error save not found."
print("Save not found locally. Trying in the cloud bucket (only valid for saves before Dec 24 2019)")
cmd = "gsutil cp gs://aidungeonstories/" + file_name + " " + save_path
os.system(cmd)
exists = os.path.isfile(os.path.join(save_path, file_name))

if not exists:
return "Error save not found locally or on the cloud."

with open(file_name, "r") as fp:
with open(os.path.join(save_path, file_name), "r") as fp:
game = json.load(fp)
self.story = Story("", upload_story=upload_story)
self.story.init_from_dict(game)
Expand Down

0 comments on commit f4bff92

Please sign in to comment.