Esempio n. 1
0
    static public PalettizedImage LoadBMP(string _path, PalettizedImageConfig _config)
    {
        string filename = System.IO.Path.GetFileNameWithoutExtension(_path);

        byte[] imageFile = System.IO.File.ReadAllBytes(_path);
        //Debug.Log("Image header from file '"+filename+"': " + imageFile[ 0 ] + "," + imageFile[ 1 ] + "," + imageFile[ 2 ]);
        int pixelsOffset     = ReadInt(imageFile, 0x0a);
        int width            = ReadInt(imageFile, 0x12);
        int height           = ReadInt(imageFile, 0x16);
        int bpp              = ReadWord(imageFile, 0x1c);
        int coloursInPalette = ReadWord(imageFile, 0x2e);

        //Debug.Log ("width=" + width + ", height=" + height + ", bpp=" + bpp + " (pixels start=" + pixelsOffset + ") Colours in palette=" + coloursInPalette );

        if (coloursInPalette == 0)
        {
            coloursInPalette = 256;
        }
        PalettizedImage image = new PalettizedImage(width, height, coloursInPalette);

        image.SetConfig(_config);
        image.m_fileName = filename;
        if (image.ReadPalette(imageFile, 0x36) == false)
        {
            return(null);
        }

        if (image.ReadImage(imageFile, pixelsOffset, bpp) == false)
        {
            return(null);
        }

        return(image);
    }
Esempio n. 2
0
    bmp2tile()
    {
        m_project = null;
        if( PlayerPrefs.HasKey( PPKEY_PROJECT_PATH ))
        {
            LoadProject( PlayerPrefs.GetString( PPKEY_PROJECT_PATH ));
            //m_project = new Project( PlayerPrefs.GetString( PPKEY_PROJECT_PATH ));
        }

        if( PlayerPrefs.HasKey( PPKEY_LAST_OPEN_DIRECTORY ))
            m_lastOpenDirectory = PlayerPrefs.GetString( PPKEY_LAST_OPEN_DIRECTORY );
        else
            m_lastOpenDirectory = Application.dataPath;

        if( PlayerPrefs.HasKey( PPKEY_LAST_EXPORT_DIRECTORY ))
            m_lastExportDirectory = PlayerPrefs.GetString( PPKEY_LAST_EXPORT_DIRECTORY );
        else
            m_lastExportDirectory = Application.dataPath;

        m_imageTexture = null;
        m_currentImageData = null;
        m_currentImageConfig = null;
        m_tileBank = null;
        m_tileMap = null;

        m_haveLoadedImage = false;

        m_collisionAlpha = 0.5f;

        m_isResizingTileBank = false;
        m_isResizingPaletteRemap = false;
        m_isResizingImageSettings = false;
        m_isResizingProject = false;
        m_isResizingMapWindow = false;
    }
    public static PalettizedImage LoadBMP( string _path, PalettizedImageConfig _config )
    {
        string filename = System.IO.Path.GetFileNameWithoutExtension( _path );

        byte[] imageFile = System.IO.File.ReadAllBytes( _path );
        //Debug.Log("Image header from file '"+filename+"': " + imageFile[ 0 ] + "," + imageFile[ 1 ] + "," + imageFile[ 2 ]);
        int pixelsOffset = ReadInt( imageFile, 0x0a );
        int width = ReadInt( imageFile, 0x12 );
        int height = ReadInt( imageFile, 0x16 );
        int bpp = ReadWord ( imageFile, 0x1c );
        int coloursInPalette = ReadWord ( imageFile, 0x2e );
        //Debug.Log ("width=" + width + ", height=" + height + ", bpp=" + bpp + " (pixels start=" + pixelsOffset + ") Colours in palette=" + coloursInPalette );

        if( coloursInPalette == 0 )
            coloursInPalette = 256;
        PalettizedImage image = new PalettizedImage( width, height, coloursInPalette );
        image.SetConfig( _config );
        image.m_fileName = filename;
        if( image.ReadPalette( imageFile, 0x36 ) == false )
            return null;

        if( image.ReadImage( imageFile, pixelsOffset, bpp ) == false )
            return null;

        return image;
    }
