远程配置
请使用 Yandex Games SDK 中的 getFlags() 方法来获取远程配置标志(Remote Config)。我们建议在游戏启动时请求一次标志。
要获取保存的标志值,请使用 getFlags() 方法。
使用 await 的方案
不使用 await 的方案
const ysdk = await YaGames.init(); // 初始化 SDK。
const flags = await ysdk.getFlags(); // 该方法返回一个包含标志的对象。
// 在游戏逻辑中可以添加条件:
if (flags.difficult === 'hard') {
    // 启用高难度。
}
YaGames.init()
    .then(ysdk => ysdk.getFlags())
    .then(flags => {
        // flags 包含一个包含标志的对象。
        // 在游戏逻辑中可以添加条件:
        if (flags.difficult === 'hard') {
            // 启用高难度。
        }
    });
本地配置
我们建议总是将本地标志配置硬编码到游戏代码中,以防万一(例如,由于地铁内的网络问题)无法从服务器获取远程配置。这提升了游戏的可靠性。
为此,getFlags() 方法支持额外的参数。需要在 defaultFlags 字段中传递本地配置(一个平面对象,值为字符串)。
结果对象是远程和本地配置的合并,优先级为远程配置。
YaGames.init()
    .then(ysdk => ysdk.getFlags({ defaultFlags: { difficult: 'easy' } }))
    .then(flags => {
        // flags 包含对象 { difficult: 'easy' }
    });
客户端参数
如果您的游戏存储了有关玩家的状态,例如,他们是否至少使用过一次游戏内货币,通过了多少关卡,是否可以将用户视为核心玩家,那么这些事实可以用于远程配置。了解如何根据条件设置标志的更多信息,请查看 步骤1. 创建标志配置 部分。
客户端参数需要以数组形式通过 getFlags() 方法的 clientFeatures 字段传递。
使用 await 的例子
const ysdk = await YaGames.init(); // 初始化 SDK。
const player = await ysdk.getPlayer(); // 获取玩家信息。
const payingStatus = player.getPayingStatus(); // 获取用户在平台上的付费活跃状态。
// 请求包含用户付费活跃状态的客户端参数的标志。
const flags = await ysdk.getFlags({
    clientFeatures: [
        {name: 'payingStatus', value: payingStatus}
    ]
});
不使用 await 的例子
// 发送客户端参数 levels=5。
YaGames.init()
    .then(ysdk => ysdk.getFlags({
        defaultFlags: {},
        clientFeatures: [
            { name: 'levels', value: '5' }
        ]})
    )
    .then(flags => {
        // 客户端参数条件未触发。
        // flags.showFullscreenAdOnStart === 'no'
    });
// 发送客户端参数 levels=10。
YaGames.init()
    .then(ysdk => ysdk.getFlags({
        defaultFlags: {},
        clientFeatures: [
            { name: 'levels', value: '10' }
        ]})
    )
    .then(flags => {
        // 客户端参数条件触发了,启动时显示广告。
        // flags.showFullscreenAdOnStart === 'yes'
    });
// 带有两个客户端参数的示例:
YaGames.init()
    .then(ysdk => ysdk.getFlags({
        defaultFlags: {},
        clientFeatures: [
            { name: 'levels', value: '10' },
            { name: 'inAppPurchaseUsed', value: 'yes' }
        ]})
    )
    .then(flags => {
    });
getFlags()方法的签名和接口
    interface IFlags {
    [key: string]: string;
}
interface ClientFeature {
    name: string;
    value: string;
}
interface IGetFlagsParams {
    defaultFlags?: IFlags;
    clientFeatures?: ClientFeature[];
}
function getFlags(getFlagsParams: IGetFlagsParams = {}): IFlags {}
备注
技术支持团队将协助您将已完成的游戏发布到 Yandex 游戏平台。关于开发和测试方面的具体问题,其他开发人员将在Discord 频道中进行回答。
如果您遇到 Yandex Games SDK 方面的问题或有其他问题想要咨询,请联系支持部门: