Skip to content

Commit ba4426b

Browse files
committed
Move controller states out of keyboard controls.
1 parent 264172f commit ba4426b

20 files changed

+638
-393
lines changed

SerialPrograms/Source/CommonFramework/Globals.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace PokemonAutomation{
2626
const bool IS_BETA_VERSION = true;
2727
const int PROGRAM_VERSION_MAJOR = 0;
2828
const int PROGRAM_VERSION_MINOR = 60;
29-
const int PROGRAM_VERSION_PATCH = 1;
29+
const int PROGRAM_VERSION_PATCH = 2;
3030

3131
const std::string PROGRAM_VERSION_BASE =
3232
"v" + std::to_string(PROGRAM_VERSION_MAJOR) +

SerialPrograms/Source/Controllers/Controller.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ enum class ControllerClass;
2424

2525

2626

27+
#if 0
2728
inline Milliseconds round_up_to_ticksize(Milliseconds ticksize, Milliseconds duration){
2829
if (ticksize == Milliseconds::zero()){
2930
return duration;
3031
}
3132
return (duration + ticksize - Milliseconds(1)) / ticksize * ticksize;
3233
}
33-
34+
#endif
3435

3536

3637

@@ -302,7 +303,7 @@ class ControllerContext final : public CancellableScope{
302303

303304
using AbstractControllerContext = ControllerContext<AbstractController>;
304305

305-
using AbstractControllerContext = ControllerContext<AbstractController>;
306+
306307

307308

308309

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* Controller State
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#include "Common/Cpp/Json/JsonValue.h"
8+
#include "CommonFramework/Exceptions/OperationFailedException.h"
9+
#include "ControllerState.h"
10+
11+
namespace PokemonAutomation{
12+
13+
14+
15+
16+
void ControllerState::load_json(const JsonValue& json){
17+
throw OperationFailedException(
18+
ErrorReport::NO_ERROR_REPORT,
19+
"This controller does not support serialization."
20+
);
21+
}
22+
JsonValue ControllerState::to_json() const{
23+
throw OperationFailedException(
24+
ErrorReport::NO_ERROR_REPORT,
25+
"This controller does not support serialization."
26+
);
27+
}
28+
void ControllerState::execute(
29+
CancellableScope& scope,
30+
AbstractController& controller,
31+
Milliseconds duration
32+
) const{
33+
throw OperationFailedException(
34+
ErrorReport::NO_ERROR_REPORT,
35+
"This controller does not support execution."
36+
);
37+
}
38+
std::string ControllerState::to_cpp(Milliseconds hold, Milliseconds release) const{
39+
throw OperationFailedException(
40+
ErrorReport::NO_ERROR_REPORT,
41+
"This controller does not support cpp conversion."
42+
);
43+
}
44+
45+
46+
47+
48+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/* Controller State
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_Controllers_ControllerState_H
8+
#define PokemonAutomation_Controllers_ControllerState_H
9+
10+
#include "Common/Cpp/Time.h"
11+
12+
namespace PokemonAutomation{
13+
14+
class JsonValue;
15+
class CancellableScope;
16+
class AbstractController;
17+
18+
19+
20+
21+
22+
23+
class ControllerState{
24+
public:
25+
virtual ~ControllerState() = default;
26+
27+
virtual void clear() = 0;
28+
29+
virtual bool operator==(const ControllerState& x) const = 0;
30+
virtual bool operator!=(const ControllerState& x) const{ return !(*this == x); }
31+
32+
virtual bool is_neutral() const = 0;
33+
34+
public:
35+
// Serialization
36+
virtual void load_json(const JsonValue& json);
37+
virtual JsonValue to_json() const;
38+
39+
public:
40+
// Execution
41+
virtual void execute(
42+
CancellableScope& scope,
43+
AbstractController& controller,
44+
Milliseconds duration
45+
) const;
46+
virtual std::string to_cpp(Milliseconds hold, Milliseconds release) const;
47+
};
48+
49+
50+
51+
52+
53+
54+
55+
56+
}
57+
#endif

SerialPrograms/Source/Controllers/KeyboardInput/KeyboardInput.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "CommonFramework/GlobalSettingsPanel.h"
1010
#include "CommonFramework/Logging/Logger.h"
1111
#include "CommonFramework/Options/Environment/PerformanceOptions.h"
12+
#include "Controllers/ControllerState.h"
1213
#include "Controllers/KeyboardInput/GlobalQtKeyMap.h"
1314
#include "KeyboardInput.h"
1415

SerialPrograms/Source/Controllers/KeyboardInput/KeyboardInput.h

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <map>
1111
#include <condition_variable>
1212
#include <Qt>
13-
#include "Common/Cpp/Json/JsonValue.h"
13+
//#include "Common/Cpp/Json/JsonValue.h"
1414
#include "Common/Cpp/Concurrency/SpinLock.h"
1515
#include "Common/Cpp/Concurrency/Thread.h"
1616
#include "Controllers/Controller.h"
@@ -23,31 +23,6 @@ class QKeyEvent;
2323
namespace PokemonAutomation{
2424

2525

26-
class ControllerSession;
27-
28-
29-
30-
31-
class ControllerState{
32-
public:
33-
virtual ~ControllerState() = default;
34-
35-
virtual void clear() = 0;
36-
37-
virtual bool operator==(const ControllerState& x) const = 0;
38-
virtual bool operator!=(const ControllerState& x) const{ return !(*this == x); }
39-
40-
virtual bool is_neutral() const = 0;
41-
42-
public:
43-
// Serialization
44-
virtual void load_json(const JsonValue& json){};
45-
virtual JsonValue to_json() const{ return JsonValue(); };
46-
virtual std::string to_cpp(Milliseconds hold, Milliseconds release) const{ return ""; }
47-
virtual void execute(AbstractControllerContext& context, Milliseconds duration) const{}
48-
};
49-
50-
5126

5227

5328
class KeyboardInputController{

SerialPrograms/Source/Controllers/StandardHid/StandardHid_Keyboard.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "CommonFramework/GlobalSettingsPanel.h"
1010
#include "CommonTools/Async/InterruptableCommands.tpp"
1111
#include "CommonTools/Async/SuperControlSession.tpp"
12+
#include "Controllers/ControllerState.h"
1213
#include "Controllers/KeyboardInput/KeyboardInput.h"
1314
#include "StandardHid_Keyboard_KeyMappings.h"
1415
#include "StandardHid_Keyboard.h"

SerialPrograms/Source/NintendoSwitch/Controllers/NintendoSwitch_Joycon.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "Controllers/KeyboardInput/KeyboardInput.h"
1212
#include "NintendoSwitch/NintendoSwitch_Settings.h"
1313
#include "NintendoSwitch_VirtualControllerState.h"
14+
#include "NintendoSwitch_JoyconState.h"
1415
#include "NintendoSwitch_Joycon.h"
1516

1617
namespace PokemonAutomation{
@@ -122,5 +123,17 @@ void JoyconController::remove_keyboard_listener(KeyboardEventHandler::KeyboardLi
122123

123124

124125

126+
127+
ControllerClass LeftJoycon::controller_class() const{
128+
return ControllerClass::NintendoSwitch_LeftJoycon;
129+
}
130+
ControllerClass RightJoycon::controller_class() const{
131+
return ControllerClass::NintendoSwitch_RightJoycon;
132+
}
133+
134+
135+
136+
137+
125138
}
126139
}

SerialPrograms/Source/NintendoSwitch/Controllers/NintendoSwitch_Joycon.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ using JoyconContext = ControllerContext<JoyconController>;
2121

2222

2323

24-
constexpr Button VALID_LEFT_JOYCON_BUTTONS =
24+
static constexpr Button VALID_LEFT_JOYCON_BUTTONS =
2525
BUTTON_DOWN |
2626
BUTTON_UP |
2727
BUTTON_RIGHT |
@@ -34,7 +34,7 @@ constexpr Button VALID_LEFT_JOYCON_BUTTONS =
3434
BUTTON_LCLICK |
3535
BUTTON_CAPTURE;
3636

37-
constexpr Button VALID_RIGHT_JOYCON_BUTTONS =
37+
static constexpr Button VALID_RIGHT_JOYCON_BUTTONS =
3838
BUTTON_Y |
3939
BUTTON_X |
4040
BUTTON_B |
@@ -50,6 +50,8 @@ constexpr Button VALID_RIGHT_JOYCON_BUTTONS =
5050

5151

5252

53+
54+
5355
class JoyconController : public AbstractController{
5456
public:
5557
using ContextType = JoyconContext;
@@ -192,9 +194,7 @@ class LeftJoycon : public JoyconController{
192194
virtual const char* name() override{
193195
return NAME;
194196
};
195-
virtual ControllerClass controller_class() const override{
196-
return ControllerClass::NintendoSwitch_LeftJoycon;
197-
}
197+
virtual ControllerClass controller_class() const override;
198198
};
199199
class RightJoycon : public JoyconController{
200200
public:
@@ -204,9 +204,7 @@ class RightJoycon : public JoyconController{
204204
virtual const char* name() override{
205205
return NAME;
206206
};
207-
virtual ControllerClass controller_class() const override{
208-
return ControllerClass::NintendoSwitch_RightJoycon;
209-
}
207+
virtual ControllerClass controller_class() const override;
210208
};
211209

212210

0 commit comments

Comments
 (0)