예제 #1
0
        public Image ReadImage(WorkspacePath src, string maskHex = "#ff00ff")
        {
//            throw new NotImplementedException();

            PNGReader reader = null;

            using (var memoryStream = new MemoryStream())
            {
                using (var fileStream = workspace.OpenFile(src, FileAccess.Read))
                {
                    fileStream.CopyTo(memoryStream);
                    fileStream.Close();
                }

                reader = new PNGReader(memoryStream.ToArray(), maskHex);
            }

            var imageParser = new ImageParser(reader, maskHex);

            imageParser.CalculateSteps();

            while (imageParser.completed == false)
            {
                imageParser.NextStep();
            }

            // TODO need to convert the image data to colors and pixel data

            // TODO need to finish this parser
            return(new Image(reader.width, reader.height, new[] { "ff00ff" }));
        }
예제 #2
0
        private AbstractParser LoadColorMap(Dictionary <string, byte[]> files)
        {
            var fileName = "color-map.png";

            if (files.ContainsKey(fileName))
            {
//                UnityEngine.Debug.Log("Create color map");

//                var tex = ReadTexture(files[fileName]);

                // Create new color map chip
                var colorMapChip = new ColorChip();

                // Add the chip to the engine
                targetEngine.chipManager.ActivateChip(ColorMapParser.chipName, colorMapChip, false);

//                targetEngine.colorMapChip = colorMapChip;

                var imageParser = new PNGReader(files[fileName], targetEngine.colorChip.maskColor);

                // Pass the chip to the new parser
                return(new ColorMapParser(imageParser, colorMapChip, maskColor));
            }

            return(null);
        }
예제 #3
0
        private AbstractParser LoadSprites(Dictionary <string, byte[]> files)
        {
            // TODO need to tell if the cache should be ignore, important when in tools
            var srcFile = "sprites.png";

            // TODO this in here to support legacy games but can be removed in future releases
            var cacheFile = "sprites.cache.png";

            string fileName = null;

            if (files.ContainsKey(cacheFile))
            {
                fileName = cacheFile;
            }
            else if (files.ContainsKey(srcFile))
            {
                fileName = srcFile;
            }

            if (fileName != null)
            {
//                var tex = ReadTexture(files[fileName]);
                var imageParser = new PNGReader(files[fileName], targetEngine.colorChip.maskColor);

                return(new SpriteParser(imageParser, targetEngine));
            }

            return(null);
        }
예제 #4
0
//        protected void LoadFlagColors(Dictionary<string, byte[]> files)
//        {
//            // First thing we do is check for any custom tilemap flag colors
//            byte[] flagTex = null;
//            var flags = "flags.png";
//
//            if (files.ContainsKey(flags)) flagTex = files[flags];
//
//            var imageParser = new PNGReader(flagTex, targetEngine.colorChip.maskColor);
//
//
//            // This will also create the custom flag color chip we need for parsing the tilemap later on
//            AddParser(new FlagColorParser(imageParser, targetEngine));
//        }

        protected void LoadTilemap(Dictionary <string, byte[]> files)
        {
            var tilemapFile     = "tilemap.png";
            var tilemapJsonFile = "tilemap.json";

//            var colorOffsetFile = "tile-color-offsets.json";

            // TODO should this be manually called?
            // Make sure we have the flag color chip
//            LoadFlagColors(files);

//            var tilemapExists = false;

            // If a tilemap json file exists, try to load that
            if (files.ContainsKey(tilemapJsonFile))
            {
                var fileContents = Encoding.UTF8.GetString(files[tilemapJsonFile]);

                var jsonParser = new TilemapJsonParser(fileContents, targetEngine);

                AddParser(jsonParser);

//                tilemapExists = true;
            }
            else if (files.ContainsKey(tilemapFile))
            {
                // If a tilemap file exists, load that instead
//                var tex = ReadTexture(files[tilemapFile]);
                byte[] tileFlagTex = null;


//                var tileFlags = "tilemap-flags.png";
//
//
//                if (files.ContainsKey(tileFlags)) tileFlagTex = files[tileFlags];


                var imageParser = new PNGReader(files[tilemapFile], targetEngine.colorChip.maskColor);
                AddParser(new TilemapParser(imageParser, tileFlagTex, targetEngine));

//                var colorFile = "tile-color-offsets.json";
//
//                if (files.ContainsKey(colorFile))
//                {
//                    colorTex = ReadTexture(files[colorFile]);
//                }
//                tilemapExists = true;
            }

            // Always load the color offset parser
//            if (files.ContainsKey(colorOffsetFile) && tilemapExists)
//            {
//                var fileContents = Encoding.UTF8.GetString(files[colorOffsetFile]);
//
//                AddParser(new TileColorOffsetJson(fileContents, targetEngine));
//            }


//            return null;
        }
