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

Method constructor

source/windowing/StarWidgetParsing.cpp:85–117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

83}
84
85List<WidgetConstructResult> WidgetParser::constructor(Json const& config) {
86 List<WidgetConstructResult> widgets;
87
88 auto addWidget = [this, &widgets](Json const& memberConfig) {
89 if (memberConfig.type() != Json::Type::Object || !memberConfig.contains("type") || !memberConfig.contains("name"))
90 throw WidgetParserException(
91 "Malformed gui json: member configuration is either not a map, or does not specify a widget name and type");
92 String type = memberConfig.getString("type");
93 if (type == "include") {
94 widgets.appendAll(constructor(Root::singleton().assets()->json(memberConfig.getString("file"))));
95 } else {
96 if (!m_constructors.contains(type)) {
97 throw WidgetParserException(strf("Unknown type in gui json. {}", type));
98 }
99 auto constructResult =
100 m_constructors.get(memberConfig.getString("type"))(memberConfig.getString("name"), memberConfig);
101 if (constructResult.obj)
102 widgets.append(constructResult);
103 }
104 };
105
106 if (config.isType(Json::Type::Object)) {
107 for (auto const& kvpair : config.iterateObject())
108 addWidget(kvpair.second.set("name", kvpair.first));
109 } else if (config.isType(Json::Type::Array)) {
110 for (auto const& elem : config.iterateArray())
111 addWidget(elem);
112 } else {
113 throw WidgetParserException(strf("Malformed gui json, expected a Map or a List. Instead got {}", config));
114 }
115
116 return widgets;
117}
118
119void WidgetParser::registerCallback(String const& name, WidgetCallbackFunc callback) {
120 m_callbacks[name] = callback;

Callers

nothing calls this directly

Calls 15

constructorFunction · 0.85
singletonClass · 0.85
strfFunction · 0.85
getStringMethod · 0.80
appendAllMethod · 0.80
jsonMethod · 0.80
assetsMethod · 0.80
iterateObjectMethod · 0.80
iterateArrayMethod · 0.80
typeMethod · 0.45
containsMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected