/* gnome-nibbles.c generated by valac 0.56.19, the Vala compiler
 * generated from gnome-nibbles.vala, do not modify */

/* -*- Mode: vala; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 * Gnome Nibbles: Gnome Worm Game
 * Copyright (C) 2015 Iulian-Gabriel Radu <iulian.radu67@gmail.com>
 * Copyright (C) 2023-2026 Ben Corby <bcorby@new-ms.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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 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/>.
 */
/*
 * Coding style.
 *
 * To help you comply with the coding style in this project use the
 * following greps. Any lines returned should be adjusted so they
 * don't match. The convoluted regular expressions are so they don't
 * match them self.
 *
 * grep -ne '[^][)(_!$ "](' *.vala
 * grep -ne '[(] ' *.vala
 * grep -ne '[ ])' *.vala
 * grep -ne ' $' *.vala
 *
 */
/* designed for Gtk 4, link with libgtk-4-dev or gtk4-devel */

#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <glib-object.h>
#include <adwaita.h>
#include <gio/gio.h>
#include <glib/gi18n-lib.h>
#include <locale.h>
#include <stdio.h>
#include <gdk/gdk.h>

#define NIBBLES_PROGRAM_NAME _ ("Nibbles")
#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define TYPE_NIBBLES (nibbles_get_type ())
#define NIBBLES(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_NIBBLES, Nibbles))
#define NIBBLES_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_NIBBLES, NibblesClass))
#define IS_NIBBLES(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_NIBBLES))
#define IS_NIBBLES_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_NIBBLES))
#define NIBBLES_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_NIBBLES, NibblesClass))

typedef struct _Nibbles Nibbles;
typedef struct _NibblesClass NibblesClass;
typedef struct _NibblesPrivate NibblesPrivate;

#define TYPE_NIBBLES_WINDOW (nibbles_window_get_type ())
#define NIBBLES_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_NIBBLES_WINDOW, NibblesWindow))
#define NIBBLES_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_NIBBLES_WINDOW, NibblesWindowClass))
#define IS_NIBBLES_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_NIBBLES_WINDOW))
#define IS_NIBBLES_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_NIBBLES_WINDOW))
#define NIBBLES_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_NIBBLES_WINDOW, NibblesWindowClass))

typedef struct _NibblesWindow NibblesWindow;
typedef struct _NibblesWindowClass NibblesWindowClass;
enum  {
	NIBBLES_0_PROPERTY,
	NIBBLES_NUM_PROPERTIES
};
static GParamSpec* nibbles_properties[NIBBLES_NUM_PROPERTIES];
typedef void (*GSimpleActionActivateCallback) (GSimpleAction* action, GVariant* parameter, gpointer user_data);
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
typedef enum  {
	SETUP_SCREEN_USUAL,
	SETUP_SCREEN_SPEED,
	SETUP_SCREEN_CONTROLS,
	SETUP_SCREEN_GAME
} SetupScreen;

#define TYPE_SETUP_SCREEN (setup_screen_get_type ())

struct _Nibbles {
	GtkApplication parent_instance;
	NibblesPrivate * priv;
};

struct _NibblesClass {
	GtkApplicationClass parent_class;
};

struct _NibblesPrivate {
	NibblesWindow* window;
};

static gint Nibbles_private_offset;
static gpointer nibbles_parent_class = NULL;
static gint nibbles_level;
static gint nibbles_progress;
static gint nibbles_nibbles;
static gint nibbles_players;
static gint nibbles_speed;
static gboolean nibbles_disable_fakes;
static gboolean nibbles_disable_fakes = FALSE;
static gboolean nibbles_enable_fakes;
static gboolean nibbles_enable_fakes = FALSE;
static gboolean nibbles_start;
static gboolean nibbles_start = FALSE;
static gint nibbles_level = G_MININT;
static gint nibbles_progress = G_MININT;
static gint nibbles_nibbles = G_MININT;
static gint nibbles_players = G_MININT;
static gint nibbles_speed = G_MININT;
static gboolean* nibbles_three_dimensional_view;
static gboolean* nibbles_three_dimensional_view = NULL;
static gboolean* nibbles_sound;
static gboolean* nibbles_sound = NULL;

VALA_EXTERN GType nibbles_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (Nibbles, g_object_unref)
VALA_EXTERN GType nibbles_window_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (NibblesWindow, g_object_unref)
static inline void nibbles_help_cb (Nibbles* self);
static void _nibbles_help_cb_gsimple_action_activate_callback (GSimpleAction* action,
                                                        GVariant* parameter,
                                                        gpointer self);
static inline void nibbles_about_cb (Nibbles* self);
static void _nibbles_about_cb_gsimple_action_activate_callback (GSimpleAction* action,
                                                         GVariant* parameter,
                                                         gpointer self);
