Documentation

Updated 3 days ago

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

  1. 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);
      
  2. StatFileExists
    • Checks if a specific stat file exists.
    • Returns: true if the file exists, otherwise false.
  3. 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.
  4. AddStatRow
    • Adds a new row to the CSV file.
    • Parameters:
      • values: Array of object values for the row. Make sure they match the column types defined in the CSV file, in the same order, and the same amount of values.
      • csvFileName: The name of the file to add the row to.
    • Example:
      mod.AddStatRow(new object[] {
          "Player1",
          100
      }, "PlayerStats");
      
  5. FormatValue
    • Converts a value to a CSV-compatible string format. This is automatically done by the AddStatRow method.
  6. GetAggregateData
    • Computes aggregate data (e.g., totals, averages) from CSV files.
  7. RemoveRows
    • Remove multiple rows from a CSV file based on a predicate.
  8. RemoveRow
    • Remove a specific row by index from a CSV file.
  9. WriteAllRows
    • Method for rewriting all rows to a CSV file, including the header row. (Careful with this one!)

Main Class

Methods

  1. 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));
            }
        }
    }
}