Switch repo to English, add i18n with EN/DE language files and first-start language selection
- 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>
This commit is contained in:
1 parent
a101f6ddc4
commit
fbf6f223fc
18 files changed
+1072
-362
No files matched your search
@@ -0,0 +1,50 @@
|
||||
// Browser integration via our own miniquad JS plugin (www/dc_plugin.js):
|
||||
// persistent key/value storage (localStorage). Native builds use an in-memory fallback.
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
mod imp {
|
||||
extern "C" {
|
||||
fn dc_storage_get(key: *const u8, key_len: u32) -> i32;
|
||||
fn dc_storage_take(dst: *mut u8);
|
||||
fn dc_storage_set(key: *const u8, key_len: u32, val: *const u8, val_len: u32);
|
||||
}
|
||||
|
||||
pub fn storage_get(key: &str) -> Option<String> {
|
||||
unsafe {
|
||||
let n = dc_storage_get(key.as_ptr(), key.len() as u32);
|
||||
if n < 0 {
|
||||
return None;
|
||||
}
|
||||
let mut buf = vec![0u8; n as usize];
|
||||
dc_storage_take(buf.as_mut_ptr());
|
||||
String::from_utf8(buf).ok()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn storage_set(key: &str, val: &str) {
|
||||
unsafe { dc_storage_set(key.as_ptr(), key.len() as u32, val.as_ptr(), val.len() as u32) }
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
mod imp {
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
thread_local! {
|
||||
static STORE: RefCell<HashMap<String, String>> = RefCell::new(HashMap::new());
|
||||
}
|
||||
pub fn storage_get(key: &str) -> Option<String> {
|
||||
STORE.with(|s| s.borrow().get(key).cloned())
|
||||
}
|
||||
pub fn storage_set(key: &str, val: &str) {
|
||||
STORE.with(|s| s.borrow_mut().insert(key.to_string(), val.to_string()));
|
||||
}
|
||||
}
|
||||
|
||||
pub use imp::*;
|
||||
|
||||
// Lets the JS plugin loader know this crate uses the "dungeoncraft" plugin
|
||||
#[no_mangle]
|
||||
pub extern "C" fn dungeoncraft_crate_version() -> u32 {
|
||||
1
|
||||
}
|
||||
Reference in new issue
Block a user