EditorMapa2D.Project.add_region C# (CSharp) Method

add_region() public method

public add_region ( Region region ) : void
region Region
return void
        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;
            }
        }

Usage Example

Exemplo n.º 1
0
        private void ExportMap()
        {
            try
            {
                if (region != null)
                {
                    project = new Project();

                    List<int> list_event = new List<int>();
                    List<int> tilesets = new List<int>();

                    foreach (Layer lyr in region.layer.Values)
                    {
                        foreach (Dictionary<int, int> events in lyr.evento.Values)
                        {
                            foreach (int event_code in events.Values)
                            {
                                if (!list_event.Contains(event_code))
                                    list_event.Add(event_code);
                            }
                        }
                        foreach (Dictionary<int, Tile> tiles in lyr.tiles.Values)
                        {
                            foreach (Tile tl in tiles.Values)
                            {
                                if (!tilesets.Contains(tl.tileset_code))
                                    tilesets.Add(tl.tileset_code);
                            }
                        }
                    }

                    foreach (int event_code in list_event)
                        if (world.events.ContainsKey(event_code))
                            project.add_event(event_code, world.events[event_code]);

                    foreach (int tileset_code in tilesets)
                        if (world.tilesets.ContainsKey(tileset_code))
                            project.add_tile_set(world.tilesets[tileset_code]);

                    project.add_region(region);

                    using (Stream stream = File.Open(default_map, FileMode.Create, FileAccess.ReadWrite))
                    {
                        BinaryFormatter bin = new BinaryFormatter();
                        bin.Serialize(stream, project);
                    }
                }
            }
            catch (IOException ex)
            {
                string error = ex.Message;
            }
        }
All Usage Examples Of EditorMapa2D.Project::add_region