Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Presence: ZombsRoyale.io #3786

Merged
merged 6 commits into from
May 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions websites/Z/ZombsRoyale.io/dist/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"$schema": "https://schemas.premid.app/metadata/1.0",
"author": {
"name": "MrBartusek",
"id": "212988300137463809"
},
"service": "ZombsRoyale.io",
"description": {
"en": "100 Player 2D Real-Time Battle Royale game inspired by PUBG and Fortnite"
},
"url": "zombsroyale.io",
"version": "1.0.0",
"logo": "https://i.imgur.com/KPoJ18U.png",
"thumbnail": "https://i.imgur.com/WPQqHRU.png",
"color": "#45bd4c",
"tags": [
"battle-royale",
"games",
"action"
],
"category": "games"
}
125 changes: 125 additions & 0 deletions websites/Z/ZombsRoyale.io/presence.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
const presence = new Presence({
clientId: "845354103118364672"
});

let matchStart: number = null;

presence.on("UpdateData", async () => {
const presenceData: PresenceData = {
largeImageKey: "logo"
},
currentGameState = await getPageletiable("game.currentGameState");

if (currentGameState === "loading" || currentGameState === "UiLoadingOverlay")
presenceData.details = "Loading...";
else if (currentGameState === "MainMenu")
presenceData.details = "Lurking in main menu";
else if (
currentGameState === "Cosmetics" ||
currentGameState === "UiCosmeticSelectorOverlay"
)
presenceData.details = "Viewing cosmetics";
else if (currentGameState === "Profile")
presenceData.details = "Viewing their profile";
else if (
currentGameState === "Shop" ||
currentGameState === "UiPreviewPackOverlay"
)
presenceData.details = "Browsing Shop";
else if (
currentGameState === "Friends" ||
currentGameState === "UiFriendAddOverlay"
)
presenceData.details = "Viewing their friends";
else if (currentGameState === "Leaderboards")
presenceData.details = "Browsing leaderboards";
else if (currentGameState === "UiLoginOverlay")
presenceData.details = "Loging in";
else if (currentGameState === "UiSettingsOverlay")
presenceData.details = "Changing settings";
else if (currentGameState === "UiSeasonPurchaseOverlay")
presenceData.details = "Buying a Battle Pass";
else if (
currentGameState.startsWith("UiSeason") ||
currentGameState === "UiPreviewItemOverlay"
)
presenceData.details = "Viewing Battle Pass";
else if (currentGameState === "UiChallengesOverlay")
presenceData.details = "Viewing challenges";
else if (currentGameState === "UiBuyGemsOverlay")
presenceData.details = "Buying gems";
else if (currentGameState === "VideoAd")
presenceData.details = "Watching video ad";
else if (currentGameState === "Countdown" || currentGameState === "Lobby") {
presenceData.details = "In Lobby";
presenceData.state = "Waiting for game to start";
} else if (
currentGameState === "Game" ||
currentGameState === "UiReportPlayerOverlay" ||
currentGameState === "UiLeaveOverlay"
) {
presenceData.details = "In Game";
} else if (currentGameState === "Plane") {
presenceData.details = "In Game";
presenceData.state = "Flying plane";
} else if (currentGameState === "Parachute") {
presenceData.details = "In Game";
presenceData.state = "Parachuting";
} else if (
currentGameState === "Dead" ||
currentGameState === "UiGameOver" ||
currentGameState === "UiSpectator" ||
currentGameState === "UiFeedbackOverlay"
) {
presenceData.details = "In Game";
presenceData.state = "Dead";
} else if (currentGameState === "UiMapOverlay") {
presenceData.details = "In Game";
presenceData.state = "Viewing map";
} else presence.error("Unknown state: " + currentGameState);

const playing =
presenceData.details === "In Game" || presenceData.details === "In Lobby";

if (playing && matchStart === null) {
matchStart = Math.floor(Date.now() / 1000);
} else if (!playing && matchStart !== null) {
matchStart = null;
}

presenceData.startTimestamp = matchStart;

if (presenceData.details === null) {
presence.setTrayTitle();
presence.setActivity();
} else {
presence.setActivity(presenceData);
}
});

// Stolen from https://github.com/PreMiD/Presences/blob/master/websites/R/Rythm/presence.ts#L461
function getPageletiable(js: string): Promise<string> {
const eventName = "PreMiD_ZombsRoyale_Pageletiable";

return new Promise<string>((resolve) => {
const script = document.createElement("script"),
_listener = (data: CustomEvent) => {
script.remove();
resolve(JSON.parse(data.detail));
window.removeEventListener(eventName, _listener, true);
};

window.addEventListener(eventName, _listener);
script.id = eventName;
script.appendChild(
document.createTextNode(`
var pmdPL = new CustomEvent("${eventName}", {detail: JSON.stringify(${js})});
window.dispatchEvent(pmdPL);
`)
);

(document.body || document.head || document.documentElement).appendChild(
script
);
});
}
6 changes: 6 additions & 0 deletions websites/Z/ZombsRoyale.io/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"outDir": "./dist/"
}
}