[gnome-games/wip/exalm/dolphin-settings: 5/6] game-cube: Introduce a game settings override system
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/exalm/dolphin-settings: 5/6] game-cube: Introduce a game settings override system
- Date: Sun, 11 Apr 2021 21:36:02 +0000 (UTC)
commit c742f4986207268e63e803d7980dd90599a9a5de
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Mon Apr 12 00:06:09 2021 +0500
game-cube: Introduce a game settings override system
Allow to inject a GameSettings config file override into the save directory
before starting the game.
plugins/game-cube/src/game-cube-plugin.vala | 9 ++++-
plugins/game-cube/src/game-cube-runner.vala | 58 +++++++++++++++++++++++++++++
plugins/game-cube/src/meson.build | 1 +
3 files changed, 67 insertions(+), 1 deletion(-)
---
diff --git a/plugins/game-cube/src/game-cube-plugin.vala b/plugins/game-cube/src/game-cube-plugin.vala
index c2ffd812..425d4cc5 100644
--- a/plugins/game-cube/src/game-cube-plugin.vala
+++ b/plugins/game-cube/src/game-cube-plugin.vala
@@ -29,7 +29,8 @@ private class Games.GameCubePlugin : Object, Plugin {
}
public RunnerFactory[] get_runner_factories () {
- var factory = new RetroRunnerFactory (platform);
+ var factory = new GenericRunnerFactory (create_runner);
+ factory.add_platform (platform);
return { factory };
}
@@ -57,6 +58,12 @@ private class Games.GameCubePlugin : Object, Plugin {
return game;
}
+
+ private static Runner? create_runner (Game game) throws Error {
+ var core_source = new RetroCoreSource (platform);
+
+ return new GameCubeRunner (game, core_source);
+ }
}
[ModuleInit]
diff --git a/plugins/game-cube/src/game-cube-runner.vala b/plugins/game-cube/src/game-cube-runner.vala
new file mode 100644
index 00000000..fd7cd639
--- /dev/null
+++ b/plugins/game-cube/src/game-cube-runner.vala
@@ -0,0 +1,58 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+private class Games.GameCubeRunner : RetroRunner {
+ public GameCubeRunner (Game game, RetroCoreSource source) {
+ base.from_source (game, source);
+ }
+
+ private bool is_dolphin () {
+ var core = get_core ();
+
+ var core_filename = core.get_filename ();
+ var file = File.new_for_path (core_filename);
+ var basename = file.get_basename ();
+
+ return basename == "dolphin_libretro.so";
+ }
+
+ private string get_game_id () {
+ var game = get_game ();
+ var prefix = game.platform.get_uid_prefix ();
+ var uid = game.uid.to_string ();
+
+ return uid.substring (prefix.length + 1).ascii_up ();
+ }
+
+ private void inject_override (string save_dir_path, string name) throws Error {
+ var file = File.new_for_uri
(@"resource:///org/gnome/Games/plugins/game-cube/game-settings/$name.ini");
+
+ if (!file.query_exists ())
+ return;
+
+ var dest_dir_path = Path.build_filename (save_dir_path, "User", "GameSettings");
+ var dest_dir = File.new_for_path (dest_dir_path);
+
+ if (!dest_dir.query_exists ())
+ dest_dir.make_directory_with_parents ();
+
+ var dest = dest_dir.get_child (file.get_basename ());
+
+ if (dest.query_exists ())
+ return;
+
+ file.copy (dest, FileCopyFlags.NONE, null, null);
+
+ debug ("Injecting game settings override: %s", dest.get_path ());
+ }
+
+ protected override void prepare_save_dir (string save_dir_path) throws Error {
+ if (!is_dolphin ())
+ return;
+
+ var game_id = get_game_id ();
+
+ inject_override (save_dir_path, game_id);
+ inject_override (save_dir_path, game_id.substring (0, 3));
+ inject_override (save_dir_path, game_id.substring (0, 1));
+ }
+}
diff --git a/plugins/game-cube/src/meson.build b/plugins/game-cube/src/meson.build
index cb383004..0d06f252 100644
--- a/plugins/game-cube/src/meson.build
+++ b/plugins/game-cube/src/meson.build
@@ -1,6 +1,7 @@
vala_sources = [
'game-cube-header.vala',
'game-cube-plugin.vala',
+ 'game-cube-runner.vala',
]
c_args = [
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]