/// <summary> /// Reads a list of overrides from a content override description file. /// </summary> /// <param name="overridesFilePath"> /// The path to the content override description file. /// </param> /// <returns> /// A dictionary mapping level filenames to lists of folder names. /// </returns> public static Dictionary<string, List<string>> GetOverridesFromFile(string overridesFilePath) { if (!File.Exists(overridesFilePath)) { throw new FileNotFoundException($"Tried to load a content overrides file, but it doesn't exist or the path is invalid. (Path: {overridesFilePath})"); } Dictionary<string, List<string>> result = new Dictionary<string, List<string>>(); DataReader overrideReader = new DataReader(overridesFilePath); var overrideSection = overrideReader.ReadFullSection("[Overrides]"); foreach (var overrideLevelEntry in overrideSection) { result.Add(overrideLevelEntry.Key, overrideLevelEntry.Value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList()); } return result; }
/// <summary> /// Loads a ComplexGraphicsObject. /// </summary> /// <param name="filePath">The file path to the image.</param> /// <param name="config"> /// A DataReader containing the configuration file for this object. /// </param> public void Load(string filePath, DataReader config) { if (!isLoaded) { FilePath = filePath; configFilePath = config.FilePath; if (!(config[0] == "[Complex]")) { throw new FormatException("ComplexGraphicsObject.Load(string, DataReader): Invalid or corrupt configuration file."); } var settings = config.ReadFullSection("[Complex]"); int totalGraphicsObjects; string startingObject; FrameSize = Vector2Extensions.Parse(settings["FrameSize"]); if (!int.TryParse(settings["TotalGraphicsObjects"], out totalGraphicsObjects)) { throw new FormatException(string.Format("ComplexGraphicsObject.Load(string, DataReader): Invalid number of graphics objects specified. Got {0}.", settings["TotalGraphicsObjects"])); } startingObject = settings["StartingObject"]; for (int i = 0; i < totalGraphicsObjects; i++) { string objectHeader = string.Concat("[Object", i, "]"); var objectData = config.ReadFullSection(objectHeader); string name = objectData["Name"]; string type = objectData["Type"]; switch (type) { case "static": StaticGraphicsObject staticObject = new StaticGraphicsObject(); staticObject.Load(objectData, this); graphicsObjects.Add(name, staticObject); break; case "animated": AnimatedGraphicsObject animatedObject = new AnimatedGraphicsObject(); animatedObject.Load(objectData, this); graphicsObjects.Add(name, animatedObject); break; case "animated_runonce": AnimatedGraphicsObject animatedRunOnceObject = new AnimatedGraphicsObject(); animatedRunOnceObject.Load(objectData, this); animatedRunOnceObject.IsRunOnce = true; graphicsObjects.Add(name, animatedRunOnceObject); break; default: break; } } CurrentObjectName = startingObject; isLoaded = true; } }
/// <summary> /// Loads an instance of an AnimatedGraphicsObject. /// </summary> /// <param name="filePath">The file path to the image to use.</param> /// <param name="config"> /// A DataReader containing the configuration for this file. /// </param> public void Load(string filePath, DataReader config) { if (!isLoaded) { this.filePath = filePath; configFilePath = config.FilePath; if (config[0] != "[Animated]" && config[0] != "[Animated_RunOnce]") { throw new InvalidDataException(string.Format("AnimatedGraphicsObject.Load(string, DataReader): Invalid or corrupt configuration data (expected header [Animated] or [Animated_RunOnce], got header {0})", config[0])); } Dictionary<string, string> data; if (config[0] == "[Animated]") { data = config.ReadFullSection("[Animated]"); } else { data = config.ReadFullSection("[Animated_RunOnce]"); IsRunOnce = true; } frameWidth = int.Parse(data["FrameWidth"]); AnimationCycleLength = decimal.Parse(data["CycleLength"]); isLoaded = true; } }