FIXME: when C++23, use std::expected here
| 130 | |
| 131 | //FIXME: when C++23, use std::expected here |
| 132 | static std::optional<ClothingRequirement> createFromParameters(color_ostream &out, vector<string> ¶meters) |
| 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; |
nothing calls this directly
no test coverage detected