Esempio n. 1
0
        /// <summary>
        /// Adds a new mapping for the given relative content path.
        /// </summary>
        /// <param name="path">The relative asset path.</param>
        /// <param name="metadata">The matching mod asset meta object.</param>
        /// <returns>The passed mod asset meta object.</returns>
        public static ModAsset Add(string path, ModAsset metadata)
        {
            path = path.Replace('\\', '/');

            if (metadata.Type == null)
            {
                path = GuessType(path, out metadata.Type, out metadata.Format);
            }

            metadata.PathVirtual = path;

            // We want our new mapping to replace the previous one, but need to replace the previous one in the shadow structure.
            ModAsset metadataPrev;

            if (!Map.TryGetValue(path, out metadataPrev))
            {
                metadataPrev = null;
            }

            // Hardcoded case: Handle directories separately.
            if (metadata.Type == typeof(AssetTypeDirectory))
            {
                MapDirs[path] = metadata;
            }

            else
            {
                Map[path] = metadata;
            }

            // If we're not already the highest level shadow "node"...
            if (path != "")
            {
                // Add directories automatically.
                string   pathDir = Path.GetDirectoryName(path).Replace('\\', '/');
                ModAsset metadataDir;
                if (!MapDirs.TryGetValue(pathDir, out metadataDir))
                {
                    metadataDir = new ModAssetBranch {
                        PathVirtual = pathDir,
                        Type        = typeof(AssetTypeDirectory)
                    };
                    Add(pathDir, metadataDir);
                }
                // If a previous mapping exists, replace it in the shadow structure.
                int metadataPrevIndex = metadataDir.Children.IndexOf(metadataPrev);
                if (metadataPrevIndex != -1)
                {
                    metadataDir.Children[metadataPrevIndex] = metadata;
                }
                else
                {
                    metadataDir.Children.Add(metadata);
                }
            }

            return(metadata);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the ModAsset mapped to the given relative path.
        /// </summary>
        /// <param name="path">The relative asset path.</param>
        /// <param name="metadata">The resulting mod asset meta object.</param>
        /// <param name="includeDirs">Whether to include directories or not.</param>
        /// <returns>True if a mapping for the given path is present, false otherwise.</returns>
        public static bool TryGet <T>(string path, out ModAsset metadata, bool includeDirs = false)
        {
            path = path.Replace('\\', '/');

            if (includeDirs && MapDirs.TryGetValue(path, out metadata) && metadata.Type == typeof(T))
            {
                return(true);
            }
            if (Map.TryGetValue(path, out metadata) && metadata.Type == typeof(T))
            {
                return(true);
            }

            metadata = null;
            return(false);
        }
Esempio n. 3
0
        /// <summary>
        /// Gets the ModAsset mapped to the given relative path.
        /// </summary>
        /// <param name="path">The relative asset path.</param>
        /// <param name="metadata">The resulting mod asset meta object.</param>
        /// <param name="includeDirs">Whether to include directories or not.</param>
        /// <returns>True if a mapping for the given path is present, false otherwise.</returns>
        public static bool TryGet(string path, out ModAsset metadata, bool includeDirs = false)
        {
            path = path.Replace('\\', '/');

            if (includeDirs)
            {
                if (MapDirs.TryGetValue(path, out metadata))
                {
                    return(true);
                }
            }
            if (Map.TryGetValue(path, out metadata))
            {
                return(true);
            }
            return(false);
        }
Esempio n. 4
0
 protected void Add(string path, ModAsset asset)
 {
     asset = ModContentManager.Add(path, asset);
     List.Add(asset);
     Map[asset.PathVirtual] = asset;
 }