Пример #1
0
    void PrepareDataToSave(string path)
    {
        _levelToSave = new SerializedMap();

        _levelToSave.Path     = path;
        _levelToSave.MapSizeX = MapSizeX;
        _levelToSave.MapSizeY = MapSizeY;

        _levelToSave.MapTiles.Clear();

        foreach (Transform t in MapHolder)
        {
            TileBase to = t.GetComponent <TileBase>();

            SerializedTile st = new SerializedTile();

            var layer1 = FillSerializedTileData(to.TileObjectLayer1);
            st.TileLayer1 = layer1;

            if (to.TileObjectLayer2 != null)
            {
                var layer2 = FillSerializedTileData(to.TileObjectLayer2);
                st.TileLayer2 = layer2;
            }

            _levelToSave.MapTiles.Add(st);
        }
    }
Пример #2
0
    void LoadMap(string path)
    {
        var    formatter = new BinaryFormatter();
        Stream stream    = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);

        _level = (SerializedMap)formatter.Deserialize(stream);
        stream.Close();

        _mapSizeX = _level.MapSizeX;
        _mapSizeY = _level.MapSizeY;

        _map = new TileBase[_mapSizeX, _mapSizeY];

        foreach (var tile in _level.MapTiles)
        {
            var layer1 = tile.TileLayer1;

            int x = layer1.CoordX;
            int y = layer1.CoordY;

            var go = Instantiate(PrefabsManager.Instance.TileBasePrefab, new Vector3(x, y, 0.0f), Quaternion.identity, MapHolder);

            TileBase tb = go.GetComponent <TileBase>();

            _map[x, y] = tb;

            InstantiateTileObject(tb, tile.TileLayer1, 0);

            if (tile.TileLayer2 != null)
            {
                InstantiateTileObject(tb, tile.TileLayer2, 1);
            }
        }
    }
Пример #3
0
        private TileMap ProcessNewMap(string mapName)
        {
            SerializedMap mapData = LoadMapData(mapName);

            MapDataProcessor mapDataProcessor = new MapDataProcessor(game, mapData, mapDepencyContainer);

            return(mapDataProcessor.Process());
        }
Пример #4
0
        public MapDataProcessor(KhvGame game, SerializedMap serializedMap, MapDepencyContainer mapDenecyContainer)
        {
            this.game               = game;
            this.serializedMap      = serializedMap;
            this.mapDenecyContainer = mapDenecyContainer;

            contentManager = game.Content;
        }
Пример #5
0
    /*
     * public Lobby(string hostIP, string name, int playersConnected, int maxPlayers, bool passProtected, List<List<Player>> teams)
     * {
     *  this.hostIP = hostIP;
     *  this.name = name;
     *  this.playersConnected = playersConnected;
     *  this.maxPlayers = maxPlayers;
     *  this.passProtected = passProtected;
     *  this.teams = teams;
     * }
     */
    public Packet ToPacket(int type)
    {
        if (type == (int)Packets.lobbyUpdate || type == (int)Packets.MapDownloadRequest)
        {
            using (Packet packet = new Packet(type))
            {
                if (type == (int)Packets.MapDownloadRequest)
                {
                    SerializedMap map = new SerializedMap(this.map);
                    packet.Write(map.name);
                    packet.Write(map.guid);
                    packet.Write(map.teamString);
                    packet.Write(map.mapdata.Length);
                    packet.Write(map.mapdata);
                    packet.Write(map.thumbnail.x);
                    packet.Write(map.thumbnail.y);
                    packet.Write(map.thumbnail.bytes.Length);
                    packet.Write(map.thumbnail.bytes);
                }

                packet.Write(map.teams.Count);
                foreach (List <Player> item in map.teams)
                {
                    packet.Write(item.Count);
                    foreach (Player player in item)
                    {
                        if (player != null)
                        {
                            packet.Write(player.name);
                            packet.Write(player.losses);
                            packet.Write(player.wins);
                            packet.Write(player.rank);
                        }
                        else
                        {
                            packet.Write("null");
                        }
                    }
                }
                packet.Write(spectators.Count);
                foreach (Player player in spectators)
                {
                    packet.Write(player.name);
                    packet.Write(player.losses);
                    packet.Write(player.wins);
                    packet.Write(player.rank);
                }
                packet.Write(name);
                packet.Write(map.guid.ToString());
                return(packet);
            }
        }
        Debug.LogError("invalid packet type");
        return(null);
    }
