Skip to content

Commit

Permalink
More sysedit support including removing spobs and moving them.
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbens committed Apr 26, 2024
1 parent 39cf532 commit fbe4316
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 54 deletions.
118 changes: 80 additions & 38 deletions src/dev_sysedit.c
Original file line number Diff line number Diff line change
Expand Up @@ -652,35 +652,61 @@ static void sysedit_btnRemove( unsigned int wid_unused, const char *unused )
(void)unused;
char *file;

if ( dialogue_YesNo( _( "Remove selected objects (excluding jumps)?" ),
_( "This can not be undone." ) ) ) {
for ( int i = 0; i < sysedit_nselect; i++ ) {
Select_t *sel = &sysedit_select[i];
if ( sel->type == SELECT_SPOB ) {
const Spob *sp = sysedit_sys->spobs[sel->u.spob];
char *filtered = uniedit_nameFilter( sp->name );
SDL_asprintf( &file, "%s/%s.xml", conf.dev_save_spob, filtered );
remove( file );

free( filtered );
free( file );

system_rmSpob( sysedit_sys, sp->name );
} else if ( sel->type == SELECT_ASTEROID ) {
AsteroidAnchor *ast = &sysedit_sys->asteroids[sel->u.asteroid];
asteroid_free( ast );
array_erase( &sysedit_sys->asteroids, ast, ast + 1 );
} else if ( sel->type == SELECT_ASTEXCLUDE ) {
AsteroidExclusion *exc =
&sysedit_sys->astexclude[sel->u.astexclude];

array_erase( &sysedit_sys->astexclude, exc, exc + 1 );
if ( uniedit_diffMode ) {
if ( dialogue_YesNo(
_( "Remove selected objects (excluding jumps)?" ),
_( "Objects will be removed through the current diff." ) ) ) {
for ( int i = 0; i < sysedit_nselect; i++ ) {
Select_t *sel = &sysedit_select[i];
if ( sel->type == SELECT_SPOB ) {
const Spob *sp = sysedit_sys->spobs[sel->u.spob];
uniedit_diffCreateSysStr( sysedit_sys, HUNK_TYPE_SPOB_REMOVE,
strdup( sp->name ) );
/* TODO asteroids too
} else if ( sel->type == SELECT_ASTEROID ) {
AsteroidAnchor *ast =
&sysedit_sys->asteroids[sel->u.asteroid]; asteroid_free( ast );
array_erase( &sysedit_sys->asteroids, ast, ast + 1 );
} else if ( sel->type == SELECT_ASTEXCLUDE ) {
AsteroidExclusion *exc =
&sysedit_sys->astexclude[sel->u.astexclude];
array_erase( &sysedit_sys->astexclude, exc, exc + 1 );
*/
}
}
}
} else {
if ( dialogue_YesNo( _( "Remove selected objects (excluding jumps)?" ),
_( "This can not be undone." ) ) ) {
for ( int i = 0; i < sysedit_nselect; i++ ) {
Select_t *sel = &sysedit_select[i];
if ( sel->type == SELECT_SPOB ) {
const Spob *sp = sysedit_sys->spobs[sel->u.spob];
char *filtered = uniedit_nameFilter( sp->name );
SDL_asprintf( &file, "%s/%s.xml", conf.dev_save_spob, filtered );
remove( file );

free( filtered );
free( file );

system_rmSpob( sysedit_sys, sp->name );
} else if ( sel->type == SELECT_ASTEROID ) {
AsteroidAnchor *ast = &sysedit_sys->asteroids[sel->u.asteroid];
asteroid_free( ast );
array_erase( &sysedit_sys->asteroids, ast, ast + 1 );
} else if ( sel->type == SELECT_ASTEXCLUDE ) {
AsteroidExclusion *exc =
&sysedit_sys->astexclude[sel->u.astexclude];

array_erase( &sysedit_sys->astexclude, exc, exc + 1 );
}
}

/* Run galaxy modifications. */
space_reconstructPresences();
economy_execQueued();
/* Run galaxy modifications. */
space_reconstructPresences();
economy_execQueued();
}
}
}

Expand Down Expand Up @@ -788,8 +814,6 @@ void sysedit_sysScale( StarSystem *sys, double factor )
exc->radius *= factor;
}

/* TODO diff. */

/* Must reconstruct jumps. */
systems_reconstructJumps();
}
Expand Down Expand Up @@ -1317,31 +1341,49 @@ static int sysedit_mouse( unsigned int wid, const SDL_Event *event, double mx,
AsteroidExclusion *exc;
Select_t *sel = &sysedit_select[i];

/* TODO add diff support to the following. */
switch ( sel->type ) {
case SELECT_SPOB:
p = sys->spobs[sel->u.spob];
p->pos.x += xmove;
p->pos.y += ymove;
if ( uniedit_diffMode ) {
sysedit_diffCreateSpobFloat( p, HUNK_TYPE_SPOB_POS_X,
p->pos.x + xmove );
sysedit_diffCreateSpobFloat( p, HUNK_TYPE_SPOB_POS_Y,
p->pos.y + ymove );
} else {
p->pos.x += xmove;
p->pos.y += ymove;
}
break;

case SELECT_JUMPPOINT:
jp = &sys->jumps[sel->u.jump];
jp->flags &= ~( JP_AUTOPOS );
jp->pos.x += xmove;
jp->pos.y += ymove;
if ( uniedit_diffMode ) {
/* TODO diff. */
} else {
jp->flags &= ~( JP_AUTOPOS );
jp->pos.x += xmove;
jp->pos.y += ymove;
}
break;

case SELECT_ASTEROID:
ast = &sys->asteroids[sel->u.asteroid];
ast->pos.x += xmove;
ast->pos.y += ymove;
if ( uniedit_diffMode ) {
/* TODO diff. */
} else {
ast->pos.x += xmove;
ast->pos.y += ymove;
}
break;

case SELECT_ASTEXCLUDE:
exc = &sys->astexclude[sel->u.astexclude];
exc->pos.x += xmove;
exc->pos.y += ymove;
if ( uniedit_diffMode ) {
/* TODO diff. */
} else {
exc->pos.x += xmove;
exc->pos.y += ymove;
}
break;
}
}
Expand Down
23 changes: 7 additions & 16 deletions src/dev_uniedit.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,6 @@ static void uniedit_btnFind( unsigned int wid_unused, const char *unused );
static int uniedit_keys( unsigned int wid, SDL_Keycode key, SDL_Keymod mod,
int isrepeat );
/* Diffs. */
static void uniedit_diffCreateSysNone( const StarSystem *sys,
UniHunkType_t type );
static void uniedit_diffCreateSysStr( const StarSystem *sys, UniHunkType_t type,
char *str );
static void uniedit_diffCreateSysInt( const StarSystem *sys, UniHunkType_t type,
int data );
static void uniedit_diffCreateSysFloat( const StarSystem *sys,
UniHunkType_t type, double fdata );
static void uniedit_diffEditor( unsigned int wid_unused, const char *unused );
static void uniedit_diff_toggle( unsigned int wid, const char *wgt );
static void uniedit_diff_remove( unsigned int wid, const char *wgt );
Expand Down Expand Up @@ -2726,8 +2718,7 @@ static int uniedit_diff_cmp( const void *p1, const void *p2 )
h2->type; /* Should not overlap with same target and type. */
}

static void uniedit_diffCreateSysNone( const StarSystem *sys,
UniHunkType_t type )
void uniedit_diffCreateSysNone( const StarSystem *sys, UniHunkType_t type )
{
UniHunk_t hunk;
memset( &hunk, 0, sizeof( hunk ) );
Expand All @@ -2738,8 +2729,8 @@ static void uniedit_diffCreateSysNone( const StarSystem *sys,
uniedit_diffAdd( &hunk );
}

static void uniedit_diffCreateSysStr( const StarSystem *sys, UniHunkType_t type,
char *str )
void uniedit_diffCreateSysStr( const StarSystem *sys, UniHunkType_t type,
char *str )
{
UniHunk_t hunk;
memset( &hunk, 0, sizeof( hunk ) );
Expand All @@ -2751,8 +2742,8 @@ static void uniedit_diffCreateSysStr( const StarSystem *sys, UniHunkType_t type,
uniedit_diffAdd( &hunk );
}

static void uniedit_diffCreateSysInt( const StarSystem *sys, UniHunkType_t type,
int data )
void uniedit_diffCreateSysInt( const StarSystem *sys, UniHunkType_t type,
int data )
{
UniHunk_t hunk;
memset( &hunk, 0, sizeof( hunk ) );
Expand All @@ -2764,8 +2755,8 @@ static void uniedit_diffCreateSysInt( const StarSystem *sys, UniHunkType_t type,
uniedit_diffAdd( &hunk );
}

static void uniedit_diffCreateSysFloat( const StarSystem *sys,
UniHunkType_t type, double fdata )
void uniedit_diffCreateSysFloat( const StarSystem *sys, UniHunkType_t type,
double fdata )
{
UniHunk_t hunk;
memset( &hunk, 0, sizeof( hunk ) );
Expand Down
8 changes: 8 additions & 0 deletions src/dev_uniedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
#pragma once

#include "space.h"
#include "unidiff.h"

#define HIDE_DEFAULT_JUMP 1.0 /**< Default hide value for new jumps. */
Expand All @@ -22,3 +23,10 @@ void uniedit_renderMap( double bx, double by, double w, double h, double x,
/* For when working in diff mode. */
extern int uniedit_diffMode;
void uniedit_diffAdd( UniHunk_t *hunk );
void uniedit_diffCreateSysNone( const StarSystem *sys, UniHunkType_t type );
void uniedit_diffCreateSysStr( const StarSystem *sys, UniHunkType_t type,
char *str );
void uniedit_diffCreateSysInt( const StarSystem *sys, UniHunkType_t type,
int data );
void uniedit_diffCreateSysFloat( const StarSystem *sys, UniHunkType_t type,
double fdata );
26 changes: 26 additions & 0 deletions src/unidiff.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ static const char *const hunk_name[HUNK_TYPE_SENTINAL + 1] = {
[HUNK_TYPE_SSYS_NOLANES_REMOVE] = N_( "ssys nolanes remove" ),
[HUNK_TYPE_SSYS_TAG_ADD] = N_( "ssys tag add" ),
[HUNK_TYPE_SSYS_TAG_REMOVE] = N_( "ssys tag remove" ),
[HUNK_TYPE_SPOB_POS_X] = N_( "spob pos x" ),
[HUNK_TYPE_SPOB_POS_X_REVERT] = N_( "spob pos x revert" ),
[HUNK_TYPE_SPOB_POS_Y] = N_( "spob pos y" ),
[HUNK_TYPE_SPOB_POS_Y_REVERT] = N_( "spob pos y revert" ),
[HUNK_TYPE_SPOB_CLASS] = N_( "spob class" ),
[HUNK_TYPE_SPOB_CLASS_REVERT] = N_( "spob class revert" ),
[HUNK_TYPE_SPOB_FACTION] = N_( "spob faction" ),
Expand Down Expand Up @@ -162,6 +166,8 @@ static const char *const hunk_tag[HUNK_TYPE_SENTINAL] = {
[HUNK_TYPE_SSYS_TAG_REMOVE] = "tag_remove",
[HUNK_TYPE_TECH_ADD] = "item_add",
[HUNK_TYPE_TECH_REMOVE] = "item_remove",
[HUNK_TYPE_SPOB_POS_X] = "pos_x",
[HUNK_TYPE_SPOB_POS_Y] = "pos_y",
[HUNK_TYPE_SPOB_CLASS] = "class",
[HUNK_TYPE_SPOB_FACTION] = "faction",
[HUNK_TYPE_SPOB_PRESENCE_BASE] = "presence_base",
Expand Down Expand Up @@ -213,6 +219,8 @@ static UniHunkType_t hunk_reverse[HUNK_TYPE_SENTINAL] = {
[HUNK_TYPE_SSYS_TAG_REMOVE] = HUNK_TYPE_SSYS_TAG_ADD,
[HUNK_TYPE_TECH_ADD] = HUNK_TYPE_TECH_REMOVE,
[HUNK_TYPE_TECH_REMOVE] = HUNK_TYPE_TECH_ADD,
[HUNK_TYPE_SPOB_POS_X] = HUNK_TYPE_SPOB_POS_X_REVERT,
[HUNK_TYPE_SPOB_POS_Y] = HUNK_TYPE_SPOB_POS_Y_REVERT,
[HUNK_TYPE_SPOB_CLASS] = HUNK_TYPE_SPOB_CLASS_REVERT,
[HUNK_TYPE_SPOB_FACTION] = HUNK_TYPE_SPOB_FACTION_REVERT,
[HUNK_TYPE_SPOB_PRESENCE_BASE] = HUNK_TYPE_SPOB_PRESENCE_BASE_REVERT,
Expand Down Expand Up @@ -622,6 +630,8 @@ static int diff_patchSpob( UniDiff_t *diff, xmlNodePtr node )
do {
xml_onlyNodes( cur );

HUNK_FLOAT( HUNK_TYPE_SPOB_POS_X );
HUNK_FLOAT( HUNK_TYPE_SPOB_POS_Y );
HUNK_STRD( HUNK_TYPE_SPOB_CLASS );
HUNK_STRD( HUNK_TYPE_SPOB_FACTION );
HUNK_FLOAT( HUNK_TYPE_SPOB_PRESENCE_BASE );
Expand Down Expand Up @@ -1009,6 +1019,22 @@ int diff_patchHunk( UniHunk_t *hunk )
case HUNK_TYPE_TECH_REMOVE:
return tech_rmItem( hunk->target.u.name, hunk->u.name );

/* Position changes. */
case HUNK_TYPE_SPOB_POS_X:
hunk->o.fdata = p->pos.x;
p->pos.x = hunk->u.fdata;
return 0;
case HUNK_TYPE_SPOB_POS_X_REVERT:
p->pos.x = hunk->o.fdata;
return 0;
case HUNK_TYPE_SPOB_POS_Y:
hunk->o.fdata = p->pos.y;
p->pos.y = hunk->u.fdata;
return 0;
case HUNK_TYPE_SPOB_POS_Y_REVERT:
p->pos.y = hunk->o.fdata;
return 0;

/* Changing spob faction. */
case HUNK_TYPE_SPOB_CLASS:
hunk->o.name = p->class;
Expand Down
4 changes: 4 additions & 0 deletions src/unidiff.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ typedef enum UniHunkType_ {
HUNK_TYPE_TECH_ADD,
HUNK_TYPE_TECH_REMOVE,
/* Target should be HUNK_TARGET_SPOB. */
HUNK_TYPE_SPOB_POS_X,
HUNK_TYPE_SPOB_POS_X_REVERT, /* For internal usage. */
HUNK_TYPE_SPOB_POS_Y,
HUNK_TYPE_SPOB_POS_Y_REVERT, /* For internal usage. */
HUNK_TYPE_SPOB_CLASS,
HUNK_TYPE_SPOB_CLASS_REVERT, /* For internal usage. */
HUNK_TYPE_SPOB_FACTION,
Expand Down

0 comments on commit fbe4316

Please sign in to comment.