diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 0000000000000000000000000000000000000000..1a2b0f9dbecdf19f7446c15e5c35fd462a4d1446 --- /dev/null +++ b/meson_options.txt @@ -0,0 +1,4 @@ +# These should be integers for Meson >= 0.45 +option('try_points', type: 'string', value: '7') +option('utry_points', type: 'string', value: '5') +option('kick_points', type: 'string', value: '3') \ No newline at end of file diff --git a/src/meson.build b/src/meson.build index 326cdead62c492d7d69b44a44578644dda3e4287..7fff179aa2affd14b3d7ecda5c9a0cc47607c6f1 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1,15 +1,22 @@ gnome = import('gnome') +conf = configuration_data() +conf.set('TRY_POINTS', get_option('try_points')) +conf.set('UTRY_POINTS', get_option('utry_points')) +conf.set('KICK_POINTS', get_option('kick_points')) + +config_h = configure_file(configuration: conf, output: 'config.h') + sources = files( 'rugby.c', 'rugby-application.c', 'rugby-app-window.c', 'rugby-list-store.c', 'rugby-possibility.c', - 'rugby-possibility-widget.c', - 'rugby-scoring.c' + 'rugby-possibility-widget.c' ) +sources += config_h sources += resources deps = [gio_dep, gtk_dep] diff --git a/src/rugby-app-window.c b/src/rugby-app-window.c index f2fa2e242ffc16d83f3d2b15a98250c1ece4dc9d..32af8db411294f45aa13ba9200a022c0c7b29524 100644 --- a/src/rugby-app-window.c +++ b/src/rugby-app-window.c @@ -18,12 +18,12 @@ #include <gtk/gtk.h> +#include "config.h" #include "rugby-application.h" #include "rugby-app-window.h" #include "rugby-list-store.h" #include "rugby-possibility.h" #include "rugby-possibility-widget.h" -#include "rugby-scoring.h" struct _RugbyAppWindow { @@ -40,6 +40,18 @@ struct _RugbyAppWindow G_DEFINE_TYPE (RugbyAppWindow, rugby_app_window, GTK_TYPE_APPLICATION_WINDOW) +static inline guint +get_max_tries (guint score) +{ + return (score % 5 == 1) ? score / UTRY_POINTS - 1 : score / UTRY_POINTS; +} + +static inline guint +get_max_kicks (guint score) +{ + return (score % 3 == 1) ? score / KICK_POINTS : score / KICK_POINTS - 1; +} + static void scorespin_value_changed_cb (GtkSpinButton *spin, RugbyAppWindow *self) @@ -48,10 +60,10 @@ scorespin_value_changed_cb (GtkSpinButton *spin, rugby_list_store_set_score (self->store, score); - gint max_tries = MAX (rugby_scoring_get_max_tries (score), 1.0); + gint max_tries = MAX (get_max_tries (score), 1.0); gtk_range_set_range (GTK_RANGE (self->tryscale), 0.0, max_tries); - gint max_kicks = MAX (rugby_scoring_get_max_kicks (score), 1.0); + gint max_kicks = MAX (get_max_kicks (score), 1.0); gtk_range_set_range (GTK_RANGE (self->kickscale), 0.0, max_kicks); } diff --git a/src/rugby-list-store.c b/src/rugby-list-store.c index 8d8b38f0e8b7aa601d6f890d81425dcc033ac927..21fc1a1d24ffe0f414fd347c44c2b25d54a8bb3f 100644 --- a/src/rugby-list-store.c +++ b/src/rugby-list-store.c @@ -18,9 +18,9 @@ * SPDX-License-Identifier: LGPL-3.0-or-later */ +#include "config.h" #include "rugby-list-store.h" #include "rugby-possibility.h" -#include "rugby-scoring.h" #include <gio/gio.h> diff --git a/src/rugby-scoring.c b/src/rugby-scoring.c deleted file mode 100644 index 967d680097c358c842efe5cc7dca3333a4eff404..0000000000000000000000000000000000000000 --- a/src/rugby-scoring.c +++ /dev/null @@ -1,32 +0,0 @@ -/* rugby-scoring.c - * - * Copyright © 2012, 2017 Bruce Cowan <bruce@bcowan.eu> - * - * This file is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 3 of the - * License, or (at your option) any later version. - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include "rugby-possibility.h" -#include "rugby-scoring.h" - -gint -rugby_scoring_get_max_tries (gint score) -{ - return (score % 5 == 1) ? score / UTRY_POINTS - 1 : score / UTRY_POINTS; -} - -gint -rugby_scoring_get_max_kicks (gint score) -{ - return (score % 3 == 1) ? score / KICK_POINTS : score / KICK_POINTS - 1; -} diff --git a/src/rugby-scoring.h b/src/rugby-scoring.h deleted file mode 100644 index 67c69d377c5b6c2a008873b6b9b55acef5a29a82..0000000000000000000000000000000000000000 --- a/src/rugby-scoring.h +++ /dev/null @@ -1,32 +0,0 @@ -/* rugby-scoring.h - * - * Copyright © 2012, 2017 Bruce Cowan <bruce@bcowan.eu> - * - * This file is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 3 of the - * License, or (at your option) any later version. - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#pragma once - -#include <gio/gio.h> - -G_BEGIN_DECLS - -#define TRY_POINTS 7 -#define UTRY_POINTS 5 -#define KICK_POINTS 3 - -gint rugby_scoring_get_max_tries (gint score); -gint rugby_scoring_get_max_kicks (gint score); - -G_END_DECLS