static void _g_application_quit_gsimple_action_activate_callback (GSimpleAction* action,
                                                           GVariant* parameter,
                                                           gpointer self);
static gint nibbles_main (gchar** args,
                   gint args_length1);
static Nibbles* nibbles_new (void);
static Nibbles* nibbles_construct (GType object_type);
static gint nibbles_real_handle_local_options (GApplication* base,
                                        GVariantDict* options);
static gboolean* _bool_dup (gboolean* self);
static void nibbles_real_startup (GApplication* base);
static void nibbles_create_window (Nibbles* self);
VALA_EXTERN GType setup_screen_get_type (void) G_GNUC_CONST ;
VALA_EXTERN NibblesWindow* nibbles_window_new (gint cli_start_level,
                                   SetupScreen start_screen);
VALA_EXTERN NibblesWindow* nibbles_window_construct (GType object_type,
                                         gint cli_start_level,
                                         SetupScreen start_screen);
static void nibbles_real_activate (GApplication* base);
static void nibbles_real_shutdown (GApplication* base);
VALA_EXTERN void nibbles_window_on_shutdown (NibblesWindow* self);
VALA_EXTERN gboolean nibbles_window_get_game_paused (NibblesWindow* self);
static void nibbles_finalize (GObject * obj);
static GType nibbles_get_type_once (void);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);

static const GActionEntry NIBBLES_action_entries[3] = {{"help", _nibbles_help_cb_gsimple_action_activate_callback}, {"about", _nibbles_about_cb_gsimple_action_activate_callback}, {"quit", _g_application_quit_gsimple_action_activate_callback}};
static const GOptionEntry NIBBLES_option_entries[14] = {{"disable-fakes", 'd', (gint) G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL, N_ ("Disable fake bonuses"), NULL}, {"enable-fakes", 'e', (gint) G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL, N_ ("Enable fake bonuses"), NULL}, {"level", 'l', (gint) G_OPTION_FLAG_NONE, G_OPTION_ARG_INT, &nibbles_level, N_ ("Start at given level (1-26)"), N_ ("NUMBER")}, {"progress", (gchar) 0, (gint) G_OPTION_FLAG_NONE, G_OPTION_ARG_INT, &nibbles_progress, N_ ("Method of progress through the boards (0 - sequentially, 1 - randomly," \
" 2 - fixed board)"), N_ ("NUMBER")}, {"nibbles", 'n', (gint) G_OPTION_FLAG_NONE, G_OPTION_ARG_INT, &nibbles_nibbles, N_ ("Set number of nibbles (4-6)"), N_ ("NUMBER")}, {"players", 'p', (gint) G_OPTION_FLAG_NONE, G_OPTION_ARG_INT, &nibbles_players, N_ ("Set number of players (1-4)"), N_ ("NUMBER")}, {"speed", 's', (gint) G_OPTION_FLAG_NONE, G_OPTION_ARG_INT, &nibbles_speed, N_ ("Set worms speed (4-1, 4 for slow)"), N_ ("NUMBER")}, {"3D", '3', (gint) G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL, N_ ("Set three dimensional view"), NULL}, {"2D", '2', (gint) G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL, N_ ("Set two dimensional view"), NULL}, {"start", (gchar) 0, (gint) G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL, N_ ("Start playing"), NULL}, {"mute", (gchar) 0, (gint) G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL, N_ ("Turn off the sound"), NULL}, {"unmute", (gchar) 0, (gint) G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL, N_ ("Turn on the sound"), NULL}, {"version", 'v', (gint) G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL, N_ ("Show release version"), NULL}, {0}};

static inline gpointer
nibbles_get_instance_private (Nibbles* self)
{
	return G_STRUCT_MEMBER_P (self, Nibbles_private_offset);
}

static void
_nibbles_help_cb_gsimple_action_activate_callback (GSimpleAction* action,
                                                   GVariant* parameter,
                                                   gpointer self)
{
	nibbles_help_cb ((Nibbles*) self);
}

static void
_nibbles_about_cb_gsimple_action_activate_callback (GSimpleAction* action,
                                                    GVariant* parameter,
                                                    gpointer self)
{
	nibbles_about_cb ((Nibbles*) self);
}

static void
_g_application_quit_gsimple_action_activate_callback (GSimpleAction* action,
                                                      GVariant* parameter,
                                                      gpointer self)
{
	g_application_quit ((GApplication*) self);
}

static gint
nibbles_main (gchar** args,
              gint args_length1)
{
	Nibbles* application = NULL;
	Nibbles* _tmp0_;
	gint result;
	setlocale (LC_ALL, "");
	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);
	adw_init ();
	_tmp0_ = nibbles_new ();
	application = _tmp0_;
	result = g_application_run ((GApplication*) application, (gint) args_length1, args);
	_g_object_unref0 (application);
	return result;
}

