Skip to content

Commit

Permalink
sanity check tribe in several places
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuki-Codes committed Sep 29, 2021
1 parent c9ee860 commit fa0b70d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Anamnesis/Character/Views/ColorControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private async void OnClick(object sender, RoutedEventArgs e)

private ColorData.Entry[]? GetColors()
{
if (this.Tribe == 0)
if (!Enum.IsDefined(this.Tribe))
return null;

switch (this.Type)
Expand Down
3 changes: 3 additions & 0 deletions Anamnesis/Character/Views/CustomizeEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ private void UpdateRaceAndTribe()

this.TribeComboBox.ItemsSource = this.Race.Tribes;

if (!Enum.IsDefined(this.Customize.Tribe))
this.Customize.Tribe = AnAppearance.Tribes.Midlander;

this.Tribe = GameDataService.Tribes.Get((uint)this.Customize.Tribe);

if (this.Customize.Tribe == 0 || this.Tribe == null)
Expand Down
6 changes: 6 additions & 0 deletions Anamnesis/Files/CharacterFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,12 @@ public async Task Apply(ActorViewModel actor, SaveModes mode)
if (actor.Customize == null)
return;

if (this.Tribe != null && !Enum.IsDefined((Customize.Tribes)this.Tribe))
throw new Exception($"Invalid tribe: {this.Tribe} in appearance file");

if (this.Race != null && !Enum.IsDefined((Customize.Races)this.Race))
throw new Exception($"Invalid race: {this.Race} in appearance file");

Log.Information("Reading appearance from file");

actor.AutomaticRefreshEnabled = false;
Expand Down

0 comments on commit fa0b70d

Please sign in to comment.