Exemple #1
0
        public new MTexture GetAtlasSubtexturesAt(string key, int index)
        {
            if (orderedTexturesCache.TryGetValue(key, out List <MTexture> list))
            {
                if (index < 0 || index >= list.Count)
                {
                    Logger.Log(LogLevel.Warn, "Atlas", $"Requested atlas subtexture that falls out of range: {key} {index}");

                    return(GetFallback());
                }
                return(list[index]);
            }

            MTexture result = GetAtlasSubtextureFromAtlasAt(key, index);

            if (result == null)
            {
                MTexture fallback = GetFallback();
                if (fallback != null)
                {
                    // SpriteData and other places use GetAtlasSubtextureAt to check if textures exist.
                    // Logging this verbosely when no fallback exists doesn't make sense in those cases.
                    Logger.Log(LogLevel.Warn, "Atlas", $"Requested atlas subtexture that does not exist: {key} {index}");
                    return(fallback);
                }
            }
            return(result);
        }
Exemple #2
0
        public new List <MTexture> GetAtlasSubtextures(string key)
        {
            List <MTexture> result = orig_GetAtlasSubtextures(key);

            if (result == null || result.Count == 0)
            {
                Logger.Log(LogLevel.Warn, "Atlas.GetAtlasSubtextures", $"Requested atlas subtextures but none were found: {key}");
            }
            return(result);
        }
Exemple #3
0
        // log missing texture when getting one by ID (for example, tilesets)
        public new MTexture this[string id] {
            [MonoModReplace]
            get {
                if (!textures.ContainsKey(id))
                {
                    Logger.Log(LogLevel.Warn, "Atlas", $"Requested texture that does not exist: {id}");
                }
                return(textures[id]);
            }

            // we don't want to modify the setter, but want it to exist in the patch class so that we can call it from within our patches.
            [MonoModIgnore]
            set { }
        }
Exemple #4
0
        // log missing texture when getting one by ID (for example, tilesets)
        public new MTexture this[string id] {
            [MonoModReplace]
            get {
                if (!textures.TryGetValue(id, out MTexture result))
                {
                    Logger.Log(LogLevel.Warn, "Atlas", $"Requested texture that does not exist: {id}");
                    return(GetFallback());
                }
                return(result);
            }

            // we don't want to modify the setter, but want it to exist in the patch class so that we can call it from within our patches.
            [MonoModIgnore]
            set { }
        }
Exemple #5
0
        public new List <MTexture> GetAtlasSubtextures(string key)
        {
            PushFallback(null);
            List <MTexture> result = orig_GetAtlasSubtextures(key);

            PopFallback();
            if (result == null || result.Count == 0)
            {
                Logger.Log(LogLevel.Warn, "Atlas", $"Requested atlas subtextures but none were found: {key}");
                MTexture fallback = GetFallback();
                if (fallback != null)
                {
                    return new List <MTexture>()
                           {
                               fallback
                           }
                }
                ;
            }
            return(result);
        }
