예제 #1
0
파일: MainForm.cs 프로젝트: Vjww/F1mpEditor
        private void ImportButton_Click(object sender, EventArgs e)
        {
            var fileName = GetSelectedSavedGame();
            var filePath = BuildSavedGameFilePath(fileName);

            using (var savedGameConnection = new SavedGameConnection(filePath))
            {
                // Import from file
                var teams = new TeamCollection();
                for (var id = 0; id < TeamCount; id++)
                {
                    var valueMapping = new Data.ValueMapping.SavedGame.Team.Team(id);
                    var team         = new Team
                    {
                        Id   = id,
                        Name = Encoding.ASCII.GetString(savedGameConnection.ReadByteArray(valueMapping.Name, Data.ValueMapping.SavedGame.Team.Team.NameLength)),

                        Department1Motivation = savedGameConnection.ReadInteger(valueMapping.Department1Motivation),
                        Department1Happiness  = savedGameConnection.ReadInteger(valueMapping.Department1Happiness),
                        Department2Motivation = savedGameConnection.ReadInteger(valueMapping.Department2Motivation),
                        Department2Happiness  = savedGameConnection.ReadInteger(valueMapping.Department2Happiness),
                        Department3Motivation = savedGameConnection.ReadInteger(valueMapping.Department3Motivation),
                        Department3Happiness  = savedGameConnection.ReadInteger(valueMapping.Department3Happiness),
                        Department4Motivation = savedGameConnection.ReadInteger(valueMapping.Department4Motivation),
                        Department4Happiness  = savedGameConnection.ReadInteger(valueMapping.Department4Happiness),
                        Department5Motivation = savedGameConnection.ReadInteger(valueMapping.Department5Motivation),
                        Department5Happiness  = savedGameConnection.ReadInteger(valueMapping.Department5Happiness)
                    };
                    teams.Add(team);
                }

                var player1TeamId     = savedGameConnection.ReadInteger(Data.ValueMapping.SavedGame.Player.Player.GetPlayer1TeamIdOffset()) - 1;
                var player1TeamRecord = teams.Single(x => x.Id == player1TeamId);

                // Populate controls
                PopulateHeaderControls(player1TeamId, player1TeamRecord.Name);
                PopulateBasicControls(player1TeamRecord);
                PopulateAdvancedControls(teams);

                MessageBox.Show("Import complete!");
            }
        }