int
main (int argc,
      char ** argv)
{
	return nibbles_main (argv, argc);
}

static Nibbles*
nibbles_construct (GType object_type)
{
	Nibbles * self = NULL;
	self = (Nibbles*) g_object_new (object_type, "application-id", "org.gnome.Nibbles", "flags", G_APPLICATION_DEFAULT_FLAGS, NULL);
	g_application_add_main_option_entries ((GApplication*) self, NIBBLES_option_entries);
	return self;
}

static Nibbles*
nibbles_new (void)
{
	return nibbles_construct (TYPE_NIBBLES);
}

static gboolean*
_bool_dup (gboolean* self)
{
	gboolean* dup;
	dup = g_new0 (gboolean, 1);
	memcpy (dup, self, sizeof (gboolean));
	return dup;
}

static gpointer
__bool_dup0 (gpointer self)
{
	return self ? _bool_dup (self) : NULL;
}

static gint
nibbles_real_handle_local_options (GApplication* base,
                                   GVariantDict* options)
{
	Nibbles * self;
	gboolean _tmp1_ = FALSE;
	gboolean _tmp6_ = FALSE;
	gboolean _tmp11_ = FALSE;
	gboolean _tmp16_ = FALSE;
	gboolean _tmp21_ = FALSE;
	gboolean _tmp26_ = FALSE;
	gboolean _tmp34_ = FALSE;
	gint result;
	self = (Nibbles*) base;
	g_return_val_if_fail (options != NULL, -1);
	if (g_variant_dict_contains (options, "version")) {
		FILE* _tmp0_;
		_tmp0_ = stderr;
		fprintf (_tmp0_, "gnome-nibbles %s\n", VERSION);
		result = EXIT_SUCCESS;
		return result;
	}
	if (nibbles_level != G_MININT) {
		gboolean _tmp2_ = FALSE;
		if (nibbles_level < 1) {
			_tmp2_ = TRUE;
		} else {
			_tmp2_ = nibbles_level > 26;
		}
		_tmp1_ = _tmp2_;
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		FILE* _tmp3_;
		gchar* _tmp4_;
		gchar* _tmp5_;
		_tmp3_ = stderr;
		_tmp4_ = g_strconcat (_ ("Start level should only be between 1 and 26."), "\n", NULL);
		_tmp5_ = _tmp4_;
		fprintf (_tmp3_, "%s", _tmp5_);
		_g_free0 (_tmp5_);
		result = EXIT_FAILURE;
		return result;
	}
	if (nibbles_progress != G_MININT) {
		gboolean _tmp7_ = FALSE;
		if (nibbles_progress < 0) {
			_tmp7_ = TRUE;
		} else {
			_tmp7_ = nibbles_progress > 2;
		}
		_tmp6_ = _tmp7_;
	} else {
		_tmp6_ = FALSE;
	}
	if (_tmp6_) {
		FILE* _tmp8_;
		gchar* _tmp9_;
		gchar* _tmp10_;
		_tmp8_ = stderr;
		_tmp9_ = g_strconcat (_ ("Progress method should be; 0 - sequentially, 1 - randomly, 2 - fixed b" \
"oard."), "\n", NULL);
		_tmp10_ = _tmp9_;
		fprintf (_tmp8_, "%s", _tmp10_);
		_g_free0 (_tmp10_);
		result = EXIT_FAILURE;
		return result;
	}
	if (nibbles_nibbles != G_MININT) {
		gboolean _tmp12_ = FALSE;
		if (nibbles_nibbles < 4) {
			_tmp12_ = TRUE;
		} else {
			_tmp12_ = nibbles_nibbles > 6;
		}
		_tmp11_ = _tmp12_;
	} else {
		_tmp11_ = FALSE;
	}
	if (_tmp11_) {
		FILE* _tmp13_;
		gchar* _tmp14_;
		gchar* _tmp15_;
		_tmp13_ = stderr;
		_tmp14_ = g_strconcat (_ ("There could only be between 4 and 6 nibbles."), "\n", NULL);
		_tmp15_ = _tmp14_;
		fprintf (_tmp13_, "%s", _tmp15_);
		_g_free0 (_tmp15_);
		result = EXIT_FAILURE;
		return result;
	}
	if (nibbles_players != G_MININT) {
		gboolean _tmp17_ = FALSE;
		if (nibbles_players < 1) {
			_tmp17_ = TRUE;
		} else {
			_tmp17_ = nibbles_players > 4;
		}
		_tmp16_ = _tmp17_;
	} else {
		_tmp16_ = FALSE;
	}
	if (_tmp16_) {
		FILE* _tmp18_;
		gchar* _tmp19_;
		gchar* _tmp20_;
		_tmp18_ = stderr;
		_tmp19_ = g_strconcat (_ ("There could only be between 1 and 4 players."), "\n", NULL);
		_tmp20_ = _tmp19_;
		fprintf (_tmp18_, "%s", _tmp20_);
		_g_free0 (_tmp20_);
		result = EXIT_FAILURE;
		return result;
	}
	if (nibbles_speed != G_MININT) {
		gboolean _tmp22_ = FALSE;
		if (nibbles_speed < 1) {
			_tmp22_ = TRUE;
		} else {
			_tmp22_ = nibbles_speed > 4;
		}
		_tmp21_ = _tmp22_;
	} else {
		_tmp21_ = FALSE;
	}
	if (_tmp21_) {
		FILE* _tmp23_;
		gchar* _tmp24_;
		gchar* _tmp25_;
		_tmp23_ = stderr;
		_tmp24_ = g_strconcat (_ ("Speed should be between 4 (slow) and 1 (fast)."), "\n", NULL);
		_tmp25_ = _tmp24_;
		fprintf (_tmp23_, "%s", _tmp25_);
		_g_free0 (_tmp25_);
		result = EXIT_FAILURE;
		return result;
	}
	nibbles_disable_fakes = g_variant_dict_contains (options, "disable-fakes");
	nibbles_enable_fakes = g_variant_dict_contains (options, "enable-fakes");
	if (nibbles_disable_fakes) {
		_tmp26_ = nibbles_enable_fakes;
	} else {
		_tmp26_ = FALSE;
	}
	if (_tmp26_) {
		FILE* _tmp27_;
		gchar* _tmp28_;
		gchar* _tmp29_;
		_tmp27_ = stderr;
		_tmp28_ = g_strconcat (_ ("Options --disable-fakes (-d) and --enable-fakes (-e) are mutually excl" \
"usive."), "\n", NULL);
		_tmp29_ = _tmp28_;
		fprintf (_tmp27_, "%s", _tmp29_);
		_g_free0 (_tmp29_);
		result = EXIT_FAILURE;
		return result;
	}
	if (g_variant_dict_contains (options, "mute")) {
		gboolean _tmp30_;
		gboolean* _tmp31_;
		_tmp30_ = FALSE;
		_tmp31_ = __bool_dup0 (&_tmp30_);
		_g_free0 (nibbles_sound);
		nibbles_sound = _tmp31_;
	} else {
		if (g_variant_dict_contains (options, "unmute")) {
			gboolean _tmp32_;
			gboolean* _tmp33_;
			_tmp32_ = TRUE;
			_tmp33_ = __bool_dup0 (&_tmp32_);
			_g_free0 (nibbles_sound);
			nibbles_sound = _tmp33_;
		}
	}
	if (g_variant_dict_contains (options, "3D")) {
		_tmp34_ = g_variant_dict_contains (options, "2D");
	} else {
		_tmp34_ = FALSE;
	}
	if (_tmp34_) {
		FILE* _tmp35_;
		gchar* _tmp36_;
		gchar* _tmp37_;
		_tmp35_ = stderr;
		_tmp36_ = g_strconcat (_ ("Options --3D (-3) and --2D (-2) are mutually exclusive."), "\n", NULL);
		_tmp37_ = _tmp36_;
		fprintf (_tmp35_, "%s", _tmp37_);
		_g_free0 (_tmp37_);
		result = EXIT_FAILURE;
		return result;
	} else {
		if (g_variant_dict_contains (options, "3D")) {
			gboolean _tmp38_;
			gboolean* _tmp39_;
			_tmp38_ = TRUE;
			_tmp39_ = __bool_dup0 (&_tmp38_);
			_g_free0 (nibbles_three_dimensional_view);
			nibbles_three_dimensional_view = _tmp39_;
		} else {
			if (g_variant_dict_contains (options, "2D")) {
				gboolean _tmp40_;
				gboolean* _tmp41_;
				_tmp40_ = FALSE;
				_tmp41_ = __bool_dup0 (&_tmp40_);
				_g_free0 (nibbles_three_dimensional_view);
				nibbles_three_dimensional_view = _tmp41_;
			}
		}
	}
	if (g_variant_dict_contains (options, "start")) {
		nibbles_start = TRUE;
	}
	result = -1;
	return result;
}

