miuu-spreadsheet-helper/ConsoleCommands.cs
2023-09-30 01:42:18 -04:00

65 lines
1.7 KiB
C#

using MIU;
using System;
using System.Collections.Generic;
using UnityEngine;
namespace SpreadsheetHelper
{
internal class ConsoleCommands
{
[ConsoleCommand(description = "Spreadsheet Helper, copy PBs into the clipboard", paramsDescription = "[chapter]")]
public static string ssh(params string[] args)
{
if (args.Length != 1)
{
return "Requires one argument, the chapter number";
}
int chapterIndex;
if (!int.TryParse(args[0], out chapterIndex))
{
return args[0] + " is not a valid integer";
}
if (chapterIndex <= 0 || chapterIndex > 10)
{
return chapterIndex + " is not between 1 and 10";
}
List<MarbleChapter> chapters = GlobalContext.LevelData.chapters;
//for (int i = 0; i < chapters.Count; i++)
//{
// MarbleChapter chapter = chapters[i];
// MIU.Console.print(i + " - " + chapter.id + " - " + chapter.name);
//}
MarbleChapter chapter = chapters[chapterIndex - 1];
MIU.Console.print("Printing stats for " + chapter.name);
string clipboardStr = "";
HighScoreManager hsm = GamePlayManager.Get().scores;
for (int i = 0; i < chapter.levels.Count; i++)
{
MarbleLevel level = chapter.levels[i];
string printStr = (i + 1) + " - " + level.name;
List<HighScoreRecord> list = new List<HighScoreRecord>();
hsm.FetchLevelTopScores(level.id, 1, list);
if (clipboardStr != "")
clipboardStr += "\n";
if (list.Count > 0)
{
string score = string.Format("{0}.{1:000}", (int)list[0].score, (int)(1000.0 * (list[0].score % 1.0)));
printStr += " - " + score + " (" + list[0].score + ")";
clipboardStr += score;
}
MIU.Console.print(printStr);
}
GUIUtility.systemCopyBuffer = clipboardStr;
return "Scores copied to clipboard";
}
}
}