Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
OctoSpacc committed Apr 24, 2024
1 parent 525dbbe commit b7472b1
Show file tree
Hide file tree
Showing 9 changed files with 9 additions and 168 deletions.
Binary file modified games/DDLC-1.1.1-web/game.zip
Binary file not shown.
166 changes: 5 additions & 161 deletions games/DDLC-1.1.1-web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@
<a href="javascript:document.getElementById('ID_SavegamesImport').click();">Import saves</a><br />
<a href="javascript:onSavegamesExport();">Export saves</a><br />
<a href="javascript:FSDownload('/log.txt', 'text/plain');">Ren'Py log</a><br />
<a href="https://www.renpy.org/" target="_blank">
<a href="https://renpy.beuc.net/" target="_blank">
<span style="font-size: smaller">
<span style="color: dimgrey">Powered by</span>
Ren'Py
RenPyWeb
</span>
</a>
</span>
Expand All @@ -184,22 +184,15 @@
/* Copyright (C) 2018, 2019, 2020, 2021 Sylvain Beucler */

/* Context menu */
const menu = document.getElementById('ContextMenu');
document.getElementById('ContextButton').addEventListener('click', function (e) {
var menu = document.getElementById('ContextMenu');
if (menu.style.display == 'none')
menu.style.display = 'block';
else
menu.style.display = 'none';
e.preventDefault();
});

menu.addEventListener('click', function (e) {
if (e.target.tagName == 'A') {
// Close context menu when a menu item is selected
menu.style.display = 'none';
}
});

function onSavegamesImport(input) {
reader = new FileReader();
reader.onload = function(e) {
Expand All @@ -210,12 +203,7 @@
console.trace(); console.log(err, err.message);
Module.print("Warning: cannot import savegames: write error: " + err.message + "\n");
} else {
renpy_exec('renpy.loadsave.location.scan()').then(result => {
Module.print("Saves imported successfully\n");
}).catch(error => {
console.error('Cannot rescan saves folder', error);
Module.print("Saves imported - restart game to apply.\n");
});
Module.print("Saves imported - restart game to apply.\n");
}
});
}
Expand Down Expand Up @@ -404,7 +392,7 @@
var appleWarning = "";

if (/RangeError/.test(event)) {
appleWarning = "\n<p>This is a known issue with this beta and recent changes to some web browsers. Reloading this page with developer tools open may help.";
appleWarning = "\n<p>This is a known issue in Safari and Webkit browsers. Please report this issue to Apple.";
}

Module.setStatus('Error: ' + event.split('\n')[0] + ' (see JavaScript console for details)' + appleWarning);
Expand All @@ -416,150 +404,6 @@
</script>
<script type='text/javascript' src="pythonhome-data.js"></script>
<script type='text/javascript' src="pyapp-data.js"></script>

<script type='text/javascript'>
/* This block contains code for running Python statements
* in Ren'Py process from JS.
*
* Copyright 2022 Teyut <[email protected]>, MIT License.
*/

(function() {
let cmd_queue = [];
let cur_cmd = undefined;
let debug = false;

function dbg_log(...args) {
if(debug) console.debug(...args);
}

/** This functions is called by the wrapper script at the end of script execution. */
function cmd_callback(result) {
dbg_log('cmd_callback', result);

if(cur_cmd === undefined) {
console.error('Unexpected command result', result);
return;
}

try {
if(result.error !== undefined) {
dbg_log('ERROR', result.name, result.error, result.traceback);
const e = new Error(result.error);
e.name = result.name;
e.traceback = result.traceback;
cur_cmd.reject(e);
} else {
dbg_log('SUCCESS', result.data);
cur_cmd.resolve(result.data);
}
} finally {
cur_cmd = undefined;
send_next_cmd();
}
}

/** Prepare and send the next command to be executed if any. */
function send_next_cmd() {
if(cmd_queue.length == 0) return

cur_cmd = cmd_queue.shift();
dbg_log('send_next_cmd', cur_cmd);

// Convert script to base64 to prevent having to escape
// the script content as a Python string
const script_b64 = btoa(cur_cmd.py_script);
const wrapper = 'import base64, emscripten, json, traceback;\n'
+ 'try:'
+ "result = None;"
+ "exec(base64.b64decode('" + script_b64 + "').decode('utf-8'));"
+ "result = json.dumps(dict(data=result));"
+ "\n"
+ "except Exception as e:"
+ "result = json.dumps(dict(error=str(e), name=e.__class__.__name__, traceback=traceback.format_exc()));"
+ "\n"
+ "emscripten.run_script('_renpy_cmd_callback(%s)' % (result,));";

dbg_log(wrapper);

// Write script to the global variable Ren'Py is monitoring
window._renpy_cmd = wrapper;
}

/** Add a command to the queue and execute it if the queue was empty. */
function add_cmd(py_script, resolve, reject) {
const cmd = {py_script: py_script, resolve: resolve, reject: reject};
dbg_log('add_cmd', cmd);
cmd_queue.push(cmd);

if(cur_cmd === undefined) send_next_cmd();
}

/* Global definitions */

/** Execute Python statements in Ren'Py Python's thread. The statements are executed
* using the renpy.python.py_exec() function, and the value of the "result" variable
* is passed to the resolve callback. In case of error, an Error instance is passed
* to the reject callback, with an extra "traceback" property.
* @param py_script The Python script to execute.
* @return A promise which resolves with the statements result.
*/
renpy_exec = function(py_script) {
return new Promise((resolve, reject) => {
add_cmd(py_script, resolve, reject);
});
};

/** Helper function to get the value of a Ren'Py variable.
* @param name The variable name (e.g., "build.name").
* @return A promise which resolves with the variable value.
*/
renpy_get = function(name) {
return new Promise((resolve, reject) => {
renpy_exec('result = ' + name)
.then(resolve).catch(reject);
});
};

/** Helper function to set the value of a Ren'Py variable.
* @param name The variable name (e.g., "build.name").
* @param value The value to set. It should either be a basic JS type that
* will be converted to JSON, or a Python expression. The raw
* parameter must be set to true for the latter case.
* @param raw (optional) If true, value is a valid Python expression.
* Otherwise, it must be a basic JS type.
* @return A promise which resolves with true in case of success
* and fails otherwise.
*/
renpy_set = function(name, value, raw) {
let script;
if(raw) {
script = name + " = " + value + "; result = True";
} else {
// Using base64 as it is unclear if we can use the output
// of JSON.stringify() directly as a Python string
script = 'import base64, json; '
+ name + " = json.loads(base64.b64decode('"
+ btoa(JSON.stringify(value))
+ "').decode('utf-8')); result = True";
}
return new Promise((resolve, reject) => {
renpy_exec(script)
.then(resolve).catch(reject);
});
};

_renpy_cmd_callback = cmd_callback;

/** Stubs for web3 functionality. */
window.loadCache = () => { };
window.clearCache = () => { };
window.webglContextLost = false;
window.webglContextRestored = false;

})();
</script>

<script type='text/javascript'>
function create_persistent() {
// populate savegames
Expand Down
2 changes: 1 addition & 1 deletion games/DDLC-1.1.1-web/index.js

Large diffs are not rendered by default.

Binary file modified games/DDLC-1.1.1-web/index.wasm
Binary file not shown.
5 changes: 1 addition & 4 deletions games/DDLC-1.1.1-web/pyapp-data.js

Large diffs are not rendered by default.

Binary file modified games/DDLC-1.1.1-web/pyapp.data
Binary file not shown.
Loading

0 comments on commit b7472b1

Please sign in to comment.