static void
nibbles_real_startup (GApplication* base)
{
	Nibbles * self;
	AdwStyleManager* _tmp0_;
	static const gchar* newgame[2] = {"<Primary>n", NULL};
	static const gchar* fullscreen[2] = {"F11", NULL};
	static const gchar* pause[3] = {"<Primary>p", "Pause", NULL};
	static const gchar* appquit[2] = {"<Primary>q", NULL};
	static const gchar* back[2] = {"Escape", NULL};
	static const gchar* hamburger[3] = {"F10", "Menu", NULL};
	self = (Nibbles*) base;
	G_APPLICATION_CLASS (nibbles_parent_class)->startup ((GApplication*) G_TYPE_CHECK_INSTANCE_CAST (self, gtk_application_get_type (), GtkApplication));
	g_set_prgname ("org.gnome.Nibbles");
	g_set_application_name (NIBBLES_PROGRAM_NAME);
	gtk_window_set_default_icon_name ("org.gnome.Nibbles");
	_tmp0_ = adw_style_manager_get_default ();
	adw_style_manager_set_color_scheme (_tmp0_, ADW_COLOR_SCHEME_FORCE_DARK);
	g_action_map_add_action_entries ((GActionMap*) self, NIBBLES_action_entries, (gint) G_N_ELEMENTS (NIBBLES_action_entries), self);
	gtk_application_set_accels_for_action ((GtkApplication*) self, "win.new-game", newgame);
	gtk_application_set_accels_for_action ((GtkApplication*) self, "win.fullscreen", fullscreen);
	gtk_application_set_accels_for_action ((GtkApplication*) self, "win.pause", pause);
	gtk_application_set_accels_for_action ((GtkApplication*) self, "app.quit", appquit);
	gtk_application_set_accels_for_action ((GtkApplication*) self, "win.back", back);
	gtk_application_set_accels_for_action ((GtkApplication*) self, "win.hamburger", hamburger);
}

