Skip to content

Commit

Permalink
Merge pull request #1123 from Nivaturimika/meowster
Browse files Browse the repository at this point in the history
template = for countries on common/countries
  • Loading branch information
schombert authored Feb 18, 2024
2 parents b9aa4d7 + 5845a33 commit 6fd373d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
10 changes: 10 additions & 0 deletions docs/extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,13 @@ province-id;size;culture;religion;pop-type;rebel-faction(optional)
This allows for higher volume of data, while keeping it readable, editable and most importantly: able to be edited on your favourite office spreadsheet program.

Using this in your mod is simple, create a file ending with `.csv`, like, `Africa.csv`, Alice will load it *alongside* other files, even `.txt` files, if you want to mix them you absolutely can, just bear in mind that every file in the `history/pops/yyyy.mm.dd` is loaded, so be aware of that.

### Country templates

This allows to remove a lot of copy-pasting for countries, and other common files.

```
template = "test.txt"
```

Where `test.txt` would be in `common/templates/test.txt`.
1 change: 1 addition & 0 deletions src/parsing/parser_defs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,7 @@ country_file
graphical_culture value none discard
party extern make_party discard
unit_names group unit_names_collection member
template value text member_fn (template_)
#any group color_from_3i member_fn

pv_party_loyalty
Expand Down
12 changes: 12 additions & 0 deletions src/parsing/parsers_declarations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2872,6 +2872,18 @@ void country_file::color(color_from_3i cvalue, error_handler& err, int32_t line,
}
}

void country_file::template_(association_type, std::string_view value, error_handler& err, int32_t line, country_file_context& context) {
auto root = simple_fs::get_root(context.outer_context.state.common_fs);
auto common_dir = simple_fs::open_directory(root, NATIVE("common"));
auto countries_dir = simple_fs::open_directory(common_dir, NATIVE("templates"));
if(auto f = simple_fs::open_file(countries_dir, simple_fs::utf8_to_native(value)); f) {
auto content = simple_fs::view_contents(*f);
err.file_name = std::string(value);
parsers::token_generator gen(content.data, content.data + content.file_size);
parsers::parse_country_file(gen, err, context);
}
}

void country_file::any_group(std::string_view name, color_from_3i c, error_handler& err, int32_t line, country_file_context& context) {
if(auto it = context.outer_context.map_of_governments.find(std::string(name)); it != context.outer_context.map_of_governments.end()) {
context.outer_context.state.world.national_identity_set_government_color(context.id, it->second, c.value);
Expand Down
3 changes: 2 additions & 1 deletion src/parsing/parsers_declarations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1444,8 +1444,9 @@ struct unit_names_collection {
void finish(country_file_context&) { }
};
struct country_file {
void color(color_from_3i cvalue, error_handler& err, int32_t line, country_file_context& context);
unit_names_collection unit_names;
void color(color_from_3i cvalue, error_handler& err, int32_t line, country_file_context& context);
void template_(association_type, std::string_view value, error_handler& err, int32_t line, country_file_context& context);
void any_group(std::string_view name, color_from_3i, error_handler& err, int32_t line, country_file_context& context);
void finish(country_file_context&) { }
};
Expand Down
8 changes: 3 additions & 5 deletions src/parsing/provinces_parsing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,15 +410,13 @@ void parse_csv_pop_history_file(sys::state& state, const char* start, const char
err.accumulated_errors += "Unspecified type (" + err.file_name + ")\n";
return;
}
if(rebel_text.empty()) {
err.accumulated_errors += "Unspecified rebel faction (" + err.file_name + ")\n";
return;
}
auto p = context.original_id_to_prov_id_map[parsers::parse_int(provid_text, 0, err)];
pop_history_province_context pop_context{context, p};
def.culture(parsers::association_type::eq_default, culture_text, err, 0, pop_context);
def.religion(parsers::association_type::eq_default, religion_text , err, 0, pop_context);
def.rebel_type(parsers::association_type::eq_default, rebel_text, err, 0, pop_context);
if(!rebel_text.empty()) {
def.rebel_type(parsers::association_type::eq_default, rebel_text, err, 0, pop_context);
}
def.size = parsers::parse_int(size_text, 0, err);
//def.rebel_type(parsers::association_type::eq_default, culture_text, err, 0, pop_context);
ppl.any_group(type_text, def, err, 0, pop_context);
Expand Down

0 comments on commit 6fd373d

Please sign in to comment.