Effects - neotje/OCG GitHub Wiki

Adding an effect

  1. Create an effect class in the 'lib/effects' folder.
class MyEffect : public Effect {
    public:
        MyEffect() : Effect("Effect Menu name") { }
};
  1. Add the effect to 'effects' list in 'lib/effects/effects.h'.
void effectsSetup() {
    ...
    effects.add(new MyEffect());
    ...
}
  1. Add persistant config variables to 'include/types.h'.
struct MyEffectConfig {
    // Variables
};

struct Config {
    // ...
    MyEffectConfig myEffect;
};
  1. Set default values to 'include/config.h'
Config config = {
    // ...
    .myEffect = {
        // ...
    }
};

bool resetConfig() {
    config = {
        // ...
        .myEffect = {
            // ...
        }
    };
    
    // ...
}
  1. Add config screen to the menu state machine.
class MainMenuState : public MenuScreen {
    public:
        MainMenuState() { }
        ~MainMenuState() { }

        int onClick(int entryIndex) {
            if (entryIndex == 2) {
                switch (getConfig()->currentEffect) {
                    case /* myEffect index */:
                        return myEffectConfigScreen.index;

            }

            return -1;
        }
};