透過 HTTP 請求執行的 Game Jolt API 的包裝器。它包含所有 Game Jolt API 端點,旨在盡可能簡化其使用。與Godot 4.x相容。對於 Godot 3.x 版本,請參閱此分支。
有關使用範例,請參閱下面的文件。 addons/gamejolt/example
中還有一個範例場景,其中包含圖形介面上的所有端點和參數。
注意:任何參數後面跟著?
是可選的。範例: sessions_ping(status?) -> GameJolt
。
Project Settings > Plugins
中啟用插件Project Settings > General > Game Jolt > Config > Global
上執行 API 請求。Project Settings > General > Game Jolt > Config > Debug
上設定預設使用者名稱和令牌。完成此設定後,您可以在程式碼中的單例GameJolt
上使用下列方法執行 API 請求。
每個 Game Jolt API 方法都會在請求完成後發出一個訊號,無論成功與否。您可以連接特定訊號來捕捉方法回呼的回應:
func _ready () -> void :
GameJolt . time_completed . connect ( _on_GameJolt_time_completed )
GameJolt . time ()
func _on_GameJolt_time_completed ( result : Dictionary ) -> void :
# Do something with the request result...
或者您可以在變數中await
訊號結果:
func _onButtonTime_pressed () -> void :
GameJolt . time ()
var result : Dictionary = await GameJolt . time_completed
# Do something with the request result...
注意:所有訊號都會回傳一個response: Dictionary
。
一般的
user_name_changed
user_token_changed
game_id_changed
private_key_changed
使用者
users_fetch_completed(response: Dictionary)
users_auth_completed(response: Dictionary)
會議
sessions_open_completed(response: Dictionary)
sessions_ping_completed(response: Dictionary)
sessions_check_completed(response: Dictionary)
sessions_close_completed(response: Dictionary)
分數
scores_fetch_completed(response: Dictionary)
scores_tables_completed(response: Dictionary)
scores_add_completed(response: Dictionary)
scores_get_rank_completed(response: Dictionary)
獎盃
trophies_fetch_completed(response: Dictionary)
trophies_add_achieved_completed(response: Dictionary)
trophies_remove_achieved_completed(response: Dictionary)
資料儲存
data_store_set_completed(response: Dictionary)
data_store_update_completed(response: Dictionary)
data_store_remove_completed(response: Dictionary)
data_store_fetch_completed(response: Dictionary)
data_store_get_keys_completed(response: Dictionary)
朋友們
friends_completed(response: Dictionary)
時間
time_completed(response: Dictionary)
批次調用
batch_completed(response: Dictionary)
在本地配置GameJolt
單例的一般方法。
設定身份驗證和其他使用者範圍任務的使用者名稱。發出user_name_changed
。
value: String
-> 使用者名稱。 取得目前使用者名稱。
設定用於身份驗證和其他使用者範圍任務的使用者令牌。發出user_token_changed
。
value: String
-> 用戶遊戲代幣。 取得當前用戶遊戲代幣。
設定所有任務所需的遊戲ID。發出game_id_changed
。
value: String
-> 來自 Game Jolt 專案的遊戲 ID。 取得當前遊戲ID。
設定所有任務所需的私鑰。發出private_key_changed
。
value: String
-> 來自 Game Jolt 專案的遊戲私鑰。 取得當前遊戲私鑰。
傳回用戶的資料。發出users_fetch_completed
。
user_name: String
(可選)-> 您要取得其資料的使用者的使用者名稱。user_ids: Array[String|int]
(可選)-> 您要取得其資料的使用者的 ID。注意:參數user_name
和user_ids
是互斥的,只能使用其中之一,或不使用。如果未提供,將從GameJolt
單例中設定的目前使用者名稱中取得。
驗證用戶的資訊。這應該在對使用者進行任何呼叫之前完成,以確保使用者的憑證(使用者名稱和令牌)有效。必須在GameJolt
單例上設定使用者名稱和令牌才能成功。發出users_auth_completed
。
為特定使用者開啟遊戲會話,並允許您告訴 Game Jolt 用戶正在玩您的遊戲。您必須對會話執行 ping 操作以使其保持活動狀態,並且在使用完畢後必須將其關閉。發出sessions_open_completed
。
筆記:
GameJolt
單例上設定使用者名稱和令牌。 對開啟的會話執行 Ping 操作以告訴系統它仍然處於活動狀態。如果 120 秒內未對會話進行 ping 操作,系統將關閉該會話,您必須開啟另一個會話。建議您大約每 30 秒左右執行一次 ping 操作,以防止系統清除您的會話。您還可以讓系統知道玩家在遊戲中處於"active"
還是"idle"
狀態。發出sessions_ping_completed
。
status: String
(可選) -> 將會話的狀態設為"active"
或"idle"
。注意:需要在GameJolt
單例上設定使用者名稱和令牌。
檢查使用者是否有開啟的會話。可用於查看特定使用者帳號在遊戲中是否處於活動狀態。發出sessions_check_completed
。
筆記:
"success"
欄位傳回false
。此行為與使用此欄位指示錯誤狀態的其他端點不同。GameJolt
單例上設定使用者名稱和令牌。 關閉活動會話。發出sessions_close_completed
。
注意:需要在GameJolt
單例上設定使用者名稱和令牌。
傳回使用者或遊戲全域的分數清單。發出scores_fetch_completed
。
limit: String|int
(可選) -> 您想要傳回的分數數量。table_id: String|int
(可選) -> 分數表的ID。guest: String
(可選)-> 客人的姓名。better_than: String|int
(可選) -> 只取得比該分數排序值更好的分數。worse_than: String|int
(可選) -> 只取得比該分數排序值更差的分數。this_user: bool
(可選) -> 如果為true
,則僅取得目前使用者的分數。否則,取得所有使用者的分數。筆記:
this_user
為true
則需要在GameJolt
單例上設定使用者名稱和代幣。limit
的預設值為10
分。您可以檢索的最大分數為100
。table_id
留空,則傳回主分數表中的分數。this_user
作為true
傳遞。將this_user
保留為true
,將guest
保留為""
以檢索所有分數。guest
允許您透過特定的 guest 姓名獲取分數。僅將this_user
作為true
或guest
(或無)傳遞,切勿同時傳遞兩者。傳回遊戲的高分錶列表。發出scores_tables_completed
。
為使用者或訪客新增分數。發出scores_add_completed
。
score: String
-> 這是與分數關聯的字串值。例: "500 Points"
。sort: String|int
-> 這是與分數相關的數字排序值。所有的排序都將基於這個數字。範例: 500
。table_id: String|int
(可選) -> 要提交到的分數表的 ID。guest: String
(可選)-> 客人的姓名。覆蓋GameJolt
單例的用戶名。extra_data: String|int|Dictionary|Array
(可選) -> 如果您想將任何額外資料儲存為字串,您可以使用此變數。筆記:
GameJolt
單例上設定使用者名稱和令牌,並將guest
保留為空白。如果您要為訪客存儲,則必須傳入guest
參數。extra_data
值只能透過 API 和遊戲的儀表板檢索。它永遠不會向網站上的用戶公開顯示。如果還有與分數相關的其他數據,例如玩的時間、收集的硬幣等,您絕對應該包含它。如果您認為玩家非法獲得高分,這將很有幫助。table_id
留空,則分數將提交至主高分錶。 傳回分數表中特定分數的排名。發出scores_get_rank_completed
。
sort: String|int
-> 這是一個數字排序值,由分數表上的排名表示。table_id: String|int
(可選) -> 若要從中取得排名的分數表的 ID。筆記:
table_id
留空,則傳回主高分錶中的排名。傳回一個或多個獎杯,取決於trophies_fetch_completed
的參數。
sort: bool|null
(可選) -> 傳入true
只傳回使用者所獲得的獎盃。傳入false
只回傳用戶未獲得的獎盃。傳遞null
以檢索所有獎盃。trophy_ids: Array[String|int]
(可選) -> 如果您想傳回一個或多個獎杯,如果您想傳回所有獎盃的子集,請在此傳遞獎盃 ID。筆記:
trophy_ids
話,如果傳遞了則忽略achieved
參數。GameJolt
單例上設定使用者名稱和令牌。 為特定使用者設定一個獎盃。發出trophies_add_achieved_completed
。
trophy_id: String|int
-> 要為使用者新增的獎盃的 ID。注意:需要在GameJolt
單例上設定使用者名稱和令牌。
刪除特定使用者之前獲得的獎盃。發出trophies_remove_achieved_completed
。
trophy_id: String|int
-> 要從使用者刪除的獎盃的 ID。注意:需要在GameJolt
單例上設定使用者名稱和令牌。
在資料儲存中設定資料。發出data_store_set_completed
。
key: String
-> 您要設定的資料項的鍵。data: String|Array|Dictionary
-> 您要設定的資料。global_data: bool
(可選) -> 如果設定為true
,則忽略GameJolt
中設定的使用者名稱和令牌並處理全域資料而不是使用者資料。筆記:
global_data
為false
,則需要在GameJolt
單例上設定使用者名稱和令牌。 更新資料儲存中的資料。發出data_store_update_completed
。
key: String
-> 您要更新的資料項的鍵。operation: String
-> 您要執行的操作。value: String|int
-> 您想要套用於資料儲存項目的值。global_data: bool
(可選) -> 如果設定為true
,則忽略GameJolt
中設定的使用者名稱和令牌並處理全域資料而不是使用者資料。筆記:
operation
的有效值: "add"
、 "subtract"
、 "multiply"
、 "divide"
、 "append"
和"prepend"
。global_data
為false
,則需要在GameJolt
單例上設定使用者名稱和令牌。 從資料儲存中刪除資料。發出data_store_remove_completed
。
key: String
-> 您要刪除的資料項目的鍵。global_data: bool
(可選) -> 如果設定為true
,則忽略GameJolt
中設定的使用者名稱和令牌並處理全域資料而不是使用者資料。筆記:
global_data
為false
,則需要在GameJolt
單例上設定使用者名稱和令牌。 從資料儲存返回資料。發出data_store_fetch_completed
。
key: String
-> 您要取得的資料項的鍵。global_data: bool
(可選) -> 如果設定為true
,則忽略GameJolt
中設定的使用者名稱和令牌並處理全域資料而不是使用者資料。筆記:
global_data
為false
,則需要在GameJolt
單例上設定使用者名稱和令牌。 傳回遊戲全域資料儲存中的所有金鑰,或使用者資料儲存中的所有金鑰。發出data_store_get_keys_completed
。
pattern: String
(可選)->套用於資料儲存中的鍵名稱的模式。global_data: bool
(可選) -> 如果設定為true
,則忽略GameJolt
中設定的使用者名稱和令牌並處理全域資料而不是使用者資料。筆記:
"*"
。"key"
值的清單。 "key"
回傳值可以出現多次。global_data
為false
,則需要在GameJolt
單例上設定使用者名稱和令牌。傳回使用者的好友清單。發出friends_completed
。
注意:需要在GameJolt
單例上設定使用者名稱和令牌。
返回 Game Jolt 伺服器的時間。發出time_completed
。
批次請求是子請求的集合,使開發人員能夠透過一個 HTTP 請求發送多個 API 呼叫。要在程式碼中使用批次調用,請將請求調用放在batch_begin
和batch_end
之間。例如,按以下順序使用您的方法:
func _onButtonBatch_pressed () -> void :
# Begin to gather batch requests
GameJolt . batch_begin ()
# Add the time request to the batch
GameJolt . time ()
# Add the scores_tables request to the batch
GameJolt . scores_tables ()
# Stop gathering batch requests
GameJolt . batch_end ()
# Perform the batch call with the two requests above (time and score_tables)
GameJolt . batch ()
var result : Dictionary = await GameJolt . batch_completed
使用batch_begin
和batch_end
收集請求後執行批次請求。發出batch_completed
。
parallel: bool
(可選) -> 預設情況下,每個子請求都會在伺服器上順序處理。如果將此設為true
,則同時處理所有子請求,而無需等待上一個子請求完成後才開始下一個子請求。break_on_error: bool
(可選) -> 如果設定為true
,則一個子請求失敗將導致整個批次停止處理後續子請求,並傳回false
值表示成功。筆記:
parallel
和break_on_error
參數是互斥的,不能在同一請求中使用。 開始收集大量請求。此呼叫後方法將不會回傳回應。呼叫batch_end
完成批次請求收集過程。
停止收集批次請求。方法將在此呼叫後再次回傳回應。必須在batch_begin
之後使用。