public async Task SaveAsLatestScoreAsync(string format, ScoreEntity score) { CreateDirectoryIfNotExists(); var fullpath = GetLatestScoreFilePath(); using (var sw = new StreamWriter(fullpath, false, Encoding.UTF8)) { var text = ScoreTextFormatter.ToString(format, score); await sw.WriteLineAsync(text); } }
public void Start() { StateControllerInit(false); SaveData sd = PD.GetSaveData(); currentName = "---"; characters = new char[] { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' }; string savedName = sd.highScoreName; inputName = new int[] { System.Array.IndexOf(characters, savedName[0]), System.Array.IndexOf(characters, savedName[1]), System.Array.IndexOf(characters, savedName[2]) }; GetGameObject(Vector3.zero, "BG", Resources.Load <Sprite>(SpritePaths.DefaultBG), false, "BG0"); keyPress = new Regex("[A-Za-z0-9]"); PD.sounds.SetMusicAndPlay(SoundPaths.M_Menu); writer = new ScoreTextFormatter(PD); List <KeyValuePair <string, int> > scores = sd.getHighScores(PD.gameType); int userScorePos = sd.getHighscorePos(scores, PD.runningScore, true); if (userScorePos < 0) { userScorePos = 100; } scorePosText = (userScorePos + 1).ToString() + ". "; if (userScorePos < 9) { scorePosText = " " + scorePosText; } scoreTxt = PD.runningScore.ToString(); float scoreX = -2.0f; List <KeyValuePair <string, int> > times = sd.getBestTimes(PD.gameType); int userTimePos = -1; if (PD.gameType == PersistData.GT.Campaign) { userTimePos = sd.getHighscorePos(times, PD.runningTime, true); } else { userTimePos = PD.won?sd.getHighscorePos(times, PD.runningTime, false):-1; } if (userTimePos < 0) { userTimePos = 100; } timePosText = (userTimePos + 1).ToString() + ". "; if (userTimePos < 9) { timePosText = " " + timePosText; } timeTxt = writer.ConvertSecondsToMinuteSecondFormat(PD.runningTime); float timeX = 2.0f; writer.SetScoreRowAndTimeRowWidths(scores, times); System.Xml.XmlNode top = GetXMLHead(); GetMeshText(new Vector3(scoreX, 1.4f), GetXmlValue(top, "highscores"), PD.mostCommonFont, "Prefabs/Text/FixedWidth"); GetMeshText(new Vector3(timeX, 1.4f), GetXmlValue(top, "besttimes"), PD.mostCommonFont, "Prefabs/Text/FixedWidth"); Sprite slab = Resources.Load <Sprite>(SpritePaths.HighScoreSlab); GetGameObject(new Vector3(scoreX, 0.15f), "Score Slab", slab); GetGameObject(new Vector3(timeX, 0.15f), "Time Slab", slab); for (int pos = 0; pos < 10; pos++) { if (pos < userScorePos) { GetTextRow(scores[pos], pos, scoreX); } else if (pos == userScorePos) { currentScore = GetTextRow(new KeyValuePair <string, int>(currentName, PD.runningScore), userScorePos, scoreX); } else if (pos > userScorePos) { GetTextRow(scores[pos - 1], pos, scoreX); } if (pos < userTimePos) { GetTextRow(times[pos], pos, timeX, true); } else if (pos == userTimePos) { currentTime = GetTextRow(new KeyValuePair <string, int>(currentName, PD.runningTime), pos, timeX, true); } else if (pos > userTimePos) { GetTextRow(times[pos - 1], pos, timeX, true); } } if (currentScore != null) { currentScore.color = Color.red; } if (currentTime != null) { currentTime.color = Color.red; } saved = (userScorePos > 10) && (userTimePos > 10); nameCursor = GetOptionsCursor(3, 1, SpritePaths.VerticalArrows, -0.17f, -0.8f, 0.17f, 0, 0, 0, 1); if (!saved) { FontData f = new FontData(TextAnchor.MiddleCenter, TextAlignment.Center); GetGameObject(new Vector3(0.0f, -0.65f), "Minislab", Resources.Load <Sprite>(SpritePaths.HighScoreInput)); GetMeshText(new Vector3(0.0f, -0.5f), GetXmlValue(top, "entername"), f); nameEntry = GetMeshText(new Vector3(0.0f, -0.8f), savedName, f, "Prefabs/Text/FixedWidth"); inputCollider = GetGameObject(new Vector3(0.0f, -0.8f), "Input Collider", Resources.Load <Sprite>(SpritePaths.ScoreCollider), true); confirmButtonSprites = Resources.LoadAll <Sprite>(SpritePaths.ConfirmButtons); confirmButton = GetGameObject(new Vector3(0.0f, -1.2f), "Confirm", confirmButtonSprites[0], true); confirmButton.SetActive(PD.usingMouse); mouseObjects.Add(confirmButton); PD.sounds.SetVoiceAndPlay(SoundPaths.NarratorPath + "036", 0); } else { nameCursor.cursor.SetActive(false); PD.sounds.SetVoiceAndPlay(SoundPaths.NarratorPath + "041", 0); } }
public void CopyEachScoreToClipboard(IEnumerable <ScoreEntity> scores) { var text = ScoreTextFormatter.ToString(AppSetting.Value.ScoreTextFormat.Value, scores.Where(x => x.集計対象)); Clipboard.SetText(text); }