Exemple #6
0
        /// <summary>
        /// Feed the given ModAsset into the atlas.
        /// </summary>
        public static void Ingest(this Atlas self, ModAsset asset)
        {
            // Crawl through all child assets.
            if (asset.Type == typeof(AssetTypeDirectory))
            {
                foreach (ModAsset child in asset.Children)
                {
                    self.Ingest(child);
                }
                return;
            }

            // Forcibly add the mod content to the atlas.
            if (asset.Type == typeof(Texture2D))
            {
                Logger.Log(LogLevel.Verbose, "Atlas.Ingest", $"{self.GetDataPath()} + {asset.PathVirtual}");

                string parentPath = self.GetDataPath();
                if (parentPath.StartsWith(Everest.Content.PathContentOrig))
                {
                    parentPath = parentPath.Substring(Everest.Content.PathContentOrig.Length + 1);
                }
                parentPath = parentPath.Replace('\\', '/');

                bool   lq   = false;
                string path = asset.PathVirtual;

                if (path.StartsWith(parentPath + "LQ/"))
                {
                    lq   = true;
                    path = path.Substring(parentPath.Length + 3);
                }
                else if (path.StartsWith(parentPath + "/"))
                {
                    path = path.Substring(parentPath.Length + 1);
                }
                else
                {
                    return;
                }

                VirtualTexture vtex = VirtualContentExt.CreateTexture(asset);
                MTexture       mtex;
                MTextureMeta   meta = asset.GetMeta <MTextureMeta>();
                if (meta != null)
                {
                    if (meta.Width == 0)
                    {
                        meta.Width = vtex.Width;
                    }
                    if (meta.Height == 0)
                    {
                        meta.Height = vtex.Height;
                    }
                }

                Dictionary <string, MTexture> textures = self.GetTextures();
                MTexture existing;
                if (textures.TryGetValue(path, out existing))
                {
                    if (lq && !CoreModule.Settings.LQAtlas)
                    {
                        return;
                    }

                    if (existing.Texture.GetMetadata() == asset)
                    {
                        return; // We're the currently active overlay.
                    }
                    if (meta != null)
                    {
                        // Apply width and height from existing meta.
                        existing.AddOverride(vtex, new Vector2(meta.X, meta.Y), meta.Width, meta.Height);
                    }
                    else
                    {
                        // Keep width and height from existing instance.
                        existing.AddOverride(vtex, existing.DrawOffset, existing.Width, existing.Height);
                    }

                    mtex = existing;
                }
                else
                {
                    if (meta != null)
                    {
                        // Apply width and height from existing meta.
                        mtex = new MTexture(vtex, new Vector2(meta.X, meta.Y), meta.Width, meta.Height);
                    }
                    else
                    {
                        // Apply width and height from replacement texture.
                        mtex = new MTexture(vtex);
                    }
                    mtex.SetAtlasPath(path);
                }

                VTextureToMTextureMap[vtex.Name] = mtex;
                self[path] = mtex;
                if (!self.Sources.Contains(vtex))
                {
                    self.Sources.Add(vtex);
                }
                return;
            }
        }
Exemple #7
0
        public void Ingest(ModAsset asset)
        {
            if (asset == null)
            {
                return;
            }

            // Crawl through all child assets.
            if (asset.Type == typeof(AssetTypeDirectory))
            {
                lock (asset.Children) {
                    foreach (ModAsset child in asset.Children)
                    {
                        Ingest(child);
                    }
                }
                return;
            }

            // Forcibly add the mod content to the atlas.
            if (asset.Type != typeof(Texture2D))
            {
                return;
            }

            string path = asset.PathVirtual;

            if (!path.StartsWith(RelativeDataPath))
            {
                return;
            }
            path = path.Substring(RelativeDataPath.Length);

            if (textures.TryGetValue(path, out MTexture mtex))
            {
                Logger.Log(LogLevel.Verbose, "Atlas.Ingest", $"{Path.GetFileName(DataPath)} + ({asset.Source?.Name ?? "???"}) {path}");
                mtex.SetOverride(asset);
                this[path] = mtex;
                return;
            }

            VirtualTexture vtex;

            try {
                vtex = VirtualContentExt.CreateTexture(asset);
            } catch {
                // The game is going to crash from this. Log the offending texture to make debugging easier.
                Logger.Log(LogLevel.Verbose, "Atlas.Ingest", $"Error while loading texture {path} ({asset.Source?.Name ?? "???"}) into atlas {Path.GetFileName(DataPath)}");
                throw;
            }
            MTextureMeta meta = asset.GetMeta <MTextureMeta>();

            if (meta != null)
            {
                // Apply width and height from meta.
                if (meta.Width == 0)
                {
                    meta.Width = vtex.Width;
                }
                if (meta.Height == 0)
                {
                    meta.Height = vtex.Height;
                }
                mtex = new MTexture(vtex, new Vector2(meta.X, meta.Y), meta.Width, meta.Height);
            }
            else
            {
                // Apply width and height from replacement texture.
                mtex = new MTexture(vtex);
            }
            mtex.AtlasPath = path;
            mtex.SetAtlas(this);
            mtex.SetOverride(asset);
            this[path] = mtex;
            Sources.Add(vtex);
        }
