InputDefinition.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * InputDefintion.h
  3. *
  4. * Created on: 5 déc. 2020
  5. * Author: fanch
  6. */
  7. #ifndef SRC_INPUTDEFINTION_H_
  8. #define SRC_INPUTDEFINTION_H_
  9. #include "utils.h"
  10. #include "AbsInput.h"
  11. /**
  12. * @brief Classe qui représente un type d'input défini dans le JSON. Il permet d'instancier et de
  13. * configurer les boutons et controllers.
  14. */
  15. class InputDefinition
  16. {
  17. public:
  18. InputDefinition(){}
  19. InputDefinition(const std::string& name, Json::Value& v){
  20. m_name=name;
  21. Json::Value root = v["actions"];
  22. for( Json::Value::const_iterator itr = root.begin() ; itr != root.end() ; itr++ ) {
  23. std::string k = itr.key().asString();
  24. Json::Value v = *itr;
  25. m_actions.push_back(new InputActionList(k, new InputAction("", v)));
  26. }
  27. std::string t = v["type"].asString();
  28. if(t=="BUTTON") m_type=BUTTON;
  29. if(t=="CONTROLLER") m_type=CONTROLLER;
  30. }
  31. virtual ~InputDefinition(){
  32. int s = m_actions.size();
  33. for(int i=0; i<s; i++) delete m_actions[i];
  34. }
  35. AbsInput* instanciate(PadDefinition* p, Json::Value& v);
  36. protected:
  37. std::string m_name;
  38. InputType m_type;
  39. std::vector<InputActionList*> m_actions;
  40. friend class PadDefinition;
  41. };
  42. #endif /* SRC_INPUTDEFINTION_H_ */