← 返回开发者中心Back to Developer Docs
v1.1

开发者 SDKDeveloper SDK

引入一个脚本,调用几个函数,你的游戏即可接入平台排行榜、评分、成绩分享与游戏跳转。无需后端、无需密钥。Add one script, call a few functions, and your game gains leaderboards, ratings, score sharing and game navigation. No backend, no API key.

🚀 快速开始Quick start

在你的游戏页面里加入下面这一行,就可以调用全部能力:Add this one line to your game page to use all capabilities:

<script src="https://game.leleleling.site/lelele-sdk.js"></script>

结算时上报分数:Report a score when a round ends:

window.LeleleSDK.submitScore(1234, { name: '小明' });

📚 API 参考API reference

submitScore(score, options?) boolean

上报分数到本游戏的全服榜。可选昵称,未填写时平台自动生成。Submit a score to this game's global leaderboard. Nickname is optional; one is generated if omitted.

参数Params: score 非负数字non-negative number; options.name 可选昵称optional nickname

submitRating(rating) boolean

上报玩家对游戏的评分,范围为 0.5 到 5。Submit a player rating for the game, from 0.5 to 5.

参数Params: rating 0.5–5

getLeaderboard() Promise<Array>

读取本游戏全服榜前十,返回 [{ name, score }]。可用于在你的游戏里自绘榜单。Read this game's global top 10 as [{ name, score }], so you can draw your own leaderboard.

LeleleSDK.getLeaderboard().then(rows => {
  rows.forEach((r, i) => console.log(i + 1, r.name, r.score));
});
getPlayerName() Promise<string|null>

获取当前玩家昵称,可用于游戏内问候语。未取得时返回 null。Get the current player's nickname for in-game greeting. Returns null if unavailable.

isInPlatform() boolean

判断游戏是否正在平台播放器内运行。可用它让同一份游戏代码在平台内外表现不同。Check whether the game is running inside the platform player, so one codebase can behave differently inside and outside.

nextGame(options?) boolean

玩完一局后调用,带玩家去玩一款相似游戏。可传 category 限定分类。Call after a round ends to take the player to a similar game. Pass category to limit the genre.

LeleleSDK.nextGame();
LeleleSDK.nextGame({ category: '射击' });
shareScore(score, text?) Promise<string|null>

生成一条平台格式的成绩分享链接,可直接复制或发给好友。可选自定义文案。无上下文时返回 null。Generate a platform-formatted score share link to copy or send to friends. Optional custom text. Returns null without context.

LeleleSDK.shareScore(1234).then(url => {
  if (url) console.log('分享链接:', url);
});
openDetail() boolean

从游戏内打开本游戏的详情页,查看简介与更新日志。Open this game's detail page from inside the game for its description and update log.

▶️ 运行环境Runtime

SDK 仅在平台播放器内打开你的游戏时生效;单独打开你的游戏页调用任何函数都不会报错,但不会上报或跳转。依赖上下文的函数返回 Promise,取不到时解析为 null 或空数组。 The SDK only takes effect when your game runs inside the platform player. Calling any function on a standalone game page is safe and silent. Context-dependent functions return a Promise that resolves to null or an empty array when unavailable.

❓ 常见问题FAQ

需要后端或 API 密钥吗?Do I need a backend or API key?

不需要。引入脚本后直接调用函数即可。No. Just add the script and call the functions.

玩家昵称从哪来?Where does the player nickname come from?

登录玩家使用其显示名;未登录时平台生成一个本地随机昵称。Signed-in players use their display name; others get a local random nickname.

成绩提交后还能修改吗?Can a submitted score be changed?

提交后不可由开发者修改。如需更正,请让玩家重新提交。Developers cannot edit a submitted score. Ask the player to resubmit instead.

榜单是实时的吗?Is the leaderboard live?

是的,提交成绩后刷新榜单即可看到更新。Yes. Refresh the leaderboard after a score is submitted to see updates.