Skip to content

Commit 4b969bf

Browse files
committed
Support for upstream EasyRPG
1 parent 90252a1 commit 4b969bf

6 files changed

Lines changed: 54 additions & 37 deletions

File tree

chat.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Module["onRuntimeInitialized"] = initChat;
1+
easyrpgPlayer["onRuntimeInitialized"] = initChat;
22
if (typeof ENV === "undefined")
33
initChat();
44

gamecanvas.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,24 @@ const canvas = document.getElementById('canvas');
55
const gameContainer = document.getElementById('gameContainer');
66
let lastTouchedId;
77

8+
// Launch the Player and configure it
9+
window.addEventListener('load', (event) => {
10+
createEasyRpgPlayer(easyrpgPlayer)
11+
.then(function(Module) {
12+
// Module is ready
13+
easyrpgPlayer = Module;
14+
easyrpgPlayer.initApi();
15+
16+
for (let loadFunc of easyrpgPlayerLoadFuncs)
17+
loadFunc();
18+
19+
canvas.focus();
20+
});
21+
});
22+
823
// Make EasyRPG player embeddable
9-
gameContainer.addEventListener('mouseenter', () => canvas.focus());
10-
gameContainer.addEventListener('click', () => canvas.focus());
24+
canvas.addEventListener('mouseenter', () => canvas.focus());
25+
canvas.addEventListener('click', () => canvas.focus());
1126

