Skip to content
Snippets Groups Projects
Commit e1ae94d7 authored by Bruce Cowan's avatar Bruce Cowan
Browse files

Make points per scoring type configurable at compile time

parent 042cc2c1
No related branches found
No related tags found
No related merge requests found
# 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
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]
......
......@@ -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);
}
......
......@@ -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>
......
/* 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;
}
/* 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment