Skip to content

Commit

Permalink
Merge pull request PreMiD#3069 from Snazzah/update/bonk-io/1
Browse files Browse the repository at this point in the history
Rename and rewrite Bonk.io (formerly Bonk2.io)
  • Loading branch information
mergify[bot] authored Feb 21, 2021
2 parents 56a3677 + b367e02 commit 004c637
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 150 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
"name": "Snazzah",
"id": "158049329150427136"
},
"url": "bonk2.io",
"url": "bonk.io",
"description": {
"en": "A multiplayer browser game where the objective is to knock all of the opponents off the edge of the screen and be the last man standing."
},
"service": "Bonk2.io",
"version": "1.0.2",
"service": "Bonk.io",
"version": "1.1.0",
"logo": "https://i.imgur.com/rGFRJec.png",
"thumbnail": "https://i.imgur.com/i67aXvn.png",
"color": "#151f29",
Expand Down
67 changes: 67 additions & 0 deletions websites/B/Bonk.io/iframe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
const iframe = new iFrame(),
menuIDs = [
// Login/Guest
"guestOrAccountContainer",
"guestContainer",
"accountContainer",
"autoLoginContainer",

// Lobby
"newbonklobby",
"mapeditorcontainer",

// MainMenu
"classic_mid",
"friendsContainer",
"skinmanager",
"skineditorcontainer",
"quickPlayWindow",
"roomListContainer",

// Game Canvas
"sm_connectingContainer",
"gamerenderer"
],
selector = menuIDs
.map(
(id) =>
"#" +
id +
'[style*="visibility: inherit"]' +
"," +
("#" + id + '[style*="display: block"]')
)
.join(",");

let lastGameMode: string = null;

// Add event listeners to buttons to set game mode
document
.querySelector("#quickPlayWindow_ClassicButton")
.addEventListener("click", () => lastGameMode = "Classic");
document
.querySelector("#quickPlayWindow_ArrowsButton")
.addEventListener("click", () => lastGameMode = "Arrows");
document
.querySelector("#quickPlayWindow_GrappleButton")
.addEventListener("click", () => lastGameMode = "Grapple");

document.querySelector("#roomlistjoinbutton").addEventListener("click", () => {
const selectedMode = document.querySelector("tr.SELECTED > td:nth-child(3)");
if (selectedMode) lastGameMode = selectedMode.textContent;
});

iframe.on("UpdateData", async () => {
const element = document.querySelector(selector),
lobbyGameMode = document.querySelector("#newbonklobby_modetext")?.textContent,
state = document.querySelector("#pretty_top_name").textContent +
" - " +
document.querySelector("#pretty_top_level").textContent,
playerCount = document.querySelectorAll(".newbonklobby_playerentry")
.length;

if (element?.id === "newbonklobby")
lastGameMode = lobbyGameMode;

iframe.send({ lastGameMode, id: element?.id, state, playerCount });
});
92 changes: 92 additions & 0 deletions websites/B/Bonk.io/presence.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
const presence = new Presence({
clientId: "778092541836656712"
}),
modePair: { [key: string]: string } = {
Arrows: "arrows2",
"Death Arrows": "arrows2",
Grapple: "grapple2"
};

interface IFrameData {
lastGameMode?: string,
id?: string;
state: string;
playerCount: number;
}

let gameStartTimestamp: number = null,
ifd: IFrameData = null;

presence.on("UpdateData", async () => {
const data: PresenceData = {
largeImageKey: "bonk"
};

if (ifd?.id) {
data.state = ifd.state;
switch (ifd.id) {
case "guestOrAccountContainer":
case "guestContainer":
case "accountContainer":
case "autoLoginContainer":
data.details = "Logging In";
delete data.state;
break;
case "classic_mid":
data.details = "Main Menu";
break;
case "friendsContainer":
data.details = "Friends List";
break;
case "skinmanager":
data.details = "Skin Manager";
break;
case "skineditorcontainer":
data.details = "Editing a skin";
break;
case "quickPlayWindow":
data.details = "Quick Play Menu";
break;
case "roomListContainer":
data.details = "Viewing Room List";
break;
case "newbonklobby":
data.details = `In a lobby - ${ifd.lastGameMode} (${ifd.playerCount} player${
ifd.playerCount === 1 ? "" : "s"
})`;
data.smallImageKey = modePair[ifd.lastGameMode] || "classic2";
data.smallImageText = ifd.lastGameMode;
break;
case "mapeditorcontainer":
data.details = "Editing a map";
break;
case "sm_connectingContainer":
data.details = "Connecting to a game...";
break;
case "gamerenderer":
data.details = "In Game";
if (ifd.lastGameMode) {
data.details += ` - ${ifd.lastGameMode}`;
data.smallImageKey = modePair[ifd.lastGameMode] || "classic2";
data.smallImageText = ifd.lastGameMode;
}
break;
}

if (ifd.id === "gamerenderer" && !gameStartTimestamp)
gameStartTimestamp = Date.now();
else if (ifd.id !== "gamerenderer") gameStartTimestamp = null;

if (gameStartTimestamp) data.startTimestamp = gameStartTimestamp;
}

if (!(await presence.getSetting("showName"))) delete data.state;

// If data doesn't exist clear else set activity to the presence data
if (!data.details) {
presence.setTrayTitle(); // Clear tray
presence.setActivity(); // Clear activity
} else presence.setActivity(data);
});

presence.on("iFrameData", (data: IFrameData) => (ifd = data));
File renamed without changes.
20 changes: 0 additions & 20 deletions websites/B/Bonk2.io/iframe.ts

This file was deleted.

127 changes: 0 additions & 127 deletions websites/B/Bonk2.io/presence.ts

This file was deleted.

0 comments on commit 004c637

Please sign in to comment.