Esempio n. 4
0
    public TileMap(TileBank _bank, PalettizedImage _sourceImage)
    {
        //
        m_tileBank = _bank;

        //
        int w = _sourceImage.m_width;
        int h = _sourceImage.m_height;

        m_width  = 64;       //(_sourceImage.m_width+7) >> 3;
        m_height = 32;       //(_sourceImage.m_height+7) >> 3;
        int sourceWidth  = w >> 3;
        int sourceHeight = h >> 3;

        //
        m_tiles    = new TileInstance[m_width, m_height];
        m_rawTiles = null;

        //
        int x, y;

        for (y = 0; y < sourceHeight; y++)
        {
            string str = y.ToString() + "=(";
            for (x = 0; x < sourceWidth; x++)
            {
                int pixel_x = x * Tile.Width;
                int pixel_y = y * Tile.Height;

                Tile         srcTile      = new Tile(_sourceImage, pixel_x, pixel_y);
                TileInstance tileInstance = m_tileBank.GetTileInstance(srcTile);
                if (tileInstance == null)
                {
                    Debug.LogException(new UnityException("PANIC! Couldn't find tile instance for tile at coordinates " + pixel_x + "," + pixel_y));
                    return;
                }

                //
                m_tiles[x, y] = tileInstance;
                str          += tileInstance.m_tileBankIndex;
                if (tileInstance.m_flipX)
                {
                    str += "x";
                }
                if (tileInstance.m_flipY)
                {
                    str += "y";
                }
                if (x < sourceWidth - 1)
                {
                    str += ",";
                }
            }

            str += ")";
            //Debug.Log( str );
        }
    }
Esempio n. 5
0
    static public TileMap LoadJson(string _fileName)
    {
        string jsonString = System.IO.File.ReadAllText(_fileName);
        Dictionary <string, object> json = (Dictionary <string, object>)MiniJSON.Json.Deserialize(jsonString);

        // Load tile bank
        List <object> tilesetsJson = (List <object>)json["tilesets"];
        Dictionary <string, object> tilesetJson = (Dictionary <string, object>)tilesetsJson[0];
        string imageFileName = (string)tilesetJson["image"];
        string imageFullPath = System.IO.Path.GetDirectoryName(_fileName) + System.IO.Path.DirectorySeparatorChar + imageFileName;
        //LoadBMP( imageFullPath );

        PalettizedImageConfig imageConfig = new PalettizedImageConfig(imageFullPath + ".config");

        PalettizedImage imageData = PalettizedImage.LoadImage(imageFullPath, imageConfig);
        TileBank        tileBank  = null;

        if (imageData != null)
        {
            //
            imageConfig.SetImage(imageData);

            bool optimizeBank = (imageConfig.m_importAsSprite == false);                // Optimize bank when we're not loading the image as a sprite (i.e. optimize when we're loading as a tile bank)
            tileBank = new TileBank(imageData, optimizeBank);
        }

        // Create map texture
        int map_tiles_w  = ((int)(long)json["width"]);
        int map_tiles_h  = ((int)(long)json["height"]);
        int map_pixels_w = map_tiles_w * 8;
        int map_pixels_h = map_tiles_h * 8;

        TileMap ret = new TileMap(map_tiles_w, map_tiles_h);

        // Find each layer
        List <object> layersJson = (List <object>)json["layers"];
        Dictionary <string, object> layerJson = (Dictionary <string, object>)layersJson[0];
        List <object> layerData = (List <object>)layerJson["data"];
        int           tile_x, tile_y;

        for (tile_y = 0; tile_y < map_tiles_h; tile_y++)
        {
            for (tile_x = 0; tile_x < map_tiles_w; tile_x++)
            {
                int i       = tile_y * map_tiles_w + tile_x;
                int tile_id = (int)(long)layerData[i];
                tile_id--;
                TileInstance tileInstance = tileBank.m_allTileInstances[tile_id];

                //
                ret.SetRawTile(tile_x, tile_y, tile_id);
                ret.SetTile(tile_x, tile_y, tileInstance);
            }
        }

        return(ret);
    }
Esempio n. 6
0
    public PlanarImage(PalettizedImage _palettizedImage)
    {
        m_width  = _palettizedImage.m_width;
        m_height = _palettizedImage.m_height;

        SanityChecks(_palettizedImage);

        //m_planarData = ChunkyToPlanarImageInterleaved (_palettizedImage.m_image);
        m_planarData = ChunkyToPlanarTilesInterleaved(_palettizedImage.m_image);
    }
Esempio n. 7
0
    public PlanarImage( PalettizedImage _palettizedImage )
    {
        m_width = _palettizedImage.m_width;
        m_height = _palettizedImage.m_height;

        SanityChecks (_palettizedImage);

        //m_planarData = ChunkyToPlanarImageInterleaved (_palettizedImage.m_image);
        m_planarData = ChunkyToPlanarTilesInterleaved (_palettizedImage.m_image);
    }
Esempio n. 8
0
    public AmigaSprite( PalettizedImage _palettizedImage, PalettizedImageConfig _imageConfig )
    {
        m_imageWidth = _palettizedImage.m_width;
        m_imageHeight = _palettizedImage.m_height;
        m_numberOfFrames = _imageConfig.GetNumFrames ();
        m_spriteWidth = m_imageWidth / m_numberOfFrames;

        SanityChecks (_palettizedImage, _imageConfig);

        m_spriteData = ChunkyToPlanarSpriteFrames (_palettizedImage.m_image);
    }
Esempio n. 9
0
    public AmigaSprite(PalettizedImage _palettizedImage, PalettizedImageConfig _imageConfig)
    {
        m_imageWidth     = _palettizedImage.m_width;
        m_imageHeight    = _palettizedImage.m_height;
        m_numberOfFrames = _imageConfig.GetNumFrames();
        m_spriteWidth    = m_imageWidth / m_numberOfFrames;

        SanityChecks(_palettizedImage, _imageConfig);

        m_spriteData = ChunkyToPlanarSpriteFrames(_palettizedImage.m_image);
    }
Esempio n. 10
0
    public TilePalette( PalettizedImage _sourceImage )
    {
        m_colors = new Color[ 16 ];

        int iCol;
        for( iCol=0; iCol<16; iCol++ )
        {
            Color c = _sourceImage.m_palette[ iCol ];
            Color qc = Quantize( c );
            m_colors[ iCol ] = qc;
        }
    }
Esempio n. 11
0
    public TilePalette(PalettizedImage _sourceImage)
    {
        m_colors = new Color[16];

        int iCol;

        for (iCol = 0; iCol < 16; iCol++)
        {
            Color c  = _sourceImage.m_palette[iCol];
            Color qc = Quantize(c);
            m_colors[iCol] = qc;
        }
    }
Esempio n. 12
0
    public TileMap( TileBank _bank, PalettizedImage _sourceImage )
    {
        //
        m_tileBank = _bank;

        //
        int w = _sourceImage.m_width;
        int h = _sourceImage.m_height;
        m_width = 64;//(_sourceImage.m_width+7) >> 3;
        m_height = 32;//(_sourceImage.m_height+7) >> 3;
        int sourceWidth = w >> 3;
        int sourceHeight = h >> 3;

        //
        m_tiles = new TileInstance[ m_width, m_height ];
        m_rawTiles = null;

        //
        int x, y;
        for( y=0; y<sourceHeight; y++ )
        {
            string str = y.ToString() + "=(";
            for( x=0; x<sourceWidth; x++ )
            {
                int pixel_x = x*Tile.Width;
                int pixel_y = y*Tile.Height;

                Tile srcTile = new Tile( _sourceImage, pixel_x, pixel_y );
                TileInstance tileInstance = m_tileBank.GetTileInstance( srcTile );
                if( tileInstance == null )
                {
                    Debug.LogException( new UnityException( "PANIC! Couldn't find tile instance for tile at coordinates "+pixel_x+","+pixel_y ));
                    return;
                }

                //
                m_tiles[ x, y ] = tileInstance;
                str += tileInstance.m_tileBankIndex;
                if( tileInstance.m_flipX ) str += "x";
                if( tileInstance.m_flipY ) str += "y";
                if( x<sourceWidth-1 )
                    str += ",";
            }

            str += ")";
            //Debug.Log( str );
        }
    }
Esempio n. 13
0
    public Tile( PalettizedImage _sourceImage, int _startX, int _startY )
    {
        // Allocate space
        m_pixels = new byte[ Width*Height ];

        // Copy from source image
        int x, y;
        for( y=0; y<Height; y++ )
        {
            for( x=0; x<Width; x++ )
            {
                int src_i = ((_startY+y)*_sourceImage.m_width)+(_startX+x);
                int dst_i = y*Width+x;
                m_pixels[ dst_i ] = _sourceImage.m_image[ src_i ];
            }
        }
    }
Esempio n. 14
0
    void SanityChecks(PalettizedImage _palettizedImage, PalettizedImageConfig _imageConfig)
    {
        if (m_spriteWidth != 16) {
            Debug.LogException (new UnityException ("PANIC! Amiga A-Sprites (hw) must be 16 pixels wide! Did you specify number of frames correctly?"));
        }

        //		int numberOfColorsUsed = 0;
        //		for (int c = 0; c <  _palettizedImage.m_colorUsed.Count; c++) {
        //			if (_palettizedImage.m_colorUsed [c]) {
        //				numberOfColorsUsed = c;
        //			}
        //		}
        //		int maxNumberOfColors = (int)Math.Pow (m_numberOfBitPlanes, 2);
        //		if (numberOfColorsUsed > maxNumberOfColors) {
        //			Debug.LogException (new UnityException (String.Format ("PANIC! Trying to create PlanarImage with more colors than _numberOfBitplanes allows [{0} > {1}]!", numberOfColorsUsed, maxNumberOfColors)));
        //		}
    }
Esempio n. 15
0
    public Tile(PalettizedImage _sourceImage, int _startX, int _startY)
    {
        // Allocate space
        m_pixels = new byte[Width * Height];

        // Copy from source image
        int x, y;

        for (y = 0; y < Height; y++)
        {
            for (x = 0; x < Width; x++)
            {
                int src_i = ((_startY + y) * _sourceImage.m_width) + (_startX + x);
                int dst_i = y * Width + x;
                m_pixels[dst_i] = _sourceImage.m_image[src_i];
            }
        }
    }
Esempio n. 16
0
    void SanityChecks(PalettizedImage _palettizedImage)
    {
        if ((m_width % 8) != 0)
        {
            Debug.LogException(new UnityException("PANIC! PlanarImage can only handle images with: width % 8 == 0"));
        }

//		int numberOfColorsUsed = 0;
//		for (int c = 0; c <  _palettizedImage.m_colorUsed.Count; c++) {
//			if (_palettizedImage.m_colorUsed [c]) {
//				numberOfColorsUsed = c;
//			}
//		}
//		int maxNumberOfColors = (int)Math.Pow (4, 2);
//		if (numberOfColorsUsed > maxNumberOfColors) {
//			Debug.LogException (new UnityException (String.Format ("PANIC! Trying to create PlanarImage with more colors than _numberOfBitplanes allows [{0} > {1}]!", numberOfColorsUsed, maxNumberOfColors)));
//		}
    }
Esempio n. 17
0
    void SanityChecks(PalettizedImage _palettizedImage, PalettizedImageConfig _imageConfig)
    {
        if (m_spriteWidth != 16)
        {
            Debug.LogException(new UnityException("PANIC! Amiga A-Sprites (hw) must be 16 pixels wide! Did you specify number of frames correctly?"));
        }

//		int numberOfColorsUsed = 0;
//		for (int c = 0; c <  _palettizedImage.m_colorUsed.Count; c++) {
//			if (_palettizedImage.m_colorUsed [c]) {
//				numberOfColorsUsed = c;
//			}
//		}
//		int maxNumberOfColors = (int)Math.Pow (m_numberOfBitPlanes, 2);
//		if (numberOfColorsUsed > maxNumberOfColors) {
//			Debug.LogException (new UnityException (String.Format ("PANIC! Trying to create PlanarImage with more colors than _numberOfBitplanes allows [{0} > {1}]!", numberOfColorsUsed, maxNumberOfColors)));
//		}
    }
Esempio n. 18
0
    bmp2tile()
    {
        m_project = null;
        if (PlayerPrefs.HasKey(PPKEY_PROJECT_PATH))
        {
            LoadProject(PlayerPrefs.GetString(PPKEY_PROJECT_PATH));
            //m_project = new Project( PlayerPrefs.GetString( PPKEY_PROJECT_PATH ));
        }

        if (PlayerPrefs.HasKey(PPKEY_LAST_OPEN_DIRECTORY))
        {
            m_lastOpenDirectory = PlayerPrefs.GetString(PPKEY_LAST_OPEN_DIRECTORY);
        }
        else
        {
            m_lastOpenDirectory = Application.dataPath;
        }

        if (PlayerPrefs.HasKey(PPKEY_LAST_EXPORT_DIRECTORY))
        {
            m_lastExportDirectory = PlayerPrefs.GetString(PPKEY_LAST_EXPORT_DIRECTORY);
        }
        else
        {
            m_lastExportDirectory = Application.dataPath;
        }

        m_imageTexture       = null;
        m_currentImageData   = null;
        m_currentImageConfig = null;
        m_tileBank           = null;
        m_tileMap            = null;

        m_haveLoadedImage = false;

        m_collisionAlpha = 0.5f;

        m_isResizingTileBank      = false;
        m_isResizingPaletteRemap  = false;
        m_isResizingImageSettings = false;
        m_isResizingProject       = false;
        m_isResizingMapWindow     = false;
    }
Esempio n. 19
0
    static public PalettizedImage LoadPNG(string _path, PalettizedImageConfig _config)
    {
        PngReader pngr = FileHelper.CreatePngReader(_path);

        if (!pngr.ImgInfo.Indexed)
        {
            Debug.LogException(new UnityException("Image wasn't indexed"));
            return(null);
        }

        PngChunkPLTE palette = pngr.GetMetadata().GetPLTE();

        PalettizedImage image = new PalettizedImage(pngr.ImgInfo.Cols, pngr.ImgInfo.Rows, palette.GetNentries());

        image.SetConfig(_config);
        image.m_fileName = System.IO.Path.GetFileNameWithoutExtension(_path);

        image.ReadPalette(palette);
        image.ReadImage(pngr);

        return(image);
    }
