Beispiel #1
0
        /// <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;
        }
Beispiel #2
0
		/// <summary>
		///   Initializes this class and loads the settings file.
		/// </summary>
		public static void Initialize()
		{
			string appDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
			string settingsPath;

#if DEBUG
			settingsPath = string.Concat(appDirectory, @"\..\..\..\GameSettings.txt");
#elif !DEBUG
            settingsPath = string.Concat(appDirectory, @"\GameSettings.txt");
#endif

			if (!File.Exists(settingsPath))
			{
				throw new FileNotFoundException(string.Format("The settings file at {0} could not be found.", settingsPath));
			}

			settingsReader = new DataReader(settingsPath);
		}
Beispiel #3
0
        /// <summary>
        ///   Loads a content package.
        /// </summary>
        /// <param name="settingsPath">
        ///   The path to the settings file for this package.
        /// </param>
        internal void Load(string settingsPath)
        {
            if (!isLoaded)
            {
                if (!File.Exists(settingsPath))
                {
                    throw new FileNotFoundException(string.Format("The settings file at {0} does not exist.", settingsPath));
                }

                settingsFilePath = settingsPath;
                Dictionary<string, string> settings = new DataReader(settingsPath).ReadFullSection("[ContentPackage]");

                Name = settings["Name"];
                Author = settings["Author"];
                BaseFolderPath = string.Concat(new FileInfo(settingsPath).DirectoryName, @"\");
                AssemblyPath = string.Concat(BaseFolderPath, settings["AssemblyPath"]);

                // Sanity check - let's make sure the assembly path is right.
                if (!File.Exists(AssemblyPath) || !AssemblyPath.EndsWith(".dll"))
                {
                    throw new FileNotFoundException(string.Format("The assembly file at {0} does not exist. Please check the settings file at {1}.", AssemblyPath, settingsPath));
                }

                // Now load the assembly.
                AssemblyManager.LoadAssembly(AssemblyPath);

                isLoaded = true;
            }
        }
        /// <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;
            }
        }
Beispiel #5
0
        /// <summary>
        ///   Loads an instance of IGraphicsObject from a given file path. If a
        ///   text file with the same name is in the same folder, that will be
        ///   used to determine what kind of graphics object it is. If no text
        ///   file is present, the object is assumed to be static. Otherwise, the
        ///   type (animated, complex) depends on what the first line of the file is.
        /// </summary>
        /// <param name="filePath">
        ///   The path to the image of the graphics object.
        /// </param>
        /// <returns>A loaded IGraphicsObject instance.</returns>
        public static IGraphicsObject LoadGraphicsObject(string filePath)
        {
            if (!loadedObjects.ContainsKey(filePath))
            {
                // We'll assume we have the right path (considering graphics overrides).
                string fileNameWithoutExt = Path.GetFileNameWithoutExtension(filePath);
                string directoryName = new FileInfo(filePath).DirectoryName;
                string configPath = Path.Combine(directoryName, string.Concat(fileNameWithoutExt, ".txt"));

                if (!File.Exists(configPath))
                {
                    // No configuration, so the object is probably static
                    var result = new StaticGraphicsObject();
                    result.Load(filePath);
                    loadedObjects.Add(filePath, result);
                    return result;
                }
                else
                {
                    // A configuration! Let's read it to find out what it is.
                    DataReader config = new DataReader(configPath);
                    if (config[0] == "[Animated]" || config[0] == "[Animated_RunOnce]")
                    {
                        var result = new AnimatedGraphicsObject();
                        result.Load(filePath, config);
                        loadedObjects.Add(filePath, result);
                        return result;
                    }
                    else if (config[0] == "[Complex]")
                    {
                        var result = new ComplexGraphicsObject();
                        result.Load(filePath, config);
                        loadedObjects.Add(filePath, result);
                        return result;
                    }
                }
            }
            else
            {
                return loadedObjects[filePath].Clone();
            }

            return null;
        }
        /// <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;
            }
        }