[gnome-games/wip/exalm/retro-runner: 2/7] retro: Add RetroRunnerBuilder
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/exalm/retro-runner: 2/7] retro: Add RetroRunnerBuilder
- Date: Fri, 4 Jan 2019 07:57:20 +0000 (UTC)
commit 9227b5889485382490d0d9dc3081a0b1e079f755
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date: Fri Jan 4 03:01:53 2019 +0500
retro: Add RetroRunnerBuilder
RetroRunner constructors are getting out of hand, let's replace that with
a builder.
src/meson.build | 1 +
src/retro/retro-runner-builder.vala | 56 +++++++++++++++++++++++++++++++++++++
src/retro/retro-runner.vala | 17 +++++++++++
3 files changed, 74 insertions(+)
---
diff --git a/src/meson.build b/src/meson.build
index 88beca3b..0bfe554f 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -114,6 +114,7 @@ vala_sources = [
'retro/retro-input-manager.vala',
'retro/retro-options.vala',
'retro/retro-runner.vala',
+ 'retro/retro-runner-builder.vala',
'retro/retro-simple-game-uri-adapter.vala',
'retro/retro-simple-type.vala',
'retro/retro-simple-types.vala',
diff --git a/src/retro/retro-runner-builder.vala b/src/retro/retro-runner-builder.vala
new file mode 100644
index 00000000..8501a5fa
--- /dev/null
+++ b/src/retro/retro-runner-builder.vala
@@ -0,0 +1,56 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+public class Games.RetroRunnerBuilder : Object {
+ public Uid uid { get; set; }
+ public Title title { get; set; }
+
+ private RetroCoreSource _core_source;
+ public RetroCoreSource core_source {
+ get { return _core_source; }
+ set {
+ _core_source = value;
+
+ if (core_source != null)
+ platform = core_source.get_platform ();
+ }
+ }
+
+ private Uri _uri;
+ public Uri uri {
+ get { return _uri; }
+ set {
+ _uri = value;
+
+ if (uri != null) {
+ var game_media = new Media ();
+ game_media.add_uri (uri);
+
+ media_set = new MediaSet ();
+ media_set.add_media (game_media);
+ }
+ }
+ }
+
+ public MediaSet media_set { get; set; }
+
+ public Retro.CoreDescriptor core_descriptor { get; set; }
+ public Platform platform { get; set; }
+
+ public InputCapabilities input_capabilities { get; set; }
+
+ construct {
+ platform = null;
+ core_source = null;
+ core_descriptor = null;
+ input_capabilities = null;
+ media_set = new MediaSet ();
+ }
+
+ public RetroRunner to_runner () {
+ return_val_if_fail (uid != null, null);
+ return_val_if_fail (title != null, null);
+ return_val_if_fail (platform != null, null);
+
+ return new RetroRunner.from_builder (this);
+ }
+}
diff --git a/src/retro/retro-runner.vala b/src/retro/retro-runner.vala
index 7d479de3..bc482551 100644
--- a/src/retro/retro-runner.vala
+++ b/src/retro/retro-runner.vala
@@ -77,6 +77,23 @@ public class Games.RetroRunner : Object, Runner {
private bool is_ready;
private bool should_save;
+ internal RetroRunner.from_builder (RetroRunnerBuilder builder) {
+ is_initialized = false;
+ is_ready = false;
+ should_save = false;
+
+ core_descriptor = builder.core_descriptor;
+ _media_set = builder.media_set;
+
+ uid = builder.uid;
+ core_source = builder.core_source;
+ platform = builder.platform;
+ input_capabilities = builder.input_capabilities;
+ game_title = builder.title;
+
+ _media_set.notify["selected-media-number"].connect (on_media_number_changed);
+ }
+
public RetroRunner (RetroCoreSource core_source, Uri uri, Uid uid, Title game_title,
InputCapabilities? input_capabilities = null) {
is_initialized = false;
is_ready = false;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]