Implemented functionality to change input map name

dev
Shariq Shah 10 years ago
parent 22e319e391
commit a40b11870d
  1. 9
      src/game.c
  2. 17
      src/input.c
  3. 1
      src/input.h

@ -43,21 +43,20 @@ void update(void)
log_message("MoveUp pressed!"); log_message("MoveUp pressed!");
if(input_map_state_get("MoveDown", GLFW_RELEASE)) if(input_map_state_get("MoveDown", GLFW_RELEASE))
{
input_map_remvove("Test");
log_message("MoveDown pressed!"); log_message("MoveDown pressed!");
}
if(input_map_state_get("Test", GLFW_RELEASE)) if(input_map_state_get("Test", GLFW_RELEASE))
log_message("Test released"); log_message("Test released");
if(input_map_state_get("Test2", GLFW_RELEASE)) if(input_map_state_get("Test2", GLFW_RELEASE))
{ {
int keys[] = {GLFW_KEY_R}; input_map_name_set("Test2", "NewTest");
input_map_keys_set("Test2", keys, 1);
log_message("Test2 released!"); log_message("Test2 released!");
} }
if(input_map_state_get("NewTest", GLFW_RELEASE))
log_message("NewTest released");
input_update(); input_update();
} }

@ -168,11 +168,26 @@ bool input_map_keys_set(const char* name, int* keys, int num_keys)
} }
success = true; success = true;
} }
if(!success) log_error("input:map_set_keys", "Map %s not found", name); if(!success) log_error("input:map_keys_set", "Map %s not found", name);
return success; return success;
} }
bool input_map_name_set(const char* name, const char* new_name)
{
assert(name && new_name);
bool success = false;
int index = map_find(name);
if(index > -1)
{
Input_Map* map = array_get(input_map_list, (unsigned int)index);
map->name = new_name;
success = true;
}
if(!success) log_error("input:map_name_set", "Map %s not found", name);
return success;
}
static int map_find(const char* name) static int map_find(const char* name)
{ {
int index = -1; int index = -1;

@ -33,5 +33,6 @@ bool input_map_state_get(const char* map_name, int state);
void input_map_create(const char* name, int* keys, size_t num_keys); void input_map_create(const char* name, int* keys, size_t num_keys);
bool input_map_remvove(const char* name); bool input_map_remvove(const char* name);
bool input_map_keys_set(const char* name, int* keys, int num_keys); bool input_map_keys_set(const char* name, int* keys, int num_keys);
bool input_map_name_set(const char* name, const char* new_name);
#endif #endif

Loading…
Cancel
Save