static void
nibbles_create_window (Nibbles* self)
{
	gboolean nibbles_changed = FALSE;
	gboolean players_changed = FALSE;
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	gboolean _tmp2_ = FALSE;
	gboolean _tmp3_ = FALSE;
	gboolean _tmp4_ = FALSE;
	gboolean _tmp5_ = FALSE;
	gboolean _tmp6_ = FALSE;
	SetupScreen setup = 0;
	gint _tmp34_ = 0;
	NibblesWindow* _tmp35_;
	NibblesWindow* _tmp36_;
	g_return_if_fail (self != NULL);
	nibbles_changed = nibbles_nibbles != G_MININT;
	players_changed = nibbles_players != G_MININT;
	if (nibbles_changed) {
		_tmp6_ = TRUE;
	} else {
		_tmp6_ = players_changed;
	}
	if (_tmp6_) {
		_tmp5_ = TRUE;
	} else {
		_tmp5_ = nibbles_progress != G_MININT;
	}
	if (_tmp5_) {
		_tmp4_ = TRUE;
	} else {
		_tmp4_ = nibbles_speed != G_MININT;
	}
	if (_tmp4_) {
		_tmp3_ = TRUE;
	} else {
		_tmp3_ = nibbles_disable_fakes;
	}
	if (_tmp3_) {
		_tmp2_ = TRUE;
	} else {
		_tmp2_ = nibbles_enable_fakes;
	}
	if (_tmp2_) {
		_tmp1_ = TRUE;
	} else {
		gboolean* _tmp7_;
		_tmp7_ = nibbles_three_dimensional_view;
		_tmp1_ = _tmp7_ != NULL;
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		gboolean* _tmp8_;
		_tmp8_ = nibbles_sound;
		_tmp0_ = _tmp8_ != NULL;
	}
	if (_tmp0_) {
		GSettings* settings = NULL;
		GSettings* _tmp9_;
		gboolean _tmp10_ = FALSE;
		gboolean _tmp19_ = FALSE;
		gboolean _tmp20_ = FALSE;
		gboolean* _tmp25_;
		gboolean* _tmp28_;
		_tmp9_ = g_settings_new ("org.gnome.Nibbles");
		settings = _tmp9_;
		if (nibbles_changed) {
			_tmp10_ = players_changed;
		} else {
			_tmp10_ = FALSE;
		}
		if (_tmp10_) {
			GSettings* _tmp11_;
			GSettings* _tmp12_;
			_tmp11_ = settings;
			g_settings_set_int (_tmp11_, "players", nibbles_players);
			_tmp12_ = settings;
			g_settings_set_int (_tmp12_, "ai", nibbles_nibbles - nibbles_players);
		} else {
			if (players_changed) {
				gint old_ai = 0;
				GSettings* _tmp13_;
				gint old_players = 0;
				GSettings* _tmp14_;
				GSettings* _tmp15_;
				gint new_ai = 0;
				_tmp13_ = settings;
				old_ai = g_settings_get_int (_tmp13_, "ai");
				_tmp14_ = settings;
				old_players = g_settings_get_int (_tmp14_, "players");
				_tmp15_ = settings;
				g_settings_set_int (_tmp15_, "players", nibbles_players);
				new_ai = CLAMP (CLAMP (old_ai + old_players, 4, 6) - nibbles_players, 0, 5);
				if (old_ai != new_ai) {
					GSettings* _tmp16_;
					_tmp16_ = settings;
					g_settings_set_int (_tmp16_, "ai", new_ai);
				}
			} else {
				if (nibbles_changed) {
					GSettings* _tmp17_;
					GSettings* _tmp18_;
					_tmp17_ = settings;
					_tmp18_ = settings;
					g_settings_set_int (_tmp17_, "ai", nibbles_nibbles - g_settings_get_int (_tmp18_, "players"));
				}
			}
		}
		if (nibbles_progress != G_MININT) {
			_tmp20_ = nibbles_progress >= 0;
		} else {
			_tmp20_ = FALSE;
		}
		if (_tmp20_) {
			_tmp19_ = nibbles_progress <= 2;
		} else {
			_tmp19_ = FALSE;
		}
		if (_tmp19_) {
			GSettings* _tmp21_;
			_tmp21_ = settings;
			g_settings_set_int (_tmp21_, "progress", nibbles_progress);
		}
		if (nibbles_speed != G_MININT) {
			GSettings* _tmp22_;
			_tmp22_ = settings;
			g_settings_set_int (_tmp22_, "speed", nibbles_speed);
		}
		if (nibbles_disable_fakes) {
			GSettings* _tmp23_;
			_tmp23_ = settings;
			g_settings_set_boolean (_tmp23_, "fakes", FALSE);
		} else {
			if (nibbles_enable_fakes) {
				GSettings* _tmp24_;
				_tmp24_ = settings;
				g_settings_set_boolean (_tmp24_, "fakes", TRUE);
			}
		}
		_tmp25_ = nibbles_three_dimensional_view;
		if (_tmp25_ != NULL) {
			GSettings* _tmp26_;
			gboolean* _tmp27_;
			_tmp26_ = settings;
			_tmp27_ = nibbles_three_dimensional_view;
			g_settings_set_boolean (_tmp26_, "three-dimensional-view", (gboolean) (*_tmp27_));
		}
		_tmp28_ = nibbles_sound;
		if (_tmp28_ != NULL) {
			GSettings* _tmp29_;
			gboolean* _tmp30_;
			_tmp29_ = settings;
			_tmp30_ = nibbles_sound;
			g_settings_set_boolean (_tmp29_, "sound", (gboolean) (*_tmp30_));
		}
		_g_object_unref0 (settings);
	}
	if (nibbles_start) {
		setup = SETUP_SCREEN_GAME;
	} else {
		gboolean _tmp31_ = FALSE;
		if (nibbles_changed) {
			_tmp31_ = players_changed;
		} else {
			_tmp31_ = FALSE;
		}
		if (_tmp31_) {
			gboolean _tmp32_ = FALSE;
			if (nibbles_speed != G_MININT) {
				gboolean _tmp33_ = FALSE;
				if (nibbles_disable_fakes) {
					_tmp33_ = TRUE;
				} else {
					_tmp33_ = nibbles_enable_fakes;
				}
				_tmp32_ = _tmp33_;
			} else {
				_tmp32_ = FALSE;
			}
			if (_tmp32_) {
				setup = SETUP_SCREEN_CONTROLS;
			} else {
				setup = SETUP_SCREEN_SPEED;
			}
		} else {
			setup = SETUP_SCREEN_USUAL;
		}
	}
	if (nibbles_level == G_MININT) {
		_tmp34_ = 0;
	} else {
		_tmp34_ = nibbles_level;
	}
	_tmp35_ = nibbles_window_new (_tmp34_, setup);
	g_object_ref_sink (_tmp35_);
	_g_object_unref0 (self->priv->window);
	self->priv->window = _tmp35_;
	_tmp36_ = self->priv->window;
	gtk_application_add_window ((GtkApplication*) self, (GtkWindow*) _tmp36_);
}

