Skip to content

Commit

Permalink
uniedit: can rename systems in diff mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbens committed Apr 26, 2024
1 parent 1f8f86a commit 95b83e3
Showing 1 changed file with 39 additions and 29 deletions.
68 changes: 39 additions & 29 deletions src/dev_uniedit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1487,15 +1487,17 @@ static void uniedit_renameSys( void )
int cancelall_prompt = 0;
for ( int i = 0; i < array_size( uniedit_sys ); i++ ) {
char *name, *oldName, *newName, *filtered;
const char *prompt;
StarSystem *sys = uniedit_sys[i];

if ( uniedit_diffMode ) {
/* TODO warning. */
}

/* Get name. */
name = dialogue_input( _( "Rename Star System" ), 1, 32,
_( "What do you want to rename #r%s#0?" ),
if ( uniedit_diffMode )
prompt = _( "What do you want to rename #r%s#0?\n\n#rNote:#0 this "
"will only change the display name of the system." );
else
prompt = _( "What do you want to rename #r%s#0?\n\n#rNote:#0 this "
"will rename and copy the system data file." );
name = dialogue_input( _( "Rename Star System" ), 1, 32, prompt,
system_name( sys ) );

/* Keep current name. */
Expand All @@ -1517,28 +1519,38 @@ static void uniedit_renameSys( void )
continue;
}

/* Change the name. */
filtered = uniedit_nameFilter( sys->name );
SDL_asprintf( &oldName, "%s/%s.xml", conf.dev_save_sys, filtered );
free( filtered );
if ( uniedit_diffMode ) {
UniHunk_t hunk;
hunk.target.type = HUNK_TARGET_SYSTEM;
hunk.target.u.name = strdup( sys->name );
hunk.type = HUNK_TYPE_SSYS_DISPLAYNAME;
hunk.dtype = HUNK_DATA_STRING;
hunk.u.name = name; /* No need to free. */
uniedit_diffAdd( &hunk );
} else {
/* Change the name. */
filtered = uniedit_nameFilter( sys->name );
SDL_asprintf( &oldName, "%s/%s.xml", conf.dev_save_sys, filtered );
free( filtered );

filtered = uniedit_nameFilter( name );
SDL_asprintf( &newName, "%s/%s.xml", conf.dev_save_sys, filtered );
free( filtered );
filtered = uniedit_nameFilter( name );
SDL_asprintf( &newName, "%s/%s.xml", conf.dev_save_sys, filtered );
free( filtered );

if ( rename( oldName, newName ) )
WARN( _( "Failed to rename '%s' to '%s'!" ), oldName, newName );
if ( rename( oldName, newName ) )
WARN( _( "Failed to rename '%s' to '%s'!" ), oldName, newName );

free( oldName );
free( newName );
free( sys->name );
free( oldName );
free( newName );
free( sys->name );

sys->name = name;
dsys_saveSystem( sys );
sys->name = name;
dsys_saveSystem( sys );

/* Re-save adjacent systems. */
for ( int j = 0; j < array_size( sys->jumps ); j++ )
dsys_saveSystem( sys->jumps[j].target );
/* Re-save adjacent systems. */
for ( int j = 0; j < array_size( sys->jumps ); j++ )
dsys_saveSystem( sys->jumps[j].target );
}
}
}

Expand All @@ -1551,7 +1563,8 @@ static void uniedit_newSys( double x, double y )
StarSystem *sys;

if ( uniedit_diffMode ) {
/* TODO warning. */
dialogue_alert( ( "Adding new systems is not supported in diff mode!" ) );
return;
}

/* Get name. */
Expand Down Expand Up @@ -2016,12 +2029,9 @@ static void uniedit_centerSystem( unsigned int wid, const char *unused )
*/
static int uniedit_sortCompare( const void *p1, const void *p2 )
{
map_find_t *f1, *f2;

/* Convert pointer. */
f1 = (map_find_t *)p1;
f2 = (map_find_t *)p2;

const map_find_t *f1 = (map_find_t *)p1;
const map_find_t *f2 = (map_find_t *)p2;
/* Sort by name, nothing more. */
return strcasecmp( f1->sys->name, f2->sys->name );
}
Expand Down

0 comments on commit 95b83e3

Please sign in to comment.