예제 #5
0
        private AbstractParser LoadFont(string fontName, byte[] data)
        {
//            var tex = ReadTexture(data);

            //var fontName = fileSystem.GetFileNameWithoutExtension(file);
            //fontName = fontName.Substring(0, fontName.Length - 5);

            var imageParser = new PNGReader(data, targetEngine.colorChip.maskColor);

            return(new FontParser(imageParser, targetEngine, fontName));
        }
예제 #6
0
//        private AbstractParser LoadColorPalette(Dictionary<string, byte[]> files)
//        {
//            var fileName = "color-palette.png";
//
//            if (files.ContainsKey(fileName))
//            {
//
////                UnityEngine.Debug.Log("Create color map");
//
////                var tex = ReadTexture(files[fileName]);
//
//                // Create new color map chip
//                var colorMapChip = new ColorChip();
//
//                // Add the chip to the engine
//                targetEngine.chipManager.ActivateChip(ColorPaletteParser.chipName, colorMapChip, false);
//
////                targetEngine.colorMapChip = colorMapChip;
//
//                var imageParser = new PNGReader(files[fileName], targetEngine.colorChip.maskColor);
//
//
//                // Pass the chip to the new parser
//                return new ColorPaletteParser(imageParser, colorMapChip, maskColor);
//            }
//
//            return null;
//        }

//        private AbstractParser LoadSystemColors(Dictionary<string, byte[]> files)
//        {
//            var fileName = "system-colors.png";
//
//            if (files.ContainsKey(fileName))
//            {
//
////                UnityEngine.Debug.Log("Create color map");
//
////                var tex = ReadTexture(files[fileName]);
//
//                // Create new color map chip
////                var systemColorChip = new ColorChip();
////
////                // Add the chip to the engine
////                targetEngine.chipManager.ActivateChip("PixelVisionSDK.Chips.SystemColorChip", systemColorChip, false);
////
////                targetEngine.colorMapChip = colorMapChip;
//
//                var imageParser = new PNGReader(files[fileName], targetEngine.colorChip.maskColor);
//
//
//                // Pass the chip to the new parser
//                return new SupportedColorParser(imageParser, targetEngine.colorChip, maskColor);
//            }
//
//            return null;
//        }

        private AbstractParser LoadColors(Dictionary <string, byte[]> files)
        {
            var fileName = "colors.png";

            if (files.ContainsKey(fileName))
            {
//                var tex = ReadTexture(files[fileName]);
                var imageParser = new PNGReader(files[fileName], targetEngine.colorChip.maskColor);

                return(new ColorParser(imageParser, targetEngine.colorChip, maskColor, targetEngine.colorChip.unique));
            }

            return(null);
        }
예제 #7
0
        private void LoadFlagColors(Dictionary <string, byte[]> files)
        {
            // First thing we do is check for any custom tilemap flag colors
            byte[] flagTex = null;
            var    flags   = "flags.png";

            if (files.ContainsKey(flags))
            {
                flagTex = files[flags];
            }

            var imageParser = new PNGReader(flagTex, targetEngine.colorChip.maskColor);


            // This will also create the custom flag color chip we need for parsing the tilemap later on
            AddParser(new FlagColorParser(imageParser, targetEngine));
        }
예제 #8
0
        public Image ReadImage(WorkspacePath src, string maskHex = "#ff00ff", string[] colorRefs = null)
        {
            PNGReader reader = null;

            using (var memoryStream = new MemoryStream())
            {
                using (var fileStream = workspace.OpenFile(src, FileAccess.Read))
                {
                    fileStream.CopyTo(memoryStream);
                    fileStream.Close();
                }

                reader = new PNGReader(memoryStream.ToArray(), maskHex);
            }

            var tmpColorChip = new ColorChip();



            var imageParser = new SpriteImageParser(reader, tmpColorChip);

            // Manually call each step
            imageParser.ParseImageData();

            // If no colors are passed in, used the image's palette
            if (colorRefs == null)
            {
                colorRefs = reader.colorPalette.Select(c => ColorUtils.RgbToHex(c.R, c.G, c.B)).ToArray();
            }

            // Resize the color chip
            tmpColorChip.total = colorRefs.Length;

            // Add the colors
            for (int i = 0; i < colorRefs.Length; i++)
            {
                tmpColorChip.UpdateColorAt(i, colorRefs[i]);
            }

            // Parse the image with the new colors
            imageParser.CreateImage();

            // Return the new image from the parser
            return(imageParser.image);
        }