コード例 #1
0
ファイル: Config.cs プロジェクト: HyVong007/Ancient-Empires
        public static Config DeSerialize(byte[] data)
        {
            var cfg = new Config();

            using (var m = new MemoryStream(data))
                using (var r = new BinaryReader(m))
                {
                    // read map
                    cfg.map = Map.DeSerialize(r.ReadBytes(r.ReadInt32()));

                    // read money
                    cfg.money = r.ReadInt32();

                    // read turn time
                    cfg.turnTime = r.ReadSingle();

                    // read army infos
                    cfg.armyInfos = new ArmyInfo[r.ReadInt32()];
                    for (int i = 0; i < cfg.armyInfos.Length; ++i)
                    {
                        cfg.armyInfos[i] = new ArmyInfo()
                        {
                            color = (Army.Color)r.ReadByte(),
                            group = (Army.Group)r.ReadByte(),
                            name  = r.ReadString()
                        }
                    }
                    ;

                    // read playMode
                    cfg.playMode = (PlayMode)r.ReadByte();

                    // read playMode config
                    switch (cfg.playMode)
                    {
                    case PlayMode.CAMPAIGN: break;

                    case PlayMode.SKIRMISH:
                    {
                        cfg.playModeConfig = SkirmishConfig.DeSerialize(r.ReadBytes(r.ReadInt32()));
                        break;
                    }

                    case PlayMode.ONLINE:
                    {
                        cfg.playModeConfig = OnlineConfig.DeSerialize(r.ReadBytes(r.ReadInt32()));
                        break;
                    }

                    case PlayMode.LAN:
                    {
                        cfg.playModeConfig = LANConfig.DeSerialize(r.ReadBytes(r.ReadInt32()));
                        break;
                    }
                    }

                    // read AI config
                    if (r.ReadBoolean())
                    {
                        cfg.aiConfig = AIConfig.DeSerialize(r.ReadBytes(r.ReadInt32()));
                    }

                    return(cfg);
                }
        }
    }