예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SkeletonFrame"/> class.
        /// </summary>
        /// <param name="reader">The <see cref="IValueReader"/> to read from.</param>
        /// <param name="contentPath">The <see cref="ContentPaths"/> to use to load from.</param>
        /// <exception cref="InvalidOperationException">The <see cref="Skeleton"/> failed to load.</exception>
        public SkeletonFrame(IValueReader reader, ContentPaths contentPath)
        {
            Read(reader, contentPath);

            if (Skeleton == null)
                throw new InvalidOperationException("Skeleton failed to load.");
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MapGrhWalls"/> class.
        /// </summary>
        /// <param name="contentPath">The content path.</param>
        /// <param name="createWall">Delegate describing how to create the <see cref="WallEntityBase"/>
        /// from an <see cref="IValueReader"/>.</param>
        public MapGrhWalls(ContentPaths contentPath, CreateWallEntityFromReaderHandler createWall)
        {
            Load(contentPath, createWall);

            // Listen for the addition and removal of walls
            GrhInfo.AddedNew += DeleteGrhDataWalls;
            GrhInfo.Removed += DeleteGrhDataWalls;
        }
 /// <summary>
 /// Saves the quest descriptions to file.
 /// </summary>
 /// <param name="contentPath">The <see cref="ContentPaths"/> to use to get the file path.</param>
 public void Save(ContentPaths contentPath)
 {
     var filePath = GetFilePath(contentPath);
     using (var w = XmlValueWriter.Create(filePath, _rootFileNodeName))
     {
         WriteState(w);
     }
 }
예제 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SkeletonManager"/> class.
        /// </summary>
        /// <param name="contentPath">The content path.</param>
        SkeletonManager(ContentPaths contentPath)
        {
            _contentPath = contentPath;

            var keyComparer = StringComparer.OrdinalIgnoreCase;
            _bodyInfoCache = new HashCache<string, SkeletonBodyInfo>(x => new SkeletonBodyInfo(x, ContentPath), keyComparer);
            _setCache = new HashCache<string, SkeletonSet>(x => new SkeletonSet(x, ContentPath), keyComparer);
        }
예제 #5
0
        /// <summary>
        /// Releases the temporary file. This must be called after the file has been properly closed.
        /// </summary>
        public void Dispose()
        {
            if (_isDisposed)
            {
                return;
            }

            _isDisposed = true;

            ContentPaths.FreeTempFile(_filePath);
        }
예제 #6
0
        /// <summary>
        /// Initializes the <see cref="ContentPaths"/> class.
        /// </summary>
        static ContentPaths()
        {
            var baseDir = AppDomain.CurrentDomain.BaseDirectory;

            _appRoot = Path.GetFullPath(baseDir);

            // Set the _freeFileIndex to a random initial value
            _freeFileIndex = RandomHelper.NextUInt();

            // Set the temp files path
            _temp = _appRoot.Join(_tempFolder);
            if (!Directory.Exists(_temp))
            {
                Directory.CreateDirectory(_temp);
            }

            _buildPaths = new ContentPaths(GetBuildContentPath(_appRoot));

            // Delete temp files
            DeleteTempFiles();
        }
예제 #7
0
        public void Load(ContentPaths contentPath, CreateWallEntityFromReaderHandler createWall)
        {
            var filePath = GetFilePath(contentPath);

            // Clear the old walls in case this isn't the first load
            _walls.Clear();

            if (!File.Exists(filePath))
                return;

            // Read the values
            var reader = XmlValueReader.CreateFromFile(filePath, _rootNodeName);
            var loadedWalls = reader.ReadManyNodes(_rootNodeName, x => ReadWalls(x, createWall));

            foreach (var wall in loadedWalls)
            {
                _walls[(int)wall.Key] = wall.Value;
            }
        }
예제 #8
0
파일: Skeleton.cs 프로젝트: wtfcolt/game
 /// <summary>
 /// Gets the absolute file path for a Skeleton file.
 /// </summary>
 /// <param name="skeletonName">The name of the Skeleton.</param>
 /// <param name="contentPath">The content path to use.</param>
 /// <returns>The absolute file path for a Skeleton file.</returns>
 public static string GetFilePath(string skeletonName, ContentPaths contentPath)
 {
     return contentPath.Skeletons.Join(skeletonName + FileSuffix);
 }
예제 #9
0
        /// <summary>
        /// Loads the <see cref="ParticleEffectManager"/> from file.
        /// </summary>
        /// <param name="contentPath">The <see cref="ContentPaths"/> to load from.</param>
        void Load(ContentPaths contentPath)
        {
            _effects.Clear();

            var filePath = GetFilePath(contentPath);
            var reader = GenericValueReader.CreateFromFile(filePath, _rootNodeName);
            var readEffects = reader.ReadManyNodes(_particleEffectsNodeName, r => new ParticleEffect(r));

            // Ensure the ParticleEffects were properly loaded into here
            Debug.Assert(readEffects.All(x => _effects[x.Name] == x));
        }
예제 #10
0
        /// <summary>
        /// Initializes the <see cref="ContentPaths"/> class.
        /// </summary>
        static ContentPaths()
        {
            var baseDir = AppDomain.CurrentDomain.BaseDirectory;
            _appRoot = Path.GetFullPath(baseDir);

            // Set the _freeFileIndex to a random initial value
            _freeFileIndex = RandomHelper.NextUInt();

            // Set the temp files path
            _temp = _appRoot.Join(_tempFolder);
            if (!Directory.Exists(_temp))
                Directory.CreateDirectory(_temp);

            _buildPaths = new ContentPaths(GetBuildContentPath(_appRoot));

            // Delete temp files
            DeleteTempFiles();
        }
예제 #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SkeletonBodyInfo"/> class.
 /// </summary>
 /// <param name="skeletonBodyName">Name of the skeleton body.</param>
 /// <param name="contentPath">The content path.</param>
 public SkeletonBodyInfo(string skeletonBodyName, ContentPaths contentPath)
     : this(GenericValueReader.CreateFromFile(GetFilePath(skeletonBodyName, contentPath), _rootNodeName))
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="QuestDescriptionCollection"/> class.
 /// </summary>
 /// <param name="contentPath">The <see cref="ContentPaths"/> to use to get the file path.</param>
 QuestDescriptionCollection(ContentPaths contentPath)
 {
     _contentPath = contentPath;
     Load(contentPath);
 }
 /// <summary>
 /// Gets the file path for the quest descriptions file.
 /// </summary>
 /// <param name="contentPath">The <see cref="ContentPaths"/> to use to get the file path.</param>
 /// <returns>The file path for the quest descriptions file.</returns>
 public static string GetFilePath(ContentPaths contentPath)
 {
     return contentPath.Data.Join("questdata" + EngineSettings.DataFileSuffix);
 }
예제 #14
0
 /// <summary>
 /// Reads the <see cref="SkeletonFrame"/> from an <see cref="IValueReader"/>.
 /// </summary>
 /// <param name="reader">The <see cref="IValueReader"/> to read from.</param>
 /// <param name="contentPath">The <see cref="ContentPaths"/> to use to load additional assets.</param>
 public void Read(IValueReader reader, ContentPaths contentPath)
 {
     _delay = reader.ReadFloat(_delayValueKey);
     _fileName = reader.ReadString(_fileNameValueKey);
     _skeleton = new Skeleton(_fileName, contentPath);
 }
예제 #15
0
        /// <summary>
        /// Gets the default file path for the <see cref="ToolStateManager"/> settings file.
        /// </summary>
        /// <param name="contentPath">The <see cref="ContentPaths"/> to get the path for.</param>
        /// <param name="profileName">The name of the settings profile to use. Use null for the default profile.</param>
        /// <returns>
        /// The default file path for the <see cref="ToolStateManager"/> settings file.
        /// </returns>
        public static string GetFilePath(ContentPaths contentPath, string profileName)
        {
            var fileName = "EditorToolStates";
            if (!string.IsNullOrEmpty(profileName))
                fileName += "." + profileName;

            fileName += EngineSettings.DataFileSuffix;

            return contentPath.Settings.Join(fileName);
        }
예제 #16
0
        /// <summary>
        /// Gets the default file path for the body info file for the given <see cref="ContentPaths"/>.
        /// </summary>
        /// <param name="contentPath">The <see cref="ContentPaths"/> to get the default body info file path for.</param>
        /// <returns>The default file path for the body info file for the <paramref name="contentPath"/>.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="contentPath"/> is null.</exception>
        public static string GetDefaultFilePath(ContentPaths contentPath)
        {
            if (contentPath == null)
                throw new ArgumentNullException("contentPath");

            return contentPath.Data.Join("bodies" + EngineSettings.DataFileSuffix);
        }
예제 #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SkeletonSet"/> class.
 /// </summary>
 /// <param name="reader">The <see cref="IValueReader"/> to read the data from.</param>
 /// <param name="contentPath">The <see cref="ContentPaths"/> to use to load other data.</param>
 public SkeletonSet(IValueReader reader, ContentPaths contentPath)
 {
     Read(reader, contentPath);
 }
예제 #18
0
 /// <summary>
 /// Saves the <see cref="BodyInfoManager"/> data to file.
 /// </summary>
 /// <param name="contentPath">The <see cref="ContentPaths"/> to save to.</param>
 public void Save(ContentPaths contentPath)
 {
     Save(GetDefaultFilePath(contentPath));
 }
예제 #19
0
 /// <summary>
 /// Loads the <see cref="BodyInfoManager"/> from the specified file.
 /// </summary>
 /// <param name="contentPath">The <see cref="ContentPaths"/> to use to load the file from.</param>
 /// <returns>
 /// The loaded <see cref="BodyInfoManager"/>.
 /// </returns>
 static BodyInfoManager Load(ContentPaths contentPath)
 {
     return Load(GetDefaultFilePath(contentPath));
 }
예제 #20
0
 /// <summary>
 /// Saves the <see cref="ParticleEffectManager"/> to file.
 /// </summary>
 /// <param name="contentPath">The <see cref="ContentPaths"/> to save to.</param>
 public void Save(ContentPaths contentPath)
 {
     var filePath = GetFilePath(contentPath);
     using (var writer = GenericValueWriter.Create(filePath, _rootNodeName, EncodingFormat))
     {
         writer.WriteManyNodes(_particleEffectsNodeName, _effects.Values, (w, v) => v.WriteState(w));
     }
 }
예제 #21
0
        public void Save(ContentPaths contentPath)
        {
            var filePath = GetFilePath(contentPath);

            // Build up a list of the valid walls, and join them with their GrhIndex
            var wallsToWrite = new List<KeyValuePair<GrhIndex, List<WallEntityBase>>>(_walls.Count);
            for (var i = 0; i < _walls.Length; i++)
            {
                var walls = _walls[i];
                if (walls == null || walls.Count == 0)
                    continue;

                var kvp = new KeyValuePair<GrhIndex, List<WallEntityBase>>(new GrhIndex(i), walls);
                wallsToWrite.Add(kvp);
            }

            // Write the values
            using (var writer = XmlValueWriter.Create(filePath, _rootNodeName))
            {
                writer.WriteManyNodes(_rootNodeName, wallsToWrite, WriteWalls);
            }
        }
예제 #22
0
 /// <summary>
 /// Saves the settings to file.
 /// </summary>
 /// <param name="contentPath">The <see cref="ContentPaths"/> to save to.</param>
 /// <param name="profileName">The name of the settings profile to use. Use null for the default profile.</param>
 public void Save(ContentPaths contentPath, string profileName)
 {
     var filePath = GetFilePath(contentPath, profileName);
     Save(filePath);
 }
예제 #23
0
        /// <summary>
        /// Runs the CopyContent program to copy content from the development directory to the build directory.
        /// </summary>
        /// <param name="dev">The path to the development directory. If null, <see cref="ContentPaths.Dev"/> will be used.</param>
        /// <param name="build">The path to the build directory. If null, <see cref="ContentPaths.Build"/> will be used.</param>
        /// <param name="copyContentFile">The path to the CopyContent.exe program file. If null, the file will be searched
        /// for in the <paramref name="dev"/> path.</param>
        /// <param name="userArgs">The additional arguments to pass to the CopyContent program..</param>
        /// <returns>
        /// True if the process was successfully run; otherwise false.
        /// </returns>
        public static bool TryCopyContent(ContentPaths dev = null, ContentPaths build = null, string copyContentFile = null,
                                          string userArgs = null)
        {
            try
            {
                // Use the default dev/build paths if not defined
                if (dev == null)
                    dev = Dev;

                if (build == null)
                    build = Build;

                if (dev == null || build == null)
                {
                    if (log.IsErrorEnabled)
                        log.ErrorFormat("Failed to run CopyContent: Could not acquire the dev ContentPath.");
                    return false;
                }

                // Get the CopyContent binary file path
                if (string.IsNullOrEmpty(copyContentFile))
                    copyContentFile = dev.Root.Join("CopyContent.exe");

                // Ensure the file exists
                if (!File.Exists(copyContentFile))
                {
                    if (log.IsErrorEnabled)
                        log.ErrorFormat("Failed to run CopyContent: Could not find the CopyContent program at `{0}`",
                            copyContentFile);
                    return false;
                }

                // Try to run the program
                var arguments = string.Format("\"{0}\" \"{1}\"", dev.Root, build.Root);
                if (!string.IsNullOrEmpty(userArgs))
                    arguments += " " + userArgs;

                var pi = new ProcessStartInfo(copyContentFile, arguments)
                { CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden };

                try
                {
                    var proc = Process.Start(pi);
                    if (proc == null)
                    {
                        if (log.IsErrorEnabled)
                            log.ErrorFormat("Failed to run CopyContent process: Process.Start returned null.");
                        return false;
                    }

                    proc.WaitForExit(30000);
                }
                catch (Exception ex)
                {
                    if (log.IsErrorEnabled)
                        log.ErrorFormat("Failed to run CopyContent process: {0}", ex);

                    return false;
                }
            }
            catch (Exception ex)
            {
                const string errmsg = "TryCopyContent() failed to unknown and unexpected exception. Exception: {0}";
                if (log.IsErrorEnabled)
                    log.ErrorFormat(errmsg, ex);
                Debug.Fail(string.Format(errmsg, ex));
            }

            return true;
        }
예제 #24
0
 /// <summary>
 /// Loads the settings from file, and applies loaded settings to the <see cref="Tool"/>s in this object.
 /// <see cref="Tool"/>s in this object that have no settings specified in the loaded file will have their values
 /// reset to default.
 /// </summary>
 /// <param name="contentPath">The <see cref="ContentPaths"/> to load from.</param>
 /// <param name="profileName">The name of the settings profile to use. Use null for the default profile.</param>
 /// <returns>True if the settings were successfully loaded from the file; otherwise false.</returns>
 public bool TryLoad(ContentPaths contentPath, string profileName)
 {
     var filePath = GetFilePath(contentPath, profileName);
     return TryLoad(filePath);
 }
 /// <summary>
 /// Creates a <see cref="QuestDescriptionCollection"/>.
 /// </summary>
 /// <param name="contentPath">The <see cref="ContentPaths"/> to use to get the file path.</param>
 /// <returns>The <see cref="QuestDescriptionCollection"/> for the given <paramref name="contentPath"/>.</returns>
 public static IQuestDescriptionCollection Create(ContentPaths contentPath)
 {
     return _instanceCache[contentPath];
 }
예제 #26
0
 /// <summary>
 /// Creates a <see cref="SkeletonManager"/> for the specified <see cref="ContentPaths"/>.
 /// </summary>
 /// <param name="contentPath">The content path.</param>
 /// <returns>The <see cref="SkeletonManager"/> for the specified <see cref="ContentPaths"/>.</returns>
 public static SkeletonManager Create(ContentPaths contentPath)
 {
     return _skeletonManagerCache[contentPath];
 }
 /// <summary>
 /// Loads the quest descriptions from file.
 /// </summary>
 /// <param name="contentPath">The <see cref="ContentPaths"/> to use to get the file path.</param>
 void Load(ContentPaths contentPath)
 {
     var filePath = GetFilePath(contentPath);
     var reader = XmlValueReader.CreateFromFile(filePath, _rootFileNodeName);
     ReadState(reader);
 }
예제 #28
0
        /// <summary>
        /// Runs the CopyContent program to copy content from the development directory to the build directory.
        /// </summary>
        /// <param name="dev">The path to the development directory. If null, <see cref="ContentPaths.Dev"/> will be used.</param>
        /// <param name="build">The path to the build directory. If null, <see cref="ContentPaths.Build"/> will be used.</param>
        /// <param name="copyContentFile">The path to the CopyContent.exe program file. If null, the file will be searched
        /// for in the <paramref name="dev"/> path.</param>
        /// <param name="userArgs">The additional arguments to pass to the CopyContent program..</param>
        /// <returns>
        /// True if the process was successfully run; otherwise false.
        /// </returns>
        public static bool TryCopyContent(ContentPaths dev = null, ContentPaths build = null, string copyContentFile = null,
                                          string userArgs  = null)
        {
            try
            {
                // Use the default dev/build paths if not defined
                if (dev == null)
                {
                    dev = Dev;
                }

                if (build == null)
                {
                    build = Build;
                }

                if (dev == null || build == null)
                {
                    if (log.IsErrorEnabled)
                    {
                        log.ErrorFormat("Failed to run CopyContent: Could not acquire the dev ContentPath.");
                    }
                    return(false);
                }

                // Get the CopyContent binary file path
                if (string.IsNullOrEmpty(copyContentFile))
                {
                    copyContentFile = dev.Root.Join("CopyContent.exe");
                }

                // Ensure the file exists
                if (!File.Exists(copyContentFile))
                {
                    if (log.IsErrorEnabled)
                    {
                        log.ErrorFormat("Failed to run CopyContent: Could not find the CopyContent program at `{0}`",
                                        copyContentFile);
                    }
                    return(false);
                }

                // Try to run the program
                var arguments = string.Format("\"{0}\" \"{1}\"", dev.Root, build.Root);
                if (!string.IsNullOrEmpty(userArgs))
                {
                    arguments += " " + userArgs;
                }

                var pi = new ProcessStartInfo(copyContentFile, arguments)
                {
                    CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden
                };

                try
                {
                    var proc = Process.Start(pi);
                    if (proc == null)
                    {
                        if (log.IsErrorEnabled)
                        {
                            log.ErrorFormat("Failed to run CopyContent process: Process.Start returned null.");
                        }
                        return(false);
                    }

                    proc.WaitForExit(30000);
                }
                catch (Exception ex)
                {
                    if (log.IsErrorEnabled)
                    {
                        log.ErrorFormat("Failed to run CopyContent process: {0}", ex);
                    }

                    return(false);
                }
            }
            catch (Exception ex)
            {
                const string errmsg = "TryCopyContent() failed to unknown and unexpected exception. Exception: {0}";
                if (log.IsErrorEnabled)
                {
                    log.ErrorFormat(errmsg, ex);
                }
                Debug.Fail(string.Format(errmsg, ex));
            }

            return(true);
        }
예제 #29
0
        static string TryGetAbsoluteFilePath(StationaryGrhData gd, ContentPaths contentPath)
        {
            string ret = null;
            var isValid = true;

            try
            {
                ret = gd.TextureName.GetAbsoluteFilePath(contentPath);
                if (!File.Exists(ret))
                    isValid = false;
            }
            catch (ArgumentException)
            {
                isValid = false;
            }

            if (!isValid)
            {
                const string errmsg =
                    "Could not update the size of GrhData `{0}` since the file for the texture named `{1}`" +
                    " could not be found in the ContentPaths.Dev. Expected file: {2}";
                if (log.IsErrorEnabled)
                    log.ErrorFormat(errmsg, gd, gd.TextureName, ret ?? "[NULL]");
                return null;
            }
            else
                return ret;
        }
예제 #30
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TempFile"/> class.
 /// </summary>
 public TempFile() : this(ContentPaths.GetTempFilePath())
 {
 }
예제 #31
0
 /// <summary>
 /// Gets the names of all the <see cref="SkeletonBodyInfo"/>s that exist in the specified <see cref="ContentPaths"/>.
 /// </summary>
 /// <param name="contentPath">The <see cref="ContentPaths"/> to search.</param>
 public static IEnumerable<string> GetBodyNames(ContentPaths contentPath)
 {
     var allFiles = Directory.GetFiles(contentPath.Skeletons, "*" + FileSuffix, SearchOption.AllDirectories);
     var withoutExtensions = allFiles.Select(Path.GetFileNameWithoutExtension);
     return withoutExtensions;
 }
예제 #32
0
 public void Read(IValueReader reader, ContentPaths contentPath)
 {
     var loadedFrames = reader.ReadManyNodes(_framesNodeName, x => new SkeletonFrame(x, contentPath));
     _keyFrames = loadedFrames;
 }
예제 #33
0
파일: Skeleton.cs 프로젝트: wtfcolt/game
 /// <summary>
 /// Initializes a new instance of the <see cref="Skeleton"/> class.
 /// </summary>
 /// <param name="skeletonName">Name of the skeleton.</param>
 /// <param name="contentPath">The <see cref="ContentPaths"/> to load from.</param>
 public Skeleton(string skeletonName, ContentPaths contentPath)
 {
     var filePath = GetFilePath(skeletonName, contentPath);
     var reader = GenericValueReader.CreateFromFile(filePath, _rootNodeName);
     Read(reader);
 }
예제 #34
0
 /// <summary>
 /// Gets the file path to use for loading and saving the <see cref="ParticleEffectManager"/>.
 /// </summary>
 /// <param name="contentPath">The <see cref="ContentPaths"/> to use.</param>
 /// <returns>The file path to the <see cref="ParticleEffectManager"/> file.</returns>
 public static string GetFilePath(ContentPaths contentPath)
 {
     return contentPath.Data.Join("particleeffects" + EngineSettings.DataFileSuffix);
 }