Yandex Games
Release-1.1
개선을 위한 아이디어가 있으시면 텔레그램/이슈/풀로 메일을 보내주시면 모두 읽어보겠습니다.
내 전보 @Alexey_Pe
이 애드온을 사용한 게임: 매치 3 퍼즐, 게임에 saving/loading
, rewarded/fullscreen advertising
, purchases
, call for feedback
있습니다.
폴더 addons/YandexGamesSDK/Demo의 데모
주석이 포함된 간단한 코드가 포함되어 있습니다.
이 애드온은 많은 개발자들이 사용하고 있습니다. 마음에 들지 않는 분들을 추가했습니다. (추가하려면 저에게 편지를 보내주세요)
No | 개발자 | 플레이어 |
---|---|---|
1 | RA 게임 | 1 500 000 + |
2 | 마지켈레 스튜디오 Yandex | 1000+ |
3 | 레가툼 스튜디오 | 1000+ |
initGame()
, getPlayer(false)
, getPayments()
, getLeaderboards()
를 호출합니다. < script src = "https://yandex.ru/games/sdk/v2" > < / script >
< script >
function get_url ( js , size ) {
return js ( size ) ;
}
< / script>
중요한
게임이 플레이어에게 표시될 준비가 되면 YandexGames.ready()
호출합니다. 예를 들어 저장 getData()
로드한 후 이 함수를 호출할 수 있습니다.
func on_initGame ():
# Here you can download the player's data, and then confirm that the game is ready to be shown
YandexGames . ready () # inform Yandex that the player has uploaded
func _ready ():
YandexGames . connect ( "on_initGame" , self , "on_initGame" ) # Connect to the sdk initialization signal
if YandexGames . is_initGame : on_initGame () # If for some reason you connected after initialization
# Interstitial Ads, signal on_showFullscreenAdv(wasShown:bool, ad_name:String)
# ad_name - this argument is not passed to yandex. I added it for signal and match
if YandexGames . current_fullscreen_ad_name == "" :
YandexGames . showFullscreenAdv ( "ad_name" )
YandexGames . connect ( "on_showFullscreenAdv" , self , "on_showFullscreenAdv" )
# example use signal
func on_showFullscreenAdv ( success : bool , ad_name : String ):
match ad_name :
"advertising after loading the game" :
# your some code when the player closed this ad
if success : pass
else : pass
# Rewarded Ads, signal on_showRewardedVideo(success:bool, current_rewarded_ad_name:String)
# ad_name - this argument is not passed to yandex. I added it for signal and match
if YandexGames . current_rewarded_ad_name == "" :
YandexGames . showRewardedVideo ( ad_name )
YandexGames . connect ( "on_showRewardedVideo" , self , "on_showRewardedVideo" )
# example use signal
func on_showRewardedVideo ( success : bool , ad_name : String ):
match ad_name :
"open chest for advertising" :
# your some code when the player closed this ad
if success : pass
else : pass
# setData(data:Dictionary) to save data on yandex, no signal
YandexGames . setData ( data )
# getData() and getData_yield()->Dictionary, signal on_getData(data:Dictionary)
var load_save : Dictionary = yield ( YandexGames . getData_yield (), "completed" )
# choose the use case that you like best
getData ()
YandexGames . connect ( "on_getData" , self , "on_getData" )
# Create DataManager.gd signleton
var can_load_data : bool = false
func _ready ():
YandexGames . connect ( "on_getPlayer" , self , "on_getPlayer" )
func on_getPlayer ( player ):
can_load_data = true
loadData ()
# Example call: a player has entered the game and does not have data, you need to get the data
# loadData is a yield function, when you call it you want to write it like this: yield(DataManager.loadData_yield(self), "completed")
# Why do you need to write yield: this means that you stop executing the code until the Yandex server sends you the data
func loadData_yield ( from : Object ):
if YandexGames . js_ysdk_player == null : print ( "DataManager.gd loadData(from: %s ) js_ysdk_player == null" % [ from ]); return
if can_load_data : print ( "DataManager.gd loadData(from: %s )" % [ from ]); return
else : print ( "DataManager.gd loadData(from: %s ) !can_load_data" % [ from ])
var load_save : Dictionary = yield ( YandexGames . getData_yield (), "completed" )
if load_save . empty (): pass # player logged in for the first time / there were no saves
# here you use the downloaded data from load_save
pass
# Example call: a player upgraded an item by spending currency, you want to save it
func saveData ( from : Object ):
print ( "DataManager.gd saveData(from: %s )" % [ from ])
if YandexGames . js_ysdk_player == null : print ( "DataManager.gd saveData(from: %s ) js_ysdk_player == null" % [ from ]); return
# setData - overwrites a variable on the yandex server
# Create a dictionary in which you write down all the data that you need to save
# The dictionary will be converted to json, check that your data does not contain classes, you need to convert classes into data that can be stored in json
var data : Dictionary = { "gold" : 100 , "inventory" : "your_value" , "etc" : 123 }
YandexGames . setData ( data )
pass
# example 1
var flags = yield ( YandexGames . getFlags_yield (), "completed" )
if flags is Dictionary : pass # you code here
# example 2
var flags = yield ( YandexGames . getFlags_yield ([
{ "name" : "var_1" , "value" : "20" },
{ "name" : "var_2" , "value" : "33" },
]), "completed" )
if flags is Dictionary : pass # you code here
# getFlags_yield() uses the on_getFlags signal
YandexGames . connect ( "on_getFlags" , self , "on_getFlags" )
func on_getFlags ( response ):
if response is Dictionary : pass # flags
else : pass # js error (the error will be printed in the browser console)
on_purchase_then()
호출하므로 이 점을 명심하세요. 비디오 1 및 비디오 2에 대한 링크(버그)on_purchase_then()
문제를 해결하는 방법 - 게임을 시작할 때 getPurchases()
사용해야 합니다. # In-game purchase, signals on_purchase_then(), on_purchase_catch()
YandexGames . purchase ( "id" )
YandexGames . connect ( "on_purchase_then" , self , "on_purchase_then" )
YandexGames . connect ( "on_purchase_catch" , self , "on_purchase_catch" )
# example use signals
func on_purchase_then ( purchase : YandexGames . Purchase ):
match purchase . product_id :
"id which you specified in the console" :
# your code
# purchase.consume() - delete a purchase from the getPurchases array
# In short, when a player buys, he must close the window to call on_purchase_then
# Moderators make a purchase without closing the window and refresh the page, which is why on_purchase_then is not called
purchase . consume ()
func on_purchase_then ( product_id : String ):
match product_id :
"1" : pass
# Getting the purchases array [YandexGames.Purchase], signals on_getPurchases()
# The array contains only those Purchases for which consume() was not called
YandexGames . getPurchases ()
YandexGames . connect ( "on_getPurchases" , self , "on_getPurchases" )
# example use signals
# purchases = Array [YandexGames.Purchase] or null
func on_getPurchases ( purchases ):
if purchases == null : pass # your variant
for purchase in purchases :
match purchase . product_id :
"id which you specified in the console" :
# your code
# check the comment on_purchase_then()
purchase . consume ()
# YandexGames.gd
class Purchase :
# product_id from Yandex Console (You specify it yourself)
var product_id : String
var _js_purchase : JavaScriptObject
func _init ( __js_purchase : JavaScriptObject ):
product_id = __js_purchase . productID
_js_purchase = __js_purchase
# consume() for to remove from array YandexGames.getPurchases() (on the Yandex side)
func consume ():
YandexGames . js_ysdk_payments . consumePurchase ( _js_purchase . purchaseToken )
리더보드의 경우 초안에 생성된 리더보드(또는 여러 개)가 있어야 합니다.
설정에서 기본 순위표를 선택할 수도 있습니다(응답에서 'default'(bool)).
리더보드 문서 링크
# setLeaderboardScore(Leaderboard_name:String, score:int)
YandexGames . setLeaderboardScore ( "Leaderboard_name" , 1000 )
# getLeaderboardDescription(leaderboardName:String), signal on_getLeaderboardDescription(description:Dictionary)
# description:{appID:String, default:bool, invert_sort_order:bool, decimal_offset:int, type:String, name:String, title:{en:String, ru:String ..}}
YandexGames . getLeaderboardDescription ( "Leaderboard_name" )
# getLeaderboardPlayerEntry(leaderboardName:String)
# signals on_getLeaderboardPlayerEntry_then(response:Dictionary), on_getLeaderboardPlayerEntry_catch(err_code:String)
# response { score:int, extraData:String, rank:int, getAvatarSrc:JavaScriptObject, getAvatarSrcSet:JavaScriptObject, lang:String, publicName:String, uniqueID:String, scopePermissions_avatar:String, scopePermissions_public_name:String, formattedScore:String}
# response, getAvatarSrc and getAvatarSrcSet - is JavaScriptObject(Function maybe?) return String. I didn't understand how to use it
YandexGames . getLeaderboardPlayerEntry ( "Leaderboard_name" )
YandexGames . connect ( "on_getLeaderboardPlayerEntry_then" , self , "on_getLeaderboardPlayerEntry_then" )
YandexGames . connect ( "on_getLeaderboardPlayerEntry_catch" , self , "on_getLeaderboardPlayerEntry_catch" )
# getLeaderboardEntries(leaderboardName:String), signal on_getLeaderboardEntries(response:Dictionary)
# response { leaderboard:Dictionary, userRank:int, entries:Array}
# leaderboard - getLeaderboardDescription response
# entries - top 20 and 10-20(up/down) players around the player who requested. entries element - getLeaderboardPlayerEntry response
YandexGames . getLeaderboardEntries ( "Leaderboard_name" )
YandexGames . connect ( "on_getLeaderboardEntries" , self , "on_getLeaderboardEntries" )
# example use
func on_getLeaderboardEntries ( response : Dictionary ):
match response [ "leaderboard" ][ "name" ]:
"best_score" : pass
"best_speed" : pass
"aaa" : pass
# canReview() and on_canReview_yield()->bool, signal on_canReview(can_review:bool)
var can_review = yield ( YandexGames . on_canReview_yield (), "completed" )
# choose the use case that you like best
YandexGames . canReview ()
YandexGames . connect ( "on_canReview" , self , "on_canReview" )
# requestReview() automatically calls canReview(), signal on_requestReview(requestReview:bool)
YandexGames . requestReview ()
YandexGames . connect ( "on_requestReview" , self , "on_requestReview" )
# canShowPrompt() and canShowPrompt_yield()->bool, signal on_canShowPrompt(canShowPrompt:bool)
var can_show_prompt = yield ( YandexGames . canShowPrompt_yield (), "completed" )
# choose the use case that you like best
YandexGames . canShowPrompt ()
YandexGames . connect ( "on_canShowPrompt" , self , "on_canShowPrompt" )
# showPrompt() automatically calls canShowPrompt(), signal on_showPrompt(accepted:bool)
YandexGames . on_showPrompt ()
YandexGames . connect ( "on_showPrompt" , self , "on_showPrompt" )
# getLang() -> String (ru/en/tr/...)
YandexGames . getLang ()
# Notifies Yandex that the game is ready
YandexGames . ready ()
# Device Info
match YandexGames . js_ysdk . deviceInfo [ "_type" ]:
"desktop" : pass
"mobile" : pass
"tablet" : pass
"tv" : pass