#include #include #include #include "../dependency/main.hpp" using namespace geode::prelude; auto test = []() { log::info("Static logged"); return 0; }; // Exported functions $on_mod(Loaded) { log::info("Loaded"); } static std::string s_recievedEvent; // Events $execute { new EventListener(+[](TestEvent* event) { log::info("Received event: {}", event->getData()); s_recievedEvent = event->getData(); }); } #include struct $modify(MenuLayer) { bool init() { if (!MenuLayer::init()) return false; auto node = CCNode::create(); auto ref = WeakRef(node); log::info("ref: {}", ref.lock().data()); node->release(); log::info("ref: {}", ref.lock().data()); // Launch arguments log::info("Testing launch args..."); log::NestScope nest; log::info("For global context:"); { log::NestScope nest; for (const auto& arg : Loader::get()->getLaunchArgumentNames()) { log::info("{}", arg); } } log::info("For this mod:"); { log::NestScope nest; for (const auto& arg : Mod::get()->getLaunchArgumentNames()) { log::info("{}", arg); } } log::info("Mod has launch arg 'mod-arg': {}", Mod::get()->hasLaunchArgument("mod-arg")); log::info("Loader flag 'bool-arg': {}", Loader::get()->getLaunchFlag("bool-arg")); log::info("Loader int 'int-arg': {}", Loader::get()->parseLaunchArgument("int-arg").unwrapOr(0)); log::debug("should run second!"); return true; } }; // Modify #include struct GJGarageLayerTest : Modify { struct Fields { int myValue = 1907; std::string myString = "yeah have fun finding a better thing for this"; }; bool init() { if (!GJGarageLayer::init()) return false; auto label = CCLabelBMFont::create("Modify works!", "bigFont.fnt"); label->setPosition(100, 110); label->setScale(.4f); label->setZOrder(99999); addChild(label); if (m_fields->myValue == 1907 && m_fields->myString != "") { auto label = CCLabelBMFont::create("Field default works!", "bigFont.fnt"); label->setPosition(100, 100); label->setScale(.4f); label->setZOrder(99999); addChild(label); } // Saved Values auto timesOpened = Mod::get()->getSavedValue("times-opened", 0); Mod::get()->setSavedValue("times-opened", timesOpened + 1); auto label2 = CCLabelBMFont::create( fmt::format("Times opened: {}", timesOpened).c_str(), "bigFont.fnt" ); label2->setPosition(100, 90); label2->setScale(.4f); label2->setZOrder(99999); addChild(label2); // Dispatch system pt. 1 MyDispatchEvent("geode.test/test-garage-open", this).post(); if (s_recievedEvent.size() > 0) { auto label = CCLabelBMFont::create("Event works!", "bigFont.fnt"); label->setPosition(100, 70); label->setScale(.4f); label->setZOrder(99999); addChild(label); } return true; } }; #include struct GJGarageLayerTest2 : Modify { struct Fields { int myOtherValue = 80085; }; bool init() { if (!GJGarageLayer::init()) return false; if (m_fields->myOtherValue == 80085) { auto label = CCLabelBMFont::create("Alternate Fields works!", "bigFont.fnt"); label->setPosition(100, 60); label->setScale(.4f); label->setZOrder(99999); this->addChild(label); } return true; } };