Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic factory std::map support #79590

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ShnitzelX2
Copy link
Contributor

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 map
  • weighted_string_id_reader, which loads pairs of string_ids and floats/ints in a variety of shorthanded formats

Describe 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 Item_factory::load( islot_comestible &slot, ...) like so:
image

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.

@github-actions github-actions bot added [C++] Changes (can be) made in C++. Previously named `Code` Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style json-styled JSON lint passed, label assigned by github actions astyled astyled PR, label is assigned by github actions labels Feb 7, 2025
@RenechCDDA
Copy link
Member

This is some important infrastructure work, thank you for doing it.

nutrients::deserialize contains an existing (de)serialization of a map, if you want a live example to work with. Also the map normally contains a union, for extra stress testing :)

@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label Feb 8, 2025
@ShnitzelX2 ShnitzelX2 marked this pull request as draft February 8, 2025 23:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions [C++] Changes (can be) made in C++. Previously named `Code` Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style json-styled JSON lint passed, label assigned by github actions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants