comparison api/WarFoundryLoader.cs @ 226:c931684f9024

Re #234: Invalid data file doesn't stop load * Add internal methods to remove game systems or races that fail to load * Add error handling on XML CompleteLoading so that game system or race is removed, but make sure not to affect error
author IBBoard <dev@ibboard.co.uk>
date Sat, 19 Dec 2009 15:40:50 +0000
parents 721891008b5c
children a36a0e9cc05d
comparison
equal deleted inserted replaced
225:0d5a17f33a36 226:c931684f9024
589 systemsTable.TryGetValue(systemID.ToLower(), out system); 589 systemsTable.TryGetValue(systemID.ToLower(), out system);
590 return system; 590 return system;
591 } 591 }
592 592
593 /// <summary> 593 /// <summary>
594 /// Removes a loaded <see cref="GameSystem"/>. Used when a GameSystem fails to complete loading
595 /// </summary>
596 /// <param name="system">The GameSystem to remove</param>
597 internal void RemoveGameSystem(GameSystem system)
598 {
599 systemsTable.Remove(system.ID.ToLower());
600 }
601
602 /// <summary>
594 /// Gets an array of the races for the specified <see cref="GameSystem"/>. 603 /// Gets an array of the races for the specified <see cref="GameSystem"/>.
595 /// </summary> 604 /// </summary>
596 /// <param name="system"> 605 /// <param name="system">
597 /// The <see cref="GameSystem"/> to get the available races for. 606 /// The <see cref="GameSystem"/> to get the available races for.
598 /// </param> 607 /// </param>
726 LoadFiles(); 735 LoadFiles();
727 } 736 }
728 737
729 Race race = null; 738 Race race = null;
730 739
731 systemID = systemID.ToLower(); 740 Dictionary<string, Race> subraces = GetRaceTable(systemID, raceID);
732 raceID = raceID.ToLower(); 741
733 raceSubID = raceSubID.ToLower(); 742 if (subraces != null)
734 743 {
735 Dictionary<string, Dictionary<string, Race>> races; 744 subraces.TryGetValue(raceSubID.ToLower(), out race);
736 racesTable.TryGetValue(systemID, out races);
737
738 if (races!=null)
739 {
740 Dictionary<string, Race> subraces;
741 races.TryGetValue(raceID, out subraces);
742
743 if (subraces!=null)
744 {
745 subraces.TryGetValue(raceSubID, out race);
746 }
747 } 745 }
748 746
749 return race; 747 return race;
748 }
749
750 private Dictionary<string, Race> GetRaceTable(string systemID, string raceID)
751 {
752 Dictionary<string, Dictionary<string, Race>> races;
753 racesTable.TryGetValue(systemID.ToLower(), out races);
754 Dictionary<string, Race> subraces = null;
755
756 if (races != null)
757 {
758 races.TryGetValue(raceID.ToLower(), out subraces);
759 }
760
761 return subraces;
762 }
763
764 internal void RemoveRace(Race race)
765 {
766 Dictionary<string, Race> subraces = GetRaceTable(race.GameSystem.ID, race.ID);
767
768 if (subraces != null)
769 {
770 subraces.Remove(race.SubID.ToLower());
771 }
750 } 772 }
751 773
752 /// <summary> 774 /// <summary>
753 /// Gets the IDs of all of the game systems currently available. 775 /// Gets the IDs of all of the game systems currently available.
754 /// </summary> 776 /// </summary>