| 1 | #include "controller/seadPatternRumbleAddon.h" |
|---|---|
| 2 | |
| 3 | #include "basis/seadRawPrint.h" |
| 4 | |
| 5 | // unchecked copy from Wii U-decomp |
| 6 | namespace sead |
| 7 | { |
| 8 | PatternRumbleAddon::PatternRumbleAddon(Controller* controller) |
| 9 | : ControllerAddon(controller), mPattern(nullptr), mPatternIdx(0), mPatternDuration(0) |
| 10 | { |
| 11 | mId = ControllerDefine::cAddon_PatternRumble; |
| 12 | } |
| 13 | |
| 14 | bool PatternRumbleAddon::isPatternEnable() const |
| 15 | { |
| 16 | return mPattern != nullptr; |
| 17 | } |
| 18 | |
| 19 | void PatternRumbleAddon::startPattern(const char* pattern, u32 duration) |
| 20 | { |
| 21 | SEAD_ASSERT(pattern != nullptr); |
| 22 | |
| 23 | mPattern = pattern; |
| 24 | mPatternIdx = 0; |
| 25 | mPatternDuration = duration; |
| 26 | } |
| 27 | |
| 28 | void PatternRumbleAddon::stopPattern() |
| 29 | { |
| 30 | mPattern = nullptr; |
| 31 | mPatternIdx = 1; |
| 32 | mPatternDuration = 0; |
| 33 | } |
| 34 | |
| 35 | bool PatternRumbleAddon::calc() |
| 36 | { |
| 37 | if (mPattern) |
| 38 | { |
| 39 | if (mPattern[mPatternIdx] == '\0') |
| 40 | { |
| 41 | mPatternIdx = 0; |
| 42 | |
| 43 | if (mPatternDuration) |
| 44 | { |
| 45 | if (mPatternDuration == 1) |
| 46 | { |
| 47 | mPattern = nullptr; |
| 48 | mPatternDuration = 0; |
| 49 | stopRumbleImpl_(); |
| 50 | return false; |
| 51 | } |
| 52 | |
| 53 | mPatternDuration--; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | if (mPattern[mPatternIdx] == '*') |
| 58 | startRumbleImpl_(); |
| 59 | |
| 60 | else |
| 61 | stopRumbleImpl_(); |
| 62 | |
| 63 | mPatternIdx++; |
| 64 | } |
| 65 | else |
| 66 | { |
| 67 | if (mPatternIdx) |
| 68 | { |
| 69 | stopRumbleImpl_(); |
| 70 | mPatternIdx = 0; |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | return false; |
| 75 | } |
| 76 | |
| 77 | } // namespace sead |
| 78 |