1227
// Handle clicking on the fullscreen button
1328
document.querySelector('#controls-fullscreen').addEventListener('click', () => {

init.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,20 @@ const tippyConfig = {
3434
allowHTML: true
3535
};
3636

37+
let easyrpgPlayer = {
38+
initialized: false,
39+
game: ynoGameId,
40+
saveFs: undefined,
41+
wsUrl: 'wss://connect.ynoproject.net/' + ynoGameId + '/'
42+
};
43+
let easyrpgPlayerLoadFuncs = [];
44+
3745
const sessionIdKey = 'ynoproject_sessionId';
3846
const serverUrl = `https://connect.ynoproject.net/${ynoGameId}`;
3947
const apiUrl = `${serverUrl}/api`;
4048
const adminApiUrl = `${serverUrl}/admin`;
4149
const ynomojiUrlPrefix = 'images/ynomoji/';
4250

43-
Module = {
44-
INITIALIZED: false,
45-
EASYRPG_GAME: ynoGameId,
46-
EASYRPG_WS_URL: 'wss://connect.ynoproject.net/' + ynoGameId + '/'
47-
};
48-
4951
async function injectScripts() {
5052
const supportsSimd = await wasmFeatureDetect.simd();
5153

@@ -78,11 +80,11 @@ async function injectScripts() {
7880
if (globalConfig.preloads)
7981
initPreloads();
8082

81-
Module.postRun.push(() => {
82-
Module.INITIALIZED = true;
83-
Module._SetNametagMode(config.nametagMode);
84-
Module._SetSoundVolume(globalConfig.soundVolume);
85-
Module._SetMusicVolume(globalConfig.musicVolume);
83+
easyrpgPlayerLoadFuncs.push(() => {
84+
easyrpgPlayer.initialized = true;
85+
easyrpgPlayer._SetNametagMode(config.nametagMode);
86+
easyrpgPlayer._SetSoundVolume(globalConfig.soundVolume);
87+
easyrpgPlayer._SetMusicVolume(globalConfig.musicVolume);
8688
const loadingOverlay = document.getElementById('loadingOverlay');
8789
removeLoader(loadingOverlay);
8890
checkShowVersionUpdate().then(() => loadingOverlay.classList.add('loaded'));
@@ -98,7 +100,7 @@ async function injectScripts() {
98100
};
99101
});
100102
if (typeof onResize !== 'undefined')
101-
Module.postRun.push(onResize);
103+
easyrpgPlayerLoadFuncs.push(onResize);
102104
};
103105

104106
const scriptTag = document.createElement('script');

play.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ function fetchAndUpdatePlayerInfo() {
140140
const isLogout = !cookieSessionId && loginToken && cookieSessionId !== loginToken;
141141
if (isLogin || isLogout) {
142142
loginToken = isLogin ? cookieSessionId : null;
143-
const ptr = Module.allocate(Module.intArrayFromString(isLogin ? loginToken : ''), Module.ALLOC_NORMAL);
144-
Module._SetSessionToken(ptr);
145-
Module._free(ptr);
143+
const ptr = easyrpgPlayer.allocate(easyrpgPlayer.intArrayFromString(isLogin ? loginToken : ''), easyrpgPlayer.ALLOC_NORMAL);
144+
easyrpgPlayer._SetSessionToken(ptr);
145+
easyrpgPlayer._free(ptr);
146146
}
147147
apiFetch('info')
148148
.then(response => response.json())
@@ -480,8 +480,8 @@ function onReceiveInputFeedback(inputId) {
480480
config[configKey] = toggled;
481481
updateConfig(isGlobal ? globalConfig : config, isGlobal);
482482
if (configKey === 'mute') {
483-
Module._SetSoundVolume(toggled ? 0 : globalConfig.soundVolume);
484-
Module._SetMusicVolume(toggled ? 0 : globalConfig.musicVolume);
483+
easyrpgPlayer._SetSoundVolume(toggled ? 0 : globalConfig.soundVolume);
484+
easyrpgPlayer._SetMusicVolume(toggled ? 0 : globalConfig.musicVolume);
485485
}
486486
}
487487
}
@@ -741,7 +741,7 @@ document.getElementById('privateModeButton').onclick = function () {
741741
if (connStatus == 1 || connStatus == 3)
742742
onUpdateConnectionStatus(config.privateMode ? 3 : 1);
743743

744-
Module._SessionReady();
744+
easyrpgPlayer._SessionReady();
745745
};
746746

747747
let reconnectCooldownTimer;
@@ -877,8 +877,8 @@ document.getElementById('clearChatButton').onclick = function () {
877877
document.getElementById('settingsButton').onclick = () => openModal('settingsModal');
878878

879879
document.getElementById('muteButton').onclick = function () {
880-
if (Module.INITIALIZED)
881-
Module._ToggleMute();
880+
if (easyrpgPlayer.INITIALIZED)
881+
easyrpgPlayer._ToggleMute();
882882
};
883883

884884
document.getElementById('soundVolume').oninput = function () {
@@ -902,13 +902,13 @@ document.getElementById('lang').onchange = function () {
902902
};
903903

904904
document.getElementById('nametagMode').onchange = function () {
905-
if (Module.INITIALIZED)
906-
Module._SetNametagMode(this.value);
905+
if (easyrpgPlayer.INITIALIZED)
906+
easyrpgPlayer._SetNametagMode(this.value);
907907
};
908908

909909
document.getElementById('playerSoundsButton').onclick = () => {
910-
if (Module.INITIALIZED)
911-
Module._TogglePlayerSounds();
910+
if (easyrpgPlayer.INITIALIZED)
911+
easyrpgPlayer._TogglePlayerSounds();
912912
};
913913

914914
if (gameId === '2kki') {
@@ -1448,7 +1448,7 @@ document.onmousemove = function () {
14481448
function setLang(lang, isInit) {
14491449
globalConfig.lang = lang;
14501450
if (isInit && gameIds.indexOf(gameId) > -1)
1451-
Module.EASYRPG_LANGUAGE = (gameDefaultLangs.hasOwnProperty(gameId) ? gameDefaultLangs[gameId] !== lang : lang !== 'en') ? lang : 'default';
1451+
easyrpgPlayer.language = (gameDefaultLangs.hasOwnProperty(gameId) ? gameDefaultLangs[gameId] !== lang : lang !== 'en') ? lang : 'default';
14521452
initLocalization(isInit);
14531453
if (!isInit)
14541454
updateConfig(globalConfig, true);
@@ -1463,8 +1463,8 @@ function setName(name, isInit) {
14631463
function setSoundVolume(value, isInit) {
14641464
if (isNaN(value))
14651465
return;
1466-
if (Module.INITIALIZED && !config.mute)
1467-
Module._SetSoundVolume(value);
1466+
if (easyrpgPlayer.INITIALIZED && !config.mute)
1467+
easyrpgPlayer._SetSoundVolume(value);
14681468
globalConfig.soundVolume = value;
14691469
if (!isInit)
14701470
updateConfig(globalConfig, true);
@@ -1473,8 +1473,8 @@ function setSoundVolume(value, isInit) {
14731473
function setMusicVolume(value, isInit) {
14741474
if (isNaN(value))
14751475
return;
1476-
if (Module.INITIALIZED && !config.mute)
1477-
Module._SetMusicVolume(value);
1476+
if (easyrpgPlayer.INITIALIZED && !config.mute)
1477+
easyrpgPlayer._SetMusicVolume(value);
14781478
globalConfig.musicVolume = value;
14791479
if (!isInit)
14801480
updateConfig(globalConfig, true);

screenshots.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,12 @@ function takeScreenshot(retryCount) {
230230

231231
const mapId = cachedMapId;
232232

233-
const coords = Module._GetPlayerCoords();
233+
const coords = easyrpgPlayer._GetPlayerCoords();
234234

235-
const mapX = Module.getValue(coords, 'int*');
236-
const mapY = Module.getValue(coords + 4, 'int*');
235+
const mapX = easyrpgPlayer.getValue(coords, 'int*');
236+
const mapY = easyrpgPlayer.getValue(coords + 4, 'int*');
237237

238-
Module._free(coords);
238+
easyrpgPlayer._free(coords);
239239

240240
if (notificationConfig.all && notificationConfig.screenshots.all && notificationConfig.screenshots.screenshotTaken) {
241241
const toast = showScreenshotToastMessage('screenshotTaken', 'image', true, null, true);

session.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function initSessionWs(attempt) {
3232
return;
3333
setTimeout(() => initSessionWs(1), 5000);
3434
};
35-
Module._SessionReady();
35+
easyrpgPlayer._SessionReady();
3636
if (config.privateMode)
3737
sendSessionCommand('pr', [ 1 ]);
3838
if (!hasConnected) {

0 commit comments

Comments
 (0)