本文整理汇总了C++中input_manager::get_keycode方法的典型用法代码示例。如果您正苦于以下问题:C++ input_manager::get_keycode方法的具体用法?C++ input_manager::get_keycode怎么用?C++ input_manager::get_keycode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类input_manager
的用法示例。
在下文中一共展示了input_manager::get_keycode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init
void input_manager::init() {
init_keycode_mapping();
std::ifstream data_file;
picojson::value input_value;
std::string file_name = "data/raw/keybindings.json";
data_file.open(file_name.c_str());
if(!data_file.good()) {
throw "Could not read " + file_name;
}
data_file >> input_value;
data_file.close();
if(!input_value.is<picojson::array>()) {
throw file_name + "is not an array";
}
//Crawl through once and create an entry for every definition
const picojson::array& root = input_value.get<picojson::array>();
for (picojson::array::const_iterator entry = root.begin();
entry != root.end(); ++entry) {
if( !(entry->is<picojson::object>()) ){
debugmsg("Invalid keybinding setting, entry not a JSON object");
continue;
}
// JSON object representing the action
const picojson::value& action_object = *entry;
const std::string& action_id = action_object.get("id").get<std::string>();
std::string context = "default";
if(action_object.contains("category")) {
context = action_object.get("category").get<std::string>();
}
// Iterate over the bindings JSON array
const picojson::array& keybindings = action_object.get("bindings").get<picojson::array>();
for (picojson::array::const_iterator subentry = keybindings.begin();
subentry != keybindings.end(); ++subentry) {
const picojson::value& keybinding = *subentry;
const std::string& input_method = keybinding.get("input_method").get<std::string>();
input_event new_event;
if(input_method == "keyboard") {
new_event.type = CATA_INPUT_KEYBOARD;
} else if(input_method == "gamepad") {
new_event.type = CATA_INPUT_GAMEPAD;
}
if(keybinding.get("key").is<std::string>()) {
const std::string& key = keybinding.get("key").get<std::string>();
new_event.sequence.push_back(inp_mngr.get_keycode(key));
} else if(keybinding.get("key").is<picojson::array>()) {
picojson::array keys = keybinding.get("key").get<picojson::array>();
for(int i=0; i<keys.size(); i++) {
const std::string& next_key = keybinding.get("key").get(i).get<std::string>();
new_event.sequence.push_back(inp_mngr.get_keycode(next_key));
}
}
if(context == "default") {
action_to_input[action_id].push_back(new_event);
} else {
action_contexts[context][action_id].push_back(new_event);
}
}
if(!action_object.contains("name")) {
actionID_to_name[action_id] = action_id;
} else {
actionID_to_name[action_id] = action_object.get("name").get<std::string>();
}
}
}