simon-git: puzzles (main): Simon Tatham
Commits to Tartarus hosted VCS
tartarus-commits at lists.tartarus.org
Sun Apr 23 13:31:33 BST 2023
TL;DR:
ec2e2f3 Missing const in configure() documentation.
a4fca32 Pass a game_ui to compute_size, print_size and print.
0d1a1f0 Move per-puzzle ad-hoc getenv preferences into game_ui.
0058331 New backend functions: get_prefs and set_prefs.
d13ece6 Generalise the midend serialisation callbacks.
ea6be8f Require games to accept new_ui(NULL) if they have preferences.
bb1ab36 Keep a set of preferences in the midend.
4752c7a Universal preference option for one-key shortcuts.
6c66e2b Support preferences in the GTK frontend.
e2add41 GTK: add a command-line --delete-prefs option.
Repository: https://git.tartarus.org/simon/puzzles.git
On the web: https://git.tartarus.org/?p=simon/puzzles.git
Branch updated: main
Committer: Simon Tatham <anakin at pobox.com>
Date: 2023-04-23 13:31:33
commit ec2e2f37703e1da4bb097c27ae5e7f1fa368624b
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=ec2e2f37703e1da4bb097c27ae5e7f1fa368624b;hp=20606f0fea14fecae55efa7fef4314a2f999ddc3
Author: Simon Tatham <anakin at pobox.com>
Date: Fri Apr 21 16:12:43 2023 +0100
Missing const in configure() documentation.
Commit de67801b0fd3dfa changed the 'name' field from char * to const
char *, but didn't update the docs to match. Better late than never.
devel.but | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
commit a4fca3286f3aa630a3641e50a8e1f44ab1504a29
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=a4fca3286f3aa630a3641e50a8e1f44ab1504a29;hp=ec2e2f37703e1da4bb097c27ae5e7f1fa368624b
Author: Simon Tatham <anakin at pobox.com>
Date: Fri Apr 21 15:30:41 2023 +0100
Pass a game_ui to compute_size, print_size and print.
I'm about to move some of the bodgy getenv-based options so that they
become fields in game_ui. So these functions, which could previously
access those options directly via getenv, will now need to be given a
game_ui where they can look them up.
blackbox.c | 2 +-
bridges.c | 10 ++++++----
cube.c | 2 +-
devel.but | 8 +++++---
dominosa.c | 10 ++++++----
fifteen.c | 2 +-
filling.c | 10 ++++++----
flip.c | 2 +-
flood.c | 2 +-
galaxies.c | 10 ++++++----
guess.c | 5 +++--
inertia.c | 2 +-
keen.c | 10 ++++++----
lightup.c | 10 ++++++----
loopy.c | 10 ++++++----
magnets.c | 10 ++++++----
map.c | 10 ++++++----
midend.c | 12 ++++++------
mines.c | 2 +-
mosaic.c | 2 +-
net.c | 10 ++++++----
netslide.c | 2 +-
nullgame.c | 2 +-
palisade.c | 10 ++++++----
pattern.c | 10 ++++++----
pearl.c | 10 ++++++----
pegs.c | 2 +-
printing.c | 17 +++++++++++++----
puzzles.h | 8 +++++---
range.c | 10 ++++++----
rect.c | 10 ++++++----
samegame.c | 2 +-
signpost.c | 10 ++++++----
singles.c | 10 ++++++----
sixteen.c | 2 +-
slant.c | 10 ++++++----
solo.c | 10 ++++++----
tents.c | 10 ++++++----
towers.c | 10 ++++++----
tracks.c | 10 ++++++----
twiddle.c | 2 +-
undead.c | 2 +-
unequal.c | 10 ++++++----
unfinished/group.c | 10 ++++++----
unfinished/separate.c | 8 +++++---
unfinished/slide.c | 8 +++++---
unfinished/sokoban.c | 8 +++++---
unruly.c | 10 ++++++----
untangle.c | 4 ++--
49 files changed, 214 insertions(+), 144 deletions(-)
commit 0d1a1f08bac25a4641c38a8e42dfa6e2bb9981d7
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=0d1a1f08bac25a4641c38a8e42dfa6e2bb9981d7;hp=a4fca3286f3aa630a3641e50a8e1f44ab1504a29
Author: Simon Tatham <anakin at pobox.com>
Date: Fri Apr 21 15:41:18 2023 +0100
Move per-puzzle ad-hoc getenv preferences into game_ui.
Environment variables that set specific settings of particular
puzzles, such as SLANT_SWAP_BUTTONS, LIGHTUP_LIT_BLOBS and
LOOPY_AUTOFOLLOW, now all affect the game behaviour via fields in
game_ui instead of being looked up by getenv in the individual
functions that need to know them.
The purpose of this refactoring is to put those config fields in a
place where other more user-friendly configuration systems will also
be able to access them, once I introduce one. However, for the moment,
there's no functional change: I haven't _yet_ changed how the user
sets those options. They're still set by environment variables alone.
All I'm changing here is where the settings are stored inside the
code, and exactly when they're read out of the environment to put into
the game_ui.
Specifically, the getenvs now happen during new_ui(). Or rather, in
all the puzzles I've changed here, they happen in a subroutine
legacy_prefs_override() called from within new_ui(), after it's set up
the default values for the settings, and then gives the environment a
chance to override them. Or rather, legacy_prefs_override() only
actually calls getenv the first time, and after that, it's cached the
answers it got.
In order to make the override functions less wordy, I've altered the
prototype of getenv_bool so that it returns an int rather than a bool,
and takes its default return value in the same form. That way you can
set the default to something other than 0 or 1, and find out whether a
value was present at all.
This commit only touches environment configuration specific to an
individual puzzle. The midend also has some standard environment-based
config options that apply to all puzzles, such as colour scheme and
default presets and preset-menu extension. I haven't handled those
yet.
fifteen.c | 38 +++++++++++--
lightup.c | 33 +++++++++--
loopy.c | 182 ++++++++++++++++++++++++++++++++++++-------------------------
map.c | 62 ++++++++++++++-------
misc.c | 2 +-
pearl.c | 76 +++++++++++++++++---------
puzzles.h | 4 +-
range.c | 72 ++++++++++++++----------
signpost.c | 48 +++++++++-------
slant.c | 26 +++++++++
towers.c | 54 ++++++++++++++----
11 files changed, 402 insertions(+), 195 deletions(-)
commit 0058331aeb027f7441a04d99cc7c1e445bd896d9
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=0058331aeb027f7441a04d99cc7c1e445bd896d9;hp=0d1a1f08bac25a4641c38a8e42dfa6e2bb9981d7
Author: Simon Tatham <anakin at pobox.com>
Date: Fri Apr 21 15:50:05 2023 +0100
New backend functions: get_prefs and set_prefs.
These are similar to the existing pair configure() and custom_params()
in that get_prefs() returns an array of config_item describing a set
of dialog-box controls to present to the user, and set_prefs()
receives the same array with answers filled in and implements the
answers. But where configure() and custom_params() operate on a
game_params structure, the new pair operate on a game_ui, and are
intended to permit GUI configuration of all the settings I just moved
into that structure.
However, nothing actually _calls_ these routines yet. All I've done in
this commit is to add them to 'struct game' and implement them for the
functions that need them.
Also, config_item has new fields, permitting each config option to
define a machine-readable identifying keyword as well as the
user-facing description. For options of type C_CHOICES, each choice
also has a keyword. These keyword fields are only defined at all by
the new get_prefs() function - they're left uninitialised in existing
uses of the dialog system. The idea is to use them when writing out
the user's preferences into a configuration file on disk, although I
haven't actually done any of that work in this commit.
blackbox.c | 1 +
bridges.c | 1 +
cube.c | 1 +
devel.but | 114 ++++++++++++++++++++++++++++++++++++++++++--------
dominosa.c | 1 +
fifteen.c | 25 +++++++++++
filling.c | 1 +
flip.c | 1 +
flood.c | 1 +
galaxies.c | 1 +
guess.c | 1 +
inertia.c | 1 +
keen.c | 1 +
lightup.c | 23 ++++++++++
loopy.c | 32 ++++++++++++++
magnets.c | 1 +
map.c | 25 +++++++++++
mines.c | 1 +
mosaic.c | 1 +
net.c | 1 +
netslide.c | 1 +
nullgame.c | 1 +
palisade.c | 1 +
pattern.c | 1 +
pearl.c | 25 +++++++++++
pegs.c | 1 +
puzzles.h | 16 ++++++-
range.c | 26 ++++++++++++
rect.c | 1 +
samegame.c | 1 +
signpost.c | 25 +++++++++++
singles.c | 1 +
sixteen.c | 1 +
slant.c | 25 +++++++++++
solo.c | 1 +
tents.c | 1 +
towers.c | 25 +++++++++++
tracks.c | 1 +
twiddle.c | 1 +
undead.c | 1 +
unequal.c | 1 +
unfinished/group.c | 1 +
unfinished/separate.c | 1 +
unfinished/slide.c | 1 +
unfinished/sokoban.c | 1 +
unruly.c | 1 +
untangle.c | 1 +
47 files changed, 378 insertions(+), 19 deletions(-)
commit d13ece698f02288c56cf46f3a20ecc1aaf8004f5
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=d13ece698f02288c56cf46f3a20ecc1aaf8004f5;hp=0058331aeb027f7441a04d99cc7c1e445bd896d9
Author: Simon Tatham <anakin at pobox.com>
Date: Fri Apr 21 16:19:49 2023 +0100
Generalise the midend serialisation callbacks.
These are currently only used for internal serialisation of midend
state in order to undo/redo across New Game, and are named
accordingly. But I'm about to reuse them for another set of
serialisation functions, so they'll want more general names, and also
need to be moved higher up in the source file so as to have been
defined where I'll want to use them.
midend.c | 56 +++++++++++++++++++++++++++++---------------------------
1 file changed, 29 insertions(+), 27 deletions(-)
commit ea6be8f0af766ed15b19260ae17fa793d3d6d4d8
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=ea6be8f0af766ed15b19260ae17fa793d3d6d4d8;hp=d13ece698f02288c56cf46f3a20ecc1aaf8004f5
Author: Simon Tatham <anakin at pobox.com>
Date: Sat Apr 22 10:51:37 2023 +0100
Require games to accept new_ui(NULL) if they have preferences.
This will be necessary in the next commit, so that the midend can make
a game_ui out of nothing in order to store preferences in it.
The only game actually affected by this requirement is Pearl, which
has a preference (GUI style) and also allocates space based on the
game_state's grid size to store the coordinates of a path being
dragged, so if there is no game_state, it can't do the latter - which
is OK, because it also won't be expected to.
devel.but | 18 +++++++++++++++---
pearl.c | 3 +--
2 files changed, 16 insertions(+), 5 deletions(-)
commit bb1ab36108942ed9b0c84bf68e22869994467a2a
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=bb1ab36108942ed9b0c84bf68e22869994467a2a;hp=ea6be8f0af766ed15b19260ae17fa793d3d6d4d8
Author: Simon Tatham <anakin at pobox.com>
Date: Sat Apr 22 12:54:11 2023 +0100
Keep a set of preferences in the midend.
This commit introduces a serialisation format for the user preferences
stored in game_ui, using the keyword identifiers that get_prefs is
required to write into its list of config_item. As a result, the
serialisation format looks enough like an ordinary config file that a
user could write one by hand.
The preferences for the game backend are kept in serialised form in
me->be_prefs. The typical use of this is to apply it to a just-created
game_ui by calling midend_apply_prefs(), which deserialises the prefs
buffer into a list of config_item and passes it to the backend's
set_prefs function, overwriting the preference fields (but no others)
of the game_ui.
This is duly done when creating a new game, when loading a game from a
save file, and also when printing a puzzle. To make the latter work,
document_add_puzzle now takes a game_ui (and keeps ownership of it
afterwards), and passes that to the backend's compute_size and print
functions.
The backend's own get_prefs and set_prefs functions are wrapped by
midend_get_prefs and midend_set_prefs. This is partly as a convenience
(it deals with optionally constructing a game_ui specially to call the
backend with), but mostly so that there will be a convenient place in
the midend to add standard preferences applying across all puzzles.
No cross-puzzle preferences are provided yet.
There are two external interfaces to all this, and in this commit,
neither one is yet called by any frontend:
A new pair of midend functions is exposed to the front end, called
midend_load_prefs and midend_save_prefs. These have a similar API to
midend_serialise and midend_deserialise, taking a read/write function
pointer and a context. So front ends that can already load/save a game
to a file on disk should find it easy to add a similar set of
functions loading/saving user preferences.
Secondly, a new value CFG_PREFS is added to the enumeration of
configuration dialog types, alongside the ones for the Custom game
type, entering a game description and entering a random seed. This
should make it easy for frontends to offer a Preferences dialog,
because it will operate almost exactly like three dialogs they already
handle.
devel.but | 32 +++++-
midend.c | 362 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
nullfe.c | 2 +-
osx.m | 2 +-
printing.c | 16 ++-
puzzles.h | 9 +-
6 files changed, 403 insertions(+), 20 deletions(-)
commit 4752c7a2d9bd83d41d418b31b931a9bb9af219fa
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=4752c7a2d9bd83d41d418b31b931a9bb9af219fa;hp=bb1ab36108942ed9b0c84bf68e22869994467a2a
Author: Simon Tatham <anakin at pobox.com>
Date: Sun Apr 23 10:09:27 2023 +0100
Universal preference option for one-key shortcuts.
With this option turned off (it's on by default), the single-letter
keyboard shortcuts like 'q' for quit and 'n' for new game don't
function any more. You can still access the same functions via more
complicated shortcuts like Ctrl-Q or Ctrl-N, and front ends can
provide any other UI they like for the same operations, but this way,
people aren't at risk of blowing away half an hour of puzzling with
one misaimed key.
This is a thing people have occasionally asked for, and I've generally
resisted on the grounds that I have sympathy for people playing
puzzles at work who need to be able to close the game quickly when an
unsympathetic boss wanders by. But now we have a preferences system,
we can cater to those people _and_ the ones who don't mind.
More immediately useful: adding _at least one_ universal preference in
the initial version of this system means that there will be no games
with no preference options at all, and therefore, no need to put
conditionals all through the participating frontends to deal with
whether the Preferences menu option should even be provided. That
would have been a waste of time because all those conditionals would
just have to be removed again as soon as the first universal
preference came along - so adding an easy one _now_ means we can save
the effort of putting in the temporary conditionals in the first
place.
midend.c | 32 +++++++++++++++++++++++---------
1 file changed, 23 insertions(+), 9 deletions(-)
commit 6c66e2b2de63b6a8159835516ee229bda3253bc2
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=6c66e2b2de63b6a8159835516ee229bda3253bc2;hp=4752c7a2d9bd83d41d418b31b931a9bb9af219fa
Author: Simon Tatham <anakin at pobox.com>
Date: Sun Apr 23 10:58:53 2023 +0100
Support preferences in the GTK frontend.
Finally, some user-visible behaviour changes as a payoff for all that
preparation work! In this commit, the GTK puzzles get a 'Preferences'
option in the menu, which presents a dialog box to configure the
preference settings.
On closing that dialog box, the puzzle preferences are enacted
immediately, and also saved to a configuration file where the next run
of the same puzzle will reload them.
The default file location is ~/.config/sgt-puzzles/<puzzlename>.conf,
although you can override the .config dir via $XDG_CONFIG_HOME or
override the Puzzles-specific subdir with $SGT_PUZZLES_DIR.
This is the first commit that actually exposes all the new preferences
work to the user, and therefore, I've also added documentation of all
the current preference options.
gtk.c | 166 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
misc.c | 31 ++++++++++++
puzzles.but | 112 +++++++++++++++++++++++++++++++++++++++-
puzzles.h | 2 +
4 files changed, 307 insertions(+), 4 deletions(-)
commit e2add4185cf1e3639b7a320384098d63dc2f3d67
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=e2add4185cf1e3639b7a320384098d63dc2f3d67;hp=6c66e2b2de63b6a8159835516ee229bda3253bc2
Author: Simon Tatham <anakin at pobox.com>
Date: Sun Apr 23 11:00:58 2023 +0100
GTK: add a command-line --delete-prefs option.
If you want to remove your saved preferences for a puzzle for any
reason (perhaps because of one of those unsympathetic managers, or
perhaps because it's become corrupted in some way), you can of course
manually go and find the config file and delete it. But if you're not
sure where it is, it's helpful to have a method of telling the puzzle
itself to delete the config file.
Perhaps it would be useful to expose this in the GUI as well, though
I'm not quite sure where is the best place to put it.
(_Perhaps_ it would also be useful to have a more thorough option that
deleted _all_ puzzles' configurations - although that would involve
telling every separate puzzle binary in this collection what all the
other ones' names are, which would be an entirely new build headache.)
gtk.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
puzzles.but | 5 ++++
2 files changed, 83 insertions(+)
More information about the tartarus-commits
mailing list