Пример #6
0
        // hakee kaikki layerit listaan
        private IEnumerable <BaseSerializedLayer> SerializedMapLayersToList(SerializedMap serializedMap)
        {
            var serializedLayers = new List <BaseSerializedLayer>();

            serializedLayers.AddRange(serializedMap.TileLayers);
            serializedLayers.AddRange(serializedMap.AnimationLayers);
            serializedLayers.AddRange(serializedMap.RuleLayers);
            serializedLayers.AddRange(serializedMap.ObjectLayers);

            return(serializedLayers);
        }
Пример #7
0
        // ISaveable

        public void LoadData()
        {
            string filePath = Path.Combine(Application.dataPath, "FourX_Utilities/Config/DefaultInput.json");

            if (File.Exists(filePath))
            {
                SerializedMap <string, KeyCode> .LoadJsonData(filePath, ref m_inputMap);
            }
            else
            {
                Debug.Log("File not found at : " + filePath);
            }
        }
Пример #8
0
        /// <summary>
        /// deserialisoi kartan ja palauttaa sen
        /// </summary>
        /// <param name="mapname">kartan polku ja nimi</param>
        /// <returns>deserialisoitu kartta</returns>
        public SerializedMap Load(string mapname)
        {
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(SerializedMap));
            SerializedMap serializedMap = null;

            string fullName = ResolveFullName(mapname + ".mp");

            using (StreamReader streamReader = new StreamReader(fullName))
            {
                serializedMap = (SerializedMap)xmlSerializer.Deserialize(streamReader);
            }

            return(serializedMap);
        }
Пример #9
0
    public Map(SerializedMap map)
    {
        Texture2D tex = new Texture2D(map.thumbnail.x, map.thumbnail.y);

        ImageConversion.LoadImage(tex, map.thumbnail.bytes);
        thumbnail  = Sprite.Create(tex, new Rect(0.0f, 0.0f, tex.width, tex.height), Vector2.one);
        guid       = new Guid(map.guid);
        name       = map.name;
        teamString = map.teamString;
        char[] teamNumbers = teamString.Replace("v", string.Empty).ToCharArray();
        for (int i = 0; i < teamString.Replace("v", string.Empty).Length; i++)
        {
            int teamsize = int.Parse(teamNumbers[i].ToString());
            teams.Add(new List <Player>());
            for (int i2 = 0; i2 < teamsize; i2++)
            {
                teams[i].Add(null);
            }
        }
    }
Пример #10
0
        public void SaveData()
        {
            string filePath = Path.Combine(Application.dataPath, "FourX_Utilities/Config/DefaultInput.json");

            SerializedMap <string, KeyCode> .SaveJsonData(filePath, ref m_inputMap);
        }
Пример #11
0
        // Prosessoi kartan komponentit.
        private void ProcessMapComponents(SerializedMap serializedMap)
        {
            MapComponentDataProcessor mapComponentDataProcessor = new MapComponentDataProcessor(game, map, mapDenecyContainer.MapComponentNamespaces, serializedMap.Attributes);

            mapComponentDataProcessor.Process();
        }
Пример #12
0
        private static void DoSerialize(BigMap map, TileSet tileset, bool IncludeTileset, Stream destination)
        {
            SerializedMap result = new SerializedMap();
            Dictionary<Tile, int> tileLookup = new Dictionary<Tile, int>();
            if (tileset != null)
            {
                result.TileHeight = tileset.TileHeight;
                result.TileWidth = tileset.TileWidth;

                foreach (Tile tile in tileset.Tiles)
                {
                    if (IncludeTileset)
                    {
                        result.Tiles.Add(SaveImage(tile.FullImage));
                    }
                    tileLookup.Add(tile, tileLookup.Count);
                }
            }
            else
            { result.Tiles = null; }
            foreach (var layer in map.Layers)
            {
                Rectangle r = layer.ImageBounds;
                MapChunk chunk = new MapChunk();
                chunk.X = r.Left;
                chunk.Y = r.Top; ;
                chunk.Width = r.Width;
                chunk.Height = r.Height;
                for (int x = r.Left; x < r.Right; x++)
                {
                    for (int y = r.Top; y < r.Bottom; y++)
                    {
                        Tile tile = layer[x, y];
                        int index = -1;
                        if (tile != null)
                        {
                            if (!tileLookup.TryGetValue(tile, out index))
                            {
                                index = tileLookup.Count;
                                tileLookup.Add(tile, index);
                            }
                        }
                        chunk.Data.Add(index);
                    }
                }
                MapLayer serializedLayer = new MapLayer();
                serializedLayer.Visible = layer.Visible;
                serializedLayer.IsWall = layer.IsWall;
                serializedLayer.Chunks.Add(chunk);
                result.Layers.Add(serializedLayer);
            }
            Serializer.Serialize(destination, result);
        }