Community levels (UGC)
A generic level-upload system under DavidnetSDK.ugc . Level data is an opaque JSON blob — the platform never looks inside it, so it works for any level/map/track
format your game defines. Levels are public once published: any player can list and download them,
same trust model as the rest of your sandboxed game (your game decides what to publish and how to
interpret what it downloads).
DavidnetSDK.ugc.publishLevel({ id?, title, data })
Publishes a new level, or — if you pass the id of a level you own — overwrites it in place (e.g. after the player edits it further). title is required (up to 100 chars); data is your opaque level payload. Resolves to: { id, title, createdAt, updatedAt }
// Publish a brand new level.
async function publishMyLevel(levelData) {
try {
const { id } = await window.DavidnetSDK.ugc.publishLevel({
title: "Lava Castle",
data: levelData // any JSON-serializable shape your game defines
});
showMessage("Level published!");
return id; // save this if you want to let the player edit it later
} catch (e) {
console.warn("Could not publish level", e);
}
}
// Overwrite a level the player already published, e.g. after they edit it.
async function updateMyLevel(levelId, newLevelData) {
await window.DavidnetSDK.ugc.publishLevel({
id: levelId,
title: "Lava Castle (remastered)",
data: newLevelData
});
}DavidnetSDK.ugc.listLevels(options?)
Lists published levels for this game, newest first. Pass { mine: true } to list only your own, { limit, offset } to page through them ( limit defaults to 20, max 50). Does NOT include the level data itself — call getLevel once the player picks one. Resolves to: { levels: [{ id, title, creator, creatorDisplayName, createdAt, updatedAt }, ...], hasMore
}
// A "browse community levels" screen with pagination.
let offset = 0;
const PAGE_SIZE = 20;
async function loadNextPage() {
const { levels, hasMore } = await window.DavidnetSDK.ugc.listLevels({
limit: PAGE_SIZE,
offset
});
renderLevelBrowser(levels); // each entry has { id, title, creator, ... } - no "data" yet
offset += levels.length;
showLoadMoreButton(hasMore);
}
// "My levels" screen.
async function showMyLevels() {
const { levels } = await window.DavidnetSDK.ugc.listLevels({ mine: true });
renderMyLevelsList(levels);
}DavidnetSDK.ugc.getLevel(id)
Fetches one level's full data, including its creator info. Resolves to: { id, title, data, creator, creatorDisplayName, createdAt, updatedAt }
async function playLevel(levelId) {
const { title, data, creatorDisplayName } = await window.DavidnetSDK.ugc.getLevel(levelId);
showLoadingScreen("Loading \"" + title + "\" by " + creatorDisplayName);
loadLevel(data); // your game's own format, whatever you passed to publishLevel
}DavidnetSDK.ugc.deleteLevel(id)
Deletes a level you published (or any level, if you're the game's creator). Resolves to: { id }
async function deleteMyLevel(levelId) {
try {
await window.DavidnetSDK.ugc.deleteLevel(levelId);
removeLevelFromMyList(levelId);
} catch (e) {
console.warn("Could not delete level", e);
}
}