Exemplo n.º 1
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);
    }
Exemplo n.º 2
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();
        }
    }
Exemplo n.º 3
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!");
    }
Exemplo n.º 4
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!");
    }
Exemplo n.º 5
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();
        }
    }
Exemplo n.º 6
0
    public static 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;
    }