public static bool SubmitScore(Score score) { if (scores == null) { scores = ScoreIO.LoadScores(); } if (score == null || !score.isValid()) { return(false); } List <Score> levelScores = GetSortedScoresFromLevel(score.level); if (levelScores == null || levelScores.Count <= Constants.SCORE_COUNT) { scores.Add(score); } else { for (int i = 0; i < levelScores.Count; i++) { if (levelScores[i].finalScore() <= score.finalScore()) { scores.Remove(levelScores[levelScores.Count - 1]); scores.Add(score); break; } } } ScoreIO.SaveScores(scores); return(true); }
public ScoreInputController(Score s) { _score = s; _input = new TextInput(); _select = new BooleanControlsFlag(delegate() { return(SwinGame.KeyTyped(KeyCode.vk_RETURN)); }); _select.StateSetTrue += (object sender, EventArgs e) => { if (_input.Text.Length != 0) { _score.PlayerName = _input.Text; ScoreIO io = new ScoreIO(); io.AddScore(_score); io.Write(); } //OnDone(new MainMenuController()); }; _renderer = delegate(object sender, EventArgs e) { Color selected = CellDrawing.GetColor("#4ac925"); SwinGame.DrawText("Please input your name to submit your score:", CellDrawing.COLOR, 16, 128); SwinGame.DrawText(_input.Text, selected, 96, 140); }; RenderEvents.RenderTick += _renderer; }
private void CmdImportDelesteBeatmap_Executed(object sender, ExecutedRoutedEventArgs e) { var mainWindow = this.GetMainWindow(); var messageBoxResult = MessageBox.Show(Application.Current.FindResource <string>(App.ResourceKeys.DelesteImportingWillReplaceCurrentScorePrompt), App.Title, MessageBoxButton.YesNo, MessageBoxImage.Exclamation); if (messageBoxResult == MessageBoxResult.Yes) { MainWindow.CmdFileSaveProject.Execute(null); } var openDialog = new OpenFileDialog(); openDialog.CheckFileExists = true; openDialog.ValidateNames = true; openDialog.Filter = Application.Current.FindResource <string>(App.ResourceKeys.DelesteTxtFileFilter); var dialogResult = openDialog.ShowDialog(); if (dialogResult ?? false) { string[] warnings; bool hasErrors; var project = mainWindow.Project; var tempProject = new Project(); tempProject.Settings.CopyFrom(project.Settings); var score = ScoreIO.LoadFromDelesteBeatmap(tempProject, mainWindow.Project.Difficulty, openDialog.FileName, out warnings, out hasErrors); if (warnings != null) { MessageBox.Show(warnings.BuildString(Environment.NewLine), App.Title, MessageBoxButton.OK, hasErrors ? MessageBoxImage.Error : MessageBoxImage.Exclamation); if (!hasErrors) { messageBoxResult = MessageBox.Show(Application.Current.FindResource <string>(App.ResourceKeys.DelesteWarningsAppearedPrompt), App.Title, MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No); if (messageBoxResult == MessageBoxResult.No) { return; } } else { return; } } // Redirect project reference. score.Project = project; project.SetScore(project.Difficulty, score); project.Settings.CopyFrom(tempProject.Settings); mainWindow.Editor.Score = score; mainWindow.NotifyProjectChanged(); var backstage = (Backstage)mainWindow.Ribbon.Menu; backstage.IsOpen = false; } }
private void CmdExportToDelesteBeatmap_Executed(object sender, ExecutedRoutedEventArgs e) { var mainWindow = this.GetMainWindow(); var saveDialog = new SaveFileDialog(); saveDialog.OverwritePrompt = true; saveDialog.ValidateNames = true; saveDialog.Filter = Application.Current.FindResource <string>(App.ResourceKeys.DelesteTxtFileFilter); var result = saveDialog.ShowDialog(); if (result ?? false) { ScoreIO.ExportToDelesteBeatmap(mainWindow.Editor.Score, saveDialog.FileName); var prompt = string.Format(Application.Current.FindResource <string>(App.ResourceKeys.ExportToDelesteBeatmapCompletePromptTemplate), saveDialog.FileName); MessageBox.Show(prompt, App.Title, MessageBoxButton.OK, MessageBoxImage.Information); } }
//load from file if it exists private void Awake() { Debug.Log("ScoreIO Awake()"); if (instance == null) { instance = this; DontDestroyOnLoad(this); BinaryFormatter bf = new BinaryFormatter(); try { FileStream file = File.Open(Application.persistentDataPath + "/low_scores.save", FileMode.Open); lowScores = new List <Score>((Score[])bf.Deserialize(file)); file.Close(); }catch (FileNotFoundException IOE) { Debug.LogWarning(IOE.Message); } } else { DestroyImmediate(gameObject); } }
public static List <Score> GetSortedScoresFromLevel(string levelName) { if (scores == null || scores.Count == 0) { scores = ScoreIO.LoadScores(); } if (string.IsNullOrWhiteSpace(levelName)) { return(null); } List <Score> returnScores = new List <Score>(); foreach (Score score in scores) { if (score.level == levelName) { returnScores.Add(score); } } returnScores.Sort(new ScoreComparer()); return(returnScores); }