Skip to content

Commit

Permalink
Add tr_ledge obsoletion
Browse files Browse the repository at this point in the history
  • Loading branch information
Procyonae committed Nov 30, 2024
1 parent 3492d65 commit 74821dd
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 2 deletions.
7 changes: 7 additions & 0 deletions data/json/obsoletion_and_migration_0.I/obsolete_traps.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[

Check failure on line 1 in data/json/obsoletion_and_migration_0.I/obsolete_traps.json

View workflow job for this annotation

GitHub Actions / Basic Build and Test (Clang 10, Ubuntu, Curses)

(~[slow] ~[.],starting_items)=> missing mandatory member "from_trap" [ ▲▲▲ { "type": "trap_migration",

Check failure on line 1 in data/json/obsoletion_and_migration_0.I/obsolete_traps.json

View workflow job for this annotation

GitHub Actions / Basic Build and Test (Clang 10, Ubuntu, Curses)

([slow] ~starting_items)=> missing mandatory member "from_trap" [ ▲▲▲ { "type": "trap_migration",
{
"type": "trap_migration",
"from_ter": "tr_ledge",
"to_ter": "tr_null"
}
]
38 changes: 36 additions & 2 deletions doc/OBSOLETION_AND_MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,49 @@ Move multiple ids that don't need to be unique any more to a single id
}
```

# Trap migration

Trap migration replaces the provided id as submaps are loaded. You can use `tr_null` with `to_trap` to remove the trap entirely without creating errors.

```json
{
"type": "trap_migration", // Mandatory. String. Must be "trap_migration"
"from_trap": "tr_old_trap", // Mandatory. String. Id of the trap to replace.
"to_trap": "tr_new_trap", // Mandatory. String. Id of the new trap to place.
},
```

## Examples

Migrate an id

```json
{
"type": "trap_migration",
"from_trap": "tr_being_migrated_id",
"to_trap": "tr_new_id"
}
```

Errorlessly obsolete an id

```json
{
"type": "trap_migration",
"from_trap": "tr_being_obsoleted_id",
"to_trap": "tr_null"
}
```

# Field migration

Field migration replaces the provided id as submaps are loaded. You can use `fd_null` with `to_field` to remove the field entirely without creating errors.

```json
{
"type": "field_type_migration", // Mandatory. String. Must be "field_type_migration"
"from_field": "t_old_field", // Mandatory. String. Id of the field to replace.
"to_field": "f_new_field", // Mandatory. String. Id of the new field to place.
"from_field": "fd_old_field", // Mandatory. String. Id of the field to replace.
"to_field": "fd_new_field", // Mandatory. String. Id of the new field to place.
},
```

Expand Down
3 changes: 3 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ void DynamicDataLoader::initialize()
requirement_data::load_requirement( jo, string_id<requirement_data>::NULL_ID(), true );
} );
add( "trap", &trap::load_trap );
add( "trap_migration", &trap_migrations::load );

add( "AMMO", []( const JsonObject & jo, const std::string & src ) {
item_controller->load_ammo( jo, src );
Expand Down Expand Up @@ -748,6 +749,7 @@ void DynamicDataLoader::unload_data()
ter_furn_migrations::reset();
ter_furn_transform::reset();
trap::reset();
trap_migrations::reset();
unload_talk_topics();
VehicleGroup::reset();
VehiclePlacement::reset();
Expand Down Expand Up @@ -935,6 +937,7 @@ void DynamicDataLoader::check_consistency()
{ _( "Start locations" ), &start_locations::check_consistency },
{ _( "Ammunition types" ), &ammunition_type::check_consistency },
{ _( "Traps" ), &trap::check_consistency },
{ _( "Trap migrations" ), &trap_migrations::check },
{ _( "Bionics" ), &bionic_data::check_bionic_consistency },
{ _( "Gates" ), &gates::check },
{ _( "NPC classes" ), &npc_class::check_consistency },
Expand Down
13 changes: 13 additions & 0 deletions src/mapdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,19 @@ class ter_furn_migrations
static void check();
};

class trap_migrations
{
public:
/** Handler for loading "trap_migration" type of json object */
static void load( const JsonObject &jo );

/** Clears migration list */
static void reset();

/** Checks migrations */
static void check();
};

class field_type_migrations
{
public:
Expand Down
25 changes: 25 additions & 0 deletions src/savegame_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4663,6 +4663,31 @@ void ter_furn_migrations::check()
}
}

static std::unordered_map<trap_str_id, trap_str_id> tr_migrations;

void trap_migrations::load( const JsonObject &jo )
{
trap_str_id from_trap;
trap_str_id to_trap;
mandatory( jo, false, "from_trap", from_trap );
mandatory( jo, false, "to_trap", to_trap );
tr_migrations.insert( std::make_pair( from_trap, to_trap ) );
}

void trap_migrations::reset()
{
tr_migrations.clear();
}

void trap_migrations::check()
{
for( const auto &migration : tr_migrations ) {
if( !migration.second.is_valid() ) {
debugmsg( "trap_migration specifies invalid to_trap id '%s'", migration.second.c_str() );
}
}
}

static std::unordered_map<field_type_str_id, field_type_str_id> field_migrations;

void field_type_migrations::load( const JsonObject &jo )
Expand Down

0 comments on commit 74821dd

Please sign in to comment.