From 99b7529fb6c092f751853ed6be7dd567efab9484 Mon Sep 17 00:00:00 2001 From: Oliveriver Date: Sat, 17 Dec 2022 21:22:02 +0000 Subject: [PATCH 1/3] Fossil error handling --- .../fossilisation/FossilisedSpecies.cs | 18 +++++++++++++----- .../pages/ThriveopediaMuseumPage.cs | 7 +++++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/thriveopedia/fossilisation/FossilisedSpecies.cs b/src/thriveopedia/fossilisation/FossilisedSpecies.cs index b810efa3dc8..4af0d6ecd95 100644 --- a/src/thriveopedia/fossilisation/FossilisedSpecies.cs +++ b/src/thriveopedia/fossilisation/FossilisedSpecies.cs @@ -119,15 +119,23 @@ public static bool IsSpeciesAlreadyFossilised(string name, List? existin /// /// The name of the .thrivefossil file (including extension) /// The species saved in the provided file - public static FossilisedSpecies LoadSpeciesFromFile(string fossilName) + public static FossilisedSpecies? LoadSpeciesFromFile(string fossilName) { var target = Path.Combine(Constants.FOSSILISED_SPECIES_FOLDER, fossilName); - var (fossilisedInfo, species, previewImage) = LoadFromFile(target); + try + { + var (fossilisedInfo, species, previewImage) = LoadFromFile(target); - return new FossilisedSpecies(fossilisedInfo, species, Path.GetFileNameWithoutExtension(fossilName)) + return new FossilisedSpecies(fossilisedInfo, species, Path.GetFileNameWithoutExtension(fossilName)) + { + PreviewImage = previewImage, + }; + } + catch (Exception) { - PreviewImage = previewImage, - }; + // This fossil is corrupt, so just don't bother showing it + return null; + } } /// diff --git a/src/thriveopedia/pages/ThriveopediaMuseumPage.cs b/src/thriveopedia/pages/ThriveopediaMuseumPage.cs index 8d5e5530463..8e958f471b2 100644 --- a/src/thriveopedia/pages/ThriveopediaMuseumPage.cs +++ b/src/thriveopedia/pages/ThriveopediaMuseumPage.cs @@ -59,10 +59,13 @@ public override void OnThriveopediaOpened() foreach (var speciesName in FossilisedSpecies.CreateListOfFossils(true)) { - var card = (MuseumCard)museumCardScene.Instance(); - var savedSpecies = FossilisedSpecies.LoadSpeciesFromFile(speciesName); + // Don't add cards for corrupt fossils + if (savedSpecies == null) + continue; + + var card = (MuseumCard)museumCardScene.Instance(); card.SavedSpecies = savedSpecies.Species; card.FossilPreviewImage = savedSpecies.PreviewImage; card.Connect(nameof(MuseumCard.OnSpeciesSelected), this, nameof(UpdateSpeciesPreview)); From 83f6303671e625c1e8818c80ea5f4edce56cf1b6 Mon Sep 17 00:00:00 2001 From: Oliveriver Date: Sat, 17 Dec 2022 21:25:31 +0000 Subject: [PATCH 2/3] Print error --- src/thriveopedia/fossilisation/FossilisedSpecies.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/thriveopedia/fossilisation/FossilisedSpecies.cs b/src/thriveopedia/fossilisation/FossilisedSpecies.cs index 4af0d6ecd95..63d1f0812cf 100644 --- a/src/thriveopedia/fossilisation/FossilisedSpecies.cs +++ b/src/thriveopedia/fossilisation/FossilisedSpecies.cs @@ -131,9 +131,10 @@ public static bool IsSpeciesAlreadyFossilised(string name, List? existin PreviewImage = previewImage, }; } - catch (Exception) + catch (Exception e) { // This fossil is corrupt, so just don't bother showing it + GD.PrintErr($"Error loading fossil: {e}"); return null; } } From 56768a5388ea7b8c968bcb673b7b3065d38cde7d Mon Sep 17 00:00:00 2001 From: Oliveriver Date: Wed, 28 Dec 2022 11:40:16 +0000 Subject: [PATCH 3/3] Update comments --- src/thriveopedia/fossilisation/FossilisedSpecies.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/thriveopedia/fossilisation/FossilisedSpecies.cs b/src/thriveopedia/fossilisation/FossilisedSpecies.cs index 63d1f0812cf..b86c91d9cf9 100644 --- a/src/thriveopedia/fossilisation/FossilisedSpecies.cs +++ b/src/thriveopedia/fossilisation/FossilisedSpecies.cs @@ -118,7 +118,7 @@ public static bool IsSpeciesAlreadyFossilised(string name, List? existin /// Loads a fossilised species by its filename. /// /// The name of the .thrivefossil file (including extension) - /// The species saved in the provided file + /// The species saved in the provided file, or null if the file doesn't exist or is corrupt public static FossilisedSpecies? LoadSpeciesFromFile(string fossilName) { var target = Path.Combine(Constants.FOSSILISED_SPECIES_FOLDER, fossilName); @@ -133,7 +133,7 @@ public static bool IsSpeciesAlreadyFossilised(string name, List? existin } catch (Exception e) { - // This fossil is corrupt, so just don't bother showing it + // This fossil doesn't exist or is corrupt, so just don't bother showing it GD.PrintErr($"Error loading fossil: {e}"); return null; }