MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / inputDescriptorFromJson

Function inputDescriptorFromJson

source/windowing/StarKeyBindings.cpp:100–121  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

98}
99
100KeyChord inputDescriptorFromJson(Json const& json) {
101 Key key;
102 auto type = json.getString("type");
103 if (type == "key") {
104 auto value = json.get("value");
105 if (value.isType(Json::Type::String)) {
106 key = KeyNames.getLeft(value.toString());
107 } else if (value.canConvert(Json::Type::Int)) {
108 key = (Key)value.toUInt();
109 } else {
110 throw StarException::format("Improper key value '{}'", value);
111 }
112 } else {
113 throw StarException::format("Improper bindings type '{}'", type);
114 }
115
116 KeyMod mods = KeyMod::NoMod;
117 for (auto mod : json.get("mods").iterateArray())
118 mods |= KeyModNames.getLeft(mod.toString());
119
120 return {key, mods};
121}
122
123Json inputDescriptorToJson(KeyChord const& chord) {
124 JsonArray modNames;

Callers 3

KeyBindingsMethod · 0.85
buildListsFromConfigMethod · 0.85
setKeybindingMethod · 0.85

Calls 8

getStringMethod · 0.80
canConvertMethod · 0.80
toUIntMethod · 0.80
iterateArrayMethod · 0.80
formatFunction · 0.50
getMethod · 0.45
isTypeMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected