Generic factory std::map support #79590
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Infrastructure "generic factory std::map support"
Purpose of change
This is a major obstacle on the long road to completing #36851. We have a ton of weighted list (or functional equivalent) fields for items that are read manually.
Describe the solution
A handler for std::map in generic_factory allows two new readers to be added:
pair_reader
, which loads simple type pairs into a mapweighted_string_id_reader
, which loads pairs of string_ids and floats/ints in a variety of shorthanded formatsDescribe alternatives you've considered
Anything more complex than a map should be a separately loaded object, string_id-typed if necessary
Testing
I didn't include any implementations of these readers, but I did test with two fields from
![image](https://private-user-images.githubusercontent.com/65314588/411052459-e902f757-b1b1-4172-953d-a372786b109e.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkxODg2NjIsIm5iZiI6MTczOTE4ODM2MiwicGF0aCI6Ii82NTMxNDU4OC80MTEwNTI0NTktZTkwMmY3NTctYjFiMS00MTcyLTk1M2QtYTM3Mjc4NmIxMDllLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEwVDExNTI0MlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWMyNjUwMzY0ZmQ3NjcyOTMyMWRkMmViOTM3ODAyM2MwYmU4ZmMwZmIwMGY5MzExYmVkZDY1YzQ5NTBhNzA3NmEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.skQviYTRVi7YI5-vt-O5ImSbPYecg8paVXBuPMedsbI)
Item_factory::load( islot_comestible &slot, ...)
like so:For the weighted_string_id_reader, I had to reformat the
contamination
field, but it otherwise worked fine with every format (array of arrays, string_id array, single string_id), and I verified that the fields loaded correctly in the debugger. Drinking murky water still gave food poisoning.For the pair_reader, modding a
retool_ar15_223rem_short
onto an AR-15 worked the same as without the pair_reader (tested with an earlier CDDA build).Additional context
I've done a lot of studying of item_factory and generic_factory code, so I hope to start working on migrations from the former to the latter soon.