static void
nibbles_real_activate (GApplication* base)
{
	Nibbles * self;
	NibblesWindow* _tmp0_;
	NibblesWindow* _tmp1_;
	self = (Nibbles*) base;
	_tmp0_ = self->priv->window;
	if (_tmp0_ == NULL) {
		nibbles_create_window (self);
	}
	_tmp1_ = self->priv->window;
	gtk_window_present ((GtkWindow*) _tmp1_);
	G_APPLICATION_CLASS (nibbles_parent_class)->activate ((GApplication*) G_TYPE_CHECK_INSTANCE_CAST (self, gtk_application_get_type (), GtkApplication));
}

static void
nibbles_real_shutdown (GApplication* base)
{
	Nibbles * self;
	NibblesWindow* _tmp0_;
	self = (Nibbles*) base;
	_tmp0_ = self->priv->window;
	if (_tmp0_ != NULL) {
		NibblesWindow* _tmp1_;
		_tmp1_ = self->priv->window;
		nibbles_window_on_shutdown (_tmp1_);
	}
	G_APPLICATION_CLASS (nibbles_parent_class)->shutdown ((GApplication*) G_TYPE_CHECK_INSTANCE_CAST (self, gtk_application_get_type (), GtkApplication));
}

static inline void
nibbles_help_cb (Nibbles* self)
{
	gboolean _tmp0_ = FALSE;
	NibblesWindow* _tmp1_;
	NibblesWindow* _tmp6_;
	g_return_if_fail (self != NULL);
	_tmp1_ = self->priv->window;
	if (_tmp1_ != NULL) {
		NibblesWindow* _tmp2_;
		gboolean _tmp3_;
		gboolean _tmp4_;
		_tmp2_ = self->priv->window;
		_tmp3_ = nibbles_window_get_game_paused (_tmp2_);
		_tmp4_ = _tmp3_;
		_tmp0_ = !_tmp4_;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		NibblesWindow* _tmp5_;
		_tmp5_ = self->priv->window;
		g_action_group_activate_action ((GActionGroup*) _tmp5_, "pause", NULL);
	}
	_tmp6_ = self->priv->window;
	gtk_show_uri ((GtkWindow*) _tmp6_, "help:gnome-nibbles", (guint32) GDK_CURRENT_TIME);
}

