aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2021-05-25 10:44:08 +0100
committerSimon Tatham <anakin@pobox.com>2021-05-25 10:59:11 +0100
commit8f3413c31ffd43c4ebde40894ac1b2f7cdf222c3 (patch)
tree2eac9b48329dc374cbfb86a08c316c5aec0095ae
parent12b64a1db1a2cb94b938295875e5583237dbe168 (diff)
downloadpuzzles-8f3413c31ffd43c4ebde40894ac1b2f7cdf222c3.zip
puzzles-8f3413c31ffd43c4ebde40894ac1b2f7cdf222c3.tar.gz
puzzles-8f3413c31ffd43c4ebde40894ac1b2f7cdf222c3.tar.bz2
puzzles-8f3413c31ffd43c4ebde40894ac1b2f7cdf222c3.tar.xz
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.
-rw-r--r--galaxies.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/galaxies.c b/galaxies.c
index 52dcaff..fbcaff2 100644
--- a/galaxies.c
+++ b/galaxies.c
@@ -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;