Skip to content

Commit

Permalink
Add more game scenes cases
Browse files Browse the repository at this point in the history
  • Loading branch information
thehatkid committed Aug 6, 2022
1 parent 2de8efe commit 18712ad
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
60 changes: 59 additions & 1 deletion mod/js/plugins/HK_DiscordRPC_10_Handler.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
const asyncDelay = ms => new Promise(resolve => setTimeout(resolve, ms));

// Cursed, but works. lol. (by Draught)
function getNameOf(obj) {
let s = Symbol();
obj[s] = () => { throw new Error() };

try {
obj[s]();
} catch (e) {
return e.stack.match(/\s+at (\w+)/)[1];
}
}

async function DRPC_Handler() {
let handlerLoop = true;
let scene, leader, chapter, hasFocus;
Expand Down Expand Up @@ -83,7 +95,7 @@ async function DRPC_Handler() {
}

// Update rich presence for each scenes
switch (scene.constructor.name) {
switch (getNameOf(scene)) {
case "Scene_Boot":
startTimestamp = Date.now(); // Sets new start timestamp
await DRPC.setActivity({
Expand Down Expand Up @@ -123,6 +135,16 @@ async function DRPC_Handler() {
});
break;

case "Scene_Gameover":
await DRPC.setActivity({
details: chapter,
state: langTexts.states.in_game_over,
largeImageKey: leaderAssetKey,
largeImageText: leader.name(),
startTimestamp: startTimestamp
});
break;

case "Scene_Menu":
await DRPC.setActivity({
details: chapter,
Expand Down Expand Up @@ -269,6 +291,42 @@ async function DRPC_Handler() {
});
break;

case "Scene_BlackJack":
await DRPC.setActivity({
details: chapter,
state: langTexts.states.in_blackjack + (hasFocus ? "" : ` ${langTexts.states.out_of_focus}`),
largeImageKey: leaderAssetKey,
largeImageText: leader.name(),
smallImageKey: "blackjack",
smallImageText: langTexts.texts.blackjack,
startTimestamp: startTimestamp
});
break;

case "Scene_PetRocks":
await DRPC.setActivity({
details: chapter,
state: langTexts.states.in_petrocks + (hasFocus ? "" : ` ${langTexts.states.out_of_focus}`),
largeImageKey: leaderAssetKey,
largeImageText: leader.name(),
smallImageKey: "petrocks",
smallImageText: langTexts.texts.petrocks,
startTimestamp: startTimestamp
});
break;

case "Scene_SpaceInvader":
await DRPC.setActivity({
details: chapter,
state: langTexts.states.in_spaceinvader + (hasFocus ? "" : ` ${langTexts.states.out_of_focus}`),
largeImageKey: leaderAssetKey,
largeImageText: leader.name(),
smallImageKey: "spaceinvader",
smallImageText: langTexts.texts.spaceinvader,
startTimestamp: startTimestamp
});
break;

case "Scene_SlotMachine":
await DRPC.setActivity({
details: chapter,
Expand Down
2 changes: 1 addition & 1 deletion mod/js/plugins/HK_DiscordRPC_90_Connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ nw.Window.get().on('close', function() {
isEnabledDRPC = false;
switch (e.message) {
case "Could not connect to Discord IPC":
case "Connection closed":
case "Connection Closed":
// Ignoring due to not opened any Discord clients,
// or Discord client is starting up.
break;
Expand Down
7 changes: 7 additions & 0 deletions mod/languages/en/HK_DiscordRPC.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ RichPresence:
in_menu_skills: "Paused, in SKILLS menu"
in_menu_options: "Paused, in OPTIONS menu"
in_battle: "In the battle"
in_game_over: "Game Over"
in_quests: "Watching QUESTS"
in_foes_facts: "Watching FOES FACTS!"
in_blackletter_map: "Watching MAP"
in_photoalbum: "Watching PHOTO ALBUM"
in_shop: "In the shop"
in_hangman: "In HANGMAN"
in_blackjack: "Playing BLACKJACK"
in_petrocks: "Playing PET ROCKS"
in_spaceinvader: "Playing SPACE INVADER"
in_slots: "Playing slots"
out_of_focus: "(in background)"

Expand All @@ -28,4 +32,7 @@ RichPresence:
photoalbum: "BASIL's PHOTO ALBUM"
shop: "Mailbox (Shop)"
hangman: "HANGMAN"
blackjack: "BLACKJACK"
petrocks: "PET ROCKS"
spaceinvader: "CAPT. SPACEBOY'S SPACE ADVENTURE"
slotmachine: "Slot machine"

0 comments on commit 18712ad

Please sign in to comment.