Stats Display API

capeling, slideglide

Stats Display API

An API mod for mod developers to add their own stats to the icon kit menu.

NOTE: This mod is intended for developers only. If you're not a mod developer, you likely won't need this mod.

Setup

Add the mod as a dependency in your mod's mod.json:

"dependencies": {
    "capeling.garage-stats-menu": ">=v2.0.0"
}

Usage

Include capeling.garage-stats-menu/stats_api.hpp and use registerStatItem in an $execute block, here's an example code with all the provided APIs listed:

#include 

using namespace stats_api;

$execute {
    // If you want a button, please do not pass a `CCMenuItem` to this function; your callback will not work.
    // Use `registerStatItemButton` with a `geode::Button` if you want a button.
    registerStatItem(
        // A unique ID for your stat item.
        "your-stat-item-id"_spr,
        // Lambda returning any CCNode (e.g., CCSprite).
        []() {
            return cocos2d::CCNode::create();
        },
        // The displayed number for your stat item.
        1,
        // Optional: The node scale for your stat item. (Default: 0.5f).
        1.f
    );

    registerStatItemButton(
        // A unique ID for your stat item.
        "your-stat-item-id"_spr,
        // Lambda returning a geode::Button*.
        []() {
            return geode::Button::create([](auto) {});
        },
        // The displayed number for your stat item.
        1,
        // Optional: The node scale for your stat item. (Default: 0.5f).
        1.f
    );

    // Check if a stat item is registered.
    isStatItemRegistered("your-stat-item-id"_spr);

    // Update the display node of your stat item.
    // Use `updateDisplayButton` instead if your stat is a button.
    // The node scale parameter is optional! If omitted, the current scale is kept.
    updateDisplayNode("your-stat-item-id"_spr, [](){ return cocos2d::CCNode::create(); }, 0.5f);

    // Update the display button of your stat item.
    // The node scale parameter is optional! If omitted, the current scale is kept.
    updateDisplayButton("your-stat-item-id"_spr, [](){ return geode::Button::create([](auto) {}); }, 0.5f);

    // Unregister your stat item.
    unregisterStatItem("your-stat-item-id"_spr);

    // Get the displayed number of your stat item.
    getDisplayedNumber("your-stat-item-id"_spr).unwrapOrDefault();

    // Set the displayed number of your stat item.
    setDisplayedNumber("your-stat-item-id"_spr, 1);
}

Migrating from the legacy API

Migrating is very easy; Change the header from StatsDisplayAPI.h to stats_api.hpp and simply stop hooking GJGarageLayer::init and instead use registerStatItem inside an $execute block.

Here's an example code that uses the old API:

#include 

class $modify(GJGarageLayer) {
    bool init() {
        if (!GJGarageLayer::init()) return false;

        auto statMenu = this->getChildByID("capeling.garage-stats-menu/stats-menu");

        auto myStatItem = StatsDisplayAPI::getNewItem(
            "fire-shards"_spr,
            cocos2d::CCSprite::createWithSpriteFrameName("fireShardSmall_001.png"),
            GameStatsManager::sharedState()->getStat(16),
            0.8f
        );

        if (statMenu) {
            statMenu->addChild(myStatItem);
            statMenu->updateLayout();
        }

        return true;
    }
};

And here's how it can be migrated to the new API:

#include 

using namespace stats_api;

$execute {
    registerStatItem(
        "fire-shards"_spr,
        []() {
            return cocos2d::CCSprite::createWithSpriteFrameName("fireShardSmall_001.png");
        },
        GameStatsManager::sharedState()->getStat("16"),
        0.8f
    );
}

Credits

  • Capeling: Original creator of the mod.
  • OmgRod: Previous maintainer of the mod.
  • slideglide: Current maintainer of the mod.

v2.0.2

  • Port to Geode v6.0.0-beta.1
  • Make the scale parameter in the update functions of the API an std::optional
  • Potentially fix the positioning of the stats menu for mobile, report if there are any bugs

v2.0.1

  • Potentially fix the stats icons being comically small on mobile

v2.0.0

  • Rewrite of the entire API! (ABI breaking; if you, as a developer, have a mod that uses the legacy API, you should update it to use the new API)
  • Numbers are now abbreviated to prevent stats with large values from overlapping with other elements on the icon kit
  • Added adaptive scaling: the stats menu should now reliably scale itself depending on your screen resolution now!
  • Previous page and next page arrows now get disabled depending on the page

v1.3.3

  • Changed old GitHub links

v1.3.2

  • Updated to v5.9.0
  • Made the API use geode::Label instead of CCLabelBMFont for labels
  • Cleaned up the code
  • Fixed a bug where the icon kit rope caused the stats menu to go down, and other improvements for different aspect ratios

v1.3.1

v1.3.1-beta.2

  • Fix ODR issue (I hope)

v1.3.1-beta.1

  • Add API tag

v1.3.0

v1.2.1

v1.2.0

  • Update to Geode v4.6.1
  • Add API tag

v1.1.0

  • Added Capeling back as a developer
  • Auto-scale and resize stats menu

v1.0.4

  • Changed mod ID

v1.0.3

  • Ported to iOS
  • Bugfix for issue in which the stats menu goes under the corner if too many stats are added

v1.0.2

  • 2.207 support

v1.0.1

  • Fix for other platforms (hopefully)

v1.0.0

  • Initial release

Original Site made by HJfod. Geode 2 parody-ish by MeFinity.

Geode-SDK is the property of the Geode Team.


This website (Geode 2, Codename Malachite) is not affiliated with the Geode Team in any way shape or form.