Ejemplo n.º 1
0
        private void OpenRegion(ProjectRegion pRegion)
        {
            try
            {
                Region region = new Region(pRegion.setor[0], pRegion.setor[1], pRegion.setor[2], pRegion.setor[3]);
                region.name = pRegion.name;

                int i;
                for (i = 0; i < pRegion.layer.Length; i++)
                {
                    ProjectLayer pLayer = pRegion.layer[i];

                    Layer layer = new Layer();

                    layer.name = pLayer.name;
                    layer.visible = pLayer.visible;

                    layer.tiles = new Dictionary<int, Dictionary<int, Tile>>();

                    int j;
                    if (pLayer.tiles != null)
                    {
                        for (j = 0; j < pLayer.tiles.Length; j++)
                        {
                            ProjectTile pTile = pLayer.tiles[j];

                            if (pTile == null)
                                continue;

                            Tile tile = new Tile();

                            tile.point = new Point(pTile.point[0], pTile.point[1]);
                            tile.tile_code = pTile.tile_code;
                            tile.tile_crop = pTile.tile_crop;
                            tile.tileset_code = pTile.tileset_code;

                            if (!layer.tiles.ContainsKey(pTile.point[0]))
                            {
                                layer.tiles.Add(pTile.point[0], new Dictionary<int, Tile>());
                            }

                            Dictionary<int, Tile> coluna = layer.tiles[pTile.point[0]];

                            if (!coluna.ContainsKey(pTile.point[1]))
                            {
                                coluna.Add(pTile.point[1], tile);
                            }
                            else
                            {
                                coluna[pTile.point[1]] = tile;
                            }
                        }
                    }
                    if (pLayer.events != null)
                    {
                        for (j = 0; j < pLayer.events.GetLongLength(0); j++)
                        {
                            int code = pLayer.events[j, 0];
                            int x = pLayer.events[j, 1];
                            int y = pLayer.events[j, 2];

                            layer.addEvent(new Point(x, y), code);
                        }
                    }
                    region.addLayer(layer);
                }
                i = world.AddRegion(region);
                insert_region(region.name, i);
            }
            catch (Exception ex)
            {
                string error = ex.Message;
            }
        }
Ejemplo n.º 2
0
        public void add_region(Region region)
        {
            try
            {
                if (region == null)
                    return;

                ProjectRegion tmp = new ProjectRegion();

                tmp.name = region.name;
                tmp.setor = new int[4];
                tmp.setor[0] = region.map_width;
                tmp.setor[1] = region.map_height;
                tmp.setor[2] = region.tile_width;
                tmp.setor[3] = region.tile_height;

                tmp.layer = new ProjectLayer[region.layer.Count];
                int i;
                for (i = 0; i < region.layer.Count; i++)
                {
                    Layer layer = region.layer[i];
                    ProjectLayer tmpLayer = new ProjectLayer();

                    tmpLayer.name = layer.name;
                    tmpLayer.visible = layer.visible;

                    int num = 0;
                    foreach (Dictionary<int, Tile> list in layer.tiles.Values)
                        num += list.Count;

                    tmpLayer.tiles = new ProjectTile[num];

                    int j = 0;
                    foreach (int x in layer.tiles.Keys)
                    {
                        Dictionary<int, Tile> list = layer.tiles[x];
                        foreach (int y in list.Keys)
                        {
                            Tile tile = list[y];
                            ProjectTile tmpTile = new ProjectTile();
                            tmpTile.point = new int[2];
                            tmpTile.point[0] = x;
                            tmpTile.point[1] = y;
                            tmpTile.tile_code = tile.tile_code;
                            tmpTile.tile_crop = tile.tile_crop;
                            tmpTile.tileset_code = tile.tileset_code;

                            tmpLayer.tiles[j] = tmpTile;

                            j++;
                        }
                    }

                    num = 0;
                    foreach (Dictionary<int, int> list in layer.evento.Values)
                        num += list.Count;

                    tmpLayer.events = new int[num, 3];

                    j = 0;
                    foreach (int x in layer.evento.Keys)
                    {
                        Dictionary<int, int> list = layer.evento[x];
                        foreach (int y in list.Keys)
                        {
                            int code = list[y];

                            tmpLayer.events[j, 0] = code;
                            tmpLayer.events[j, 1] = x;
                            tmpLayer.events[j, 2] = y;

                            j++;
                        }
                    }

                    tmp.layer[i] = tmpLayer;
                }
                regions.Add(tmp);
            }
            catch (Exception ex)
            {
                string error = ex.Message;
            }
        }
Ejemplo n.º 3
0
        public void add_region(Region region)
        {
            try
            {
                if (region == null)
                {
                    return;
                }

                ProjectRegion tmp = new ProjectRegion();

                tmp.name     = region.name;
                tmp.setor    = new int[4];
                tmp.setor[0] = region.map_width;
                tmp.setor[1] = region.map_height;
                tmp.setor[2] = region.tile_width;
                tmp.setor[3] = region.tile_height;

                tmp.layer = new ProjectLayer[region.layer.Count];
                int i;
                for (i = 0; i < region.layer.Count; i++)
                {
                    Layer        layer    = region.layer[i];
                    ProjectLayer tmpLayer = new ProjectLayer();

                    tmpLayer.name    = layer.name;
                    tmpLayer.visible = layer.visible;

                    int num = 0;
                    foreach (Dictionary <int, Tile> list in layer.tiles.Values)
                    {
                        num += list.Count;
                    }

                    tmpLayer.tiles = new ProjectTile[num];

                    int j = 0;
                    foreach (int x in layer.tiles.Keys)
                    {
                        Dictionary <int, Tile> list = layer.tiles[x];
                        foreach (int y in list.Keys)
                        {
                            Tile        tile    = list[y];
                            ProjectTile tmpTile = new ProjectTile();
                            tmpTile.point        = new int[2];
                            tmpTile.point[0]     = x;
                            tmpTile.point[1]     = y;
                            tmpTile.tile_code    = tile.tile_code;
                            tmpTile.tile_crop    = tile.tile_crop;
                            tmpTile.tileset_code = tile.tileset_code;

                            tmpLayer.tiles[j] = tmpTile;

                            j++;
                        }
                    }

                    num = 0;
                    foreach (Dictionary <int, int> list in layer.evento.Values)
                    {
                        num += list.Count;
                    }

                    tmpLayer.events = new int[num, 3];

                    j = 0;
                    foreach (int x in layer.evento.Keys)
                    {
                        Dictionary <int, int> list = layer.evento[x];
                        foreach (int y in list.Keys)
                        {
                            int code = list[y];

                            tmpLayer.events[j, 0] = code;
                            tmpLayer.events[j, 1] = x;
                            tmpLayer.events[j, 2] = y;

                            j++;
                        }
                    }

                    tmp.layer[i] = tmpLayer;
                }
                regions.Add(tmp);
            }
            catch (Exception ex)
            {
                string error = ex.Message;
            }
        }