Esempio n. 20
0
    public void Export(string _directory, bool _dryRun = false)
    {
        m_allFiles            = new List <string>();
        m_lastExportDirectory = _directory;

        //
        // Build data.asm and files.asm content
        //
        string asmData     = "";
        string asmFileList = "";
        string asmFileMap  = "FileIDMap:\n";

        //
        // Export all images
        //
        foreach (string imageFile in m_imageFiles)
        {
            if (_dryRun == false)
            {
                Debug.Log("Exporting file '" + imageFile + "'");
            }

            string outFileNameNoExt = GetOutFileNameNoExt(imageFile);
            //string outBaseName = GetOutBaseName( imageFile );

            //
            PalettizedImageConfig imageConfig = new PalettizedImageConfig(imageFile + ".config");
            PalettizedImage       imageData   = PalettizedImage.LoadImage(imageFile, imageConfig);
            if (imageData == null)
            {
                FullColorImage.LoadImage(imageFile, imageConfig);
            }

            //
            if (imageData != null)
            {
                // Export it
                if (imageConfig.m_importAsSprite)
                {
                    string alternativeAmigaSpriteName;
                    if (imageConfig.m_importAsBSprite)
                    {
                        alternativeAmigaSpriteName = "_sprite_bank_amiga_b_hw.bin";
                    }
                    else
                    {
                        alternativeAmigaSpriteName = "_sprite_bank_amiga_a_bob.bin";
                    }

                    AddFile(ref asmData, ref asmFileList, ref asmFileMap, GetSpriteTileName(outFileNameNoExt), outFileNameNoExt + alternativeAmigaSpriteName);
                    AddFile(ref asmData, ref asmFileList, ref asmFileMap, GetPaletteName(outFileNameNoExt));
                    AddFile(ref asmData, ref asmFileList, ref asmFileMap, GetSpriteName(outFileNameNoExt));
                }
                else
                {
                    AddFile(ref asmData, ref asmFileList, ref asmFileMap, GetTileBankName(outFileNameNoExt), outFileNameNoExt + "_bank_amiga.bin");
                    AddFile(ref asmData, ref asmFileList, ref asmFileMap, GetTileMapName(outFileNameNoExt));
                    AddFile(ref asmData, ref asmFileList, ref asmFileMap, GetPaletteName(outFileNameNoExt));
                }
            }
        }

        //
        // Export all maps
        //
        foreach (string mapFile in m_mapFiles)
        {
            if (_dryRun == false)
            {
                Debug.Log("Exporting map '" + mapFile + "'");
            }

            string outFileNameNoExt = GetOutFileNameNoExt(mapFile);

            //
            AddFile(ref asmData, ref asmFileList, ref asmFileMap, GetTileMapName(outFileNameNoExt));
            AddFile(ref asmData, ref asmFileList, ref asmFileMap, GetCollisionMapName(outFileNameNoExt));
        }

        //
        // Export all game objects
        //
        foreach (string goFile in m_gameObjectCollectionFiles)
        {
            if (_dryRun == false)
            {
                Debug.Log("Exporting file '" + goFile + "'");
            }

            string outFileNameNoExt = GetOutFileNameNoExt(goFile);
            //string outBaseName = GetOutBaseName( imageFile );

            GameObjectCollection ggo = new GameObjectCollection(goFile);

            //
            AddFile(ref asmData, ref asmFileList, ref asmFileMap, GetGreatGameObjectName(outFileNameNoExt));
        }

        //
        // Generate assembly files that tie everything together
        //
        if (_dryRun == false)
        {
            System.IO.File.WriteAllText(m_lastExportDirectory + System.IO.Path.DirectorySeparatorChar + "data.asm", asmData);
            System.IO.File.WriteAllText(m_lastExportDirectory + System.IO.Path.DirectorySeparatorChar + "files.asm", asmFileList + "\n" + asmFileMap);
        }
    }
Esempio n. 21
0
    void LoadBMP( string _path )
    {
        m_openImageName = "<Untitled>";

        // Load corresponding config first as it have information on how the image should be loaded
        m_currentImageConfig = new PalettizedImageConfig( _path + ".config" );
        m_haveLoadedImage = true;

        m_currentImageData = PalettizedImage.LoadImage( _path, m_currentImageConfig );
        if( m_currentImageData != null )
        {
            //
            m_currentImageConfig.SetImage( m_currentImageData );

            //
            m_currentFramesString = m_currentImageConfig.GetNumFrames().ToString();
            m_currentFrameTimesString = new Dictionary<int, string>();
            int iFrame;
            for( iFrame=0; iFrame<m_currentImageConfig.GetNumFrames(); iFrame++ )
            {
                m_currentFrameTimesString[ iFrame ] = m_currentImageConfig.GetFrameTime( iFrame ).ToString();
            }

            //
            m_openImageName = System.IO.Path.GetFileNameWithoutExtension( _path );
            m_tileBankWindowRect = new Rect( m_projectWindowWidth + (m_windowPadding*2.0f), m_windowTop, m_currentImageData.m_width*2.0f+10.0f, m_currentImageData.m_height*2.0f+10.0f+15.0f );
            m_imageSettingsRect = new Rect( m_tileBankWindowRect.x + m_tileBankWindowRect.width + m_windowPadding, m_tileBankWindowRect.y, 200.0f, 200.0f );
            m_paletteRemapRect = new Rect( m_imageSettingsRect.x + m_imageSettingsRect.width + m_windowPadding, m_imageSettingsRect.y, 100.0f, 15.0f + (16.0f * 30.0f) );

            //
        //			m_planarImage = new PlanarImage( m_currentImageData);
            bool OptimizedTilebank = (m_currentImageConfig.m_importAsSprite == false); // If we import the image as a sprite we should not optimize the tile bank
            m_tileBank = new TileBank( m_currentImageData, OptimizedTilebank );
            m_tileMap = new TileMap( m_tileBank, m_currentImageData );
            m_tilePalette = new TilePalette( m_currentImageData );

            //
            int w, h;
            w = m_currentImageData.m_width;
            h = m_currentImageData.m_height;

            //
            m_imageTexture = new Texture2D( w, h, TextureFormat.ARGB32, false );
            m_imageTexture.filterMode = FilterMode.Point;

            //
            int x, y;
            for( y=0; y<h; y++ )
            {
                for( x=0; x<w; x++ )
                {
                    int ii = ((h-1-y)*w)+x;
                    int ic = m_currentImageData.m_image[ ii ];
                    Color col = m_currentImageData.m_palette[ ic ];
                    m_imageTexture.SetPixel( x, y, col );
                }
            }

            //
            m_imageTexture.Apply();
        }
    }
