Skip to content

Commit

Permalink
Simplified unidiff API for adding / remove objects in a system.
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbens committed Apr 26, 2024
1 parent 54d6756 commit 310a5f4
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 125 deletions.
4 changes: 2 additions & 2 deletions dat/unidiff/FLF_base.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<unidiff name="FLF_base">
<system name="Sigur">
<spob name="Sindbad">add</spob>
<spob_virtual name="Virtual Sindbad">remove</spob_virtual>
<spob_add>Sindbad</spob_add>
<spob_virtual_remove>Virtual Sindbad</spob_virtual_remove>
</system>
</unidiff>
2 changes: 1 addition & 1 deletion dat/unidiff/Fury_Station.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<unidiff name="Fury_Station">
<system name="Anger">
<spob name="Fury Station">add</spob>
<spob_add>Fury Station</spob_add>
</system>
</unidiff>
30 changes: 15 additions & 15 deletions dat/unidiff/collective_dead.xml
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<unidiff name="collective_dead">
<system name="C-00">
<spob name="S00000">remove</spob>
<spob name="S23001">remove</spob>
<spob name="S49588">remove</spob>
<spob_remove>S00000</spob_remove>
<spob_remove>S23001</spob_remove>
<spob_remove>S49588</spob_remove>
</system>
<system name="C-14">
<spob name="S49281">remove</spob>
<spob name="S49335">remove</spob>
<spob_remove>S49281</spob_remove>
<spob_remove>S49335</spob_remove>
</system>
<system name="C-28">
<spob name="S00018">remove</spob>
<spob name="S00522">remove</spob>
<spob name="S00653">remove</spob>
<spob name="S38729">remove</spob>
<spob_remove>S00018</spob_remove>
<spob_remove>S00522</spob_remove>
<spob_remove>S00653</spob_remove>
<spob_remove>S38729</spob_remove>
</system>
<system name="C-59">
<spob name="S13024">remove</spob>
<spob name="S72288">remove</spob>
<spob name="S72839">remove</spob>
<spob_remove>S13024</spob_remove>
<spob_remove>S72288</spob_remove>
<spob_remove>S72839</spob_remove>
</system>
<system name="C-43">
<spob name="S23491">remove</spob>
<spob name="S58309">remove</spob>
<spob name="S91456">remove</spob>
<spob_remove>S23491</spob_remove>
<spob_remove>S58309</spob_remove>
<spob_remove>S91456</spob_remove>
</system>
<tech name="Heavy Weapons 1">
<add>__Collective Outfits</add>
Expand Down
2 changes: 1 addition & 1 deletion dat/unidiff/eye_of_night_station.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<unidiff name="Eye of Night Station">
<system name="Eye of Night">
<spob name="Eye of Night Station">add</spob>
<spob_add>Eye of Night Station</spob_add>
</system>
</unidiff>
16 changes: 8 additions & 8 deletions dat/unidiff/flf_dead.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<unidiff name="flf_dead">
<system name="Sigur">
<spob_virtual name="Virtual Sindbad">remove</spob_virtual>
<spob_virtual name="Empire Unpresence">remove</spob_virtual>
<spob_virtual name="Soromid Unpresence">remove</spob_virtual>
<spob_virtual_remove>Virtual Sindbad</spob_virtual_remove>
<spob_virtual_remove>Empire Unpresence</spob_virtual_remove>
<spob_virtual_remove>Soromid Unpresence</spob_virtual_remove>
</system>
<system name="Raelid">
<spob_virtual name="FLF Small">remove</spob_virtual>
<spob_virtual_remove>FLF Small</spob_virtual_remove>
</system>
<system name="Tuoladis">
<spob_virtual name="FLF Small">remove</spob_virtual>
<spob_virtual_remove>FLF Small</spob_virtual_remove>
</system>
<system name="Dakron">
<spob_virtual name="FLF Small">remove</spob_virtual>
<spob_virtual_remove>FLF Small</spob_virtual_remove>
</system>
<system name="Tarsus">
<spob_virtual name="FLF Small">remove</spob_virtual>
<spob_virtual_remove>FLF Small</spob_virtual_remove>
</system>
<system name="Torg">
<spob_virtual name="FLF Small">remove</spob_virtual>
<spob_virtual_remove>FLF Small</spob_virtual_remove>
</system>
</unidiff>
2 changes: 1 addition & 1 deletion dat/unidiff/hypergates_3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<tag_add>active</tag_add>
</spob>
<system name="Haven">
<spob name="Hypergate Haven">add</spob>
<spob_add>Hypergate Haven</spob_add>
</system>
<tech name="Pirate Maps">
<add>Map: Kretogg's Hypergate</add>
Expand Down
2 changes: 1 addition & 1 deletion dat/unidiff/onewing_goddard.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<unidiff name="onewing_goddard_gone">
<system name="Taiomi">
<spob name="One-Wing Goddard">remove</spob>
<spob_remove>One-Wing Goddard</spob_remove>
</system>
</unidiff>
2 changes: 1 addition & 1 deletion dat/unidiff/raelid_outpost_death.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<unidiff name="raelid_outpost_death">
<system name="Raelid">
<spob name="Fort Raelid">remove</spob>
<spob_remove>Fort Raelid</spob_remove>
</system>
</unidiff>
2 changes: 1 addition & 1 deletion dat/unidiff/raglan_outpost_death.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<unidiff name="raglan_outpost_death">
<system name="Haleb">
<spob name="Fort Raglan">remove</spob>
<spob_remove>Fort Raglan</spob_remove>
</system>
</unidiff>
2 changes: 1 addition & 1 deletion dat/unidiff/strangelove.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<unidiff name="strangelove">
<system name="Westhaven">
<spob name="Strangelove Lab">add</spob>
<spob_add>Strangelove Lab</spob_add>
</system>
</unidiff>
154 changes: 61 additions & 93 deletions src/unidiff.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,58 @@ static const char *hunk_name[HUNK_TYPE_SENTINAL + 1] = {
[HUNK_TYPE_FACTION_REALIGN] = N_( "faction alignment reset" ),
[HUNK_TYPE_SENTINAL] = N_( "sentinal" ),
};
/*
static const char *hunk_tag[HUNK_TYPE_SENTINAL] = {
[HUNK_TYPE_NONE] = "none",
[HUNK_TYPE_SPOB_ADD] = "spob add",
[HUNK_TYPE_SPOB_REMOVE] = "spob remove",
[HUNK_TYPE_VSPOB_ADD] = "virtual spob add",
[HUNK_TYPE_VSPOB_REMOVE] = "virtual spob remove",
[HUNK_TYPE_JUMP_ADD] = "jump add",
[HUNK_TYPE_JUMP_REMOVE] = "jump remove",
[HUNK_TYPE_TECH_ADD] = "tech add",
[HUNK_TYPE_TECH_REMOVE] = "tech remove",
[HUNK_TYPE_SSYS_BACKGROUND] = "ssys background",
[HUNK_TYPE_SSYS_BACKGROUND_REVERT] = "ssys background revert",
[HUNK_TYPE_SSYS_FEATURES] = "ssys features",
[HUNK_TYPE_SSYS_FEATURES_REVERT] = "ssys features revert",
[HUNK_TYPE_SSYS_POS_X] = "ssys pos x",
[HUNK_TYPE_SSYS_POS_X_REVERT] = "ssys pos x revert",
[HUNK_TYPE_SSYS_POS_Y] = "ssys pos y",
[HUNK_TYPE_SSYS_POS_Y_REVERT] = "ssys pos x revert",
[HUNK_TYPE_SPOB_FACTION] = "spob faction",
[HUNK_TYPE_SPOB_FACTION_REMOVE] = "spob faction removal",
[HUNK_TYPE_SPOB_POPULATION] = "spob population",
[HUNK_TYPE_SPOB_POPULATION_REMOVE] = "spob population removal",
[HUNK_TYPE_SPOB_DISPLAYNAME] = "spob displayname",
[HUNK_TYPE_SPOB_DISPLAYNAME_REVERT] = "spob displayname revert",
[HUNK_TYPE_SPOB_DESCRIPTION] = "spob description",
[HUNK_TYPE_SPOB_DESCRIPTION_REVERT] = "spob description revert",
[HUNK_TYPE_SPOB_BAR] = "spob bar",
[HUNK_TYPE_SPOB_BAR_REVERT] = "spob bar revert",
[HUNK_TYPE_SPOB_SPACE] = "spob space",
[HUNK_TYPE_SPOB_SPACE_REVERT] = "spob space revert",
[HUNK_TYPE_SPOB_EXTERIOR] = "spob exterior",
[HUNK_TYPE_SPOB_EXTERIOR_REVERT] = "spob exterior revert",
[HUNK_TYPE_SPOB_LUA] = "spob lua",
[HUNK_TYPE_SPOB_LUA_REVERT] = "spob lua revert",
[HUNK_TYPE_SPOB_SERVICE_ADD] = "spob service add",
[HUNK_TYPE_SPOB_SERVICE_REMOVE] = "spob service remove",
[HUNK_TYPE_SPOB_NOMISNSPAWN_ADD] = "spob nomissionspawn add",
[HUNK_TYPE_SPOB_NOMISNSPAWN_REMOVE] = "spob nomissionspawn remove",
[HUNK_TYPE_SPOB_TECH_ADD] = "spob tech add",
[HUNK_TYPE_SPOB_TECH_REMOVE] = "spob tech remove",
[HUNK_TYPE_SPOB_TAG_ADD] = "spob tech add",
[HUNK_TYPE_SPOB_TAG_REMOVE] = "spob tech remove",
[HUNK_TYPE_FACTION_VISIBLE] = "faction visible",
[HUNK_TYPE_FACTION_INVISIBLE] = "faction invisible",
[HUNK_TYPE_FACTION_ALLY] = "faction set ally",
[HUNK_TYPE_FACTION_ENEMY] = "faction set enemy",
[HUNK_TYPE_FACTION_NEUTRAL] = "faction set neutral",
[HUNK_TYPE_FACTION_REALIGN] = "faction alignment reset",
[HUNK_TYPE_SENTINAL] = "sentinal",
};
*/
static UniHunkType_t hunk_reverse[HUNK_TYPE_SENTINAL] = {
[HUNK_TYPE_NONE] = HUNK_TYPE_SENTINAL,
[HUNK_TYPE_SPOB_ADD] = HUNK_TYPE_SPOB_REMOVE,
Expand Down Expand Up @@ -411,7 +463,6 @@ static int diff_patchSystem( UniDiff_t *diff, xmlNodePtr node )
{
UniHunk_t base, hunk;
xmlNodePtr cur;
char *buf;

/* Set the target. */
memset( &base, 0, sizeof( UniHunk_t ) );
Expand All @@ -428,96 +479,13 @@ static int diff_patchSystem( UniDiff_t *diff, xmlNodePtr node )
cur = node->xmlChildrenNode;
do {
xml_onlyNodes( cur );
if ( xml_isNode( cur, "spob" ) ) {
buf = xml_get( cur );
if ( buf == NULL ) {
WARN( _( "Unidiff '%s': Null hunk type." ), diff->name );
continue;
}

hunk.target.type = base.target.type;
hunk.target.u.name = strdup( base.target.u.name );

/* Get the spob to modify. */
hunk.dtype = HUNK_DATA_STRING;
xmlr_attr_strd( cur, "name", hunk.u.name );

/* Get the type. */
if ( strcmp( buf, "add" ) == 0 )
hunk.type = HUNK_TYPE_SPOB_ADD;
else if ( strcmp( buf, "remove" ) == 0 )
hunk.type = HUNK_TYPE_SPOB_REMOVE;
else
WARN( _( "Unidiff '%s': Unknown hunk type '%s' for spob '%s'." ),
diff->name, buf, hunk.u.name );

/* Apply diff. */
if ( diff_patchHunk( &hunk ) < 0 )
diff_hunkFailed( diff, &hunk );
else
diff_hunkSuccess( diff, &hunk );
continue;
} else if ( xml_isNode( cur, "spob_virtual" ) ) {
buf = xml_get( cur );
if ( buf == NULL ) {
WARN( _( "Unidiff '%s': Null hunk type." ), diff->name );
continue;
}

hunk.target.type = base.target.type;
hunk.target.u.name = strdup( base.target.u.name );

/* Get the spob to modify. */
hunk.dtype = HUNK_DATA_STRING;
xmlr_attr_strd( cur, "name", hunk.u.name );

/* Get the type. */
if ( strcmp( buf, "add" ) == 0 )
hunk.type = HUNK_TYPE_VSPOB_ADD;
else if ( strcmp( buf, "remove" ) == 0 )
hunk.type = HUNK_TYPE_VSPOB_REMOVE;
else
WARN( _( "Unidiff '%s': Unknown hunk type '%s' for virtual spob "
"'%s'." ),
diff->name, buf, hunk.u.name );

/* Apply diff. */
if ( diff_patchHunk( &hunk ) < 0 )
diff_hunkFailed( diff, &hunk );
else
diff_hunkSuccess( diff, &hunk );
continue;
} else if ( xml_isNode( cur, "jump" ) ) {
buf = xml_get( cur );
if ( buf == NULL ) {
WARN( _( "Unidiff '%s': Null hunk type." ), diff->name );
continue;
}

hunk.target.type = base.target.type;
hunk.target.u.name = strdup( base.target.u.name );

/* Get the jump point to modify. */
hunk.dtype = HUNK_DATA_STRING;
xmlr_attr_strd( cur, "target", hunk.u.name );

/* Get the type. */
if ( strcmp( buf, "add" ) == 0 )
hunk.type = HUNK_TYPE_JUMP_ADD;
else if ( strcmp( buf, "remove" ) == 0 )
hunk.type = HUNK_TYPE_JUMP_REMOVE;
else
WARN( _( "Unidiff '%s': Unknown hunk type '%s' for jump '%s'." ),
diff->name, buf, hunk.u.name );

/* Apply diff. */
if ( diff_patchHunk( &hunk ) < 0 )
diff_hunkFailed( diff, &hunk );
else
diff_hunkSuccess( diff, &hunk );
continue;
}

HUNK_STRD( "spob_add", HUNK_TYPE_SPOB_ADD );
HUNK_STRD( "spob_remove", HUNK_TYPE_SPOB_REMOVE );
HUNK_STRD( "spob_virtual_add", HUNK_TYPE_VSPOB_ADD );
HUNK_STRD( "spob_virtual_remove", HUNK_TYPE_VSPOB_REMOVE );
HUNK_STRD( "jump_add", HUNK_TYPE_JUMP_ADD );
HUNK_STRD( "jump_remove", HUNK_TYPE_JUMP_REMOVE );
HUNK_STRD( "background", HUNK_TYPE_SSYS_BACKGROUND );
HUNK_STRD( "features", HUNK_TYPE_SSYS_FEATURES );
HUNK_FLOAT( "pos_x", HUNK_TYPE_SSYS_POS_X );
Expand Down Expand Up @@ -831,18 +799,18 @@ int diff_patchHunk( UniHunk_t *hunk )
diff_universe_changed = 1;
return system_rmSpob( system_get( hunk->target.u.name ), hunk->u.name );

/* Adding an spob. */
/* Adding a virtual spob. */
case HUNK_TYPE_VSPOB_ADD:
diff_universe_changed = 1;
return system_addVirtualSpob( system_get( hunk->target.u.name ),
hunk->u.name );
/* Removing an spob. */
/* Removing a virtual spob. */
case HUNK_TYPE_VSPOB_REMOVE:
diff_universe_changed = 1;
return system_rmVirtualSpob( system_get( hunk->target.u.name ),
hunk->u.name );

/* Adding a Jump. */
/* Adding a jump. */
case HUNK_TYPE_JUMP_ADD:
diff_universe_changed = 1;
return system_addJump( system_get( hunk->target.u.name ), hunk->u.name );
Expand Down

0 comments on commit 310a5f4

Please sign in to comment.