ref: 8f3413c31ffd43c4ebde40894ac1b2f7cdf222c3
parent: 12b64a1db1a2cb94b938295875e5583237dbe168
author: Simon Tatham <anakin@pobox.com>
date: Tue May 25 06:44:08 EDT 2021
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.
--- a/galaxies.c
+++ b/galaxies.c
@@ -394,6 +394,7 @@
}
}
+#ifndef EDITOR
static space *sp2dot(const game_state *state, int x, int y)
{
space *sp = &SPACE(state, x, y);
@@ -400,6 +401,7 @@
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 @@
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 @@
*p = '\0';
return ret;
+#endif
}
static void dbg_state(const game_state *state)
@@ -943,7 +962,7 @@
* 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;