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

Load faults / fault_fixes with generic_factory #73816

Merged
merged 2 commits into from
May 16, 2024

Conversation

irwiss
Copy link
Contributor

@irwiss irwiss commented May 15, 2024

Summary

None

Purpose of change

Load faults / fault_fixes with generic_factory

Describe the solution

Refactor, also slightly clean up the random fault of type and add a null sentinel

Describe alternatives you've considered

Testing

Dump faults and fixes before and after the patch, the difference should be the added null sentinel

Dump stub
static void dump()
{
  const auto dump_req = []( JsonOut & jo, const std::string & name, const requirement_data & rd ) {
      if( rd.is_empty() ) {
          return;
      }
      jo.write( name );
      jo.write_member_separator();
      rd.dump( jo );
  };
  {
      std::vector<std::string> fault_ids;
      for( const auto&[id, f] : faults_all ) {
          fault_ids.push_back( id.str() );
      }
      std::sort( fault_ids.begin(), fault_ids.end() );
      write_to_file( PATH_INFO::base_path_path() / "faults_dump.json", [&]( std::ostream & fout ) {
          JsonOut jo( fout, true );
          jo.start_array();
          for( const std::string &fid_str : fault_ids ) {
              const fault &f = fault_id( fid_str ).obj();
              jo.start_object( true );
              jo.member( "id", f.id().str() );
              jo.member( "name", f.name() );
              jo.member( "description", f.description() );
              jo.member( "get_fixes", f.get_fixes() );
              jo.member( "item_prefix", f.item_prefix() );
              jo.member( "type", f.type() );
              jo.member( "price_mod", f.price_mod() );
              //dump_req( jo, "install_reqs", vpi.install_requirements() );
              jo.end_object();
          }
          jo.end_array();
      } );

      std::vector<std::string> fix_ids;
      for( const auto &[id, f] : fault_fixes_all ) {
          fix_ids.push_back( id.str() );
      }
      std::sort( fix_ids.begin(), fix_ids.end() );
      write_to_file( PATH_INFO::base_path_path() / "faults_fixes_dump.json", [&]( std::ostream & fout ) {
          JsonOut jo( fout, true );
          jo.start_array();
          for( const std::string &fid_str : fix_ids ) {
              const fault_fix &f = fault_fix_id( fid_str ).obj();
              jo.start_object( true );
              jo.member( "id", f.id_.str() );
              jo.member( "faults_added", f.faults_added );
              jo.member( "faults_removed", f.faults_removed );
              jo.member( "mod_damage", f.mod_damage );
              jo.member( "mod_degradation", f.mod_degradation );
              jo.member( "name", f.name.translated() );
              jo.member( "set_variables", f.set_variables );
              jo.member( "skills", f.skills );
              jo.member( "success_msg", f.success_msg.translated() );
              jo.member( "time", f.time );
              jo.member( "time_save_flags", f.time_save_flags );
              jo.member( "time_save_profs", f.time_save_profs );
              dump_req( jo, "get_requirements", f.get_requirements() );
              jo.end_object();
          }
          jo.end_array();
      } );
  }
}

Additional context

@github-actions github-actions bot added [JSON] Changes (can be) made in JSON [C++] Changes (can be) made in C++. Previously named `Code` astyled astyled PR, label is assigned by github actions json-styled JSON lint passed, label assigned by github actions labels May 15, 2024
@dseguin dseguin merged commit 5072eed into CleverRaven:master May 16, 2024
25 of 28 checks passed
@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label May 16, 2024
@irwiss irwiss deleted the faults-factory branch May 16, 2024 22:40
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` [JSON] Changes (can be) made in JSON 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