StatsMod
Class
Properties
ModName
: Name of the mod for indentifying and organizing data files.
storeEntryTime
: Boolean value to include timestamps for each entry.
DebugMode
: Boolean value to enable debug mode (logging to console).
Methods
InitializeStatFile
- Creates a new CSV file with specified columns.
- Parameters:
fileName
: Name of the CSV file.
columns
: Dictionary (string, type) of column names and their data types.
- Example:
var columns = new Dictionary<string, Type>
{
{ "Player Name", typeof(string) },
{ "Battle Points", typeof(int) }
};
mod.InitializeStatFile("PlayerStats", columns);
StatFileExists
- Checks if a specific stat file exists.
- Returns:
true
if the file exists, otherwise false
.
GetAllRows
- Reads all rows from a CSV file.
- Parameters:
csvFileName
: The name of the file to read.
skipHeader
: Boolean value to skip the header row.
- Returns: A list of string arrays representing rows.
AddStatRow
FormatValue
- Converts a value to a CSV-compatible string format. This is automatically done by the
AddStatRow
method.
GetAggregateData
- Computes aggregate data (e.g., totals, averages) from CSV files.
RemoveRows
- Remove multiple rows from a CSV file based on a predicate.
RemoveRow
- Remove a specific row by index from a CSV file.
WriteAllRows
- Method for rewriting all rows to a CSV file, including the header row. (Careful with this one!)
Main
Class
Methods
RegisterCSVFile
- Registers a CSV file for ModUI toggles
- Parameters:
csvFileName
: The name of the CSV file to register.
Example Mod
using MelonLoader;
using RumbleStats;
//other references...
namespace MyMod
{
public class Main : MelonMod
{
StatsMod mod = new StatsMod();
public override void OnLateInitializeMelon()
{
mod.ModName = "MyModName";
mod.storeEntryTime = true; //Stores entry timestamps when calling AddStatRow
mod.DebugMode = true; //Logs when things are being stored in case something is not working
var columns = new Dictionary<string, Type>
{
{ "Column1Name", typeof(string) },
{ "Column2Name", typeof(int) },
{ "Column3Name", typeof(bool) },
//etc...
};
mod.InitializeStatFile("CSVFileName", columns);
RumbleStats.Main.instance.RegisterCSVFile("CSVFileName");
//Do this for each CSV file you want to store stats for...
}
private void SomeRandomMethod()
{
mod.AddStatRow(new object[]
{
"Stat1",
1000101,
true,
//etc, same as the columns provided in the InitializeStatFile method...
}, "CSVFileName");
var rows = mod.GetAllRows("CSVFileName", skipHeader: true);
foreach (var row in rows)
{
MelonLogger.Msg(string.Join(", ", row));
}
}
}
}