galaxieseditor: make 'copy to clipboard' give the game id.

This seems like a generally helpful design for game editors in
general: if we're going to have a helper program that can construct an
instance of a game, then one obvious thing you'd want as output from
it would be the descriptive game id, suitable for pasting back into
the playing UI.

So, in the just-re-enabled helper program 'galaxieseditor', I've
rewritten game_text_format so that it generates exactly that. Now you
can place dots until you have a puzzle you like, then use the 'Copy'
menu item to make it into a game id usable in 'galaxies' proper.

This doesn't set a precedent that I'm planning to _write_ editors for
all the other games, or even any of them (right now). For some, it
wouldn't be too hard (especially games where the solution and clues
are the same kind of thing, like default-mode Solo); for others, it
would be a huge UI nightmare.
This commit is contained in:
Simon Tatham
2021-05-25 10:44:08 +01:00
parent 12b64a1db1
commit 8f3413c31f

View File

@ -394,12 +394,14 @@ static void add_assoc_with_opposite(game_state *state, space *tile, space *dot)
}
}
#ifndef EDITOR
static space *sp2dot(const game_state *state, int x, int y)
{
space *sp = &SPACE(state, x, y);
if (!(sp->flags & F_TILE_ASSOC)) return NULL;
return &SPACE(state, sp->dotx, sp->doty);
}
#endif
#define IS_VERTICAL_EDGE(x) ((x % 2) == 0)
@ -408,8 +410,24 @@ static bool game_can_format_as_text_now(const game_params *params)
return true;
}
static char *encode_game(const game_state *state);
static char *game_text_format(const game_state *state)
{
#ifdef EDITOR
game_params par;
char *params, *desc, *ret;
par.w = state->w;
par.h = state->h;
par.diff = DIFF_MAX; /* shouldn't be used */
params = encode_params(&par, false);
desc = encode_game(state);
ret = snewn(strlen(params) + strlen(desc) + 2, char);
sprintf(ret, "%s:%s", params, desc);
sfree(params);
sfree(desc);
return ret;
#else
int maxlen = (state->sx+1)*state->sy, x, y;
char *ret, *p;
space *sp;
@ -463,6 +481,7 @@ static char *game_text_format(const game_state *state)
*p = '\0';
return ret;
#endif
}
static void dbg_state(const game_state *state)
@ -943,7 +962,7 @@ static void free_game(game_state *state)
* an edit mode.
*/
static char *encode_game(game_state *state)
static char *encode_game(const game_state *state)
{
char *desc, *p;
int run, x, y, area;