Skip to content

Commit

Permalink
Update gpgs to v2 (#52)
Browse files Browse the repository at this point in the history
* Update gpgs to v2

* Update documentation.
Finish event API documentation.

* Update bob.yaml

* Compilation fix

* Delete global ref of gpgs jni
  • Loading branch information
ekharkunov authored Feb 5, 2025
1 parent 4461c4b commit e791d36
Show file tree
Hide file tree
Showing 15 changed files with 318 additions and 2,184 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/bob.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ jobs:

name: Build
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v3
with: { java-version: '17.0.5+8', distribution: 'temurin'}
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: actions/setup-java@7a6d8a8234af8eb26422e24e3006232cccaa061b
with: { java-version: '21.0.5+11.0.LTS', distribution: 'temurin', architecture: 'x64'}

- name: Get Defold version
run: |
Expand Down Expand Up @@ -47,9 +47,9 @@ jobs:

name: Build
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v3
with: { java-version: '17.0.5+8', distribution: 'temurin'}
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: actions/setup-java@7a6d8a8234af8eb26422e24e3006232cccaa061b
with: { java-version: '21.0.5+11.0.LTS', distribution: 'temurin', architecture: 'x64'}

- name: Get Defold version
run: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ Thumbs.db
.cproject
builtins
_site
/.editor_settings
4 changes: 1 addition & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ Add the following section into your `game.project` file (open and edit as a text
app_id = 1234567890
use_saved_games = 1
request_server_auth_code = 0
request_id_token = 0
```

Where `app_id` is the 12 or 13 digit Application ID from the Google Play Console, found under Development Tools > Services & APIs and Google Play game services.</p>

Where `use_saved_games` indicates if the [Game Saves service](https://developers.google.com/games/services/common/concepts/savedgames) should be used (0 is disabled, 1 is enabled).</p>

If you want to retrieve server auth code set `gpgs.request_server_auth_code` to 1 and provide `gpgs.client_token`. Client token should be configured to Web application.

## Usage

Expand Down Expand Up @@ -72,8 +72,6 @@ local function gpgs_callback(self, message_id, message)
else
print("Sign in error!")
end
elseif message_id == gpgs.MSG_SIGN_OUT then
print("Signed out")
end
end

Expand Down
5 changes: 2 additions & 3 deletions game.project
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ shared_state = 1

[android]
package = com.defold.extension.gpgs
minimum_sdk_version = 16
target_sdk_version = 28
minimum_sdk_version = 21
target_sdk_version = 34

[ios]
bundle_identifier = com.defold.extension.gpgs
Expand All @@ -35,7 +35,6 @@ app_id = 741832396715
client_id = 741832396715-sl2dn4pjiqop78t1pgflb6ob4aqsvom5.apps.googleusercontent.com
use_saved_games = 1
request_server_auth_code = 0
request_id_token = 0

[library]
include_dirs = gpgs
Expand Down
193 changes: 63 additions & 130 deletions gpgs/api/gpgs.script_api
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,6 @@

This function is trying to retrieve the currently signed-in player’s account.

[icon:attention] By default login methods request `GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN`.
But if you use Disk, we have to request extra scope `Drive.SCOPE_APPFOLDER`.
Or if you use ID token, we have to request ID token with provided client_id.
If so it causes the first time silent sign-in to fail, except for users who
have already signed in successfully on a different device. Turn off GPGS
features you don't want to use in `game.project`.

examples:
- desc: |-
```lua
Expand All @@ -63,20 +56,6 @@
end
```

#*****************************************************************************************************

- name: logout
type: function
desc: Logout from GPGS

examples:
- desc: |-
```lua
if gpgs then
gpgs.logout()
end
```

#*****************************************************************************************************

- name: get_display_name
Expand Down Expand Up @@ -115,36 +94,21 @@
end
```

#*****************************************************************************************************

- name: get_id_token
type: function
desc: Get the current GPGS player id token. Available only if "gpgs.client_id" is configured in game.project
and "gpgs.request_id_token = 1".

returns:
- name: id_token
type: string
desc: The player ID token.

examples:
- desc: |-
```lua
if gpgs then
local id_token = gpgs.get_id_token()
end
```

#*****************************************************************************************************

- name: get_server_auth_code
type: function
desc: Returns a one-time server auth code to send to your web server which can be exchanged for access token

Token can be retrieved only if `gpgs.request_server_auth_code` set to 1 and `gpgs.client` is set.

returns:
- name: server_auth_code
type: string
desc: The server auth code for logged in account.
desc: The server auth code for logged in account. Can be nil if operation is not completed yet.

Auth token is avaliable after receiving message with id `gpgs.MSG_GET_SERVER_TOKEN`
in callback set via `gpgs.set_callback`.

examples:
- desc: |-
Expand Down Expand Up @@ -173,46 +137,6 @@
end
```

#*****************************************************************************************************

- name: set_popup_position
type: function
desc: This method sets the position for the login popup.

parameters:
- name: position
type: number
desc: An position can be one of the predefined constants below

- `gpgs.POPUP_POS_TOP_LEFT`

- `gpgs.POPUP_POS_TOP_CENTER`

- `gpgs.POPUP_POS_TOP_RIGHT`

- `gpgs.POPUP_POS_CENTER_LEFT`

- `gpgs.POPUP_POS_CENTER`

- `gpgs.POPUP_POS_CENTER_RIGHT`

- `gpgs.POPUP_POS_BOTTOM_LEFT`

- `gpgs.POPUP_POS_BOTTOM_CENTER`

- `gpgs.POPUP_POS_BOTTOM_RIGHT`


Default value is `gpgs.POPUP_POS_TOP_CENTER`

examples:
- desc: |-
```lua
if gpgs then
gpgs.set_popup_position(gpgs.POPUP_POS_BOTTOM_CENTER)
end
```

#*****************************************************************************************************

- name: set_callback
Expand All @@ -236,8 +160,6 @@

- `gpgs.MSG_SILENT_SIGN_IN`

- `gpgs.MSG_SIGN_OUT`

- `gpgs.MSG_SHOW_SNAPSHOTS`

- `gpgs.MSG_LOAD_SNAPSHOT`
Expand Down Expand Up @@ -309,8 +231,6 @@
if message.status == gpgs.STATUS_SUCCESS then
-- do something after login
end
elseif message_id == gpgs.MSG_SIGN_OUT then
-- do something after logout
elseif message_id == gpgs.MSG_LOAD_SNAPSHOT then
-- do something when a save was loaded
end
Expand Down Expand Up @@ -723,44 +643,50 @@

- name: achievement_reveal
type: function
desc: Reveal achievement
desc: Reveals a hidden achievement to the current player.

parameters:
- name: achievementId
type: string
desc: Achievement id (from GP console)

#*****************************************************************************************************
- name: achievement_unlock
type: function
desc: Unlock achievement
desc: Unlocks an achievement for the current player.

parameters:
- name: achievementId
type: string
desc: Achievement id (from GP console)

#*****************************************************************************************************
- name: achievement_set
type: function
desc: Set achievement progress
desc: Sets an achievement to have at least the given number of steps completed.

parameters:
- name: achievementId
type: string
desc: Achievement id (from GP console)

- name: steps
type: number
desc: The number of steps to set the achievement to. Must be greater than 0.

#*****************************************************************************************************
- name: achievement_increment
type: function
desc: Increase achievement progress
desc: Increments an achievement by the given number of steps.

parameters:
- name: achievementId
type: string
desc: Achievement id (from GP console)

- name: steps
type: number
desc: The number of steps to increment by. Must be greater than 0.

#*****************************************************************************************************
- name: achievement_show
Expand All @@ -770,59 +696,66 @@
#*****************************************************************************************************
- name: achievement_get
type: function
desc: Get information about all achievement's state asynchronously. Result return to callback previously set by
`gpgs.set_callback` with `message_id == gpgs.MSG_ACHIEVEMENTS`. Result is array of tables which contain
following fields

- `id` - achievement id (from GP console)

- `name` - achievement name

- `description` - achievement description

- `xp` - how much experience points will be added when achievement will be unlocked

- `steps` - current step of incremental achievement

- `total_steps` - total amount of steps of incremental achievement

- `unlocked` - set to `true` if achievement is unlocked. Otherwise field is missed.

- `hidden` - set to `true if achievement is hidden. Otherwise field is missed.

- `revealed` - set to `true` if achievement is revealed. Otherwise field is missed.


#*****************************************************************************************************
- name: event_increment
type: function
desc: Increments an event specified by `eventId` by the given number of steps

parameters:
- name: eventId
type: string
desc: Event id (from GP console)

- name: amount
type: number
desc: The amount increment by. Must be greater than or equal to 0

#*****************************************************************************************************
- name: event_get
type: function
desc: Get information about all events asynchronously. Result returns to callback previously set by
`gpgs.set_callback` with `message_id == gpgs.MSG_GET_EVENTS`. Result is array of tables which contain
following fields

#*****************************************************************************************************
- `id` - event id

- `formatted_value` - sum of all increments have been made to this event

- `value` - the number of increments this user has made to this event

- `description` - event's description

- `image` - URI that can be used to load the event's image icon

- `name` - event's name

- `visible` - whether the event should be displayed to the user in any event related UIs

- name: POPUP_POS_TOP_LEFT
type: number
desc: The login popup position at the top-left corner.

- name: POPUP_POS_TOP_CENTER
type: number
desc: The login popup position at the top-center.

- name: POPUP_POS_TOP_RIGHT
type: number
desc: The login popup position at the top-right corner.

- name: POPUP_POS_CENTER_LEFT
type: number
desc: The login popup position at the center-left.

- name: POPUP_POS_CENTER
type: number
desc: The login popup position at the center of the screen.

- name: POPUP_POS_CENTER_RIGHT
type: number
desc: The login popup position at the center-right.

- name: POPUP_POS_BOTTOM_LEFT
type: number
desc: The login popup position at the bottom-left corner.

- name: POPUP_POS_BOTTOM_CENTER
type: number
desc: The login popup position at the bottom-centre.

- name: POPUP_POS_BOTTOM_RIGHT
type: number
desc: The login popup position at the bottom-right corner.
#*****************************************************************************************************

- name: RESOLUTION_POLICY_MANUAL
type: number
Expand Down Expand Up @@ -854,11 +787,6 @@
desc: The message type that GPGS sends when finishing the asynchronous operation
after calling `gpgs.silent_login()`

- name: MSG_SIGN_OUT
type: number
desc: The message type that GPGS sends when finishing the asynchronous operation
after calling `gpgs.logout()`

- name: MSG_SHOW_SNAPSHOTS
type: number
desc: The message type that GPGS sends when finishing the asynchronous operation
Expand All @@ -874,6 +802,11 @@
desc: The message type that GPGS sends when finishing the asynchronous operation
after calling `gpgs.snapshot_commit_and_close()`

- name: MSG_GET_SERVER_TOKEN
type: number
desc: The message type that GPGS sends when finishing the asynchronous operation
of server token retrieval

- name: STATUS_SUCCESS
type: number
desc: An operation success.
Expand Down
Loading

0 comments on commit e791d36

Please sign in to comment.