cordova-plugin-harfin-pgs-v2 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -0
- package/package.json +30 -0
- package/plugin.xml +27 -0
- package/src/android/HarfinPlayGamesV2.java +121 -0
- package/src/android/pgs-v2-repositories.gradle +5 -0
- package/www/harfin-play-games-v2.js +32 -0
package/README.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# cordova-plugin-harfin-pgs-v2
|
|
2
|
+
|
|
3
|
+
Independent Cordova Android bridge for Google Play Games Services v2.
|
|
4
|
+
|
|
5
|
+
Active: PlayGamesSdk.initialize, GamesSignInClient.isAuthenticated, and play-services-games-v2:22.1.0.
|
|
6
|
+
|
|
7
|
+
Saved Games action names saveCloud, loadCloud and hasCloudSave are scaffolded. The native layer obtains a SnapshotsClient but intentionally returns a clear error until the save schema and synchronization flow are implemented. This preparation package writes no cloud data.
|
|
8
|
+
|
|
9
|
+
Publish this package to npm, then reference cordova-plugin-harfin-pgs-v2 version 1.0.0 from the HarfinPGS GDevelop extension.
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "cordova-plugin-harfin-pgs-v2",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Google Play Games Services v2 Cordova bridge for Harf'in Izinde.",
|
|
5
|
+
"cordova": {
|
|
6
|
+
"id": "cordova-plugin-harfin-pgs-v2",
|
|
7
|
+
"platforms": [
|
|
8
|
+
"android"
|
|
9
|
+
]
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"ecosystem:cordova",
|
|
13
|
+
"cordova-android",
|
|
14
|
+
"google-play-games",
|
|
15
|
+
"pgs-v2",
|
|
16
|
+
"saved-games"
|
|
17
|
+
],
|
|
18
|
+
"license": "UNLICENSED",
|
|
19
|
+
"private": false,
|
|
20
|
+
"engines": {
|
|
21
|
+
"cordova": ">=11.0.0"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"plugin.xml",
|
|
25
|
+
"src/android/HarfinPlayGamesV2.java",
|
|
26
|
+
"src/android/pgs-v2-repositories.gradle",
|
|
27
|
+
"www/harfin-play-games-v2.js",
|
|
28
|
+
"README.md"
|
|
29
|
+
]
|
|
30
|
+
}
|
package/plugin.xml
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" id="cordova-plugin-harfin-pgs-v2" version="1.0.0">
|
|
3
|
+
<name>HarfinPlayGamesV2</name>
|
|
4
|
+
<description>Google Play Games Services v2 initialization, authentication and Saved Games bridge.</description>
|
|
5
|
+
<license>UNLICENSED</license>
|
|
6
|
+
<keywords>cordova,android,google-play-games,v2,saved-games</keywords>
|
|
7
|
+
<engines>
|
|
8
|
+
<engine name="cordova" version=">=11.0.0" />
|
|
9
|
+
</engines>
|
|
10
|
+
<js-module src="www/harfin-play-games-v2.js" name="HarfinPlayGamesV2"><clobbers target="HarfinPlayGamesV2" /></js-module>
|
|
11
|
+
<platform name="android">
|
|
12
|
+
<preference name="PLAY_GAMES_PROJECT_ID" default="593340834504" />
|
|
13
|
+
<config-file target="res/xml/config.xml" parent="/*">
|
|
14
|
+
<feature name="HarfinPlayGamesV2"><param name="android-package" value="com.metkasu.harfinizinde.pgs.HarfinPlayGamesV2" />
|
|
15
|
+
<param name="onload" value="true" /></feature>
|
|
16
|
+
</config-file>
|
|
17
|
+
<config-file target="AndroidManifest.xml" parent="/manifest/application">
|
|
18
|
+
<meta-data android:name="com.google.android.gms.games.APP_ID" android:value="@string/game_services_project_id" />
|
|
19
|
+
</config-file>
|
|
20
|
+
<config-file target="app/src/main/res/values/cdv_strings.xml" parent="/resources">
|
|
21
|
+
<string name="game_services_project_id" translatable="false">$PLAY_GAMES_PROJECT_ID</string>
|
|
22
|
+
</config-file>
|
|
23
|
+
<framework src="com.google.android.gms:play-services-games-v2:22.1.0" />
|
|
24
|
+
<framework src="src/android/pgs-v2-repositories.gradle" custom="true" type="gradleReference" />
|
|
25
|
+
<source-file src="src/android/HarfinPlayGamesV2.java" target-dir="src/com/metkasu/harfinizinde/pgs" />
|
|
26
|
+
</platform>
|
|
27
|
+
</plugin>
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
package com.metkasu.harfinizinde.pgs;
|
|
2
|
+
|
|
3
|
+
import android.app.Activity;
|
|
4
|
+
import android.content.Context;
|
|
5
|
+
import com.google.android.gms.games.AuthenticationResult;
|
|
6
|
+
import com.google.android.gms.games.PlayGames;
|
|
7
|
+
import com.google.android.gms.games.PlayGamesSdk;
|
|
8
|
+
import com.google.android.gms.games.SnapshotsClient;
|
|
9
|
+
import org.apache.cordova.CallbackContext;
|
|
10
|
+
import org.apache.cordova.CordovaPlugin;
|
|
11
|
+
import org.apache.cordova.PluginResult;
|
|
12
|
+
import org.json.JSONArray;
|
|
13
|
+
import org.json.JSONException;
|
|
14
|
+
import org.json.JSONObject;
|
|
15
|
+
|
|
16
|
+
/** PGS v2 bridge. Saved Games actions are scaffolded but intentionally do not persist data yet. */
|
|
17
|
+
public final class HarfinPlayGamesV2 extends CordovaPlugin {
|
|
18
|
+
private static final String SNAPSHOT_NAME = "harfin_izinde_save_v1";
|
|
19
|
+
private final Object initializationLock = new Object();
|
|
20
|
+
private volatile boolean initialized = false;
|
|
21
|
+
|
|
22
|
+
@Override
|
|
23
|
+
protected void pluginInitialize() {
|
|
24
|
+
initializeSdk();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
private void initializeSdk() {
|
|
28
|
+
if (initialized) return;
|
|
29
|
+
synchronized (initializationLock) {
|
|
30
|
+
if (initialized) return;
|
|
31
|
+
Activity activity = cordova.getActivity();
|
|
32
|
+
if (activity == null) throw new IllegalStateException("Cordova activity is not available.");
|
|
33
|
+
Context applicationContext = activity.getApplicationContext();
|
|
34
|
+
PlayGamesSdk.initialize(applicationContext);
|
|
35
|
+
initialized = true;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@Override
|
|
40
|
+
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
|
|
41
|
+
Activity activity = cordova.getActivity();
|
|
42
|
+
if (activity == null) {
|
|
43
|
+
callbackContext.error("Cordova activity is not available.");
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
if ("initialize".equals(action)) {
|
|
47
|
+
activity.runOnUiThread(() -> {
|
|
48
|
+
try {
|
|
49
|
+
initializeSdk();
|
|
50
|
+
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, true));
|
|
51
|
+
} catch (RuntimeException exception) {
|
|
52
|
+
callbackContext.error(errorMessage("PGS v2 initialization failed", exception));
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
if ("isAuthenticated".equals(action)) {
|
|
58
|
+
activity.runOnUiThread(() -> checkAuthentication(callbackContext));
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
if ("saveCloud".equals(action)) {
|
|
62
|
+
String payload = args.optString(0, null);
|
|
63
|
+
if (payload == null || payload.trim().isEmpty()) {
|
|
64
|
+
callbackContext.error("saveCloud requires a UTF-8 JSON payload.");
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
try { new JSONObject(payload); } catch (JSONException exception) {
|
|
68
|
+
callbackContext.error("saveCloud payload is not valid JSON.");
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
activity.runOnUiThread(() -> savedGamesScaffold("saveCloud", callbackContext));
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
if ("loadCloud".equals(action)) {
|
|
75
|
+
activity.runOnUiThread(() -> savedGamesScaffold("loadCloud", callbackContext));
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
if ("hasCloudSave".equals(action)) {
|
|
79
|
+
activity.runOnUiThread(() -> savedGamesScaffold("hasCloudSave", callbackContext));
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
private void checkAuthentication(CallbackContext callbackContext) {
|
|
86
|
+
try {
|
|
87
|
+
initializeSdk();
|
|
88
|
+
Activity activity = cordova.getActivity();
|
|
89
|
+
PlayGames.getGamesSignInClient(activity).isAuthenticated().addOnCompleteListener(task -> {
|
|
90
|
+
if (!task.isSuccessful()) {
|
|
91
|
+
callbackContext.error(errorMessage("PGS v2 authentication check failed", task.getException()));
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
AuthenticationResult result = task.getResult();
|
|
95
|
+
boolean authenticated = result != null && result.isAuthenticated();
|
|
96
|
+
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, authenticated));
|
|
97
|
+
});
|
|
98
|
+
} catch (RuntimeException exception) {
|
|
99
|
+
callbackContext.error(errorMessage("PGS v2 authentication check failed", exception));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private void savedGamesScaffold(String action, CallbackContext callbackContext) {
|
|
104
|
+
try {
|
|
105
|
+
initializeSdk();
|
|
106
|
+
Activity activity = cordova.getActivity();
|
|
107
|
+
SnapshotsClient snapshotsClient = PlayGames.getSnapshotsClient(activity);
|
|
108
|
+
if (snapshotsClient == null) {
|
|
109
|
+
callbackContext.error("PGS v2 SnapshotsClient is unavailable.");
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
callbackContext.error(action + " Saved Games scaffold is present but persistence is not enabled yet. Snapshot: " + SNAPSHOT_NAME);
|
|
113
|
+
} catch (RuntimeException exception) {
|
|
114
|
+
callbackContext.error(errorMessage("PGS v2 Saved Games scaffold failed", exception));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
private static String errorMessage(String prefix, Exception exception) {
|
|
118
|
+
if (exception == null || exception.getMessage() == null || exception.getMessage().trim().isEmpty()) return prefix;
|
|
119
|
+
return prefix + ": " + exception.getMessage();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var exec = require('cordova/exec');
|
|
3
|
+
function asBoolean(value) {
|
|
4
|
+
return value === true || value === 1 || value === '1' || value === 'true';
|
|
5
|
+
}
|
|
6
|
+
exports.initialize = function () {
|
|
7
|
+
return new Promise(function (resolve, reject) {
|
|
8
|
+
exec(function (value) { resolve(asBoolean(value)); }, reject, 'HarfinPlayGamesV2', 'initialize', []);
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
exports.isAuthenticated = function () {
|
|
12
|
+
return new Promise(function (resolve, reject) {
|
|
13
|
+
exec(function (value) { resolve(asBoolean(value)); }, reject, 'HarfinPlayGamesV2', 'isAuthenticated', []);
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
exports.saveCloud = function (json) {
|
|
18
|
+
var payload = typeof json === "string" ? json : JSON.stringify(json);
|
|
19
|
+
return new Promise(function (resolve, reject) {
|
|
20
|
+
exec(resolve, reject, "HarfinPlayGamesV2", "saveCloud", [payload]);
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
exports.loadCloud = function () {
|
|
24
|
+
return new Promise(function (resolve, reject) {
|
|
25
|
+
exec(resolve, reject, "HarfinPlayGamesV2", "loadCloud", []);
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
exports.hasCloudSave = function () {
|
|
29
|
+
return new Promise(function (resolve, reject) {
|
|
30
|
+
exec(function (value) { resolve(asBoolean(value)); }, reject, "HarfinPlayGamesV2", "hasCloudSave", []);
|
|
31
|
+
});
|
|
32
|
+
};
|