Exemplo n.º 1
0
        private void ExportButton_Click(object sender, EventArgs e)
        {
            var fileName = GetSelectedSavedGame();
            var filePath = BuildSavedGameFilePath(fileName);

            using (var savedGameConnection = new SavedGameConnection(filePath))
            {
                // Export to file
                var teams = TeamsDataGridView.DataSource as TeamCollection;
                if (teams == null)
                {
                    MessageBox.Show("Please import data from a saved game file first before attempting to export.",
                                    Settings.Default.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                foreach (var team in teams)
                {
                    var valueMapping = new Data.ValueMapping.SavedGame.Team.Team(team.Id);
                    savedGameConnection.WriteInteger(valueMapping.Department1Motivation, team.Department1Motivation);
                    savedGameConnection.WriteInteger(valueMapping.Department1Happiness, team.Department1Happiness);
                    savedGameConnection.WriteInteger(valueMapping.Department2Motivation, team.Department2Motivation);
                    savedGameConnection.WriteInteger(valueMapping.Department2Happiness, team.Department2Happiness);
                    savedGameConnection.WriteInteger(valueMapping.Department3Motivation, team.Department3Motivation);
                    savedGameConnection.WriteInteger(valueMapping.Department3Happiness, team.Department3Happiness);
                    savedGameConnection.WriteInteger(valueMapping.Department4Motivation, team.Department4Motivation);
                    savedGameConnection.WriteInteger(valueMapping.Department4Happiness, team.Department4Happiness);
                    savedGameConnection.WriteInteger(valueMapping.Department5Motivation, team.Department5Motivation);
                    savedGameConnection.WriteInteger(valueMapping.Department5Happiness, team.Department5Happiness);
                }

                MessageBox.Show("Export complete!");
            }
        }
Exemplo n.º 2
0
        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!");
            }
        }