Skip to content

Commit

Permalink
Simplified unidiff faction standing change XML API.
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbens committed Apr 26, 2024
1 parent 310a5f4 commit aec9b66
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 37 deletions.
6 changes: 3 additions & 3 deletions dat/unidiff/flf_pirate_ally.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<unidiff name="flf_pirate_ally">
<faction name="FLF">
<faction name="Dreamer Clan">neutral</faction>
<faction name="Pirate">neutral</faction>
<faction name="Marauder">neutral</faction>
<faction_neutral>Dreamer Clan</faction_neutral>
<faction_neutral>Pirate</faction_neutral>
<faction_neutral>Marauder</faction_neutral>
</faction>
</unidiff>
2 changes: 1 addition & 1 deletion dat/unidiff/flf_vs_empire.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<unidiff name="flf_vs_empire">
<faction name="FLF">
<faction name="Empire">enemy</faction>
<faction_enemy>Empire</faction_enemy>
</faction>
</unidiff>
36 changes: 3 additions & 33 deletions src/unidiff.c
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,6 @@ static int diff_patchFaction( UniDiff_t *diff, xmlNodePtr node )
{
UniHunk_t base, hunk;
xmlNodePtr cur;
char *buf;

/* Set the target. */
memset( &base, 0, sizeof( UniHunk_t ) );
Expand All @@ -636,38 +635,9 @@ static int diff_patchFaction( UniDiff_t *diff, xmlNodePtr node )

HUNK_NONE( "visible", HUNK_TYPE_FACTION_VISIBLE );
HUNK_NONE( "invisible", HUNK_TYPE_FACTION_INVISIBLE );

if ( xml_isNode( cur, "faction" ) ) {
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 faction to set the association of. */
xmlr_attr_strd( cur, "name", hunk.u.name );

/* Get the type. */
if ( strcmp( buf, "ally" ) == 0 )
hunk.type = HUNK_TYPE_FACTION_ALLY;
else if ( strcmp( buf, "enemy" ) == 0 )
hunk.type = HUNK_TYPE_FACTION_ENEMY;
else if ( strcmp( buf, "neutral" ) == 0 )
hunk.type = HUNK_TYPE_FACTION_NEUTRAL;
else
WARN( _( "Unidiff '%s': Unknown hunk type '%s' for faction '%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( "faction_ally", HUNK_TYPE_FACTION_ALLY );
HUNK_STRD( "faction_enemy", HUNK_TYPE_FACTION_ENEMY );
HUNK_STRD( "faction_neutral", HUNK_TYPE_FACTION_NEUTRAL );

WARN( _( "Unidiff '%s' has unknown node '%s'." ), diff->name,
node->name );
Expand Down

0 comments on commit aec9b66

Please sign in to comment.