Exemple #8
0
        public static void Ingest(this Atlas self, AssetMetadata asset)
        {
            Logger.Log("Atlas.Ingest", $"{self.GetDataPath()} + {asset.PathRelative}");

            // Crawl through all child assets.
            if (asset.AssetType == typeof(AssetTypeDirectory))
            {
                foreach (AssetMetadata child in asset.Children)
                {
                    self.Ingest(child);
                }
                return;
            }

            // Forcibly add the mod content to the atlas.
            if (asset.AssetType == typeof(Texture2D))
            {
                string parentPath = self.GetDataPath();
                if (parentPath.StartsWith(Everest.Content.PathContentOrig))
                {
                    parentPath = parentPath.Substring(Everest.Content.PathContentOrig.Length + 1);
                }
                parentPath = parentPath.Replace('\\', '/');

                string path = asset.PathRelative;
                if (!path.StartsWith(parentPath))
                {
                    return;
                }
                path = path.Substring(parentPath.Length + 1);

                VirtualTexture replacementV = VirtualContentExt.CreateTexture(asset);
                MTexture       replacement;
                MTextureMeta   meta = asset.GetMeta <MTextureMeta>();

                Dictionary <string, MTexture> textures = self.GetTextures();
                MTexture existing;
                if (textures.TryGetValue(path, out existing))
                {
                    // We're the currently active overlay.
                    if (existing.Texture.GetMetadata() == asset)
                    {
                        return;
                    }

                    if (meta != null)
                    {
                        // Apply width and height from existing meta.
                        existing.AddOverlay(replacementV, new Vector2(meta.X, meta.Y), meta.Width, meta.Height);
                    }
                    else
                    {
                        // Keep width and height from existing instance.
                        existing.AddOverlay(replacementV, existing.DrawOffset, existing.Width, existing.Height);
                    }

                    replacement = existing;
                }
                else
                {
                    if (meta != null)
                    {
                        // Apply width and height from existing meta.
                        replacement = new MTexture(replacementV, new Vector2(meta.X, meta.Y), meta.Width, meta.Height);
                    }
                    else
                    {
                        // Apply width and height from replacement texture.
                        replacement = new MTexture(replacementV);
                    }
                    // TODO: What's with the AtlasPath? Seems to stem from an atlas metadata property...
                }

                self[path] = replacement;
                return;
            }
        }
Exemple #9
0
        /// <summary>
        /// Feed the given ModAsset into the atlas.
        /// </summary>
        public static void Ingest(this Atlas atlas, ModAsset asset)
        {
            if (asset == null)
            {
                return;
            }

            // Crawl through all child assets.
            if (asset.Type == typeof(AssetTypeDirectory))
            {
                lock (asset.Children) {
                    foreach (ModAsset child in asset.Children)
                    {
                        atlas.Ingest(child);
                    }
                }
                return;
            }

            // Forcibly add the mod content to the atlas.
            if (asset.Type != typeof(Texture2D))
            {
                return;
            }

            string parentPath = atlas.GetDataPath();

            if (parentPath.StartsWith(Everest.Content.PathContentOrig))
            {
                parentPath = parentPath.Substring(Everest.Content.PathContentOrig.Length + 1);
            }
            parentPath = parentPath.Replace('\\', '/');

            string path = asset.PathVirtual;

            if (!path.StartsWith(parentPath + "/"))
            {
                return;
            }
            path = path.Substring(parentPath.Length + 1);

            Logger.Log(LogLevel.Verbose, "Atlas.Ingest", $"{Path.GetFileName(atlas.GetDataPath())} + ({asset.Source?.Name ?? "???"}) {path}");

            MTexture mtex;

            Dictionary <string, MTexture> textures = atlas.GetTextures();

            if (textures.TryGetValue(path, out mtex))
            {
                mtex.SetOverride(asset);
            }
            else
            {
                VirtualTexture vtex = VirtualContentExt.CreateTexture(asset);
                MTextureMeta   meta = asset.GetMeta <MTextureMeta>();
                if (meta != null)
                {
                    // Apply width and height from meta.
                    if (meta.Width == 0)
                    {
                        meta.Width = vtex.Width;
                    }
                    if (meta.Height == 0)
                    {
                        meta.Height = vtex.Height;
                    }
                    mtex = new MTexture(vtex, new Vector2(meta.X, meta.Y), meta.Width, meta.Height);
                }
                else
                {
                    // Apply width and height from replacement texture.
                    mtex = new MTexture(vtex);
                }
                mtex.AtlasPath = path;
                mtex.SetAtlas(atlas);
                mtex.SetOverride(asset);
            }

            atlas.ResetCaches();
            atlas[path] = mtex;
        }