/// <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; } }
public static void Ingest(this Atlas self, AssetMetadata asset) { // 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; } }
/// <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; }