* There are many repeated (un)serialization cases throughout the stockpile_settings structure, * so the most common cases have been generalized into generic functions using lambdas. * * The basic process to serialize a stockpile_settings structure is: * 1. loop through the list * 2. for every element that is TRUE: * 3. map the specific stockpile_settings index into a general material, crea
| 271 | * The unserialization process is the same in reverse. |
| 272 | */ |
| 273 | static bool serialize_list_itemdef(color_ostream& out, FuncWriteExport add_value, |
| 274 | vector<char> list, |
| 275 | vector<df::itemdef*> items, |
| 276 | item_type::item_type type) { |
| 277 | bool all = true; |
| 278 | for (size_t i = 0; i < list.size(); ++i) { |
| 279 | if (!list.at(i)) { |
| 280 | all = false; |
| 281 | continue; |
| 282 | } |
| 283 | const df::itemdef* a = items.at(i); |
| 284 | // skip procedurally generated items |
| 285 | if (a->base_flags.is_set(df::itemdef_flags::GENERATED)) |
| 286 | continue; |
| 287 | ItemTypeInfo ii; |
| 288 | if (!ii.decode(type, i)) |
| 289 | continue; |
| 290 | DEBUG(log, out).print("adding itemdef type {}\n", ii.getToken()); |
| 291 | add_value(ii.getToken()); |
| 292 | } |
| 293 | return all; |
| 294 | } |
| 295 | |
| 296 | static void unserialize_list_itemdef(color_ostream& out, const char* subcat, bool all, char val, const vector<string>& filters, |
| 297 | FuncReadImport read_value, int32_t list_size, vector<char>& pile_list, item_type::item_type type) { |