iOS向けサービス¶
現時点では、GameCenterとStorekitの2つのiOS APIが部分的に実装されています。両方とも、以下で説明する非同期呼び出しの同じモデルを使用します。
非同期メソッド¶
非同期操作を要求する場合、メソッドは次のようになります:
Error purchase(Variant p_params);
通常、パラメーターは、要求を行うのに必要な情報を含むDictionaryであり、呼び出しには2つのフェーズがあります。 まず、メソッドはすぐにエラー値を返します。 エラーが OK
でない場合、コール操作は終了しますが、おそらく、ローカルで発生したエラー(インターネット接続がない、APIが正しく構成されていないなど)です。 エラー値が OK
の場合、応答イベントが生成され、'pending events' キューに追加されます。 例:
func on_purchase_pressed():
var result = InAppStore.purchase( { "product_id": "my_product" } )
if result == OK:
animation.play("busy") # show the "waiting for response" animation
else:
show_error()
# put this on a 1 second timer or something
func check_events():
while InAppStore.get_pending_event_count() > 0:
var event = InAppStore.pop_pending_event()
if event.type == "purchase":
if event.result == "ok":
show_success(event.product_id)
else:
show_error()
呼び出しがOKを返すと、エラーやネットワークタイムアウトなどであっても、APIは 常に pending_eventインターフェースを介してイベントを生成することに注意してください。 たとえば、サーバーからの応答を待っているインターフェイスを安全にブロックできる必要があります。 APIのいずれかがこのように動作しない場合は、バグとして扱う必要があります。
保留中のイベント(pending event)インターフェイスは、2つのメソッドで構成されています:
get_pending_event_count()
キュー上の保留中のイベントの数を返します。Variant pop_pending_event()
キューから最初のイベントをポップし、それを返します。
Store Kit¶
platform/iphone/in_app_store.mm
に実装されています。
Store Kit APIは "InAppStore" シングルトンからアクセスできます(常にgdscriptから利用可能です)。自動的に初期化されます。 購入には3つの方法があります:
Error purchase(Variant p_params);
Error request_product_info(Variant p_params);
Error restore_purchases();
およびpending_eventインターフェース
int get_pending_event_count();
Variant pop_pending_event();
購入¶
Store Kit APIを介して製品IDを購入します。
Parameters¶
製品IDを含む文字列である product_id
という1つのフィールドを持つ Dictionary をパラメーターとして受け取ります。例:
var result = InAppStore.purchase( { "product_id": "my_product" } )
応答イベント¶
応答イベントは、次のフィールドを持つ Dictionary になります:
エラー時:
{
"type": "purchase",
"result": "error",
"product_id": "the product id requested"
}
成功時:
{
"type": "purchase",
"result": "ok",
"product_id": "the product id requested"
}
request_product_info¶
製品IDのリストで製品情報を要求します。
Parameters¶
製品IDを含む文字列配列である product_ids
という1つのフィールドを持つ Dictionary をパラメーターとして受け取ります。例:
var result = InAppStore.request_product_info( { "product_ids": ["my_product1", "my_product2"] } )
応答イベント¶
応答イベントは、次のフィールドを持つ Dictionary になります:
{
"type": "product_info",
"result": "ok",
"invalid_ids": [ list of requested ids that were invalid ],
"ids": [ list of ids that were valid ],
"titles": [ list of valid product titles (corresponds with list of valid ids) ],
"descriptions": [ list of valid product descriptions ] ,
"prices": [ list of valid product prices ],
"localized_prices": [ list of valid product localized prices ],
}
Game Center¶
platform/iphone/game_center.mm
に実装されています。
The Game Center API is available through the "GameCenter" singleton. It has 9 methods:
Error authenticate();
bool is_authenticated();
Error post_score(Variant p_score);
Error award_achievement(Variant p_params);
void reset_achievements();
void request_achievements();
void request_achievement_descriptions();
Error show_game_center(Variant p_params);
Error request_identity_verification_signature();
さらに、標準の pending event インターフェイス。
authenticate¶
Authenticates a user in Game Center.
応答イベント¶
応答イベントは、次のフィールドを持つ Dictionary になります:
エラー時:
{
"type": "authentication",
"result": "error",
"error_code": the value from NSError::code,
"error_description": the value from NSError::localizedDescription,
}
成功時:
{
"type": "authentication",
"result": "ok",
"player_id": the value from GKLocalPlayer::playerID,
}
post_score¶
Game Centerリーダーボードにスコアを投稿します。
Parameters¶
次の2つのフィールドを使用した、Dictionaryをパラメーターとして受け取ります。
score
浮動小数点数category
カテゴリー名の文字列
例:
var result = GameCenter.post_score( { "score": 100, "category": "my_leaderboard", } )
応答イベント¶
応答イベントは、次のフィールドを持つ Dictionary になります:
エラー時:
{
"type": "post_score",
"result": "error",
"error_code": the value from NSError::code,
"error_description": the value from NSError::localizedDescription,
}
成功時:
{
"type": "post_score",
"result": "ok",
}
award_achievement¶
Game Centerアチーブメント(実績)の進捗を変更します。
Parameters¶
3つのフィールドを持つ Dictionary をパラメーターとして受け取ります:
name
(string) 実績名progress
(float) 0.0から100.0への達成の進捗(``GKAchievement::percentComplete``に渡されます)show_completion_banner
(bool) Game Centerが画面の上部に実績バナーを表示するかどうか
例:
var result = award_achievement( { "name": "hard_mode_completed", "progress": 6.1 } )
応答イベント¶
応答イベントは、次のフィールドを持つ Dictionary になります:
エラー時:
{
"type": "award_achievement",
"result": "error",
"error_code": the error code taken from NSError::code,
}
成功時:
{
"type": "award_achievement",
"result": "ok",
}
reset_achievements¶
Game Centerのすべての実績をクリアします。 この関数はパラメーターを受け取りません。
応答イベント¶
応答イベントは、次のフィールドを持つ Dictionary になります:
エラー時:
{
"type": "reset_achievements",
"result": "error",
"error_code": the value from NSError::code
}
成功時:
{
"type": "reset_achievements",
"result": "ok",
}
request_achievements¶
プレイヤーが進捗したGame Centerのすべての実績を要求します。この関数はパラメーターを受け取りません。
応答イベント¶
応答イベントは、次のフィールドを持つ Dictionary になります:
エラー時:
{
"type": "achievements",
"result": "error",
"error_code": the value from NSError::code
}
成功時:
{
"type": "achievements",
"result": "ok",
"names": [ list of the name of each achievement ],
"progress": [ list of the progress made on each achievement ]
}
request_achievement_descriptions¶
進行状況に関係なく、既存のすべてのGame Centerの実績の説明を要求します。この関数はパラメーターを受け取りません。
応答イベント¶
応答イベントは、次のフィールドを持つ Dictionary になります:
エラー時:
{
"type": "achievement_descriptions",
"result": "error",
"error_code": the value from NSError::code
}
成功時:
{
"type": "achievement_descriptions",
"result": "ok",
"names": [ list of the name of each achievement ],
"titles": [ list of the title of each achievement ]
"unachieved_descriptions": [ list of the description of each achievement when it is unachieved ]
"achieved_descriptions": [ list of the description of each achievement when it is achieved ]
"maximum_points": [ list of the points earned by completing each achievement ]
"hidden": [ list of booleans indicating whether each achievement is initially visible ]
"replayable": [ list of booleans indicating whether each achievement can be earned more than once ]
}
show_game_center¶
組み込みのGame Centerオーバーレイを表示し、リーダーボード、実績、課題を示します。
Parameters¶
次の2つのフィールドを使用した、Dictionaryをパラメーターとして受け取ります。
view
(string) (オプション) 表示するビューの名前。"default"、"leaderboards"、 "achievements"、または "challenges" を受け入れます。 デフォルトは "default" です。leaderboard_name
(string) (オプション) 提示するリーダーボードの名前。"view" が "leaderboards" (または "default" がリーダーボードを表示するように設定されている)の場合にのみ使用されます。指定しない場合、Game Centerは集計リーダーボードを表示します。
例:
var result = show_game_center( { "view": "leaderboards", "leaderboard_name": "best_time_leaderboard" } )
var result = show_game_center( { "view": "achievements" } )
マルチプラットフォームゲーム¶
マルチプラットフォームゲームで作業する場合、"GameCenter"シングルトンを常に使用できるとは限りません(たとえば、PCまたはAndroidで実行している場合)。 gdscriptコンパイラはコンパイル時にシングルトンを検索するため、シングルトンにクエリを実行して条件ブロック内で必要なものを確認して使用することはできません。また、シングルトンを有効な識別子(ローカル変数またはクラスメンバー)として定義する必要があります。これは、クラスでこれを回避する方法の例です:
var GameCenter = null # define it as a class member
func post_score(p_score):
if GameCenter == null:
return
GameCenter.post_score( { "value": p_score, "category": "my_leaderboard" } )
func check_events():
while GameCenter.get_pending_event_count() > 0:
# do something with events here
pass
func _ready():
# check if the singleton exists
if Globals.has_singleton("GameCenter"):
GameCenter = Globals.get_singleton("GameCenter")
# connect your timer here to the "check_events" function