|
1 | | -import { ActivityType } from 'premid' |
| 1 | +import { ActivityType, StatusDisplayType } from 'premid' |
2 | 2 |
|
3 | 3 | const presence = new Presence({ |
4 | 4 | clientId: '1511505666664038460', |
5 | 5 | }) |
6 | 6 | const NintendoMusicLogo = 'https://cdn.rcd.gg/PreMiD/websites/N/Nintendo%20Music/assets/logo.png' |
7 | 7 |
|
| 8 | +const TrackOriginList: Record<string, Record<string, string>> = { |
| 9 | + 'Mario Kart World': { |
| 10 | + 'Desert Hills': 'DS Desert Hills', |
| 11 | + 'Shy Guy Bazaar': '3DS Shy Guy Bazaar', |
| 12 | + 'Wario Stadium': 'N64 Wario Stadium', |
| 13 | + 'Airship Fortress': 'DS Airship Fortress', |
| 14 | + 'DK Pass': 'DS DK Pass', |
| 15 | + 'Sky-High Sundae': 'SW Sky-High Sundae', |
| 16 | + 'Wario\'s Galleon': '3DS Wario\'s Galleon', |
| 17 | + 'Wario\'s Shipyard': '3DS Wario\'s Shipyard', |
| 18 | + 'Koopa Troopa Beach': 'SNES Koopa Troopa Beach', |
| 19 | + 'Peach Beach': 'GCN Peach Beach', |
| 20 | + 'Dino Dino Jungle': 'GCN Dino Dino Jungle', |
| 21 | + 'Moo Moo Meadows': 'Wii Moo Moo Meadows', |
| 22 | + 'Choco Mountain': 'N64 Choco Mountain', |
| 23 | + 'Toad\'s Factory': 'Wii Toad\'s Factory', |
| 24 | + 'Mario Circuit': 'SNES Mario Circuit', |
| 25 | + 'Desert Hills (Intro)': 'DS Desert Hills (Intro)', |
| 26 | + 'Shy Guy Bazaar (Intro)': '3DS Shy Guy Bazaar (Intro)', |
| 27 | + 'Wario Stadium (Intro)': 'N64 Wario Stadium (Intro)', |
| 28 | + 'Airship Fortress (Intro)': 'DS Airship Fortress (Intro)', |
| 29 | + 'DK Pass (Intro)': 'DS DK Pass (Intro)', |
| 30 | + 'Sky-High Sundae (Intro)': 'SW Sky-High Sundae (Intro)', |
| 31 | + 'Wario\'s Galleon (Intro)': '3DS Wario\'s Galleon (Intro)', |
| 32 | + 'Wario\'s Shipyard (Intro)': '3DS Wario\'s Shipyard (Intro)', |
| 33 | + 'Koopa Troopa Beach (Intro)': 'SNES Koopa Troopa Beach (Intro)', |
| 34 | + 'Peach Beach (Intro)': 'GCN Peach Beach (Intro)', |
| 35 | + 'Dino Dino Jungle (Intro)': 'GCN Dino Dino Jungle (Intro)', |
| 36 | + 'Moo Moo Meadows (Intro)': 'Wii Moo Moo Meadows (Intro)', |
| 37 | + 'Choco Mountain (Intro)': 'N64 Choco Mountain (Intro)', |
| 38 | + 'Toad\'s Factory (Intro)': 'Wii Toad\'s Factory (Intro)', |
| 39 | + 'Mario Circuit (Intro)': 'SNES Mario Circuit (Intro)', |
| 40 | + }, |
| 41 | +} |
| 42 | + |
8 | 43 | presence.on('UpdateData', async () => { |
9 | 44 | const { pathname } = document.location |
10 | 45 | const title = document.title |
11 | 46 | const audio = document.querySelector('audio') |
12 | 47 | const mediaSession = navigator.mediaSession |
13 | 48 | const isPlaying = mediaSession.playbackState === 'playing' |
14 | 49 | const currentTime = audio?.currentTime ?? 0 |
15 | | - const duration = audio?.duration || 0 // NOTE: audio.duration is NaN before loadedmetadata fires |
| 50 | + const duration = audio?.duration || 0 |
16 | 51 | const now = Math.floor(Date.now() / 1000) |
17 | 52 |
|
18 | 53 | const albumArt = document.querySelector<HTMLImageElement>('#main-column img')?.src ?? NintendoMusicLogo |
19 | 54 |
|
20 | | - const [showTimestamps, showSongArt] = await Promise.all([ |
| 55 | + const [showTimestamps, showSongArt, displayFormat, marioKartTrackOrigin] = await Promise.all([ |
21 | 56 | presence.getSetting<boolean>('showTimestamps'), |
22 | 57 | presence.getSetting<boolean>('showSongArt'), |
| 58 | + presence.getSetting<number>('displayFormat'), |
| 59 | + presence.getSetting<boolean>('marioKartTrackOrigin'), |
23 | 60 | ]) |
24 | 61 |
|
25 | 62 | const presenceData: PresenceData = { |
@@ -99,6 +136,31 @@ presence.on('UpdateData', async () => { |
99 | 136 | delete presenceData.endTimestamp |
100 | 137 | } |
101 | 138 |
|
| 139 | + if (marioKartTrackOrigin) { |
| 140 | + const soundtrackName = presenceData.state |
| 141 | + const songName = presenceData.details |
| 142 | + if (typeof soundtrackName === 'string' && typeof songName === 'string') { |
| 143 | + const gameKey = soundtrackName as keyof typeof TrackOriginList |
| 144 | + const gameTrack = TrackOriginList[gameKey] |
| 145 | + if (gameTrack && songName in gameTrack) { |
| 146 | + const mappedTrackValue = (gameTrack as Record<string, string>)[songName] |
| 147 | + presenceData.details = mappedTrackValue |
| 148 | + } |
| 149 | + } |
| 150 | + } |
| 151 | + |
| 152 | + switch (displayFormat) { |
| 153 | + case 0: |
| 154 | + presenceData.statusDisplayType = StatusDisplayType.Details |
| 155 | + break |
| 156 | + case 1: |
| 157 | + presenceData.statusDisplayType = StatusDisplayType.State |
| 158 | + break |
| 159 | + case 2: |
| 160 | + presenceData.statusDisplayType = StatusDisplayType.Name |
| 161 | + break |
| 162 | + } |
| 163 | + |
102 | 164 | if (presenceData.details) { |
103 | 165 | presence.setActivity(presenceData) |
104 | 166 | } |
|
0 commit comments