McRogueFace/src/Scene.h
John McCardle d6446e18ea Tinkering with input
I want to move keyboard input defs to the Python API. I laid the groundwork for it today.

From the JANKFILE:

- working on API endpoint `_registerInputAction`.

it will add "_py" as a suffix to the action string and register it along with other scene actions.

- Adding public Scene methods. These are on the base class with default of return `false`.

`bool Scene::registerActionInjected(int code, std::string name)` and `unregisterActionInjected`

the PythonScene (and other scenes that support injected user input) can override this method, check existing registrations, and return `true` when succeeding.

Also, upgraded to C++20 (g++ `c++2a`), mostly because I want to use map::contains.
2023-07-13 23:01:09 -04:00

40 lines
1.1 KiB
C++

#pragma once
// macros for scene input
#define ACTION(X, Y) (name.compare(X) == 0 && type.compare(Y) == 0)
#define ACTIONONCE(X) ((name.compare(X) == 0 && type.compare("start") == 0 && !actionState[name]))
#define ACTIONAFTER(X) ((name.compare(X) == 0 && type.compare("end") == 0))
#define ACTIONPY ((name.size() > 3 && name.compare(name.size() - 3, 3, "_py") == 0))
#include "Common.h"
//#include "GameEngine.h"
class GameEngine; // forward declare
class Scene
{
protected:
bool hasEnded = false;
bool paused = false;
std::map<int, std::string> actions;
std::map<std::string, bool> actionState;
GameEngine* game;
void simulate(int);
void registerAction(int, std::string);
public:
//Scene();
Scene(GameEngine*);
virtual void update() = 0;
virtual void sRender() = 0;
virtual void doAction(std::string, std::string) = 0;
bool hasAction(std::string);
bool hasAction(int);
std::string action(int);
virtual bool registerActionInjected(int, std::string);
virtual bool unregisterActionInjected(int, std::string);
};