-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Configurable key binding and offset (mCount) save/restore (#10)
* working on mcount offset * mcount and configure works * format * extra space
- Loading branch information
1 parent
c2041f5
commit faf8486
Showing
36 changed files
with
1,225 additions
and
904 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#pragma once | ||
|
||
#include "types.h" | ||
#include "util/StringBuffer.hpp" | ||
|
||
namespace botwsavs::core { | ||
enum Key : u32 { | ||
A = 0, | ||
B = 1 << 1, | ||
ZL = 1 << 2, | ||
Y = 1 << 3, | ||
X = 1 << 4, | ||
ZR = 1 << 5, | ||
RStick = 1 << 6, | ||
LStick = 1 << 7, | ||
|
||
Minus = (1 << 9) | (1 << 12), | ||
Plus = (1 << 10) | (1 << 11), | ||
|
||
L = 1 << 13, | ||
R = 1 << 14, | ||
|
||
DpadUp = 1 << 16, | ||
DpadDown = 1 << 17, | ||
DpadLeft = 1 << 18, | ||
DpadRight = 1 << 19 | ||
}; | ||
|
||
namespace key { | ||
template <u32 L> | ||
void GetKeyString(u32 mask, util::StringBuffer<L>& outBuffer) { | ||
static_assert(L >= 100, "Key string buffer length should be at least 100"); | ||
outBuffer.Clear(); | ||
if (mask == 0) { | ||
return; | ||
} | ||
if (mask & Key::A) { | ||
outBuffer.SafeAppend("A+"); | ||
} | ||
if (mask & Key::B) { | ||
outBuffer.SafeAppend("B+"); | ||
} | ||
if (mask & Key::X) { | ||
outBuffer.SafeAppend("X+"); | ||
} | ||
if (mask & Key::Y) { | ||
outBuffer.SafeAppend("Y+"); | ||
} | ||
if (mask & Key::L) { | ||
outBuffer.SafeAppend("L+"); | ||
} | ||
if (mask & Key::R) { | ||
outBuffer.SafeAppend("R+"); | ||
} | ||
if (mask & Key::ZL) { | ||
outBuffer.SafeAppend("ZL+"); | ||
} | ||
if (mask & Key::ZR) { | ||
outBuffer.SafeAppend("ZR+"); | ||
} | ||
if (mask & Key::DpadUp) { | ||
outBuffer.SafeAppend("DpadUp+"); | ||
} | ||
if (mask & Key::DpadDown) { | ||
outBuffer.SafeAppend("DpadDown+"); | ||
} | ||
if (mask & Key::DpadLeft) { | ||
outBuffer.SafeAppend("DpadLeft+"); | ||
} | ||
if (mask & Key::DpadRight) { | ||
outBuffer.SafeAppend("DpadRight+"); | ||
} | ||
if (mask & Key::Minus) { | ||
outBuffer.SafeAppend("Minus+"); | ||
} | ||
if (mask & Key::Plus) { | ||
outBuffer.SafeAppend("Plus+"); | ||
} | ||
if (mask & Key::LStick) { | ||
outBuffer.SafeAppend("LStick+"); | ||
} | ||
if (mask & Key::RStick) { | ||
outBuffer.SafeAppend("RStick+"); | ||
} | ||
outBuffer.SafeDeleteEnd(1); | ||
} | ||
} // namespace key | ||
} // namespace botwsavs::core |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#include "KeyMgr.hpp" | ||
#include "fs/ConfigFile.hpp" | ||
#include "fs/Logger.hpp" | ||
|
||
namespace botwsavs::core { | ||
|
||
bool KeyMgr::DidHoldFor(u32 keys, u32 seconds) { | ||
if (mHoldingKeys != keys) { | ||
mHoldCounter = 0; | ||
mHoldingKeys = keys; | ||
} else { | ||
mHoldCounter++; | ||
} | ||
// 1 tick = 3 frames | ||
// 1s = 30 frames = 10 ticks | ||
u32 ticks = seconds * 10; | ||
if (mHoldCounter >= ticks) { | ||
mHoldCounter = 0; | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
void KeyMgr::StartConfigure(u32* configureKey) { | ||
info("Configuring key binding"); | ||
ClearHold(); | ||
mpConfiguringKey = configureKey; | ||
mConfigureCounter = 0; | ||
} | ||
|
||
KeyMgr::ConfigureResult KeyMgr::FinishConfigure(u32 newKey) { | ||
if (newKey == 0) { | ||
mConfigureCounter = 0; | ||
return ConfigureResult::Pending; | ||
} | ||
if (mConfigureCounter < 30) { | ||
mConfigureCounter++; | ||
return ConfigureResult::Pending; | ||
} | ||
|
||
ClearHold(); | ||
if (newKey == 0) { | ||
mpConfiguringKey = nullptr; | ||
return ConfigureResult::FailEmpty; | ||
} | ||
*mpConfiguringKey = newKey; | ||
mpConfiguringKey = nullptr; | ||
infof("New combo: %x", newKey); | ||
return ConfigureResult::Success; | ||
} | ||
|
||
void KeyMgr::Save(fs::ConfigFile& file) const { | ||
file.WriteInteger(named(mKeySave)); | ||
file.WriteInteger(named(mKeySaveFile)); | ||
file.WriteInteger(named(mKeyRestore)); | ||
file.WriteInteger(named(mKeyRestoreFile)); | ||
} | ||
|
||
void KeyMgr::Load(fs::ConfigFile& file) { | ||
file.ReadInteger(&mKeySave); | ||
file.ReadInteger(&mKeySaveFile); | ||
file.ReadInteger(&mKeyRestore); | ||
file.ReadInteger(&mKeyRestoreFile); | ||
} | ||
|
||
} // namespace botwsavs::core |
Oops, something went wrong.