static inline void
nibbles_about_cb (Nibbles* self)
{
	gboolean _tmp0_ = FALSE;
	NibblesWindow* _tmp1_;
	gchar** authors = NULL;
	gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	gchar* _tmp10_;
	gchar* _tmp11_;
	gchar** _tmp12_;
	gint authors_length1;
	gint _authors_size_;
	gchar** documenters = NULL;
	gchar* _tmp13_;
	gchar** _tmp14_;
	gint documenters_length1;
	gint _documenters_size_;
	gchar** artists = NULL;
	gchar* _tmp15_;
	gchar** _tmp16_;
	gint artists_length1;
	gint _artists_size_;
	AdwAboutDialog* about_dialog = NULL;
	AdwAboutDialog* _tmp17_;
	gchar* _tmp18_;
	gchar* _tmp19_;
	gchar* _tmp20_;
	gchar* _tmp21_;
	gchar* _tmp22_;
	gchar* _tmp23_;
	gchar* _tmp24_;
	gchar* _tmp25_;
	gchar* _tmp26_;
	gchar* _tmp27_;
	gchar* _tmp28_;
	gchar* _tmp29_;
	gchar* _tmp30_;
	gchar* _tmp31_;
	gchar* _tmp32_;
	gchar* _tmp33_;
	GtkWindow* _tmp34_;
	g_return_if_fail (self != NULL);
	_tmp1_ = self->priv->window;
	if (_tmp1_ != NULL) {
		NibblesWindow* _tmp2_;
		gboolean _tmp3_;
		gboolean _tmp4_;
		_tmp2_ = self->priv->window;
		_tmp3_ = nibbles_window_get_game_paused (_tmp2_);
		_tmp4_ = _tmp3_;
		_tmp0_ = !_tmp4_;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		NibblesWindow* _tmp5_;
		_tmp5_ = self->priv->window;
		g_action_group_activate_action ((GActionGroup*) _tmp5_, "pause", NULL);
	}
	_tmp6_ = g_strdup (_ ("Sean MacIsaac"));
	_tmp7_ = g_strdup (_ ("Ian Peters"));
	_tmp8_ = g_strdup (_ ("Andreas Røsdal"));
	_tmp9_ = g_strdup (_ ("Guillaume Beland"));
	_tmp10_ = g_strdup (_ ("Iulian-Gabriel Radu"));
	_tmp11_ = g_strdup (_ ("Ben Corby"));
	_tmp12_ = g_new0 (gchar*, 6 + 1);
	_tmp12_[0] = _tmp6_;
	_tmp12_[1] = _tmp7_;
	_tmp12_[2] = _tmp8_;
	_tmp12_[3] = _tmp9_;
	_tmp12_[4] = _tmp10_;
	_tmp12_[5] = _tmp11_;
	authors = _tmp12_;
	authors_length1 = 6;
	_authors_size_ = authors_length1;
	_tmp13_ = g_strdup (_ ("Kevin Breit"));
	_tmp14_ = g_new0 (gchar*, 1 + 1);
	_tmp14_[0] = _tmp13_;
	documenters = _tmp14_;
	documenters_length1 = 1;
	_documenters_size_ = documenters_length1;
	_tmp15_ = g_strdup (_ ("Allan Day"));
	_tmp16_ = g_new0 (gchar*, 1 + 1);
	_tmp16_[0] = _tmp15_;
	artists = _tmp16_;
	artists_length1 = 1;
	_artists_size_ = artists_length1;
	_tmp17_ = (AdwAboutDialog*) adw_about_dialog_new ();
	g_object_ref_sink (_tmp17_);
	about_dialog = _tmp17_;
	adw_about_dialog_set_application_icon (about_dialog, "org.gnome.Nibbles");
	adw_about_dialog_set_application_name (about_dialog, NIBBLES_PROGRAM_NAME);
	adw_about_dialog_set_developer_name (about_dialog, _ ("The GNOME Project"));
	adw_about_dialog_set_version (about_dialog, VERSION " (adwaita)");
	adw_about_dialog_set_developers (about_dialog, authors);
	adw_about_dialog_set_documenters (about_dialog, documenters);
	adw_about_dialog_set_artists (about_dialog, artists);
	_tmp18_ = g_strconcat (_ ("Copyright © 1999-2008 – Sean MacIsaac, Ian Peters, Andreas Røsdal"), "\n", NULL);
	_tmp19_ = _tmp18_;
	_tmp20_ = g_strconcat (_tmp19_, _ ("Copyright © 2009 – Guillaume Beland"), NULL);
	_tmp21_ = _tmp20_;
	_tmp22_ = g_strconcat (_tmp21_, "\n", NULL);
	_tmp23_ = _tmp22_;
	_tmp24_ = g_strdup_printf (_ ("Copyright © %u-%u – Iulian-Gabriel Radu"), (guint) 2015, (guint) 2020);
	_tmp25_ = _tmp24_;
	_tmp26_ = g_strconcat (_tmp23_, _tmp25_, NULL);
	_tmp27_ = _tmp26_;
	_tmp28_ = g_strconcat (_tmp27_, "\n", NULL);
	_tmp29_ = _tmp28_;
	_tmp30_ = g_strdup_printf (_ ("Copyright © %u-%u – Ben Corby"), (guint) 2022, (guint) 2026);
	_tmp31_ = _tmp30_;
	_tmp32_ = g_strconcat (_tmp29_, _tmp31_, NULL);
	_tmp33_ = _tmp32_;
	adw_about_dialog_set_copyright (about_dialog, _tmp33_);
	_g_free0 (_tmp33_);
	_g_free0 (_tmp31_);
	_g_free0 (_tmp29_);
	_g_free0 (_tmp27_);
	_g_free0 (_tmp25_);
	_g_free0 (_tmp23_);
	_g_free0 (_tmp21_);
	_g_free0 (_tmp19_);
	adw_about_dialog_set_license_type (about_dialog, GTK_LICENSE_GPL_3_0);
	adw_about_dialog_set_translator_credits (about_dialog, _ ("translator-credits"));
	adw_about_dialog_set_website (about_dialog, WEBSITE);
	_tmp34_ = gtk_application_get_active_window ((GtkApplication*) self);
	adw_dialog_present ((AdwDialog*) about_dialog, (GtkWidget*) _tmp34_);
	_g_object_unref0 (about_dialog);
	artists = (_vala_array_free (artists, artists_length1, (GDestroyNotify) g_free), NULL);
	documenters = (_vala_array_free (documenters, documenters_length1, (GDestroyNotify) g_free), NULL);
	authors = (_vala_array_free (authors, authors_length1, (GDestroyNotify) g_free), NULL);
}