Esempio n. 22
0
    //
    // Optimized tile bank means to remove duplicates
    //
    public TileBank( PalettizedImage _image, bool _optimized )
    {
        //
        m_tiles = new List<Tile>();

        //
        int w = _image.m_width;
        int h = _image.m_height;
        int tiles_w = w >> 3;
        int tiles_h = h >> 3;

        //
        m_allTileInstances = new Dictionary<int, TileInstance>();

        //
        // Normally I write loops that iterate on Y first and then X, but sprites on Mega Drive should actually be
        // exported Y first then X, so if we do the Y in the inner loop that means the first two tiles are at 0,0
        // and 0,8, which means Y down. So instead of reordering anything at export time I reorder here instead.
        //
        // Oooh, I just realized this probably isn't true for sprite animation frames, so I probably still need to
        // do some clever iterations and stuff here. ARGH!
        //
        int x, y;
        for( x=0; x<tiles_w; x++ )
        {
            for( y=0; y<tiles_h; y++ )
            {
                int pixel_x = x*Tile.Width;
                int pixel_y = y*Tile.Height;

                Tile newTile = new Tile( _image, pixel_x, pixel_y );

                if( _optimized )
                {
                    TileInstance tileInstance = GetTileInstance( newTile );
                    if( tileInstance == null )
                    {
                        //Debug.Log ("Adding tile from coordinates "+pixel_x+","+pixel_y );
                        AddTile( newTile );

                        // Get the newly created instance
                        tileInstance = GetTileInstance( newTile );
                    } else
                    {
                        //Debug.Log ("Ignoring tile from coordinates "+pixel_x+","+pixel_y );
                    }
                    int i = (y*tiles_w) + x;
                    m_allTileInstances[ i ] = tileInstance;
                } else
                {
                    // If we're not building an optimized tile bank we always export all tiles
                    AddTile( newTile );

                    // Get the newly created instance
                    TileInstance tileInstance = GetTileInstance( newTile );
                    int i = (y*tiles_w) + x;
                    m_allTileInstances[ i ] = tileInstance;
                }
            }
        }

        Debug.Log ("tile instances=" + m_allTileInstances.Count );
    }
Esempio n. 23
0
    //
    // Optimized tile bank means to remove duplicates
    //
    public TileBank(PalettizedImage _image, bool _optimized)
    {
        //
        m_tiles = new List <Tile>();

        //
        int w       = _image.m_width;
        int h       = _image.m_height;
        int tiles_w = w >> 3;
        int tiles_h = h >> 3;

        //
        m_allTileInstances = new Dictionary <int, TileInstance>();

        //
        // Normally I write loops that iterate on Y first and then X, but sprites on Mega Drive should actually be
        // exported Y first then X, so if we do the Y in the inner loop that means the first two tiles are at 0,0
        // and 0,8, which means Y down. So instead of reordering anything at export time I reorder here instead.
        //
        // Oooh, I just realized this probably isn't true for sprite animation frames, so I probably still need to
        // do some clever iterations and stuff here. ARGH!
        //
        int x, y;

        for (x = 0; x < tiles_w; x++)
        {
            for (y = 0; y < tiles_h; y++)
            {
                int pixel_x = x * Tile.Width;
                int pixel_y = y * Tile.Height;

                Tile newTile = new Tile(_image, pixel_x, pixel_y);

                if (_optimized)
                {
                    TileInstance tileInstance = GetTileInstance(newTile);
                    if (tileInstance == null)
                    {
                        //Debug.Log ("Adding tile from coordinates "+pixel_x+","+pixel_y );
                        AddTile(newTile);

                        // Get the newly created instance
                        tileInstance = GetTileInstance(newTile);
                    }
                    else
                    {
                        //Debug.Log ("Ignoring tile from coordinates "+pixel_x+","+pixel_y );
                    }
                    int i = (y * tiles_w) + x;
                    m_allTileInstances[i] = tileInstance;
                }
                else
                {
                    // If we're not building an optimized tile bank we always export all tiles
                    AddTile(newTile);

                    // Get the newly created instance
                    TileInstance tileInstance = GetTileInstance(newTile);
                    int          i            = (y * tiles_w) + x;
                    m_allTileInstances[i] = tileInstance;
                }
            }
        }

        Debug.Log("tile instances=" + m_allTileInstances.Count);
    }
Esempio n. 24
0
    //
    void ExportAll()
    {
        //
        string outFileName = EditorUtility.SaveFilePanel("Select folder to export to", m_lastExportDirectory, "filenameignored", "bin");

        //
        m_lastExportDirectory = System.IO.Path.GetDirectoryName(outFileName);
        SaveLastExportDirectory();

        m_project.Export(m_lastExportDirectory);

        //
        // Export all images
        //
        string[] imageFiles = m_project.m_imageFiles;
        foreach (string imageFile in imageFiles)
        {
            Debug.Log("Exporting file '" + imageFile + "'");

            string outFileNameNoExt = System.IO.Path.GetFileNameWithoutExtension(imageFile).ToLower();
            string outBaseName      = m_lastExportDirectory + System.IO.Path.DirectorySeparatorChar + outFileNameNoExt;

            //
            PalettizedImageConfig imageConfig = new PalettizedImageConfig(imageFile + ".config");
            PalettizedImage       imageData   = PalettizedImage.LoadImage(imageFile, imageConfig);

            //
            if (imageData != null)
            {
                //
                imageConfig.SetImage(imageData);

                // Convert to tile banks / planar images
//				PlanarImage planarImage = new PlanarImage( imageData);
                TileBank    tileBank    = new TileBank(imageData, (imageConfig.m_importAsSprite == false));
                TilePalette tilePalette = new TilePalette(imageData);

                // Export it
                if (imageConfig.m_importAsSprite)
                {
                    Sprite sprite = new Sprite(imageConfig);
                    string alternativeAmigaSpriteName;
                    if (imageConfig.m_importAsBSprite)
                    {
                        AmigaSprite amigaSprite = new AmigaSprite(imageData, imageConfig);
                        alternativeAmigaSpriteName = "_sprite_bank_amiga_b_hw.bin";
                        amigaSprite.Export(outBaseName + alternativeAmigaSpriteName);
                    }
                    else
                    {
                        AmigaBob amigaBob = new AmigaBob(imageData, imageConfig);
                        alternativeAmigaSpriteName = "_sprite_bank_amiga_a_bob.bin";
                        amigaBob.Export(outBaseName + alternativeAmigaSpriteName);
                    }
                    tileBank.ExportMegaDrive(outBaseName + "_sprite_bank.bin");
                    tilePalette.Export(outBaseName + "_palette.bin");
                    sprite.Export(outBaseName + "_sprite.bin");
                }
                else
                {
                    TileMap tileMap = new TileMap(tileBank, imageData);

                    tileBank.ExportMegaDrive(outBaseName + "_bank.bin");
                    tileBank.ExportAmiga(outBaseName + "_bank_amiga.bin");
                    tileMap.Export(outBaseName + "_map.bin");
                    tilePalette.Export(outBaseName + "_palette.bin");
                }
            }
        }

        //
        // Export all maps
        //
        string[] mapFiles = m_project.m_mapFiles;
        foreach (string mapFile in mapFiles)
        {
            Debug.Log("Exporting map '" + mapFile + "'");

            string outFileNameNoExt = System.IO.Path.GetFileNameWithoutExtension(mapFile).ToLower();
            string outBaseName      = m_lastExportDirectory + System.IO.Path.DirectorySeparatorChar + outFileNameNoExt;

            //
            TileMap      tileMap      = TileMap.LoadJson(mapFile);
            CollisionMap collisionmap = new CollisionMap(tileMap);

            tileMap.Export(outBaseName + "_map.bin");
            collisionmap.Export(outBaseName + "_collisionmap.bin");
        }

        //
        // Export all game objects
        //
        foreach (string goFile in m_project.m_gameObjectCollectionFiles)
        {
            Debug.Log("Exporting game object '" + goFile + "'");

            string outFileNameNoExt = m_project.GetOutFileNameNoExt(goFile);
            string outBaseName      = m_lastExportDirectory + System.IO.Path.DirectorySeparatorChar;

            GameObjectCollection ggo = new GameObjectCollection(goFile);
            ggo.Export(outBaseName + m_project.GetGreatGameObjectName(goFile), m_project);
        }

        Debug.Log("Export is finished!");
    }
 public void SetImage(PalettizedImage _imageData)
 {
     m_sourceImageWidth  = _imageData.m_width;
     m_sourceImageHeight = _imageData.m_height;
     RefreshInternalThings();
 }
 public void SetImage( PalettizedImage _imageData )
 {
     m_sourceImageWidth = _imageData.m_width;
     m_sourceImageHeight = _imageData.m_height;
     RefreshInternalThings();
 }
