public static void ExportAtlasSafe(String outputDirectory, UIAtlas atlas) { try { if (Directory.Exists(outputDirectory)) { Log.Warning("[GraphicResourceExporter] Export was skipped bacause a directory already exists: [{0}].", outputDirectory); return; } String outputPath = outputDirectory + ".png"; if (File.Exists(outputPath)) { Log.Warning("[GraphicResourceExporter] Export was skipped bacause a file already exists: [{0}].", outputPath); return; } Directory.CreateDirectory(outputDirectory); Texture2D texture = TextureHelper.CopyAsReadable(atlas.texture); TextureHelper.WriteTextureToFile(texture, outputPath); foreach (UISpriteData sprite in atlas.spriteList) { Texture2D fragment = TextureHelper.GetFragment(texture, sprite.x, texture.height - sprite.y - sprite.height, sprite.width, sprite.height); TextureHelper.WriteTextureToFile(fragment, Path.Combine(outputDirectory, sprite.name + ".png")); } } catch (Exception ex) { Log.Error(ex, "[GraphicResourceExporter] Failed to export atlas [{0}].", atlas.name); } }
private static void ExportMapSafe(String mapName) { try { String relativePath = FieldMap.GetMapResourcePath(mapName); String outputDirectory = Path.Combine(Configuration.Export.Path, relativePath); if (Directory.Exists(outputDirectory)) { Log.Warning($"[FieldSceneExporter] Export was skipped bacause a directory already exists: [{outputDirectory}]."); //return; } Log.Message("[FieldSceneExporter] Exporting [{0}]...", mapName); BGSCENE_DEF scene = new BGSCENE_DEF(true); scene.LoadEBG(null, relativePath, mapName); //String directoryPath = Path.GetDirectoryName(outputPath); Directory.CreateDirectory(outputDirectory); Texture2D atlasTexture = TextureHelper.CopyAsReadable(scene.atlas); Int32 factor = (Int32)scene.SPRITE_W / 16; Int32 textureWidth = (Int32)(scene.overlayList.SelectMany(s => s.spriteList).Max(s => s.offY * factor) + scene.SPRITE_H); Int32 textureHeight = (Int32)(scene.overlayList.SelectMany(s => s.spriteList).Max(s => s.offX * factor) + scene.SPRITE_W); using (Stream output = File.Create(outputDirectory + "test.psd")) { PsdFile file = new PsdFile(); file.BitDepth = 8; file.ChannelCount = 4; file.ColorMode = PsdColorMode.Rgb; file.RowCount = textureWidth; file.ColumnCount = textureHeight; file.Resolution = new ResolutionInfo { Name = "ResolutionInfo ", HDpi = new UFixed1616(72, 0), HResDisplayUnit = ResolutionInfo.ResUnit.PxPerInch, HeightDisplayUnit = ResolutionInfo.Unit.Centimeters, VDpi = new UFixed1616(72, 0), VResDisplayUnit = ResolutionInfo.ResUnit.PxPerInch, WidthDisplayUnit = ResolutionInfo.Unit.Centimeters }; file.BaseLayer.Name = "Base"; for (Int16 i = 0; i < 4; i++) { Channel channel = new Channel(i, file.BaseLayer); channel.ImageCompression = file.ImageCompression; channel.Length = file.RowCount * Util.BytesPerRow(file.BaseLayer.Rect.Size, file.BitDepth); channel.ImageData = new Byte[channel.Length]; file.BaseLayer.Channels.Add(channel); } file.BaseLayer.Channels.Last().ID = -1; for (Int32 index = scene.overlayList.Count - 1; index >= 0; index--) //scene.overlayList.Count { BGOVERLAY_DEF overlay = scene.overlayList[index]; String outputPath = outputDirectory + $"Overlay{index}.png"; ExportOverlay(overlay, atlasTexture, outputPath, scene, file); //return; } file.Save(output, Encoding.UTF8); } string strings = $"[PsdSection]\nLayerOrder=name\nReversed = 0"; System.IO.StreamWriter sw = new System.IO.StreamWriter(Path.Combine(outputDirectory, "psd.meta")); sw.WriteLine(strings); sw.Close(); TextureHelper.WriteTextureToFile(TextureHelper.CopyAsReadable(scene.atlas), Path.Combine(outputDirectory, "atlas.png")); Log.Message("[FieldSceneExporter] Exporting completed successfully."); } catch (Exception ex) { Log.Error(ex, "[FieldSceneExporter] Failed to export map [{0}].", mapName); } }