예제 #1
0
        private static void InitializeLayers()
        {
            if (LayersInitialized)
            {
                return;
            }
            LayersInitialized = true;

            LayerTypes = FileUtils.LoadJsonListFromMultipleSources <LayerType>("Entities/Dwarf/Layers/layer-types.json", null, p => p.Name);
            Layers     = new List <Layer>();

            foreach (var file in AssetManager.EnumerateAllFiles("Entities/Dwarf/Layers").Where(filename => System.IO.Path.GetExtension(filename) == ".psd" && filename.Contains("layer")))
            {
                foreach (var sheet in TextureTool.LoadPSD(System.IO.File.OpenRead(file)))
                {
                    var tags = sheet.LayerName.Split(' ');
                    if (tags.Length < 2)
                    {
                        continue;
                    }

                    var l = new Layer()
                    {
                        CachedTexture = TextureTool.DecomposeTexture(sheet.Data, BasePalette.CachedPalette),
                        Type          = tags[0]
                    };

                    l.Names.AddRange(tags.Skip(1));
                    Layers.Add(l);
                }
            }
        }
예제 #2
0
        private static void Initialize()
        {
            if (Layers != null && Palettes != null)
            {
                return;
            }

            Layers = FileUtils.LoadJsonListFromMultipleSources <Layer>(ContentPaths.dwarf_layers, null, l => l.Type + "&" + l.Asset);

            foreach (var layer in Layers)
            {
                var rawTexture = AssetManager.GetContentTexture(layer.Asset);
                var memTexture = TextureTool.MemoryTextureFromTexture2D(rawTexture);
                if (memTexture == null)
                {
                    continue;
                }
                layer.CachedTexture = TextureTool.DecomposeTexture(memTexture, BaseDwarfPalette.CachedPalette);
            }

            Palettes = FileUtils.LoadJsonListFromMultipleSources <Palette>(ContentPaths.dwarf_palettes, null, l => l.Asset);

            foreach (var palette in Palettes)
            {
                var rawTexture = AssetManager.GetContentTexture(palette.Asset);
                palette.CachedPalette = TextureTool.RawPaletteFromTexture2D(rawTexture);
            }
        }
예제 #3
0
        public static void ConvertTestPSD()
        {
            var stream = System.IO.File.OpenRead("Content/Entities/Dwarf/Layers/test.psd");
            var psd    = new PhotoshopFile.PsdFile(stream, new PhotoshopFile.LoadContext());

            if (FindPalette("Hair 02").HasValue(out var conversionPalette))
            {
                foreach (var layer in psd.Layers)
                {
                    var channels = new List <PhotoshopFile.Channel>();
                    channels.Add(layer.Channels.Where(c => c.ID == 0).FirstOrDefault());
                    channels.Add(layer.Channels.Where(c => c.ID == 1).FirstOrDefault());
                    channels.Add(layer.Channels.Where(c => c.ID == 2).FirstOrDefault());
                    channels.Add(layer.AlphaChannel);

                    var rawMemText = new MemoryTexture(layer.Rect.Width, layer.Rect.Height);

                    for (var index = 0; index < layer.Rect.Width * layer.Rect.Height; ++index)
                    {
                        if (channels[3].ImageData[index] == 0)
                        {
                            rawMemText.Data[index] = new Color(0, 0, 0, 0);
                        }
                        else
                        {
                            rawMemText.Data[index] = new Color(channels[0].ImageData[index], channels[1].ImageData[index], channels[2].ImageData[index], channels[3].ImageData[index]);
                        }
                    }

                    var memTex = new MemoryTexture(psd.ColumnCount, psd.RowCount);
                    TextureTool.Blit(rawMemText, new Rectangle(0, 0, layer.Rect.Width, layer.Rect.Height), memTex, new Point(layer.Rect.X, layer.Rect.Y));

                    var decomposed = TextureTool.DecomposeTexture(memTex, conversionPalette.CachedPalette);
                    var composed   = TextureTool.ComposeTexture(decomposed, BasePalette.CachedPalette);

                    TextureTool.Blit(composed, new Rectangle(layer.Rect.X, layer.Rect.Y, layer.Rect.Width, layer.Rect.Height), rawMemText, new Rectangle(0, 0, rawMemText.Width, rawMemText.Height));

                    for (var index = 0; index < rawMemText.Width * rawMemText.Height; ++index)
                    {
                        channels[0].ImageData[index] = rawMemText.Data[index].R;
                        channels[1].ImageData[index] = rawMemText.Data[index].G;
                        channels[2].ImageData[index] = rawMemText.Data[index].B;
                        channels[3].ImageData[index] = rawMemText.Data[index].A;
                    }

                    foreach (var channel in layer.Channels)
                    {
                        channel.ImageDataRaw = null;
                    }
                }
            }

            psd.PrepareSave();
            psd.Save("processed.psd", Encoding.Unicode);
        }