static void
nibbles_class_init (NibblesClass * klass,
                    gpointer klass_data)
{
	nibbles_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &Nibbles_private_offset);
	((GApplicationClass *) klass)->handle_local_options = (gint (*) (GApplication*, GVariantDict*)) nibbles_real_handle_local_options;
	((GApplicationClass *) klass)->startup = (void (*) (GApplication*)) nibbles_real_startup;
	((GApplicationClass *) klass)->activate = (void (*) (GApplication*)) nibbles_real_activate;
	((GApplicationClass *) klass)->shutdown = (void (*) (GApplication*)) nibbles_real_shutdown;
	G_OBJECT_CLASS (klass)->finalize = nibbles_finalize;
}

static void
nibbles_instance_init (Nibbles * self,
                       gpointer klass)
{
	self->priv = nibbles_get_instance_private (self);
}

static void
nibbles_finalize (GObject * obj)
{
	Nibbles * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_NIBBLES, Nibbles);
	_g_object_unref0 (self->priv->window);
	G_OBJECT_CLASS (nibbles_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
nibbles_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (NibblesClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) nibbles_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Nibbles), 0, (GInstanceInitFunc) nibbles_instance_init, NULL };
	GType nibbles_type_id;
	nibbles_type_id = g_type_register_static (gtk_application_get_type (), "Nibbles", &g_define_type_info, G_TYPE_FLAG_NONE);
	Nibbles_private_offset = g_type_add_instance_private (nibbles_type_id, sizeof (NibblesPrivate));
	return nibbles_type_id;
}

GType
nibbles_get_type (void)
{
	static GType nibbles_type_id__once = 0;
	if (g_once_init_enter_pointer (&nibbles_type_id__once)) {
		GType nibbles_type_id;
		nibbles_type_id = nibbles_get_type_once ();
		g_once_init_leave_pointer (&nibbles_type_id__once, nibbles_type_id);
	}
	return nibbles_type_id__once;
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

