MCPcopy Create free account
hub / github.com/DFHack/dfhack / createFromParameters

Method createFromParameters

plugins/autoclothing.cpp:132–163  ·  view source on GitHub ↗

FIXME: when C++23, use std::expected here

Source from the content-addressed store, hash-verified

130
131 //FIXME: when C++23, use std::expected here
132 static std::optional<ClothingRequirement> createFromParameters(color_ostream &out, vector<string> &parameters)
133 {
134 df::job_material_category material_category;
135 if (parameters.size() < 1) return std::nullopt;
136
137 size_t idx = 0;
138 if (parameters[0] == "clear") idx++;
139
140 if (parameters.size() < idx + 1) return std::nullopt;
141
142 if (!set_bitfield_field(&material_category, parameters[idx], 1))
143 {
144 out << "Unrecognized material type: " << parameters[idx] << endl;
145 return std::nullopt;
146 }
147
148 if (auto req = setItem(parameters[idx+1]); !req)
149 {
150 out << "Unrecognized item name or token: " << parameters[idx+1] << endl;
151 return std::nullopt;
152 }
153
154 else if (!validateMaterialCategory(*req)) {
155 out << parameters[idx] << " is not a valid material category for " << parameters[idx+1] << endl;
156 return std::nullopt;
157 }
158 else
159 {
160 req->material_category = material_category;
161 return req;
162 }
163 }
164
165 string ToReadableLabel() {
166 std::stringstream stream;

Callers

nothing calls this directly

Calls 4

set_bitfield_fieldFunction · 0.85
setItemFunction · 0.85
validateMaterialCategoryFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected