Hey! I’m still quite new to ProffieOS and particularly Lightsabers.
I have been trying to create a way for an accent LED to be in a different color depending on which mode you have selected (for example red = kill, green = auto, blue = stun). I tried searching the documentation and on here but couldn’t find it.
My thought was to perhaps get the current mode from the blaster.h file into a IsLessThan function in the blade style, but I haven’t been able to find a way to do that.
Do you guys have any ideas on how to do something like this, if possible.
That’s a blade style thing.
I don’t think I’ve ever seen it used before, but you should be able to use ColorSelect<> with EFFECT_MODE.
Try something like:
lol. I would second this, do not try to start learning C++ with ProffieOS blade styles. Templating and meta programming is not exactly beginner friendly
// blaster_mode.h
#ifndef FUNCTIONS_BLASTER_MODE_H
#define FUNCTIONS_BLASTER_MODE_H
#ifdef BLASTER_SHOTS_UNTIL_EMPTY
#include "props/blaster.h"
// Usage: BlasterModeF
// Returns the current blaster mode as an integer:
// 0 for MODE_STUN, 1 for MODE_KILL, 2 for MODE_AUTO
// This function should only be used when BLASTER_SHOTS_UNTIL_EMPTY is defined,
// indicating that the current prop is a Blaster.
// Example usage in a style:
// StylePtr<ColorSelect<BlasterModeF, TrInstant, Red, Green, Blue>>()
extern Blaster prop;
class BlasterModeSVF {
public:
void run(BladeBase* blade) {}
int getInteger(int led) { return prop.blaster_mode; }
int calculate(BladeBase* blade) { return prop.blaster_mode; }
};
template<>
class SingleValueAdapter<BlasterModeSVF> : public BlasterModeSVF {};
using BlasterModeF = SingleValueAdapter<BlasterModeSVF>;
#endif // BLASTER_SHOTS_UNTIL_EMPTY
#endif // FUNCTIONS_BLASTER_MODE_H
Nope, not even a little bit.
However, there are a few issues:
prop files have side effects and should only be included once, and only if that’s the prop file you want to use. To work around this, you can add a global function for getting the blaster mode. This function would be declared in this file, and defined in blaster.h, which would mean that you get a linker error if you try to use without the blaster prop.
Not all blasters use BLASTER_SHOTS_UNTIL_EMPTY, so it’s not the best define to use to decide if we should have a BlasterModeSVF or not. In fact, we don’t need an #ifdef at all since we’ll get a linker error (see 1 above)