- in-game texts moved to lang/en.lang and lang/de.lang (key = text, placeholders) - game logic emits message keys + args, translated at display time - localStorage access via own miniquad JS plugin (www/dc_plugin.js) - code comments, DESIGN.md, CREDITS.md translated; README.md added Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
33 lines
1.1 KiB
JavaScript
33 lines
1.1 KiB
JavaScript
// DungeonCraft browser plugin for miniquad: localStorage access for the Rust code.
|
|
(function () {
|
|
"use strict";
|
|
var pending = null;
|
|
|
|
function bytes(ptr, len) {
|
|
return new Uint8Array(wasm_memory.buffer, ptr, len);
|
|
}
|
|
function str(ptr, len) {
|
|
return new TextDecoder().decode(bytes(ptr, len));
|
|
}
|
|
|
|
function register(importObject) {
|
|
importObject.env.dc_storage_get = function (kp, kl) {
|
|
var v = null;
|
|
try { v = window.localStorage.getItem(str(kp, kl)); } catch (e) { }
|
|
if (v === null) { pending = null; return -1; }
|
|
pending = new TextEncoder().encode(v);
|
|
return pending.length;
|
|
};
|
|
importObject.env.dc_storage_take = function (ptr) {
|
|
if (pending === null) return;
|
|
bytes(ptr, pending.length).set(pending);
|
|
pending = null;
|
|
};
|
|
importObject.env.dc_storage_set = function (kp, kl, vp, vl) {
|
|
try { window.localStorage.setItem(str(kp, kl), str(vp, vl)); } catch (e) { }
|
|
};
|
|
}
|
|
|
|
miniquad_add_plugin({ register_plugin: register, version: 1, name: "dungeoncraft" });
|
|
})();
|