mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-19 14:52:40 +08:00
Implementation of google play auto login, achievements, PGS Recall API (#18416)
This commit is contained in:
Vendored
+82
@@ -1415,6 +1415,88 @@ declare namespace jsb {
|
||||
showExternalOfferInformationDialog: (listener: ExternalOfferInformationDialogListener) => void;
|
||||
showInAppMessages: (params: InAppMessageParams, listener: InAppMessageResponseListener) => void;
|
||||
}
|
||||
|
||||
export class PlayException {
|
||||
getMessage(): string;
|
||||
getLocalizedMessage(): string;
|
||||
printStackTrace(): void;
|
||||
toString(): string;
|
||||
}
|
||||
|
||||
export interface OnCanceledListener {
|
||||
onCanceled(): void;
|
||||
}
|
||||
|
||||
export interface OnCompleteListener {
|
||||
onComplete(task: any): void;
|
||||
}
|
||||
|
||||
export interface OnFailureListener {
|
||||
onFailure(e: PlayException): void;
|
||||
}
|
||||
|
||||
export interface OnSuccessListener {
|
||||
onSuccess(result: any): void;
|
||||
}
|
||||
|
||||
export interface OnContinueWithListener {
|
||||
then(result: any): void;
|
||||
}
|
||||
|
||||
export interface OnContinueWithTaskListener {
|
||||
then(result: any): void;
|
||||
}
|
||||
|
||||
export class PlayTask {
|
||||
public addOnCanceledListener(listener: OnCanceledListener): PlayTask;
|
||||
public addOnCompleteListener(listener: OnCompleteListener): PlayTask;
|
||||
public addOnFailureListener(listener: OnFailureListener): PlayTask;
|
||||
public addOnSuccessListener(listener: OnSuccessListener): PlayTask;
|
||||
public continueWith(listener: OnContinueWithListener): PlayTask;
|
||||
public getResult(listener: OnSuccessListener): any;
|
||||
public isCanceled(): boolean;
|
||||
public isComplete(): boolean;
|
||||
public isSuccessful(): boolean;
|
||||
}
|
||||
export class AuthenticationResult {
|
||||
private constructor();
|
||||
public isAuthenticated(): boolean;
|
||||
}
|
||||
export class RecallAccess {
|
||||
private constructor();
|
||||
public hashCode(): number;
|
||||
public getSessionId(): string;
|
||||
public equals(other: RecallAccess): boolean;
|
||||
}
|
||||
export class GamesSignInClient {
|
||||
public isAuthenticated(): PlayTask;
|
||||
public requestServerSideAccess(serverClientId: string, forceRefreshToken: boolean): PlayTask;
|
||||
public signIn(): PlayTask;
|
||||
}
|
||||
export class AchievementsClient {
|
||||
public showAchievements(): void;
|
||||
public incrementImmediate(id: string, numSteps: number): PlayTask;
|
||||
public load(forceReload: boolean): PlayTask;
|
||||
public revealImmediate(id: string): PlayTask;
|
||||
public setStepsImmediate(id: string, numSteps: number): PlayTask;
|
||||
public unlockImmediate(id: string): PlayTask;
|
||||
public increment(id: string, numSteps: number): void;
|
||||
public reveal(id: string): void;
|
||||
public setSteps(id: string, numSteps: number): void;
|
||||
public unlock(id: string): void;
|
||||
}
|
||||
|
||||
export class RecallClient {
|
||||
public requestRecallAccess(): PlayTask;
|
||||
}
|
||||
export class PlayGames {
|
||||
public static getAchievementsClient(): AchievementsClient;
|
||||
public static getGamesSignInClient(): GamesSignInClient;
|
||||
public static getRecallClient(): RecallClient;
|
||||
}
|
||||
export class PlayGamesSdk {
|
||||
public static initialize(): void;
|
||||
}
|
||||
}
|
||||
|
||||
declare namespace ns {
|
||||
|
||||
+50
-2
@@ -53,7 +53,8 @@ cc_set_if_undefined(USE_WEBP ON)
|
||||
cc_set_if_undefined(NET_MODE 0) # 0 is client
|
||||
cc_set_if_undefined(USE_REMOTE_LOG OFF)
|
||||
cc_set_if_undefined(USE_ADPF OFF)
|
||||
cc_set_if_undefined(USE_GOOGLE_BILLING OFF)
|
||||
cc_set_if_undefined(USE_GOOGLE_BILLING OFF)
|
||||
cc_set_if_undefined(USE_GOOGLE_PLAY_GAMES OFF)
|
||||
|
||||
if(ANDROID AND NOT DEFINED USE_CCACHE)
|
||||
if("$ENV{COCOS_USE_CCACHE}" STREQUAL "1")
|
||||
@@ -763,6 +764,18 @@ elseif(ANDROID OR OHOS)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
if(USE_GOOGLE_BILLING OR USE_GOOGLE_PLAY_GAMES)
|
||||
cocos_source_files(
|
||||
vendor/google/common/ScopedListener.cpp
|
||||
vendor/google/common/ScopedListener.h
|
||||
vendor/google/common/JniUtils.cpp
|
||||
vendor/google/common/JniUtils.h
|
||||
vendor/google/common/JsUtils.cpp
|
||||
vendor/google/common/JsUtils.h
|
||||
)
|
||||
endif()
|
||||
|
||||
if(USE_GOOGLE_BILLING)
|
||||
cocos_source_files(
|
||||
vendor/google/billing/GoogleBilling.cpp
|
||||
@@ -796,6 +809,25 @@ if(USE_GOOGLE_BILLING)
|
||||
)
|
||||
endif()
|
||||
|
||||
if(USE_GOOGLE_PLAY_GAMES)
|
||||
cocos_source_files(
|
||||
vendor/google/play/PlayTask.h
|
||||
vendor/google/play/PlayTask.cpp
|
||||
vendor/google/play/PlayTaskManager.h
|
||||
vendor/google/play/PlayTaskManager.cpp
|
||||
vendor/google/play/TResult.h
|
||||
|
||||
vendor/google/play/PlayGames.h
|
||||
vendor/google/play/PlayGames.cpp
|
||||
vendor/google/play/GamesSignInClient.h
|
||||
vendor/google/play/GamesSignInClient.cpp
|
||||
vendor/google/play/AchievementsClient.h
|
||||
vendor/google/play/AchievementsClient.cpp
|
||||
vendor/google/play/RecallClient.h
|
||||
vendor/google/play/RecallClient.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
if(ANDROID)
|
||||
cocos_source_files(
|
||||
cocos/platform/android/modules/Screen.cpp
|
||||
@@ -1102,9 +1134,12 @@ set(SWIG_OUTPUT ${SWIG_OUTPUT_ROOT}/cocos/bindings/auto)
|
||||
cc_gen_swig_files(${CMAKE_CURRENT_LIST_DIR}/tools/swig-config ${SWIG_OUTPUT})
|
||||
|
||||
if(USE_GOOGLE_BILLING)
|
||||
cc_gen_swig_files(${CMAKE_CURRENT_LIST_DIR}/tools/swig-config/android ${SWIG_OUTPUT})
|
||||
cc_gen_swig_files(${CMAKE_CURRENT_LIST_DIR}/tools/swig-config/android/google/billing ${SWIG_OUTPUT})
|
||||
endif()
|
||||
|
||||
if(USE_GOOGLE_PLAY_GAMES)
|
||||
cc_gen_swig_files(${CMAKE_CURRENT_LIST_DIR}/tools/swig-config/android/google/play ${SWIG_OUTPUT})
|
||||
endif()
|
||||
##### platform
|
||||
cocos_source_files(
|
||||
cocos/platform/Image.cpp
|
||||
@@ -1228,6 +1263,10 @@ if(USE_GOOGLE_BILLING)
|
||||
list(APPEND CC_JNI_SRC_FILES ${CWD}/cocos/platform/java/jni/JniGoogleBillingHandler.cpp)
|
||||
endif()
|
||||
|
||||
if(USE_GOOGLE_PLAY_GAMES)
|
||||
list(APPEND CC_JNI_SRC_FILES ${CWD}/cocos/platform/java/jni/JniGooglePlayHandler.cpp)
|
||||
endif()
|
||||
|
||||
##### renderer
|
||||
cocos_source_files(
|
||||
cocos/renderer/core/PassUtils.h
|
||||
@@ -2286,6 +2325,13 @@ if(USE_GOOGLE_BILLING)
|
||||
)
|
||||
endif()
|
||||
|
||||
if(USE_GOOGLE_PLAY_GAMES)
|
||||
cocos_source_files(
|
||||
NO_WERROR NO_UBUILD ${SWIG_OUTPUT}/jsb_google_play_auto.cpp
|
||||
${SWIG_OUTPUT}/jsb_google_play_auto.h
|
||||
)
|
||||
endif()
|
||||
|
||||
if(USE_XR_REMOTE_PREVIEW)
|
||||
cocos_source_files(
|
||||
NO_WERROR cocos/xr/XRRemotePreviewManager.h
|
||||
@@ -3386,7 +3432,9 @@ function(cc_apply_definations target)
|
||||
$<$<OR:$<CONFIG:Debug>,$<BOOL:${CC_DEBUG_FORCE}>>:CC_DEBUG=1>
|
||||
$<IF:$<BOOL:${USE_ADPF}>,CC_USE_ADPF=1,CC_USE_ADPF=0>
|
||||
$<IF:$<BOOL:${USE_GOOGLE_BILLING}>,CC_USE_GOOGLE_BILLING=1,CC_USE_GOOGLE_BILLING=0>
|
||||
$<IF:$<BOOL:${USE_GOOGLE_PLAY_GAMES}>,CC_USE_GOOGLE_PLAY_GAMES=1,CC_USE_GOOGLE_PLAY_GAMES=0>
|
||||
$<IF:$<BOOL:${USE_BOX2D_JSB}>,CC_USE_BOX2D_JSB=1,CC_USE_BOX2D_JSB=0>
|
||||
|
||||
)
|
||||
endfunction()
|
||||
|
||||
|
||||
@@ -138,6 +138,10 @@
|
||||
#include "cocos/bindings/auto/jsb_google_billing_auto.h"
|
||||
#endif
|
||||
|
||||
#if CC_USE_GOOGLE_PLAY_GAMES
|
||||
#include "cocos/bindings/auto/jsb_google_play_auto.h"
|
||||
#endif
|
||||
|
||||
bool jsb_register_all_modules() {
|
||||
se::ScriptEngine *se = se::ScriptEngine::getInstance();
|
||||
|
||||
@@ -211,6 +215,10 @@ bool jsb_register_all_modules() {
|
||||
se->addRegisterCallback(register_all_billing);
|
||||
#endif
|
||||
|
||||
#if CC_USE_GOOGLE_PLAY_GAMES
|
||||
se->addRegisterCallback(register_all_play);
|
||||
#endif
|
||||
|
||||
#if CC_USE_MIDDLEWARE
|
||||
se->addRegisterCallback(register_all_editor_support);
|
||||
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2024 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2025 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
package google.play;
|
||||
|
||||
import static androidx.core.app.ActivityCompat.startActivityForResult;
|
||||
|
||||
import android.content.Intent;
|
||||
import androidx.annotation.IntRange;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.cocos.lib.GlobalObject;
|
||||
import com.google.android.gms.games.AchievementsClient;
|
||||
import com.google.android.gms.games.AnnotatedData;
|
||||
import com.google.android.gms.games.PlayGames;
|
||||
import com.google.android.gms.games.achievement.AchievementBuffer;
|
||||
import com.google.android.gms.tasks.OnSuccessListener;
|
||||
import com.google.android.gms.tasks.Task;
|
||||
|
||||
public final class AchievementsClientHelper {
|
||||
public static void showAchievements() {
|
||||
GlobalObject.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PlayGames.getAchievementsClient(GlobalObject.getActivity())
|
||||
.getAchievementsIntent()
|
||||
.addOnSuccessListener(new OnSuccessListener<Intent>() {
|
||||
@Override
|
||||
public void onSuccess(Intent intent) {
|
||||
GlobalObject.getActivity().startActivityForResult(intent, 100);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
public static int incrementImmediate(@NonNull String id, @IntRange(from = 0L) int numSteps) {
|
||||
AchievementsClient achievementsClient = PlayGames.getAchievementsClient(GlobalObject.getActivity());
|
||||
Task<Boolean> task = achievementsClient.incrementImmediate(id, numSteps);
|
||||
return TaskManager.putTask(task);
|
||||
}
|
||||
|
||||
public static int load(boolean forceReload) {
|
||||
AchievementsClient achievementsClient = PlayGames.getAchievementsClient(GlobalObject.getActivity());
|
||||
Task<AnnotatedData<AchievementBuffer>> task = achievementsClient.load(forceReload);
|
||||
return TaskManager.putTask(task);
|
||||
}
|
||||
public static int revealImmediate(@NonNull String id) {
|
||||
AchievementsClient achievementsClient = PlayGames.getAchievementsClient(GlobalObject.getActivity());
|
||||
Task<Void> task = achievementsClient.revealImmediate(id);
|
||||
return TaskManager.putTask(task);
|
||||
}
|
||||
|
||||
public static int setStepsImmediate(@NonNull String id, @IntRange(from = 0L) int numSteps) {
|
||||
AchievementsClient achievementsClient = PlayGames.getAchievementsClient(GlobalObject.getActivity());
|
||||
Task<Boolean> task = achievementsClient.setStepsImmediate(id, numSteps);
|
||||
return TaskManager.putTask(task);
|
||||
}
|
||||
|
||||
public static int unlockImmediate(@NonNull String id) {
|
||||
AchievementsClient achievementsClient = PlayGames.getAchievementsClient(GlobalObject.getActivity());
|
||||
Task<Void> task = achievementsClient.unlockImmediate(id);
|
||||
return TaskManager.putTask(task);
|
||||
}
|
||||
|
||||
public static void increment(@NonNull String id, @IntRange(from = 0L) int numSteps) {
|
||||
AchievementsClient achievementsClient = PlayGames.getAchievementsClient(GlobalObject.getActivity());
|
||||
achievementsClient.increment(id, numSteps);
|
||||
}
|
||||
|
||||
public static void reveal(@NonNull String id) {
|
||||
AchievementsClient achievementsClient = PlayGames.getAchievementsClient(GlobalObject.getActivity());
|
||||
achievementsClient.reveal(id);
|
||||
}
|
||||
|
||||
public static void setSteps(@NonNull String id, @IntRange(from = 0L) int numSteps) {
|
||||
AchievementsClient achievementsClient = PlayGames.getAchievementsClient(GlobalObject.getActivity());
|
||||
achievementsClient.setSteps(id, numSteps);
|
||||
}
|
||||
|
||||
public static void unlock(@NonNull String id) {
|
||||
AchievementsClient achievementsClient = PlayGames.getAchievementsClient(GlobalObject.getActivity());
|
||||
achievementsClient.unlock(id);
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2025 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
package google.play;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.cocos.lib.GlobalObject;
|
||||
import com.google.android.gms.games.AuthenticationResult;
|
||||
import com.google.android.gms.games.GamesSignInClient;
|
||||
import com.google.android.gms.games.PlayGames;
|
||||
import com.google.android.gms.tasks.Task;
|
||||
|
||||
public final class GamesSignInClientHelper {
|
||||
public static int isAuthenticated() {
|
||||
GamesSignInClient gamesSignInClient = PlayGames.getGamesSignInClient(GlobalObject.getActivity());
|
||||
Task<AuthenticationResult> task = gamesSignInClient.isAuthenticated();
|
||||
return TaskManager.putTask(task);
|
||||
}
|
||||
|
||||
public static int requestServerSideAccess(@NonNull String serverClientId, boolean forceRefreshToken) {
|
||||
GamesSignInClient gamesSignInClient = PlayGames.getGamesSignInClient(GlobalObject.getActivity());
|
||||
Task<String> task = gamesSignInClient.requestServerSideAccess(serverClientId, forceRefreshToken);
|
||||
return TaskManager.putTask(task);
|
||||
}
|
||||
|
||||
public static int signIn() {
|
||||
GamesSignInClient gamesSignInClient = PlayGames.getGamesSignInClient(GlobalObject.getActivity());
|
||||
Task<AuthenticationResult> task = gamesSignInClient.signIn();
|
||||
return TaskManager.putTask(task);
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2025 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
package google.play;
|
||||
import com.cocos.lib.GlobalObject;
|
||||
import com.cocos.lib.R;
|
||||
import com.google.android.gms.games.PlayGamesSdk;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
public final class PlayGamesSdkHelper {
|
||||
private static final String TAG = TaskManager.class.getSimpleName();
|
||||
public static void initialize() {
|
||||
String gameServicesProjectId = GlobalObject.getActivity().getResources().getString(R.string.game_services_project_id);
|
||||
if(gameServicesProjectId.isEmpty()) {
|
||||
Log.e(TAG, "The game server's project ID has not been configured");
|
||||
}
|
||||
PlayGamesSdk.initialize(GlobalObject.getActivity());
|
||||
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2025 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
package google.play;
|
||||
|
||||
import com.cocos.lib.GlobalObject;
|
||||
import com.google.android.gms.games.PlayGames;
|
||||
import com.google.android.gms.games.RecallAccess;
|
||||
import com.google.android.gms.games.RecallClient;
|
||||
import com.google.android.gms.tasks.Task;
|
||||
|
||||
public final class RecallClientHelper {
|
||||
public static int requestRecallAccess() {
|
||||
RecallClient recallClient = PlayGames.getRecallClient(GlobalObject.getActivity());
|
||||
Task<RecallAccess> task = recallClient.requestRecallAccess();
|
||||
return TaskManager.putTask(task);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,212 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2025 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
package google.play;
|
||||
import android.util.Log;
|
||||
|
||||
import com.cocos.lib.CocosHelper;
|
||||
import com.google.android.gms.tasks.Continuation;
|
||||
import com.google.android.gms.tasks.Task;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
public final class TaskManager {
|
||||
private static final String TAG = TaskManager.class.getSimpleName();
|
||||
private static Map<Integer, Task<?>> _taskMap = new HashMap<>();
|
||||
private static Map<Integer, Exception> _exceptionsMap = new HashMap<>();
|
||||
private static int _nextTaskId = 0;
|
||||
private static int _nextExceptionId = 0;
|
||||
|
||||
private static native void onTaskCanceledNative(int taskId, int listenerId);
|
||||
private static native void onTaskCompleteNative(int taskId, int listenerId, int nextTaskId);
|
||||
private static native void onTaskFailureNative(int taskId, int listenerId, Object obj, int nextExceptionId);
|
||||
private static native void onTaskSuccessNative(int taskId, int listenerId, Object obj);
|
||||
private static native Object onContinueWithNative(int taskId, int listenerId, int nextTaskId);
|
||||
|
||||
static int putTask(Task<?> task) {
|
||||
int taskId = ++_nextTaskId;
|
||||
_taskMap.put(taskId, task);
|
||||
return taskId;
|
||||
}
|
||||
|
||||
static void removeTask(int taskId) {
|
||||
if(_taskMap.containsKey(taskId)) {
|
||||
_taskMap.remove(taskId);
|
||||
}
|
||||
}
|
||||
|
||||
static void removeTaskException(int exceptionId) {
|
||||
if(_exceptionsMap.containsKey(exceptionId)) {
|
||||
_exceptionsMap.remove(exceptionId);
|
||||
}
|
||||
}
|
||||
|
||||
static void printExceptStackTrace(int exceptionId) {
|
||||
if(_exceptionsMap.containsKey(exceptionId)) {
|
||||
_exceptionsMap.get(exceptionId).printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
static Task<?> getTask(int taskId) {
|
||||
if(_taskMap.containsKey(taskId)) {
|
||||
return _taskMap.get(taskId);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
static Object getResult(int taskId) {
|
||||
if(_taskMap.containsKey(taskId)) {
|
||||
return _taskMap.get(taskId).getResult();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
static boolean isCanceled(int taskId) {
|
||||
if(_taskMap.containsKey(taskId)) {
|
||||
return _taskMap.get(taskId).isCanceled();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
static boolean isSuccessful(int taskId) {
|
||||
if(_taskMap.containsKey(taskId)) {
|
||||
return _taskMap.get(taskId).isSuccessful();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
static boolean isComplete(int taskId) {
|
||||
if(_taskMap.containsKey(taskId)) {
|
||||
return _taskMap.get(taskId).isComplete();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static int addOnCanceledListener(int taskId, int listenerId) {
|
||||
if(!_taskMap.containsKey(taskId)) {
|
||||
Log.e(TAG, "Called task id does not exist");
|
||||
return -1;
|
||||
}
|
||||
Task<?> newTask = _taskMap.get(taskId).addOnCanceledListener(()->{
|
||||
CocosHelper.runOnGameThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
onTaskCanceledNative(taskId, listenerId);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return putTask(newTask);
|
||||
}
|
||||
|
||||
static int addOnCompleteListener(int taskId, int listenerId) {
|
||||
if(!_taskMap.containsKey(taskId)) {
|
||||
Log.e(TAG, "Called task id does not exist");
|
||||
return -1;
|
||||
}
|
||||
Task<?> newTask = _taskMap.get(taskId).addOnCompleteListener((task)->{
|
||||
CocosHelper.runOnGameThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int nextTaskId = putTask(task);
|
||||
onTaskCompleteNative(taskId, listenerId, nextTaskId);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return putTask(newTask);
|
||||
}
|
||||
static int addOnFailureListener(int taskId, int listenerId) {
|
||||
if(!_taskMap.containsKey(taskId)) {
|
||||
Log.e(TAG, "Called task id does not exist");
|
||||
return -1;
|
||||
}
|
||||
Task<?> newTask = _taskMap.get(taskId).addOnFailureListener((e)->{
|
||||
CocosHelper.runOnGameThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int nextExceptionId = ++_nextExceptionId;
|
||||
_exceptionsMap.put(nextExceptionId, e);
|
||||
onTaskFailureNative(taskId, listenerId, e, nextExceptionId);
|
||||
}
|
||||
});
|
||||
});
|
||||
return putTask(newTask);
|
||||
}
|
||||
static int addOnSuccessListener(int taskId, int listenerId) {
|
||||
if(!_taskMap.containsKey(taskId)) {
|
||||
Log.e(TAG, "Called task id does not exist");
|
||||
return -1;
|
||||
}
|
||||
Task<?> newTask = _taskMap.get(taskId).addOnSuccessListener((result)->{
|
||||
CocosHelper.runOnGameThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
onTaskSuccessNative(taskId, listenerId, result);
|
||||
}
|
||||
});
|
||||
});
|
||||
return putTask(newTask);
|
||||
}
|
||||
|
||||
|
||||
private static <TResult, TContinuationResult> Task<TContinuationResult> continueWithTaskForAny(
|
||||
Task<TResult> task, final Continuation<TResult, TContinuationResult> continuation) {
|
||||
|
||||
return task.continueWith(new Continuation<TResult, TContinuationResult>() {
|
||||
@Override
|
||||
public TContinuationResult then(Task<TResult> task) throws Exception {
|
||||
return continuation.then(task);
|
||||
}
|
||||
});
|
||||
}
|
||||
static int continueWith(int taskId, int listenerId) {
|
||||
if(!_taskMap.containsKey(taskId)) {
|
||||
Log.e(TAG, "Called task id does not exist");
|
||||
return -1;
|
||||
}
|
||||
Task<Object> task = (Task<Object>)_taskMap.get(taskId);
|
||||
Task<?> newTask = task.continueWith(new Continuation<Object, Object>() {
|
||||
@Override
|
||||
public Object then(Task<Object> task) throws Exception {
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
final AtomicReference<Object> resultHolder = new AtomicReference<>();
|
||||
if (task.isSuccessful()) {
|
||||
CocosHelper.runOnGameThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int calllbackTaskId = putTask(task);
|
||||
resultHolder.set(onContinueWithNative(taskId, listenerId, calllbackTaskId));
|
||||
latch.countDown();
|
||||
}
|
||||
});
|
||||
latch.await();
|
||||
} else {
|
||||
resultHolder.set(null);
|
||||
}
|
||||
return resultHolder.get();
|
||||
}
|
||||
});
|
||||
return putTask(newTask);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,8 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
<application>
|
||||
<meta-data android:name="com.google.android.gms.games.APP_ID"
|
||||
android:value="@string/game_services_project_id"/>
|
||||
</application>
|
||||
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||
<uses-permission android:name="com.android.vending.BILLING" />
|
||||
|
||||
@@ -22,8 +22,13 @@ android {
|
||||
}
|
||||
|
||||
if(project.hasProperty("PROP_ENABLE_GOOGLE_BILLING") && project.PROP_ENABLE_GOOGLE_BILLING.toBoolean()) {
|
||||
sourceSets.main.java.srcDirs += ["../java/vendor"]
|
||||
sourceSets.main.java.srcDirs += ["../java/vendor/billing"]
|
||||
}
|
||||
|
||||
if(project.hasProperty("PROP_ENABLE_GOOGLE_PLAY_GAMES") && project.PROP_ENABLE_GOOGLE_PLAY_GAMES.toBoolean()) {
|
||||
sourceSets.main.java.srcDirs += ["../java/vendor/play"]
|
||||
}
|
||||
|
||||
buildDir = new File(rootProject.buildDir, project.name)
|
||||
|
||||
buildTypes {
|
||||
@@ -43,4 +48,7 @@ dependencies {
|
||||
if(project.hasProperty("PROP_ENABLE_GOOGLE_BILLING") && project.PROP_ENABLE_GOOGLE_BILLING.toBoolean()) {
|
||||
implementation "com.android.billingclient:billing:7.1.0"
|
||||
}
|
||||
if(project.hasProperty("PROP_ENABLE_GOOGLE_PLAY_GAMES") && project.PROP_ENABLE_GOOGLE_PLAY_GAMES.toBoolean()) {
|
||||
implementation "com.google.android.gms:play-services-games-v2:+"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,4 +7,5 @@
|
||||
<string name="go" translatable="false">前往</string>
|
||||
<string name="send" translatable="false">发送</string>
|
||||
<string name="tip_disable_safe_input_type" translatable="false">请到系统设置关闭安全键盘</string>
|
||||
<string name="game_services_project_id" translatable="false"></string>
|
||||
</resources>
|
||||
|
||||
@@ -7,4 +7,5 @@
|
||||
<string name="go" translatable="false">Go</string>
|
||||
<string name="send" translatable="false">Send</string>
|
||||
<string name="tip_disable_safe_input_type" translatable="false">Please go to the system settings to turn off the security keyboard!</string>
|
||||
<string name="game_services_project_id" translatable="false"></string>
|
||||
</resources>
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2025 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include <jni.h>
|
||||
#include "platform/java/jni/JniHelper.h"
|
||||
#include "vendor/google/play/PlayTaskManager.h"
|
||||
extern "C" {
|
||||
|
||||
// NOLINTNEXTLINE
|
||||
JNIEXPORT void JNICALL Java_google_play_TaskManager_onTaskCanceledNative(JNIEnv *env, jclass clazz, jint taskId, jint listenerId) {
|
||||
cc::PlayTaskManager::getInstance()->onTaskCanceled(taskId, listenerId);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_google_play_TaskManager_onTaskCompleteNative(JNIEnv *env, jclass clazz, jint taskId, jint listenerId, jint nextTaskId) {
|
||||
cc::PlayTaskManager::getInstance()->onTaskComplete(taskId, listenerId, nextTaskId);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_google_play_TaskManager_onTaskFailureNative(JNIEnv *env, jclass clazz, jint taskId, jint listenerId, jobject obj, jint exceptionId) {
|
||||
cc::PlayTaskManager::getInstance()->onTaskFailure(taskId, listenerId, reinterpret_cast<void*>(obj), exceptionId);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_google_play_TaskManager_onTaskSuccessNative(JNIEnv *env, jclass clazz, jint taskId, jint listenerId, jobject obj) {
|
||||
cc::PlayTaskManager::getInstance()->onTaskSucess(taskId, listenerId, reinterpret_cast<void*>(obj));
|
||||
}
|
||||
|
||||
JNIEXPORT jobject JNICALL Java_google_play_TaskManager_onContinueWithNative(JNIEnv *env, jclass clazz, jint taskId, jint listenerId, jint nextTaskId) {
|
||||
return reinterpret_cast<jobject>(cc::PlayTaskManager::getInstance()->onContinueWith(taskId, listenerId, nextTaskId));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
// Define module
|
||||
// target_namespace means the name exported to JS, could be same as which in other modules
|
||||
// audio at the last means the suffix of binding function name, different modules should use unique name
|
||||
// Note: doesn't support number prefix
|
||||
%module(target_namespace="jsb") play
|
||||
|
||||
// Disable some swig warnings, find warning number reference here ( https://www.swig.org/Doc4.1/Warnings.html )
|
||||
#pragma SWIG nowarn=503,302,401,317,402
|
||||
|
||||
// Insert code at the beginning of generated header file (.h)
|
||||
%insert(header_file) %{
|
||||
#pragma once
|
||||
#include "bindings/jswrapper/SeApi.h"
|
||||
#include "bindings/manual/jsb_conversions.h"
|
||||
#include "vendor/google/play/PlayTask.h"
|
||||
#include "vendor/google/play/TResult.h"
|
||||
#include "vendor/google/play/PlayGames.h"
|
||||
%}
|
||||
|
||||
// Insert code at the beginning of generated source file (.cpp)
|
||||
%{
|
||||
#include "bindings/auto/jsb_google_play_auto.h"
|
||||
#include "vendor/google/play/PlayTask.h"
|
||||
#include "vendor/google/play/TResult.h"
|
||||
%}
|
||||
|
||||
// ----- Import Section ------
|
||||
// Brief: Import header files which are depended by 'Include Section'
|
||||
// Note:
|
||||
// %import "your_header_file.h" will not generate code for that header file
|
||||
//
|
||||
%import "base/Macros.h"
|
||||
|
||||
// ----- Include Section ------
|
||||
// Brief: Include header files in which classes and methods will be bound
|
||||
%include "vendor/google/play/TResult.h"
|
||||
%include "vendor/google/play/PlayTask.h"
|
||||
%include "vendor/google/play/GamesSignInClient.h"
|
||||
%include "vendor/google/play/RecallClient.h"
|
||||
%include "vendor/google/play/AchievementsClient.h"
|
||||
%include "vendor/google/play/PlayGames.h"
|
||||
|
||||
|
||||
-25
@@ -39,31 +39,6 @@
|
||||
#include "vendor/google/billing/result-values/BillingResult.h"
|
||||
|
||||
namespace cc {
|
||||
BillingClient::scopedListener::scopedListener(se::Object* obj) : _obj(obj) {
|
||||
if (_obj) {
|
||||
_obj->root();
|
||||
_obj->incRef();
|
||||
}
|
||||
}
|
||||
|
||||
BillingClient::scopedListener::~scopedListener() {
|
||||
if (_obj) {
|
||||
_obj->unroot();
|
||||
_obj->decRef();
|
||||
}
|
||||
}
|
||||
|
||||
void BillingClient::scopedListener::reset(se::Object* obj) {
|
||||
if (_obj) {
|
||||
_obj->unroot();
|
||||
_obj->decRef();
|
||||
}
|
||||
_obj = obj;
|
||||
if (_obj) {
|
||||
_obj->root();
|
||||
_obj->incRef();
|
||||
}
|
||||
}
|
||||
|
||||
BillingClient::Builder& BillingClient::Builder::enableUserChoiceBilling(se::Object* listener) {
|
||||
if (!listener) {
|
||||
|
||||
+1
-16
@@ -28,6 +28,7 @@
|
||||
#include <vector>
|
||||
#include "base/Macros.h"
|
||||
#include "base/RefCounted.h"
|
||||
#include "vendor/google/common/ScopedListener.h"
|
||||
|
||||
namespace se {
|
||||
class Object;
|
||||
@@ -46,22 +47,6 @@ class BillingResult;
|
||||
|
||||
class CC_DLL BillingClient : public cc::RefCounted {
|
||||
private:
|
||||
class scopedListener {
|
||||
public:
|
||||
scopedListener() = default;
|
||||
scopedListener(se::Object* obj);
|
||||
~scopedListener();
|
||||
se::Object* get() const {
|
||||
return _obj;
|
||||
}
|
||||
void reset(se::Object* obj);
|
||||
operator bool() const {
|
||||
return _obj != nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
se::Object* _obj{nullptr};
|
||||
};
|
||||
|
||||
public:
|
||||
class Builder {
|
||||
|
||||
+10
-43
@@ -40,6 +40,8 @@
|
||||
#include "vendor/google/billing/build-params/ConsumeParams.h"
|
||||
#include "vendor/google/billing/result-values/ProductDetails.h"
|
||||
#include "vendor/google/billing/result-values/Purchase.h"
|
||||
#include "vendor/google/common/JsUtils.h"
|
||||
|
||||
namespace {
|
||||
|
||||
#ifndef JCLS_BILLING
|
||||
@@ -48,49 +50,14 @@ namespace {
|
||||
}; // namespace
|
||||
|
||||
namespace cc {
|
||||
namespace {
|
||||
void invokeJsCallback(se::Object* obj, const char* jsFunctionName, const se::ValueArray& args) {
|
||||
if (!obj) {
|
||||
return;
|
||||
}
|
||||
|
||||
se::Value funcVal;
|
||||
if (!obj->getProperty(jsFunctionName, &funcVal) || !funcVal.isObject()) {
|
||||
return;
|
||||
}
|
||||
se::Value rval;
|
||||
funcVal.toObject()->call(args, obj, &rval);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void callJSfunc(se::Object* obj, const char* jsFunctionName, Args&&... inargs) { // NOLINT(readability-identifier-naming)
|
||||
if (!se::ScriptEngine::getInstance()->isValid()) {
|
||||
return;
|
||||
}
|
||||
se::AutoHandleScope scope;
|
||||
se::ValueArray args;
|
||||
args.resize(sizeof...(Args));
|
||||
nativevalue_to_se_args_v(args, inargs...);
|
||||
invokeJsCallback(obj, jsFunctionName, args);
|
||||
}
|
||||
|
||||
void callJSfunc(se::Object* obj, const char* jsFunctionName) { // NOLINT(readability-identifier-naming)
|
||||
if (!se::ScriptEngine::getInstance()->isValid()) {
|
||||
return;
|
||||
}
|
||||
se::AutoHandleScope scope;
|
||||
invokeJsCallback(obj, jsFunctionName, se::ValueArray());
|
||||
}
|
||||
|
||||
template void callJSfunc(se::Object* obj, const char*, BillingResult*&&);
|
||||
template void callJSfunc(se::Object* obj, const char*, BillingResult*&&, const std::vector<cc::ProductDetails*>&);
|
||||
template void callJSfunc(se::Object* obj, const char*, BillingResult*&&, const std::vector<cc::Purchase*>&);
|
||||
template void callJSfunc(se::Object* obj, const char*, BillingResult*&&, const std::string&);
|
||||
template void callJSfunc(se::Object* obj, const char*, BillingResult*&&, BillingConfig*&&);
|
||||
template void callJSfunc(se::Object* obj, const char*, BillingResult*&&, AlternativeBillingOnlyReportingDetails*&&);
|
||||
template void callJSfunc(se::Object* obj, const char*, BillingResult*&&, ExternalOfferReportingDetails*&&);
|
||||
template void callJSfunc(se::Object* obj, const char*, InAppMessageResult*&&);
|
||||
} // namespace
|
||||
template se::Value callJSfunc(se::Object* obj, const char*, BillingResult*&&);
|
||||
template se::Value callJSfunc(se::Object* obj, const char*, BillingResult*&&, const std::vector<cc::ProductDetails*>&);
|
||||
template se::Value callJSfunc(se::Object* obj, const char*, BillingResult*&&, const std::vector<cc::Purchase*>&);
|
||||
template se::Value callJSfunc(se::Object* obj, const char*, BillingResult*&&, const std::string&);
|
||||
template se::Value callJSfunc(se::Object* obj, const char*, BillingResult*&&, BillingConfig*&&);
|
||||
template se::Value callJSfunc(se::Object* obj, const char*, BillingResult*&&, AlternativeBillingOnlyReportingDetails*&&);
|
||||
template se::Value callJSfunc(se::Object* obj, const char*, BillingResult*&&, ExternalOfferReportingDetails*&&);
|
||||
template se::Value callJSfunc(se::Object* obj, const char*, InAppMessageResult*&&);
|
||||
|
||||
int GoogleBillingHelper::createGoogleBilling(BillingClient::Builder* builder) {
|
||||
int tag = JniHelper::callStaticIntMethod(JCLS_BILLING, "newTag");
|
||||
|
||||
+1
-33
@@ -35,46 +35,14 @@
|
||||
#include "cocos/bindings/manual/jsb_global_init.h"
|
||||
#include "vendor/google/billing/GoogleBilling.h"
|
||||
#include "vendor/google/billing/build-params/PendingPurchasesParams.h"
|
||||
|
||||
#include "vendor/google/common/JniUtils.h"
|
||||
namespace {
|
||||
|
||||
#ifndef JCLS_BILLING
|
||||
#define JCLS_BILLING "google/billing/GoogleBillingHelper"
|
||||
#endif
|
||||
}; // namespace
|
||||
|
||||
namespace cc {
|
||||
namespace {
|
||||
std::string callStringMethod(JNIEnv* env, jclass clazz, jobject obj, const char* methodName) {
|
||||
jmethodID methodId = env->GetMethodID(clazz, methodName, "()Ljava/lang/String;");
|
||||
jobject jStringObj = env->CallObjectMethod(obj, methodId);
|
||||
if (jStringObj != nullptr) {
|
||||
return cc::StringUtils::getStringUTFCharsJNI(env, static_cast<jstring>(jStringObj));
|
||||
}
|
||||
return "";
|
||||
}
|
||||
jobject callObjectMethod(JNIEnv* env, jclass clazz, jobject obj, const char* methodName, const char* returnType) {
|
||||
std::string returnSign = cc::StringUtils::format("()L%s", returnType);
|
||||
jmethodID methodId = env->GetMethodID(clazz, methodName, returnSign.c_str());
|
||||
return env->CallObjectMethod(obj, methodId);
|
||||
}
|
||||
|
||||
int callIntMethod(JNIEnv* env, jclass clazz, jobject obj, const char* methodName) {
|
||||
jmethodID methodId = env->GetMethodID(clazz, methodName, "()I");
|
||||
return env->CallIntMethod(obj, methodId);
|
||||
}
|
||||
|
||||
bool callBooleanMethod(JNIEnv* env, jclass clazz, jobject obj, const char* methodName) {
|
||||
jmethodID methodId = env->GetMethodID(clazz, methodName, "()Z");
|
||||
return env->CallBooleanMethod(obj, methodId);
|
||||
}
|
||||
|
||||
long callLongMethod(JNIEnv* env, jclass clazz, jobject obj, const char* methodName) {
|
||||
jmethodID methodId = env->GetMethodID(clazz, methodName, "()J");
|
||||
return env->CallLongMethod(obj, methodId);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
cc::BillingResult* JniBilling::toBillingResult(JNIEnv* env, jobject obj) {
|
||||
jclass clazz = env->GetObjectClass(obj);
|
||||
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2025 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "vendor/google/common/JniUtils.h"
|
||||
#include "base/UTF8.h"
|
||||
|
||||
namespace cc {
|
||||
std::string callStringMethod(JNIEnv* env, jclass clazz, jobject obj, const char* methodName) {
|
||||
jmethodID methodId = env->GetMethodID(clazz, methodName, "()Ljava/lang/String;");
|
||||
jobject jStringObj = env->CallObjectMethod(obj, methodId);
|
||||
if (jStringObj != nullptr) {
|
||||
return cc::StringUtils::getStringUTFCharsJNI(env, static_cast<jstring>(jStringObj));
|
||||
}
|
||||
return "";
|
||||
}
|
||||
jobject callObjectMethod(JNIEnv* env, jclass clazz, jobject obj, const char* methodName, const char* returnType) {
|
||||
std::string returnSign = cc::StringUtils::format("()L%s", returnType);
|
||||
jmethodID methodId = env->GetMethodID(clazz, methodName, returnSign.c_str());
|
||||
return env->CallObjectMethod(obj, methodId);
|
||||
}
|
||||
|
||||
int callIntMethod(JNIEnv* env, jclass clazz, jobject obj, const char* methodName) {
|
||||
jmethodID methodId = env->GetMethodID(clazz, methodName, "()I");
|
||||
return env->CallIntMethod(obj, methodId);
|
||||
}
|
||||
|
||||
bool callBooleanMethod(JNIEnv* env, jclass clazz, jobject obj, const char* methodName) {
|
||||
jmethodID methodId = env->GetMethodID(clazz, methodName, "()Z");
|
||||
return env->CallBooleanMethod(obj, methodId);
|
||||
}
|
||||
|
||||
long callLongMethod(JNIEnv* env, jclass clazz, jobject obj, const char* methodName) {
|
||||
jmethodID methodId = env->GetMethodID(clazz, methodName, "()J");
|
||||
return env->CallLongMethod(obj, methodId);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
jobject convertToJObject(JNIEnv* env, T value, const char* className, const char* methodSig) {
|
||||
jclass clazz = env->FindClass(className);
|
||||
if (!clazz) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
jmethodID valueOfMethod = env->GetStaticMethodID(clazz, "valueOf", methodSig);
|
||||
if (!valueOfMethod) {
|
||||
return nullptr;
|
||||
}
|
||||
return env->CallStaticObjectMethod(clazz, valueOfMethod, value);
|
||||
}
|
||||
|
||||
jobject intToJObject(JNIEnv* env, int value) {
|
||||
return convertToJObject(env, value, "java/lang/Integer", "(I)Ljava/lang/Integer;");
|
||||
}
|
||||
|
||||
jobject doubleToJObject(JNIEnv* env, double value) {
|
||||
return convertToJObject(env, value, "java/lang/Double", "(D)Ljava/lang/Double;");
|
||||
}
|
||||
|
||||
jobject boolToJObject(JNIEnv* env, bool value) {
|
||||
return convertToJObject(env, value, "java/lang/Boolean", "(Z)Ljava/lang/Boolean;");
|
||||
}
|
||||
|
||||
jstring stringToJString(JNIEnv* env, const std::string& str) {
|
||||
return env->NewStringUTF(str.c_str());
|
||||
}
|
||||
|
||||
int integerObjectToInt(JNIEnv* env, jclass clazz, jobject obj) {
|
||||
jmethodID valueMethod = env->GetMethodID(clazz, "intValue", "()I");
|
||||
if (!valueMethod) {
|
||||
return 0;
|
||||
}
|
||||
return env->CallIntMethod(obj, valueMethod);
|
||||
}
|
||||
|
||||
double doubleObjectToDouble(JNIEnv* env, jclass clazz, jobject obj) {
|
||||
jmethodID valueMethod = env->GetMethodID(clazz, "doubleValue", "()D");
|
||||
if (!valueMethod) {
|
||||
return 0.0f;
|
||||
}
|
||||
return env->CallDoubleMethod(obj, valueMethod);
|
||||
}
|
||||
|
||||
bool BooleanObjectToBool(JNIEnv* env, jclass clazz, jobject obj) {
|
||||
jmethodID valueMethod = env->GetMethodID(clazz, "booleanValue", "()Z");
|
||||
if (!valueMethod) {
|
||||
return false;
|
||||
}
|
||||
return env->CallBooleanMethod(obj, valueMethod);
|
||||
}
|
||||
|
||||
} // namespace cc
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2025 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "platform/java/jni/JniHelper.h"
|
||||
|
||||
namespace cc {
|
||||
std::string callStringMethod(JNIEnv* env, jclass clazz, jobject obj, const char* methodName);
|
||||
jobject callObjectMethod(JNIEnv* env, jclass clazz, jobject obj, const char* methodName, const char* returnType);
|
||||
int callIntMethod(JNIEnv* env, jclass clazz, jobject obj, const char* methodName);
|
||||
bool callBooleanMethod(JNIEnv* env, jclass clazz, jobject obj, const char* methodName);
|
||||
long callLongMethod(JNIEnv* env, jclass clazz, jobject obj, const char* methodName);
|
||||
|
||||
// int -> Integer
|
||||
jobject intToJObject(JNIEnv* env, int value);
|
||||
// double -> Double
|
||||
jobject doubleToJObject(JNIEnv* env, double value);
|
||||
// bool -> Boolean
|
||||
jobject boolToJObject(JNIEnv* env, bool value);
|
||||
// std::string -> jstring
|
||||
jstring stringToJString(JNIEnv* env, const std::string& str);
|
||||
|
||||
int integerObjectToInt(JNIEnv* env, jclass clazz, jobject obj);
|
||||
double doubleObjectToDouble(JNIEnv* env, jclass clazz, jobject obj);
|
||||
bool BooleanObjectToBool(JNIEnv* env, jclass clazz, jobject obj);
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2025 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#include "vendor/google/common/JsUtils.h"
|
||||
|
||||
namespace cc {
|
||||
se::Value invokeJsCallback(se::Object* obj, const char* jsFunctionName, const se::ValueArray& args) {
|
||||
if (!obj) {
|
||||
return se::Value();
|
||||
}
|
||||
|
||||
se::Value funcVal;
|
||||
if (!obj->getProperty(jsFunctionName, &funcVal) || !funcVal.isObject()) {
|
||||
return se::Value();
|
||||
}
|
||||
se::Value rval;
|
||||
funcVal.toObject()->call(args, obj, &rval);
|
||||
return rval;
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
se::Value callJSfunc(se::Object* obj, const char* jsFunctionName, Args&&... inargs);
|
||||
|
||||
se::Value callJSfunc(se::Object* obj, const char* jsFunctionName) { // NOLINT(readability-identifier-naming)
|
||||
if (!se::ScriptEngine::getInstance()->isValid()) {
|
||||
return se::Value();
|
||||
}
|
||||
se::AutoHandleScope scope;
|
||||
return invokeJsCallback(obj, jsFunctionName, se::ValueArray());
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2025 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "bindings/jswrapper/SeApi.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
se::Value invokeJsCallback(se::Object* obj, const char* jsFunctionName, const se::ValueArray& args);
|
||||
|
||||
template <typename... Args>
|
||||
se::Value callJSfunc(se::Object* obj, const char* jsFunctionName, Args&&... inargs){ // NOLINT(readability-identifier-naming)
|
||||
if (!se::ScriptEngine::getInstance()->isValid()) {
|
||||
return se::Value();
|
||||
}
|
||||
se::AutoHandleScope scope;
|
||||
se::ValueArray args;
|
||||
args.resize(sizeof...(Args));
|
||||
nativevalue_to_se_args_v(args, inargs...);
|
||||
return invokeJsCallback(obj, jsFunctionName, args);
|
||||
}
|
||||
|
||||
se::Value callJSfunc(se::Object* obj, const char* jsFunctionName);
|
||||
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
|
||||
#include "vendor/google/common/ScopedListener.h"
|
||||
#include "cocos/bindings/jswrapper/SeApi.h"
|
||||
|
||||
namespace cc {
|
||||
scopedListener::scopedListener(se::Object* obj) : _obj(obj) {
|
||||
if (_obj) {
|
||||
_obj->root();
|
||||
_obj->incRef();
|
||||
}
|
||||
}
|
||||
|
||||
scopedListener::~scopedListener() {
|
||||
if (_obj) {
|
||||
_obj->unroot();
|
||||
_obj->decRef();
|
||||
}
|
||||
}
|
||||
|
||||
void scopedListener::reset(se::Object* obj) {
|
||||
if (_obj) {
|
||||
_obj->unroot();
|
||||
_obj->decRef();
|
||||
}
|
||||
_obj = obj;
|
||||
if (_obj) {
|
||||
_obj->root();
|
||||
_obj->incRef();
|
||||
}
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2025 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace se {
|
||||
class Object;
|
||||
}
|
||||
|
||||
namespace cc {
|
||||
class scopedListener {
|
||||
public:
|
||||
scopedListener() = default;
|
||||
scopedListener(se::Object* obj);
|
||||
~scopedListener();
|
||||
se::Object* get() const {
|
||||
return _obj;
|
||||
}
|
||||
void reset(se::Object* obj);
|
||||
operator bool() const {
|
||||
return _obj != nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
se::Object* _obj{nullptr};
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2025 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#include "cocos/platform/java/jni/JniHelper.h"
|
||||
#include "vendor/google/play/PlayTaskManager.h"
|
||||
#include "vendor/google/play/AchievementsClient.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
namespace {
|
||||
#ifndef JCLS_GOOGLE_PLAY_ACHIEVEMENTS_CLIENT
|
||||
#define JCLS_GOOGLE_PLAY_ACHIEVEMENTS_CLIENT "google/play/AchievementsClientHelper"
|
||||
#endif
|
||||
}; // namespace
|
||||
|
||||
void AchievementsClient::showAchievements() {
|
||||
JniHelper::callStaticVoidMethod(JCLS_GOOGLE_PLAY_ACHIEVEMENTS_CLIENT, "showAchievements");
|
||||
}
|
||||
|
||||
PlayTask* AchievementsClient::load(bool forceReload) {
|
||||
int taskId = JniHelper::callStaticIntMethod(JCLS_GOOGLE_PLAY_ACHIEVEMENTS_CLIENT, "load", forceReload);
|
||||
return PlayTaskManager::getInstance()->addTask(taskId);
|
||||
}
|
||||
|
||||
PlayTask* AchievementsClient::incrementImmediate(const std::string& id, int numSteps) {
|
||||
int taskId = JniHelper::callStaticIntMethod(JCLS_GOOGLE_PLAY_ACHIEVEMENTS_CLIENT, "incrementImmediate", id, numSteps);
|
||||
return PlayTaskManager::getInstance()->addTask(taskId);
|
||||
}
|
||||
|
||||
PlayTask* AchievementsClient::revealImmediate(const std::string& id) {
|
||||
int taskId = JniHelper::callStaticIntMethod(JCLS_GOOGLE_PLAY_ACHIEVEMENTS_CLIENT, "revealImmediate", id);
|
||||
return PlayTaskManager::getInstance()->addTask(taskId);
|
||||
}
|
||||
|
||||
PlayTask* AchievementsClient::setStepsImmediate(const std::string& id, int numSteps) {
|
||||
int taskId = JniHelper::callStaticIntMethod(JCLS_GOOGLE_PLAY_ACHIEVEMENTS_CLIENT, "setStepsImmediate", id, numSteps);
|
||||
return PlayTaskManager::getInstance()->addTask(taskId);
|
||||
}
|
||||
|
||||
PlayTask* AchievementsClient::unlockImmediate(const std::string& id) {
|
||||
int taskId = JniHelper::callStaticIntMethod(JCLS_GOOGLE_PLAY_ACHIEVEMENTS_CLIENT, "unlockImmediate", id);
|
||||
return PlayTaskManager::getInstance()->addTask(taskId);
|
||||
}
|
||||
|
||||
void AchievementsClient::increment(const std::string& id, int numSteps) {
|
||||
JniHelper::callStaticVoidMethod(JCLS_GOOGLE_PLAY_ACHIEVEMENTS_CLIENT, "increment", id, numSteps);
|
||||
}
|
||||
|
||||
void AchievementsClient::reveal(const std::string& id) {
|
||||
JniHelper::callStaticVoidMethod(JCLS_GOOGLE_PLAY_ACHIEVEMENTS_CLIENT, "reveal", id);
|
||||
}
|
||||
|
||||
void AchievementsClient::setSteps(const std::string& id, int numSteps) {
|
||||
JniHelper::callStaticVoidMethod(JCLS_GOOGLE_PLAY_ACHIEVEMENTS_CLIENT, "setSteps", id, numSteps);
|
||||
}
|
||||
|
||||
void AchievementsClient::unlock(const std::string& id) {
|
||||
JniHelper::callStaticVoidMethod(JCLS_GOOGLE_PLAY_ACHIEVEMENTS_CLIENT, "unlock", id);
|
||||
}
|
||||
} // namespace cc
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2025 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <unordered_map>
|
||||
#include "base/RefCounted.h"
|
||||
|
||||
namespace cc {
|
||||
class PlayTask;
|
||||
class AchievementsClient {
|
||||
public:
|
||||
void showAchievements();
|
||||
PlayTask* load(bool forceReload);
|
||||
PlayTask* incrementImmediate(const std::string& id, int numSteps);
|
||||
PlayTask* revealImmediate(const std::string& id);
|
||||
PlayTask* setStepsImmediate(const std::string& id, int numSteps);
|
||||
PlayTask* unlockImmediate(const std::string& id);
|
||||
|
||||
void increment(const std::string& id, int numSteps);
|
||||
void reveal(const std::string& id);
|
||||
void setSteps(const std::string& id, int numSteps);
|
||||
void unlock(const std::string& id);
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
|
||||
/****************************************************************************
|
||||
Copyright (c) 2025 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#include "cocos/platform/java/jni/JniHelper.h"
|
||||
#include "vendor/google/play/PlayTaskManager.h"
|
||||
#include "vendor/google/play/GamesSignInClient.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
namespace {
|
||||
#ifndef JCLS_GOOGLE_PLAY_GAMES_SIGNIN_CLIENT
|
||||
#define JCLS_GOOGLE_PLAY_GAMES_SIGNIN_CLIENT "google/play/GamesSignInClientHelper"
|
||||
#endif
|
||||
}; // namespace
|
||||
|
||||
PlayTask* GamesSignInClient::isAuthenticated() {
|
||||
int taskId = JniHelper::callStaticIntMethod(JCLS_GOOGLE_PLAY_GAMES_SIGNIN_CLIENT, "isAuthenticated");
|
||||
return PlayTaskManager::getInstance()->addTask(taskId);
|
||||
}
|
||||
|
||||
PlayTask* GamesSignInClient::requestServerSideAccess(const std::string& serverClientId, bool forceRefreshToken) {
|
||||
int taskId = JniHelper::callStaticIntMethod(JCLS_GOOGLE_PLAY_GAMES_SIGNIN_CLIENT, "requestServerSideAccess", serverClientId, forceRefreshToken);
|
||||
return PlayTaskManager::getInstance()->addTask(taskId);
|
||||
}
|
||||
|
||||
PlayTask* GamesSignInClient::signIn() {
|
||||
int taskId = JniHelper::callStaticIntMethod(JCLS_GOOGLE_PLAY_GAMES_SIGNIN_CLIENT, "signIn");
|
||||
return PlayTaskManager::getInstance()->addTask(taskId);
|
||||
}
|
||||
|
||||
} // namespace cc
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2025 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <unordered_map>
|
||||
#include "base/RefCounted.h"
|
||||
|
||||
namespace cc {
|
||||
class PlayTask;
|
||||
class GamesSignInClient {
|
||||
public:
|
||||
PlayTask* isAuthenticated();
|
||||
PlayTask* requestServerSideAccess(const std::string& serverClientId, bool forceRefreshToken);
|
||||
PlayTask* signIn();
|
||||
};
|
||||
} // namespace cc
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
|
||||
/****************************************************************************
|
||||
Copyright (c) 2025 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#include "vendor/google/play/PlayGames.h"
|
||||
#include "platform/java/jni/JniHelper.h"
|
||||
|
||||
namespace cc {
|
||||
GamesSignInClient PlayGames::_signinClient;
|
||||
AchievementsClient PlayGames::_achievementsClient;
|
||||
RecallClient PlayGames::_recallClient;
|
||||
|
||||
|
||||
void PlayGamesSdk::initialize() {
|
||||
JniHelper::callStaticVoidMethod("google/play/PlayGamesSdkHelper", "initialize");
|
||||
}
|
||||
|
||||
} // namespace cc
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2025 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <unordered_map>
|
||||
#include "base/RefCounted.h"
|
||||
#include "vendor/google/play/AchievementsClient.h"
|
||||
#include "vendor/google/play/GamesSignInClient.h"
|
||||
#include "vendor/google/play/RecallClient.h"
|
||||
|
||||
namespace cc {
|
||||
class PlayGamesSdk {
|
||||
public:
|
||||
static void initialize();
|
||||
};
|
||||
|
||||
class PlayGames {
|
||||
public:
|
||||
static GamesSignInClient& getGamesSignInClient() {
|
||||
return _signinClient;
|
||||
}
|
||||
static AchievementsClient& getAchievementsClient() {
|
||||
return _achievementsClient;
|
||||
}
|
||||
static RecallClient& getRecallClient() {
|
||||
return _recallClient;
|
||||
}
|
||||
|
||||
private:
|
||||
static GamesSignInClient _signinClient;
|
||||
static AchievementsClient _achievementsClient;
|
||||
static RecallClient _recallClient;
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace cc
|
||||
+235
@@ -0,0 +1,235 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2025 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#include "vendor/google/play/PlayTask.h"
|
||||
#include "base/UTF8.h"
|
||||
#include "bindings/jswrapper/SeApi.h"
|
||||
#include "cocos/bindings/jswrapper/SeApi.h"
|
||||
#include "cocos/bindings/jswrapper/Value.h"
|
||||
#include "cocos/bindings/manual/jsb_conversions.h"
|
||||
|
||||
#include "vendor/google/play/PlayTaskManager.h"
|
||||
#include "vendor/google/play/TResult.h"
|
||||
#include "vendor/google/common/JsUtils.h"
|
||||
#include "vendor/google/common/JniUtils.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
template se::Value callJSfunc<cc::AuthenticationResult*>(se::Object* obj, const char*, cc::AuthenticationResult*&&);
|
||||
template se::Value callJSfunc<cc::PlayTask*>(se::Object* obj, const char*, cc::PlayTask*&&);
|
||||
namespace {
|
||||
#ifndef JCLS_GOOGLE_PLAY_TASK_MANAGER
|
||||
#define JCLS_GOOGLE_PLAY_TASK_MANAGER "google/play/TaskManager"
|
||||
#endif
|
||||
} // namespace
|
||||
|
||||
TaskException::~TaskException() {
|
||||
JniHelper::callStaticVoidMethod(JCLS_GOOGLE_PLAY_TASK_MANAGER, "removeTaskException", _exceptionId);
|
||||
}
|
||||
|
||||
void TaskException::printStackTrace() {
|
||||
JniHelper::callStaticVoidMethod(JCLS_GOOGLE_PLAY_TASK_MANAGER, "printExceptStackTrace", _exceptionId);
|
||||
}
|
||||
|
||||
int PlayTask::_nextListnerId = 0;
|
||||
|
||||
PlayTask::PlayTask(int taskId) : _taskId(taskId) {
|
||||
}
|
||||
|
||||
PlayTask::~PlayTask() {
|
||||
PlayTaskManager::getInstance()->removeTask(_taskId);
|
||||
JniHelper::callStaticVoidMethod(JCLS_GOOGLE_PLAY_TASK_MANAGER, "removeTask", _taskId);
|
||||
}
|
||||
|
||||
int PlayTask::getNextListenerId() {
|
||||
return _nextListnerId++;
|
||||
}
|
||||
|
||||
PlayTask* PlayTask::addOnCanceledListener(se::Object* listener) {
|
||||
int listenerId = addListener(listener);
|
||||
int taskId = JniHelper::callStaticIntMethod(JCLS_GOOGLE_PLAY_TASK_MANAGER, "addOnCanceledListener", _taskId, listenerId);
|
||||
return PlayTaskManager::getInstance()->addTask(taskId);
|
||||
}
|
||||
|
||||
PlayTask* PlayTask::addOnCompleteListener(se::Object* listener) {
|
||||
int listenerId = addListener(listener);
|
||||
int taskId = JniHelper::callStaticIntMethod(JCLS_GOOGLE_PLAY_TASK_MANAGER, "addOnCompleteListener", _taskId, listenerId);
|
||||
return PlayTaskManager::getInstance()->addTask(taskId);
|
||||
}
|
||||
|
||||
PlayTask* PlayTask::addOnFailureListener(se::Object* listener) {
|
||||
int listenerId = addListener(listener);
|
||||
int taskId = JniHelper::callStaticIntMethod(JCLS_GOOGLE_PLAY_TASK_MANAGER, "addOnFailureListener", _taskId, listenerId);
|
||||
return PlayTaskManager::getInstance()->addTask(taskId);
|
||||
}
|
||||
|
||||
PlayTask* PlayTask::addOnSuccessListener(se::Object* listener) {
|
||||
int listenerId = addListener(listener);
|
||||
int taskId = JniHelper::callStaticIntMethod(JCLS_GOOGLE_PLAY_TASK_MANAGER, "addOnSuccessListener", _taskId, listenerId);
|
||||
return PlayTaskManager::getInstance()->addTask(taskId);
|
||||
}
|
||||
|
||||
PlayTask* PlayTask::continueWith(se::Object* listener) {
|
||||
int listenerId = addListener(listener);
|
||||
int taskId = JniHelper::callStaticIntMethod(JCLS_GOOGLE_PLAY_TASK_MANAGER, "continueWith", _taskId, listenerId);
|
||||
return PlayTaskManager::getInstance()->addTask(taskId);
|
||||
}
|
||||
|
||||
|
||||
void PlayTask::getResult(se::Object* listener) {
|
||||
auto* env = JniHelper::getEnv();
|
||||
cc::JniMethodInfo t;
|
||||
if (cc::JniHelper::getStaticMethodInfo(t, JCLS_GOOGLE_PLAY_TASK_MANAGER, "getResult", "(I)Ljava/lang/Object;")) {
|
||||
jobject obj = t.env->CallStaticObjectMethod(t.classID, t.methodID, _taskId);
|
||||
callJSfuncWithJObject(listener, "onSuccess", reinterpret_cast<void*>(obj));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
bool PlayTask::isCanceled() {
|
||||
return JniHelper::callStaticBooleanMethod(JCLS_GOOGLE_PLAY_TASK_MANAGER, "isCanceled", _taskId);
|
||||
}
|
||||
|
||||
bool PlayTask::isComplete() {
|
||||
return JniHelper::callStaticBooleanMethod(JCLS_GOOGLE_PLAY_TASK_MANAGER, "isComplete", _taskId);
|
||||
}
|
||||
|
||||
bool PlayTask::isSuccessful() {
|
||||
return JniHelper::callStaticBooleanMethod(JCLS_GOOGLE_PLAY_TASK_MANAGER, "isSuccessful", _taskId);
|
||||
}
|
||||
|
||||
int PlayTask::addListener(se::Object* listener) {
|
||||
int listenerId = getNextListenerId();
|
||||
_listeners[listenerId].reset(listener);
|
||||
return listenerId;
|
||||
}
|
||||
|
||||
void PlayTask::onTaskCanceled(int listerId) {
|
||||
auto it = _listeners.find(listerId);
|
||||
if (it != _listeners.end()) {
|
||||
cc::callJSfunc(it->second.get(), "onCanceled");
|
||||
_listeners.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
void PlayTask::onTaskComplete(int listerId, int nextTaskId) {
|
||||
auto it = _listeners.find(listerId);
|
||||
if (it != _listeners.end()) {
|
||||
PlayTask* newTask = PlayTaskManager::getInstance()->addTask(nextTaskId);
|
||||
cc::callJSfunc(it->second.get(), "onComplete", newTask);
|
||||
_listeners.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
void PlayTask::onTaskFailure(int listerId, void* obj, int exceptionId) {
|
||||
auto it = _listeners.find(listerId);
|
||||
if (it != _listeners.end()) {
|
||||
auto* env = JniHelper::getEnv();
|
||||
jobject jobj = reinterpret_cast<jobject>(obj);
|
||||
jclass objClass = env->GetObjectClass(jobj);
|
||||
jmethodID getNameMethod = env->GetMethodID(env->FindClass("java/lang/Class"), "getName", "()Ljava/lang/String;");
|
||||
jstring className = (jstring)env->CallObjectMethod(objClass, getNameMethod);
|
||||
std::string name = cc::StringUtils::getStringUTFCharsJNI(env, className);
|
||||
if(name == "java.lang.Exception") {
|
||||
auto* taskException = new TaskException;
|
||||
taskException->_detailMessage = callStringMethod(env, objClass, jobj, "getMessage");
|
||||
taskException->_toString = callStringMethod(env, objClass, jobj, "toString");
|
||||
cc::callJSfunc(it->second.get(), "onFailure", taskException);
|
||||
}
|
||||
_listeners.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
void PlayTask::onTaskSuccess(int listerId, void* obj) {
|
||||
auto it = _listeners.find(listerId);
|
||||
if (it != _listeners.end()) {
|
||||
callJSfuncWithJObject(it->second.get(), "onSuccess", obj);
|
||||
_listeners.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
void* PlayTask::onTaskContinueWith(int listerId, int nextTaskId) {
|
||||
void * ptr = nullptr;
|
||||
auto it = _listeners.find(listerId);
|
||||
if (it != _listeners.end()) {
|
||||
se::Value r = callJSfunc(it->second.get(), "then");
|
||||
|
||||
if(r.isNumber()) {
|
||||
ptr = reinterpret_cast<void*>(intToJObject(JniHelper::getEnv(), r.toInt32()));
|
||||
} else if(r.isBoolean()) {
|
||||
ptr = reinterpret_cast<void*>(boolToJObject(JniHelper::getEnv(), r.toBoolean()));
|
||||
} else if(r.isString()) {
|
||||
ptr = reinterpret_cast<void*>(stringToJString(JniHelper::getEnv(), r.toString()));
|
||||
} else if(r.isObject()) {
|
||||
// Currently, there is no need to parse objects, and the implemented functional objects (such as AuthenticationResult) do not provide constructors.
|
||||
// If needed in the future, they can be parsed as follows :
|
||||
// se::Object* obj = r.toObject();
|
||||
// std::string name = obj->_getClass()->getName();
|
||||
// if(name == "AuthenticationResult") {
|
||||
// auto* result = reinterpret_cast<cc::AuthenticationResult*>(obj->getPrivateData());
|
||||
// }
|
||||
}
|
||||
_listeners.erase(it);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void PlayTask::callJSfuncWithJObject(se::Object* listener, const char* functionName, void* obj) {
|
||||
jobject jobj = reinterpret_cast<jobject>(obj);
|
||||
if(jobj != nullptr) {
|
||||
auto* env = JniHelper::getEnv();
|
||||
jclass objClass = env->GetObjectClass(jobj);
|
||||
jmethodID getNameMethod = env->GetMethodID(env->FindClass("java/lang/Class"), "getName", "()Ljava/lang/String;");
|
||||
jstring className = (jstring)env->CallObjectMethod(objClass, getNameMethod);
|
||||
std::string name = cc::StringUtils::getStringUTFCharsJNI(env, className);
|
||||
if (name == "com.google.android.gms.games.AuthenticationResult") {
|
||||
auto* authenticationResult = new AuthenticationResult;
|
||||
authenticationResult->_isAuthenticated = callBooleanMethod(env, objClass, jobj, "isAuthenticated");
|
||||
cc::callJSfunc(listener, functionName, authenticationResult);
|
||||
} else if (name == "com.google.android.gms.games.RecallAccess") {
|
||||
auto* recallAccess = new RecallAccess;
|
||||
recallAccess->_hashCode = callIntMethod(env, objClass, jobj, "hashCode");
|
||||
recallAccess->_sessionId = callStringMethod(env, objClass, jobj, "getSessionId");
|
||||
cc::callJSfunc(listener, functionName, recallAccess);
|
||||
} else if(name == "java.lang.Integer") {
|
||||
int value = integerObjectToInt(env, objClass, jobj);
|
||||
cc::callJSfunc(listener, functionName, value);
|
||||
} else if(name == "java.lang.Double") {
|
||||
double value = doubleObjectToDouble(env, objClass, jobj);
|
||||
cc::callJSfunc(listener, functionName, value);
|
||||
} else if(name == "java.lang.Boolean") {
|
||||
bool value = BooleanObjectToBool(env, objClass, jobj);
|
||||
cc::callJSfunc(listener, functionName, value);
|
||||
} else if(name == "java.lang.String") {
|
||||
std::string value = cc::StringUtils::getStringUTFCharsJNI(env, static_cast<jstring>(jobj));
|
||||
cc::callJSfunc(listener, functionName, value);
|
||||
} else {
|
||||
CC_LOG_WARNING("Unsupported types");
|
||||
cc::callJSfunc(listener, functionName);
|
||||
}
|
||||
} else {
|
||||
cc::callJSfunc(listener, functionName);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace cc
|
||||
Vendored
+89
@@ -0,0 +1,89 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2025 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <unordered_map>
|
||||
#include "base/RefCounted.h"
|
||||
#include "vendor/google/common/ScopedListener.h"
|
||||
|
||||
namespace se {
|
||||
class Object;
|
||||
}
|
||||
namespace cc {
|
||||
class TaskException : public RefCounted {
|
||||
public:
|
||||
~TaskException();
|
||||
const std::string& getMessage() const {
|
||||
return _detailMessage;
|
||||
}
|
||||
const std::string& toString() const {
|
||||
return _toString;
|
||||
}
|
||||
const std::string& getLocalizedMessage() const {
|
||||
return getMessage();
|
||||
}
|
||||
void printStackTrace();
|
||||
private:
|
||||
friend class PlayTask;
|
||||
int _exceptionId{0};
|
||||
std::string _detailMessage;
|
||||
std::string _toString;
|
||||
};
|
||||
|
||||
class PlayTask : public RefCounted {
|
||||
public:
|
||||
PlayTask(int taskId);
|
||||
~PlayTask();
|
||||
PlayTask* addOnCanceledListener(se::Object* listener);
|
||||
PlayTask* addOnCompleteListener(se::Object* listener);
|
||||
PlayTask* addOnFailureListener(se::Object* listener);
|
||||
PlayTask* addOnSuccessListener(se::Object* listener);
|
||||
|
||||
PlayTask* continueWith(se::Object* listener);
|
||||
void getResult(se::Object* listener);
|
||||
bool isCanceled();
|
||||
bool isComplete();
|
||||
bool isSuccessful();
|
||||
|
||||
protected:
|
||||
friend class PlayTaskManager;
|
||||
void onTaskCanceled(int listerId);
|
||||
void onTaskComplete(int listerId, int nextTaskId);
|
||||
void onTaskFailure(int listerId, void* obj, int exceptionId);
|
||||
void onTaskSuccess(int listerId, void* obj);
|
||||
void* onTaskContinueWith(int listerId, int nextTaskId);
|
||||
void callJSfuncWithJObject(se::Object* listener, const char* functionName, void* obj);
|
||||
|
||||
private:
|
||||
int getNextListenerId();
|
||||
int addListener(se::Object* listener);
|
||||
|
||||
private:
|
||||
static int _nextListnerId;
|
||||
int _taskId{0};
|
||||
std::unordered_map<int, scopedListener> _listeners;
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2025 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#include "vendor/google/play/PlayTaskManager.h"
|
||||
#include "cocos/platform/java/jni/JniHelper.h"
|
||||
#include "vendor/google/play/PlayTask.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
void PlayTaskManager::onTaskCanceled(int taskId, int listenerId) {
|
||||
auto it = _tasks.find(taskId);
|
||||
if (it != _tasks.end()) {
|
||||
it->second->onTaskCanceled(listenerId);
|
||||
}
|
||||
}
|
||||
|
||||
void PlayTaskManager::onTaskComplete(int taskId, int listenerId, int nextTaskId) {
|
||||
auto it = _tasks.find(taskId);
|
||||
if (it != _tasks.end()) {
|
||||
it->second->onTaskComplete(listenerId, nextTaskId);
|
||||
}
|
||||
}
|
||||
|
||||
void PlayTaskManager::onTaskFailure(int taskId, int listenerId, void* obj, int exceptionId) {
|
||||
auto it = _tasks.find(taskId);
|
||||
if (it != _tasks.end()) {
|
||||
it->second->onTaskFailure(listenerId, obj, exceptionId);
|
||||
}
|
||||
}
|
||||
|
||||
void PlayTaskManager::onTaskSucess(int taskId, int listenerId, void* obj) {
|
||||
auto it = _tasks.find(taskId);
|
||||
if (it != _tasks.end()) {
|
||||
it->second->onTaskSuccess(listenerId, obj);
|
||||
}
|
||||
}
|
||||
|
||||
PlayTask* PlayTaskManager::addTask(int taskId) {
|
||||
auto it = _tasks.find(taskId);
|
||||
if (it != _tasks.end()) {
|
||||
CC_LOG_WARNING("The task already exists.");
|
||||
return nullptr;
|
||||
}
|
||||
auto* task = new PlayTask(taskId);
|
||||
_tasks.insert(std::make_pair(taskId, task));
|
||||
return task;
|
||||
}
|
||||
|
||||
void PlayTaskManager::removeTask(int taskId) {
|
||||
auto it = _tasks.find(taskId);
|
||||
if (it == _tasks.end()) {
|
||||
CC_LOG_WARNING("The task does not exist.");
|
||||
return;
|
||||
}
|
||||
_tasks.erase(it);
|
||||
}
|
||||
|
||||
void* PlayTaskManager::onContinueWith(int taskId, int listenerId, int nextTaskId) {
|
||||
auto it = _tasks.find(taskId);
|
||||
if (it != _tasks.end()) {
|
||||
return it->second->onTaskContinueWith(listenerId, nextTaskId);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace cc
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2025 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <unordered_map>
|
||||
#include "base/RefCounted.h"
|
||||
|
||||
namespace se {
|
||||
class Object;
|
||||
}
|
||||
namespace cc {
|
||||
class PlayTask;
|
||||
|
||||
class PlayTaskManager {
|
||||
public:
|
||||
static PlayTaskManager* getInstance() {
|
||||
static PlayTaskManager mgr;
|
||||
return &mgr;
|
||||
}
|
||||
|
||||
void onTaskCanceled(int taskId, int listenerId);
|
||||
void onTaskComplete(int taskId, int listenerId, int nextTaskId);
|
||||
void onTaskFailure(int taskId, int listenerId, void* obj, int exceptionId);
|
||||
void onTaskSucess(int taskId, int listenerId, void* obj);
|
||||
void* onContinueWith(int taskId, int listenerId, int nextTaskId);
|
||||
PlayTask* addTask(int taskId);
|
||||
void removeTask(int taskId);
|
||||
private:
|
||||
int getNextListenerId();
|
||||
int addListener(se::Object* listener);
|
||||
|
||||
PlayTaskManager(/* args */) = default;
|
||||
~PlayTaskManager() = default;
|
||||
|
||||
private:
|
||||
std::unordered_map<int, PlayTask*> _tasks;
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
|
||||
/****************************************************************************
|
||||
Copyright (c) 2025 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#include "cocos/platform/java/jni/JniHelper.h"
|
||||
#include "vendor/google/play/PlayTaskManager.h"
|
||||
#include "vendor/google/play/RecallClient.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
PlayTask* RecallClient::requestRecallAccess() {
|
||||
int taskId = JniHelper::callStaticIntMethod("google/play/RecallClientHelper", "requestRecallAccess");
|
||||
return PlayTaskManager::getInstance()->addTask(taskId);
|
||||
}
|
||||
|
||||
} // namespace cc
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2025 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <unordered_map>
|
||||
#include "base/RefCounted.h"
|
||||
|
||||
namespace cc {
|
||||
class PlayTask;
|
||||
class RecallClient {
|
||||
public:
|
||||
PlayTask* requestRecallAccess();
|
||||
};
|
||||
} // namespace cc
|
||||
Vendored
+63
@@ -0,0 +1,63 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2025 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "base/RefCounted.h"
|
||||
|
||||
namespace cc {
|
||||
class AuthenticationResult : public RefCounted {
|
||||
public:
|
||||
bool isAuthenticated() const {
|
||||
return _isAuthenticated;
|
||||
}
|
||||
private:
|
||||
friend class PlayTask;
|
||||
bool _isAuthenticated {false};
|
||||
};
|
||||
|
||||
class RecallAccess : public RefCounted {
|
||||
public:
|
||||
int hashCode() const {
|
||||
return _hashCode;
|
||||
}
|
||||
|
||||
const std::string& getSessionId() const {
|
||||
return _sessionId;
|
||||
}
|
||||
|
||||
bool equals(const RecallAccess& other) {
|
||||
if(&other == this) {
|
||||
return true;
|
||||
}
|
||||
return _sessionId == other._sessionId;
|
||||
}
|
||||
private:
|
||||
friend class PlayTask;
|
||||
int _hashCode{0};
|
||||
std::string _sessionId;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
@@ -50,6 +50,7 @@ export interface IAndroidParams {
|
||||
appBundle: boolean;
|
||||
resizeableActivity: boolean;
|
||||
googleBilling: boolean;
|
||||
playGames: boolean;
|
||||
customIconInfo: ICustomIconInfo,
|
||||
}
|
||||
|
||||
@@ -404,7 +405,7 @@ export class GooglePlayPackTool extends NativePackTool {
|
||||
content = content.replace(/NATIVE_DIR=.*/, `NATIVE_DIR=${cchelper.fixPath(this.paths.platformTemplateDirInPrj)}`);
|
||||
|
||||
content = content.replace(/PROP_ENABLE_GOOGLE_BILLING=.*/, `PROP_ENABLE_GOOGLE_BILLING=${options.googleBilling ? "true" : "false"}`);
|
||||
|
||||
content = content.replace(/PROP_ENABLE_GOOGLE_PLAY_GAMES=.*/, `PROP_ENABLE_GOOGLE_PLAY_GAMES=${options.playGames ? "true" : "false"}`);
|
||||
|
||||
|
||||
if (process.platform === 'win32') {
|
||||
|
||||
@@ -54,6 +54,8 @@ COCOS_ENGINE_PATH=
|
||||
|
||||
# Billing
|
||||
PROP_ENABLE_GOOGLE_BILLING=true
|
||||
# PLAY
|
||||
PROP_ENABLE_GOOGLE_PLAY_GAMES=true
|
||||
|
||||
# Res path
|
||||
RES_PATH=
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ import { JSB } from 'internal:constants';
|
||||
|
||||
declare const jsb: any;
|
||||
|
||||
if (JSB) {
|
||||
if (JSB && jsb.BillingClient) {
|
||||
jsb.BillingClient.ConnectionState = {
|
||||
DISCONNECTED: 0,
|
||||
CONNECTING: 1,
|
||||
|
||||
Vendored
-159
@@ -1,159 +0,0 @@
|
||||
/* eslint-disable @typescript-eslint/no-namespace */
|
||||
/****************************************************************************
|
||||
Copyright (c) 2024 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*****************************************************************************/
|
||||
|
||||
import { JSB } from 'internal:constants';
|
||||
import './billing-enum';
|
||||
|
||||
const ns = JSB ? jsb : {} as unknown as typeof jsb;
|
||||
export namespace google {
|
||||
export namespace billing {
|
||||
export const BillingClient = ns.BillingClient;
|
||||
export const BillingResult = ns.BillingResult;
|
||||
export const InAppMessageResult = ns.InAppMessageResult;
|
||||
export const ProductDetails = ns.ProductDetails;
|
||||
export const Purchase = ns.Purchase;
|
||||
export const PendingPurchasesParams = ns.PendingPurchasesParams;
|
||||
export const QueryProductDetailsParams = ns.QueryProductDetailsParams;
|
||||
export const BillingFlowParams = ns.BillingFlowParams;
|
||||
export const ConsumeParams = ns.ConsumeParams;
|
||||
export const AcknowledgePurchaseParams = ns.AcknowledgePurchaseParams;
|
||||
export const QueryPurchasesParams = ns.QueryPurchasesParams;
|
||||
export const GetBillingConfigParams = ns.GetBillingConfigParams;
|
||||
export const InAppMessageParams = ns.InAppMessageParams;
|
||||
}
|
||||
}
|
||||
export declare namespace google {
|
||||
export namespace billing {
|
||||
export type AcknowledgePurchaseResponseListener = jsb.AcknowledgePurchaseResponseListener;
|
||||
export type AlternativeBillingOnlyAvailabilityListener = jsb.AlternativeBillingOnlyAvailabilityListener;
|
||||
export type AlternativeBillingOnlyInformationDialogListener = jsb.AlternativeBillingOnlyInformationDialogListener;
|
||||
export type AlternativeBillingOnlyReportingDetailsListener = jsb.AlternativeBillingOnlyReportingDetailsListener;
|
||||
export type BillingConfigResponseListener = jsb.BillingConfigResponseListener;
|
||||
export type ConsumeResponseListener = jsb.ConsumeResponseListener;
|
||||
export type ExternalOfferAvailabilityListener = jsb.ExternalOfferAvailabilityListener;
|
||||
export type ExternalOfferInformationDialogListener = jsb.ExternalOfferInformationDialogListener;
|
||||
export type ExternalOfferReportingDetailsListener = jsb.ExternalOfferReportingDetailsListener;
|
||||
export type InAppMessageResponseListener = jsb.InAppMessageResponseListener;
|
||||
export type ProductDetailsResponseListener = jsb.ProductDetailsResponseListener;
|
||||
export type PurchasesResponseListener = jsb.PurchasesResponseListener;
|
||||
export type PurchasesUpdatedListener = jsb.PurchasesUpdatedListener;
|
||||
export type UserChoiceBillingListener = jsb.UserChoiceBillingListener;
|
||||
export type BillingClientStateListener = jsb.BillingClientStateListener;
|
||||
|
||||
export type UserChoiceDetails = jsb.UserChoiceDetails;
|
||||
export type AccountIdentifiers = jsb.AccountIdentifiers;
|
||||
export type PendingPurchaseUpdate = jsb.PendingPurchaseUpdate;
|
||||
export type BillingConfig = jsb.BillingConfig;
|
||||
export type AlternativeBillingOnlyReportingDetails = jsb.AlternativeBillingOnlyReportingDetails;
|
||||
export type ExternalOfferReportingDetails = jsb.ExternalOfferReportingDetails;
|
||||
export namespace InAppMessageResult {
|
||||
export type InAppMessageResponseCode = jsb.InAppMessageResponseCode;
|
||||
}
|
||||
export type InAppMessageResult = jsb.InAppMessageResult;
|
||||
|
||||
export namespace PendingPurchasesParams {
|
||||
export type Builder = jsb.PendingPurchasesParamsBuilder;
|
||||
}
|
||||
export type PendingPurchasesParams = jsb.PendingPurchasesParams;
|
||||
|
||||
export namespace ProductDetails {
|
||||
export type RecurrenceMode = jsb.RecurrenceMode;
|
||||
export type OneTimePurchaseOfferDetails = jsb.OneTimePurchaseOfferDetails;
|
||||
export type InstallmentPlanDetails = jsb.InstallmentPlanDetails;
|
||||
export type PricingPhase = jsb.PricingPhase;
|
||||
export type PricingPhases = jsb.PricingPhases;
|
||||
export type SubscriptionOfferDetails = jsb.SubscriptionOfferDetails;
|
||||
}
|
||||
export type ProductDetails = jsb.ProductDetails;
|
||||
|
||||
export namespace Purchase {
|
||||
export type PurchaseState = jsb.PurchaseState;
|
||||
}
|
||||
export type Purchase = jsb.Purchase;
|
||||
|
||||
export namespace BillingClient {
|
||||
export type Builder = jsb.BillingClientBuilder;
|
||||
export type ConnectionState = jsb.ConnectionState;
|
||||
export type BillingResponseCode = jsb.BillingResponseCode;
|
||||
export type FeatureType = jsb.FeatureType;
|
||||
export type ProductType = jsb.ProductType;
|
||||
}
|
||||
export type BillingClient = jsb.BillingClient;
|
||||
export namespace BillingFlowParams {
|
||||
export type Builder = jsb.BillingFlowParamsBuilder;
|
||||
export namespace SubscriptionUpdateParams {
|
||||
export type Builder = jsb.SubscriptionUpdateParamsBuilder;
|
||||
export type ReplacementMode = jsb.ReplacementMode;
|
||||
}
|
||||
export type SubscriptionUpdateParams = jsb.SubscriptionUpdateParams;
|
||||
export namespace ProductDetailsParams {
|
||||
export type Builder = jsb.ProductDetailsParamsBuilder;
|
||||
}
|
||||
export type ProductDetailsParams = jsb.ProductDetailsParams;
|
||||
|
||||
}
|
||||
export type BillingFlowParams = jsb.BillingFlowParams;
|
||||
|
||||
export namespace QueryProductDetailsParams {
|
||||
export type Builder = jsb.QueryProductDetailsParamsBuilder;
|
||||
export namespace Product {
|
||||
export type Builder = jsb.QueryProductDetailsParamsProductBuilder;
|
||||
}
|
||||
export type Product = jsb.QueryProductDetailsParamsProduct;
|
||||
}
|
||||
export type QueryProductDetailsParams = jsb.QueryProductDetailsParams;
|
||||
|
||||
export namespace BillingResult {
|
||||
export type Builder = jsb.BillingResultBuilder;
|
||||
}
|
||||
export type BillingResult = jsb.BillingResult;
|
||||
|
||||
export namespace ConsumeParams {
|
||||
export type Builder = jsb.ConsumeParamsBuilder;
|
||||
}
|
||||
export type ConsumeParams = jsb.ConsumeParams;
|
||||
|
||||
export namespace AcknowledgePurchaseParams {
|
||||
export type Builder = jsb.AcknowledgePurchaseParamsBuilder;
|
||||
}
|
||||
export type AcknowledgePurchaseParams = jsb.AcknowledgePurchaseParams;
|
||||
|
||||
export namespace QueryPurchasesParams {
|
||||
export type Builder = jsb.QueryPurchasesParamsBuilder;
|
||||
}
|
||||
export type QueryPurchasesParams = jsb.QueryPurchasesParams;
|
||||
|
||||
namespace InAppMessageParams {
|
||||
export type Builder = jsb.InAppMessageParamsBuilder;
|
||||
export type InAppMessageCategoryId = jsb.InAppMessageCategoryId;
|
||||
}
|
||||
export type InAppMessageParams = jsb.InAppMessageParams;
|
||||
namespace GetBillingConfigParams {
|
||||
export type Builder = jsb.GetBillingConfigParams;
|
||||
}
|
||||
export type GetBillingConfigParams = jsb.GetBillingConfigParams;
|
||||
|
||||
}
|
||||
}
|
||||
Vendored
+156
-2
@@ -1,5 +1,6 @@
|
||||
/* eslint-disable @typescript-eslint/no-namespace */
|
||||
/*
|
||||
Copyright (c) 2024 Xiamen Yaji Software Co., Ltd.
|
||||
Copyright (c) 2024-2025 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
@@ -22,4 +23,157 @@
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
export * from './billing/billing';
|
||||
import { JSB } from 'internal:constants';
|
||||
import './billing/billing-enum';
|
||||
import { PlayGamesHelper, GamesSignInClientHelper } from './play/games';
|
||||
import { TaskHelper, ContinuationHelper } from './play/task';
|
||||
|
||||
//export * from './play/games';
|
||||
const ns = JSB ? jsb : {} as unknown as typeof jsb;
|
||||
export namespace google {
|
||||
export namespace billing {
|
||||
export const BillingClient = ns.BillingClient;
|
||||
export const BillingResult = ns.BillingResult;
|
||||
export const InAppMessageResult = ns.InAppMessageResult;
|
||||
export const ProductDetails = ns.ProductDetails;
|
||||
export const Purchase = ns.Purchase;
|
||||
export const PendingPurchasesParams = ns.PendingPurchasesParams;
|
||||
export const QueryProductDetailsParams = ns.QueryProductDetailsParams;
|
||||
export const BillingFlowParams = ns.BillingFlowParams;
|
||||
export const ConsumeParams = ns.ConsumeParams;
|
||||
export const AcknowledgePurchaseParams = ns.AcknowledgePurchaseParams;
|
||||
export const QueryPurchasesParams = ns.QueryPurchasesParams;
|
||||
export const GetBillingConfigParams = ns.GetBillingConfigParams;
|
||||
export const InAppMessageParams = ns.InAppMessageParams;
|
||||
}
|
||||
export namespace play {
|
||||
export const PlayGamesSdk = ns.PlayGamesSdk;
|
||||
export const PlayGames = PlayGamesHelper;
|
||||
export const GamesSignInClient = GamesSignInClientHelper;
|
||||
export const AuthenticationResult = ns.AuthenticationResult;
|
||||
export const RecallAccess = ns.RecallAccess;
|
||||
export const PlayException = ns.PlayException;
|
||||
}
|
||||
}
|
||||
export declare namespace google {
|
||||
export namespace billing {
|
||||
export type AcknowledgePurchaseResponseListener = jsb.AcknowledgePurchaseResponseListener;
|
||||
export type AlternativeBillingOnlyAvailabilityListener = jsb.AlternativeBillingOnlyAvailabilityListener;
|
||||
export type AlternativeBillingOnlyInformationDialogListener = jsb.AlternativeBillingOnlyInformationDialogListener;
|
||||
export type AlternativeBillingOnlyReportingDetailsListener = jsb.AlternativeBillingOnlyReportingDetailsListener;
|
||||
export type BillingConfigResponseListener = jsb.BillingConfigResponseListener;
|
||||
export type ConsumeResponseListener = jsb.ConsumeResponseListener;
|
||||
export type ExternalOfferAvailabilityListener = jsb.ExternalOfferAvailabilityListener;
|
||||
export type ExternalOfferInformationDialogListener = jsb.ExternalOfferInformationDialogListener;
|
||||
export type ExternalOfferReportingDetailsListener = jsb.ExternalOfferReportingDetailsListener;
|
||||
export type InAppMessageResponseListener = jsb.InAppMessageResponseListener;
|
||||
export type ProductDetailsResponseListener = jsb.ProductDetailsResponseListener;
|
||||
export type PurchasesResponseListener = jsb.PurchasesResponseListener;
|
||||
export type PurchasesUpdatedListener = jsb.PurchasesUpdatedListener;
|
||||
export type UserChoiceBillingListener = jsb.UserChoiceBillingListener;
|
||||
export type BillingClientStateListener = jsb.BillingClientStateListener;
|
||||
|
||||
export type UserChoiceDetails = jsb.UserChoiceDetails;
|
||||
export type AccountIdentifiers = jsb.AccountIdentifiers;
|
||||
export type PendingPurchaseUpdate = jsb.PendingPurchaseUpdate;
|
||||
export type BillingConfig = jsb.BillingConfig;
|
||||
export type AlternativeBillingOnlyReportingDetails = jsb.AlternativeBillingOnlyReportingDetails;
|
||||
export type ExternalOfferReportingDetails = jsb.ExternalOfferReportingDetails;
|
||||
export namespace InAppMessageResult {
|
||||
export type InAppMessageResponseCode = jsb.InAppMessageResponseCode;
|
||||
}
|
||||
export type InAppMessageResult = jsb.InAppMessageResult;
|
||||
|
||||
export namespace PendingPurchasesParams {
|
||||
export type Builder = jsb.PendingPurchasesParamsBuilder;
|
||||
}
|
||||
export type PendingPurchasesParams = jsb.PendingPurchasesParams;
|
||||
|
||||
export namespace ProductDetails {
|
||||
export type RecurrenceMode = jsb.RecurrenceMode;
|
||||
export type OneTimePurchaseOfferDetails = jsb.OneTimePurchaseOfferDetails;
|
||||
export type InstallmentPlanDetails = jsb.InstallmentPlanDetails;
|
||||
export type PricingPhase = jsb.PricingPhase;
|
||||
export type PricingPhases = jsb.PricingPhases;
|
||||
export type SubscriptionOfferDetails = jsb.SubscriptionOfferDetails;
|
||||
}
|
||||
export type ProductDetails = jsb.ProductDetails;
|
||||
|
||||
export namespace Purchase {
|
||||
export type PurchaseState = jsb.PurchaseState;
|
||||
}
|
||||
export type Purchase = jsb.Purchase;
|
||||
|
||||
export namespace BillingClient {
|
||||
export type Builder = jsb.BillingClientBuilder;
|
||||
export type ConnectionState = jsb.ConnectionState;
|
||||
export type BillingResponseCode = jsb.BillingResponseCode;
|
||||
export type FeatureType = jsb.FeatureType;
|
||||
export type ProductType = jsb.ProductType;
|
||||
}
|
||||
export type BillingClient = jsb.BillingClient;
|
||||
export namespace BillingFlowParams {
|
||||
export type Builder = jsb.BillingFlowParamsBuilder;
|
||||
export namespace SubscriptionUpdateParams {
|
||||
export type Builder = jsb.SubscriptionUpdateParamsBuilder;
|
||||
export type ReplacementMode = jsb.ReplacementMode;
|
||||
}
|
||||
export type SubscriptionUpdateParams = jsb.SubscriptionUpdateParams;
|
||||
export namespace ProductDetailsParams {
|
||||
export type Builder = jsb.ProductDetailsParamsBuilder;
|
||||
}
|
||||
export type ProductDetailsParams = jsb.ProductDetailsParams;
|
||||
|
||||
}
|
||||
export type BillingFlowParams = jsb.BillingFlowParams;
|
||||
|
||||
export namespace QueryProductDetailsParams {
|
||||
export type Builder = jsb.QueryProductDetailsParamsBuilder;
|
||||
export namespace Product {
|
||||
export type Builder = jsb.QueryProductDetailsParamsProductBuilder;
|
||||
}
|
||||
export type Product = jsb.QueryProductDetailsParamsProduct;
|
||||
}
|
||||
export type QueryProductDetailsParams = jsb.QueryProductDetailsParams;
|
||||
|
||||
export namespace BillingResult {
|
||||
export type Builder = jsb.BillingResultBuilder;
|
||||
}
|
||||
export type BillingResult = jsb.BillingResult;
|
||||
|
||||
export namespace ConsumeParams {
|
||||
export type Builder = jsb.ConsumeParamsBuilder;
|
||||
}
|
||||
export type ConsumeParams = jsb.ConsumeParams;
|
||||
|
||||
export namespace AcknowledgePurchaseParams {
|
||||
export type Builder = jsb.AcknowledgePurchaseParamsBuilder;
|
||||
}
|
||||
export type AcknowledgePurchaseParams = jsb.AcknowledgePurchaseParams;
|
||||
|
||||
export namespace QueryPurchasesParams {
|
||||
export type Builder = jsb.QueryPurchasesParamsBuilder;
|
||||
}
|
||||
export type QueryPurchasesParams = jsb.QueryPurchasesParams;
|
||||
|
||||
namespace InAppMessageParams {
|
||||
export type Builder = jsb.InAppMessageParamsBuilder;
|
||||
export type InAppMessageCategoryId = jsb.InAppMessageCategoryId;
|
||||
}
|
||||
export type InAppMessageParams = jsb.InAppMessageParams;
|
||||
namespace GetBillingConfigParams {
|
||||
export type Builder = jsb.GetBillingConfigParams;
|
||||
}
|
||||
export type GetBillingConfigParams = jsb.GetBillingConfigParams;
|
||||
|
||||
}
|
||||
|
||||
export namespace play {
|
||||
export type PlayGamesSdk = jsb.PlayGamesSdk;
|
||||
export type AuthenticationResult = jsb.AuthenticationResult;
|
||||
export type Continuation<T, K = void> = ContinuationHelper<T, K>;
|
||||
export type Task<T, K = void> = TaskHelper<T, K>;
|
||||
export type RecallAccess = jsb.RecallAccess;
|
||||
export type PlayException = jsb.PlayException;
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+253
@@ -0,0 +1,253 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2025 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*****************************************************************************/
|
||||
|
||||
import { TaskHelper, ContinuationHelper, OnCompleteListener, OnCanceledListener, OnFailureListener, OnSuccessListener } from './task';
|
||||
|
||||
/**
|
||||
* TaskManager is responsible for managing the lifecycle of tasks.
|
||||
*
|
||||
* Example usage in TypeScript:
|
||||
*
|
||||
* task.addOnSuccessListener({
|
||||
* onSuccess: (result: google.play.AuthenticationResult): void => {
|
||||
* console.log('Authenticated: ', result.isAuthenticated());
|
||||
* },
|
||||
* });
|
||||
*
|
||||
* Ideally, after invoking this function, the callback should be awaited.
|
||||
* However, in TypeScript, if the task object is not stored, it may be released
|
||||
* before the callback is executed. To prevent this, a class is needed to manage
|
||||
* the tasks being listened to.
|
||||
*/
|
||||
class TaskManager<TResult, TContinuationResult = void> {
|
||||
private tasks: Map<number, GooglePlayTask<TResult, TContinuationResult>> = new Map<number, GooglePlayTask<TResult, TContinuationResult>>();
|
||||
private nextTaskId: number = 0;
|
||||
addTask (task: GooglePlayTask<TResult, TContinuationResult>, taskId: number | null = null): void {
|
||||
if (typeof taskId === 'number') {
|
||||
this.tasks.set(taskId, task);
|
||||
} else {
|
||||
this.tasks.set(this.getNextTaskId(), task);
|
||||
}
|
||||
}
|
||||
|
||||
getNextTaskId (): number {
|
||||
return this.nextTaskId++;
|
||||
}
|
||||
|
||||
removeTask (taskId: number): void {
|
||||
this.tasks.delete(taskId);
|
||||
}
|
||||
}
|
||||
|
||||
export class GooglePlayTask<TResult, TContinuationResult = void> implements TaskHelper<TResult, TContinuationResult> {
|
||||
private _nativeTask: jsb.PlayTask;
|
||||
public static taskMgr: TaskManager<any, any> = new TaskManager<any, any>();
|
||||
constructor (task: jsb.PlayTask) {
|
||||
this._nativeTask = task;
|
||||
}
|
||||
|
||||
addOnCanceledListener (listener: OnCanceledListener): TaskHelper<TResult, TContinuationResult> {
|
||||
const taskId = GooglePlayTask.taskMgr.getNextTaskId();
|
||||
const newNativeTask = this._nativeTask.addOnCanceledListener({
|
||||
onCanceled: (): void => {
|
||||
listener.onCanceled();
|
||||
GooglePlayTask.taskMgr.removeTask(taskId);
|
||||
},
|
||||
});
|
||||
const newTask = new GooglePlayTask<TResult, TContinuationResult>(newNativeTask);
|
||||
GooglePlayTask.taskMgr.addTask(newTask, taskId);
|
||||
return newTask;
|
||||
}
|
||||
|
||||
addOnCompleteListener (listener: OnCompleteListener<TResult, TContinuationResult>): TaskHelper<TResult, TContinuationResult> {
|
||||
const taskId = GooglePlayTask.taskMgr.getNextTaskId();
|
||||
const newNativeTask = this._nativeTask.addOnCompleteListener({
|
||||
onComplete: (result: jsb.PlayTask): void => {
|
||||
listener.onComplete(new GooglePlayTask<TResult, TContinuationResult>(result));
|
||||
GooglePlayTask.taskMgr.removeTask(taskId);
|
||||
},
|
||||
});
|
||||
const newTask = new GooglePlayTask<TResult, TContinuationResult>(newNativeTask);
|
||||
GooglePlayTask.taskMgr.addTask(newTask, taskId);
|
||||
return newTask;
|
||||
}
|
||||
|
||||
addOnFailureListener (listener: OnFailureListener): TaskHelper<TResult, TContinuationResult> {
|
||||
const taskId = GooglePlayTask.taskMgr.getNextTaskId();
|
||||
const newNativeTask = this._nativeTask.addOnFailureListener({
|
||||
onFailure: (result: jsb.PlayException): void => {
|
||||
listener.onFailure(result);
|
||||
GooglePlayTask.taskMgr.removeTask(taskId);
|
||||
},
|
||||
});
|
||||
|
||||
const newTask = new GooglePlayTask<TResult, TContinuationResult>(newNativeTask);
|
||||
GooglePlayTask.taskMgr.addTask(newTask, taskId);
|
||||
return newTask;
|
||||
}
|
||||
|
||||
addOnSuccessListener (continuation: OnSuccessListener<TResult>): TaskHelper<TResult, TContinuationResult> {
|
||||
const taskId = GooglePlayTask.taskMgr.getNextTaskId();
|
||||
const newNativeTask = this._nativeTask.addOnSuccessListener({
|
||||
onSuccess: (result: any): void => {
|
||||
continuation.onSuccess(result as TResult);
|
||||
GooglePlayTask.taskMgr.removeTask(taskId);
|
||||
},
|
||||
});
|
||||
const newTask = new GooglePlayTask<TResult, TContinuationResult>(newNativeTask);
|
||||
GooglePlayTask.taskMgr.addTask(newTask, taskId);
|
||||
return newTask;
|
||||
}
|
||||
|
||||
continueWith (continuation: ContinuationHelper<TResult, TContinuationResult>): TaskHelper<TContinuationResult> {
|
||||
const newNativeTask = this._nativeTask.continueWith({
|
||||
then: (result: jsb.PlayTask): TContinuationResult => {
|
||||
const newTask = new GooglePlayTask<TResult, TContinuationResult>(result);
|
||||
GooglePlayTask.taskMgr.addTask(newTask);
|
||||
return continuation.then(newTask);
|
||||
},
|
||||
});
|
||||
const newTask = new GooglePlayTask<TContinuationResult>(newNativeTask);
|
||||
GooglePlayTask.taskMgr.addTask(newTask);
|
||||
return newTask;
|
||||
}
|
||||
|
||||
continueWithTask (continuation: TaskHelper<TContinuationResult, GooglePlayTask<TContinuationResult>>): TaskHelper<TContinuationResult> {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
|
||||
getResult (): TResult | null {
|
||||
// Since getResult can return any type, it is not possible to directly return an arbitrary type to TypeScript in C++.
|
||||
// Therefore, a solution was implemented:
|
||||
// a callback function is set up to receive a value of type any.
|
||||
// In C++, this callback function can be called with any type, and it will handle automatic type conversion.
|
||||
let anyType: TResult | null = null;
|
||||
this._nativeTask.getResult({
|
||||
onSuccess: (result: any): void => {
|
||||
anyType = result as TResult;
|
||||
},
|
||||
});
|
||||
return anyType;
|
||||
}
|
||||
|
||||
isCanceled (): boolean {
|
||||
return this._nativeTask.isCanceled();
|
||||
}
|
||||
isComplete (): boolean {
|
||||
return this._nativeTask.isComplete();
|
||||
}
|
||||
isSuccessful (): boolean {
|
||||
return this._nativeTask.isSuccessful();
|
||||
}
|
||||
}
|
||||
|
||||
export class GamesSignInClientHelper {
|
||||
isAuthenticated (): TaskHelper<jsb.AuthenticationResult> {
|
||||
const newTask = new GooglePlayTask<jsb.AuthenticationResult>(jsb.PlayGames.getGamesSignInClient().isAuthenticated());
|
||||
GooglePlayTask.taskMgr.addTask(newTask);
|
||||
return newTask;
|
||||
}
|
||||
|
||||
requestServerSideAccess (serverClientId: string, forceRefreshToken: boolean): TaskHelper<string> {
|
||||
const newTask = new GooglePlayTask<string>(jsb.PlayGames.getGamesSignInClient().requestServerSideAccess(serverClientId, forceRefreshToken));
|
||||
GooglePlayTask.taskMgr.addTask(newTask);
|
||||
return newTask;
|
||||
}
|
||||
|
||||
signIn (): TaskHelper<jsb.AuthenticationResult> {
|
||||
const newTask = new GooglePlayTask<jsb.AuthenticationResult>(jsb.PlayGames.getGamesSignInClient().signIn());
|
||||
GooglePlayTask.taskMgr.addTask(newTask);
|
||||
return newTask;
|
||||
}
|
||||
}
|
||||
|
||||
export class AchievementsClient {
|
||||
showAchievements (): void {
|
||||
jsb.PlayGames.getAchievementsClient().showAchievements();
|
||||
}
|
||||
|
||||
incrementImmediate (id: string, numSteps: number): TaskHelper<boolean> {
|
||||
const newTask = new GooglePlayTask<boolean>(jsb.PlayGames.getAchievementsClient().incrementImmediate(id, numSteps));
|
||||
GooglePlayTask.taskMgr.addTask(newTask);
|
||||
return newTask;
|
||||
}
|
||||
load (id: boolean): TaskHelper<boolean> {
|
||||
const newTask = new GooglePlayTask<boolean>(jsb.PlayGames.getAchievementsClient().load(id));
|
||||
GooglePlayTask.taskMgr.addTask(newTask);
|
||||
return newTask;
|
||||
}
|
||||
revealImmediate (id: string): TaskHelper<void> {
|
||||
const newTask = new GooglePlayTask<void>(jsb.PlayGames.getAchievementsClient().revealImmediate(id));
|
||||
GooglePlayTask.taskMgr.addTask(newTask);
|
||||
return newTask;
|
||||
}
|
||||
setStepsImmediate (id: string, numSteps: number): TaskHelper<boolean> {
|
||||
const newTask = new GooglePlayTask<boolean>(jsb.PlayGames.getAchievementsClient().setStepsImmediate(id, numSteps));
|
||||
GooglePlayTask.taskMgr.addTask(newTask);
|
||||
return newTask;
|
||||
}
|
||||
unlockImmediate (id: string): TaskHelper<void> {
|
||||
const newTask = new GooglePlayTask<void>(jsb.PlayGames.getAchievementsClient().unlockImmediate(id));
|
||||
GooglePlayTask.taskMgr.addTask(newTask);
|
||||
return newTask;
|
||||
}
|
||||
increment (id: string, numSteps: number): void {
|
||||
jsb.PlayGames.getAchievementsClient().increment(id, numSteps);
|
||||
}
|
||||
|
||||
reveal (id: string): void {
|
||||
jsb.PlayGames.getAchievementsClient().reveal(id);
|
||||
}
|
||||
|
||||
setSteps (id: string, numSteps: number): void {
|
||||
jsb.PlayGames.getAchievementsClient().setSteps(id, numSteps);
|
||||
}
|
||||
|
||||
unlock (id: string): void {
|
||||
jsb.PlayGames.getAchievementsClient().unlock(id);
|
||||
}
|
||||
}
|
||||
|
||||
export class RecallClient {
|
||||
requestRecallAccess (): TaskHelper<jsb.RecallAccess> {
|
||||
const newTask = new GooglePlayTask<jsb.RecallAccess>(jsb.PlayGames.getRecallClient().requestRecallAccess());
|
||||
GooglePlayTask.taskMgr.addTask(newTask);
|
||||
return newTask;
|
||||
}
|
||||
}
|
||||
|
||||
export class PlayGamesHelper {
|
||||
private static achievementsClient: AchievementsClient = new AchievementsClient();
|
||||
private static gamesSignInClient: GamesSignInClientHelper = new GamesSignInClientHelper();
|
||||
private static recallClient: RecallClient = new RecallClient();
|
||||
public static getAchievementsClient (): AchievementsClient {
|
||||
return this.achievementsClient;
|
||||
}
|
||||
public static getGamesSignInClient (): GamesSignInClientHelper {
|
||||
return this.gamesSignInClient;
|
||||
}
|
||||
public static getRecallClient (): RecallClient {
|
||||
return this.recallClient;
|
||||
}
|
||||
}
|
||||
Vendored
+55
@@ -0,0 +1,55 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2025 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*****************************************************************************/
|
||||
export interface OnCanceledListener {
|
||||
onCanceled(): void;
|
||||
}
|
||||
|
||||
export interface OnCompleteListener<TResult, TContinuationResult = void> {
|
||||
onComplete(result: TaskHelper<TResult, TContinuationResult>): void;
|
||||
}
|
||||
|
||||
export interface OnFailureListener {
|
||||
onFailure(e: jsb.PlayException): void;
|
||||
}
|
||||
|
||||
export interface OnSuccessListener<TResult> {
|
||||
onSuccess(result: TResult): void;
|
||||
}
|
||||
|
||||
export interface ContinuationHelper<TResult, TContinuationResult> {
|
||||
then(task: TaskHelper<TResult, TContinuationResult>): TContinuationResult;
|
||||
}
|
||||
|
||||
export interface TaskHelper<TResult, TContinuationResult = void> {
|
||||
addOnCanceledListener(listener: OnCanceledListener): TaskHelper<TResult, TContinuationResult>;
|
||||
addOnCompleteListener(listener: OnCompleteListener<TResult, TContinuationResult>): TaskHelper<TResult, TContinuationResult>;
|
||||
addOnFailureListener(listener: OnFailureListener): TaskHelper<TResult, TContinuationResult>;
|
||||
addOnSuccessListener(listener: OnSuccessListener<TResult>): TaskHelper<TResult, TContinuationResult>;
|
||||
continueWith(result: ContinuationHelper<TResult, TContinuationResult>): TaskHelper<TContinuationResult>;
|
||||
continueWithTask (result: TaskHelper<TContinuationResult, TaskHelper<TContinuationResult>>): TaskHelper<TContinuationResult>;
|
||||
getResult(): TResult | null;
|
||||
isCanceled(): boolean;
|
||||
isComplete(): boolean;
|
||||
isSuccessful(): boolean;
|
||||
}
|
||||
Reference in New Issue
Block a user