Esempio n. 27
0
    void LoadBMP(string _path)
    {
        m_openImageName = "<Untitled>";

        // Load corresponding config first as it have information on how the image should be loaded
        m_currentImageConfig = new PalettizedImageConfig(_path + ".config");
        m_haveLoadedImage    = true;

        m_currentImageData = PalettizedImage.LoadImage(_path, m_currentImageConfig);
        if (m_currentImageData != null)
        {
            //
            m_currentImageConfig.SetImage(m_currentImageData);

            //
            m_currentFramesString     = m_currentImageConfig.GetNumFrames().ToString();
            m_currentFrameTimesString = new Dictionary <int, string>();
            int iFrame;
            for (iFrame = 0; iFrame < m_currentImageConfig.GetNumFrames(); iFrame++)
            {
                m_currentFrameTimesString[iFrame] = m_currentImageConfig.GetFrameTime(iFrame).ToString();
            }

            //
            m_openImageName      = System.IO.Path.GetFileNameWithoutExtension(_path);
            m_tileBankWindowRect = new Rect(m_projectWindowWidth + (m_windowPadding * 2.0f), m_windowTop, m_currentImageData.m_width * 2.0f + 10.0f, m_currentImageData.m_height * 2.0f + 10.0f + 15.0f);
            m_imageSettingsRect  = new Rect(m_tileBankWindowRect.x + m_tileBankWindowRect.width + m_windowPadding, m_tileBankWindowRect.y, 200.0f, 200.0f);
            m_paletteRemapRect   = new Rect(m_imageSettingsRect.x + m_imageSettingsRect.width + m_windowPadding, m_imageSettingsRect.y, 100.0f, 15.0f + (16.0f * 30.0f));

            //
//			m_planarImage = new PlanarImage( m_currentImageData);
            bool OptimizedTilebank = (m_currentImageConfig.m_importAsSprite == false);             // If we import the image as a sprite we should not optimize the tile bank
            m_tileBank    = new TileBank(m_currentImageData, OptimizedTilebank);
            m_tileMap     = new TileMap(m_tileBank, m_currentImageData);
            m_tilePalette = new TilePalette(m_currentImageData);

            //
            int w, h;
            w = m_currentImageData.m_width;
            h = m_currentImageData.m_height;

            //
            m_imageTexture            = new Texture2D(w, h, TextureFormat.ARGB32, false);
            m_imageTexture.filterMode = FilterMode.Point;

            //
            int x, y;
            for (y = 0; y < h; y++)
            {
                for (x = 0; x < w; x++)
                {
                    int   ii  = ((h - 1 - y) * w) + x;
                    int   ic  = m_currentImageData.m_image[ii];
                    Color col = m_currentImageData.m_palette[ic];
                    m_imageTexture.SetPixel(x, y, col);
                }
            }

            //
            m_imageTexture.Apply();
        }
    }
    public static PalettizedImage LoadPNG( string _path, PalettizedImageConfig _config )
    {
        PngReader pngr = FileHelper.CreatePngReader( _path );
        if( !pngr.ImgInfo.Indexed )
        {
            Debug.LogException( new UnityException( "Image wasn't indexed" ));
            return null;
        }

        PngChunkPLTE palette = pngr.GetMetadata().GetPLTE();

        PalettizedImage image = new PalettizedImage( pngr.ImgInfo.Cols, pngr.ImgInfo.Rows, palette.GetNentries());
        image.SetConfig( _config );
        image.m_fileName = System.IO.Path.GetFileNameWithoutExtension( _path );

        image.ReadPalette( palette );
        image.ReadImage( pngr );

        return image;
    }
Esempio n. 29
0
    void SanityChecks(PalettizedImage _palettizedImage)
    {
        if ((m_width % 8) != 0) {
            Debug.LogException (new UnityException ("PANIC! PlanarImage can only handle images with: width % 8 == 0"));
        }

        //		int numberOfColorsUsed = 0;
        //		for (int c = 0; c <  _palettizedImage.m_colorUsed.Count; c++) {
        //			if (_palettizedImage.m_colorUsed [c]) {
        //				numberOfColorsUsed = c;
        //			}
        //		}
        //		int maxNumberOfColors = (int)Math.Pow (4, 2);
        //		if (numberOfColorsUsed > maxNumberOfColors) {
        //			Debug.LogException (new UnityException (String.Format ("PANIC! Trying to create PlanarImage with more colors than _numberOfBitplanes allows [{0} > {1}]!", numberOfColorsUsed, maxNumberOfColors)));
        //		}
    }