Skip to content

Commit

Permalink
Add itemgroup field that activate spawned item (CleverRaven#75663)
Browse files Browse the repository at this point in the history
* Add itemgroup field that activate spawned item

* make it std::optional<bool> as Snup suggested

* Apply suggestions from code review

* Apply suggestions from code review
  • Loading branch information
GuardianDll authored Aug 20, 2024
1 parent 36d1042 commit 3c60b62
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions doc/ITEM_SPAWN.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ Each entry can have more values (shown above as `...`). They allow further prop
"container-group": "<group-id>",
"entry-wrapper": "<item-id>",
"sealed": <boolean>
"active": <boolean>
"custom-flags": <array of string>,
"variant": <string>
"artifact": <object>
Expand All @@ -112,6 +113,8 @@ Each entry can have more values (shown above as `...`). They allow further prop

`sealed`: If true, a container will be sealed when the item spawns. Default is `true`.

`active`: If true, item would be spawned activated. Be sure to use active versions of item, like `flashlight_on` instead of `flashlight`. Default is `false`

`custom-flags`: An array of flags that will be applied to this item.

`variant`: A valid itype variant id for this item.
Expand Down
3 changes: 3 additions & 0 deletions src/item_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5037,6 +5037,9 @@ void Item_factory::add_entry( Item_group &ig, const JsonObject &obj, const std::
modifier.sealed = obj.get_bool( "sealed" );
use_modifier = true;
}
if( obj.has_member( "active" ) ) {
sptr->active = obj.get_bool( "active" );
}
std::vector<std::string> custom_flags;
use_modifier |= load_string( custom_flags, obj, "custom-flags" );
modifier.custom_flags.clear();
Expand Down
5 changes: 5 additions & 0 deletions src/item_group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ item Single_item_creator::create_single_without_container( const time_point &bir
if( one_in( 3 ) && tmp.has_flag( flag_VARSIZE ) ) {
tmp.set_flag( flag_FIT );
}

if( active.has_value() ) {
tmp.active = *active;
}

if( components_items ) {
for( itype_id component_id : *components_items ) {
if( !component_id.is_valid() ) {
Expand Down
1 change: 1 addition & 0 deletions src/item_group.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ class Item_spawn_data
*/
std::optional<std::vector<itype_id>> components_items;
bool sealed = true;
std::optional<bool> active = std::nullopt;

struct relic_generator {
relic_procgen_data::generation_rules rules;
Expand Down

0 comments on commit 3c60b62

Please sign in to comment.