-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.html
More file actions
173 lines (150 loc) · 7.41 KB
/
Copy pathgame.html
File metadata and controls
173 lines (150 loc) · 7.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Arcade</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
background: #000;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
overflow: hidden;
}
#game-container { width: 100%; height: 100%; }
#status {
position: fixed;
top: 8px;
right: 10px;
font-family: monospace;
font-size: 11px;
color: #ffcc00;
background: rgba(0,0,0,0.7);
padding: 3px 8px;
border-radius: 4px;
z-index: 999;
display: none;
}
</style>
</head>
<body>
<div id="status"></div>
<div id="game-container">
<div id="game"></div>
</div>
<script>
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// CONFIG — all driven by URL params
//
// Arcade A (Pokemon Insurgence):
// game.html?rom=PLACEHOLDER_ROM_FILENAME_A&core=gba&id=pokemon-insurgence&wallet=0xABC
//
// Arcade B (A Plumber for All Seasons):
// game.html?rom=a-plumber-for-all-seasons_2021-11-22.sfc&core=snes&id=a-plumber-for-all-seasons&wallet=0xABC
//
// Arcade C (SMB3 Mix):
// game.html?rom=smb3mix-rev2B-prg0.nes&core=nes&id=smb3mix-rev2b&wallet=0xABC
//
// Arcade D (Rainbow Realms 1.3):
// game.html?rom=The%20Rainbow%20Realms%201.3.nes&core=nes&id=rainbow-realms-1-3&wallet=0xABC
//
// Arcade E (Rainbow Realms 2):
// game.html?rom=Rainbow%20Realms%202.nes&core=nes&id=rainbow-realms-2&wallet=0xABC
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var params = new URLSearchParams(window.location.search);
var ROM_FILE = params.get("rom") || "a-plumber-for-all-seasons_2021-11-22.sfc";
var ROM_CORE = params.get("core") || "snes";
var ROM_ID = params.get("id") || "a-plumber-for-all-seasons";
var WALLET = params.get("wallet") || "anonymous";
var SERVER = "https://gamer-production.up.railway.app";
var ROM_TOKEN = "kaizo-arcade-2024-secret";
// Set page title to the ROM being played
document.title = ROM_ID;
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// EMULATORJS — reads ROM_FILE and ROM_CORE set above
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
EJS_player = "#game";
EJS_core = ROM_CORE;
EJS_gameUrl = SERVER + "/rom/" + encodeURIComponent(ROM_FILE) + "?token=" + ROM_TOKEN;
EJS_pathtodata = "https://cdn.emulatorjs.org/stable/data/";
EJS_startOnLoaded = true;
EJS_color = "#e8000d";
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// STATUS HELPER
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
function showStatus(msg, duration) {
duration = duration || 2500;
var el = document.getElementById("status");
el.textContent = msg;
el.style.display = "block";
clearTimeout(el._timer);
el._timer = setTimeout(function() { el.style.display = "none"; }, duration);
}
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// WAIT FOR EMULATOR TO BOOT
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
function waitForEmulator(callback, attempts) {
attempts = attempts || 0;
if (typeof EJS_emulator !== "undefined" && EJS_emulator.gameManager) {
callback(EJS_emulator);
} else if (attempts < 60) {
setTimeout(function() { waitForEmulator(callback, attempts + 1); }, 500);
}
}
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// SAVE STATES
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
function loadSaveState(emulator) {
if (WALLET === "anonymous") return;
fetch(SERVER + "/save?wallet=" + WALLET + "&rom=" + ROM_ID)
.then(function(res) { return res.json(); })
.then(function(data) {
if (data.state) {
var binary = atob(data.state);
var bytes = new Uint8Array(binary.length);
for (var i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
emulator.gameManager.loadState(bytes);
showStatus("💾 Save loaded");
}
}).catch(function(e) { console.warn("Could not load save state:", e); });
}
function writeSaveState(emulator) {
if (WALLET === "anonymous") return;
try {
var stateBytes = emulator.gameManager.saveState();
var base64 = btoa(String.fromCharCode.apply(null, stateBytes));
fetch(SERVER + "/save", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ wallet: WALLET, rom: ROM_ID, state: base64 })
}).then(function() { showStatus("💾 Saved"); })
.catch(function(e) { console.warn("Could not write save state:", e); });
} catch(e) { console.warn("Save state error:", e); }
}
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// AUTO-SAVE EVERY 60 SECONDS
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
function startAutoSave(emulator) {
setInterval(function() { writeSaveState(emulator); }, 60000);
}
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// BOOT
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
window.addEventListener("load", function() {
waitForEmulator(function(emulator) {
loadSaveState(emulator);
startAutoSave(emulator);
});
});
window.addEventListener("beforeunload", function() {
if (typeof EJS_emulator !== "undefined" && EJS_emulator.gameManager) {
writeSaveState(EJS_emulator);
}
});
</script>
<script src="https://cdn.emulatorjs.org/stable/data/loader.js"></script>
</body>
</html>