@bloomengine/engine 0.4.11 → 0.4.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1394,9 +1394,38 @@ pub extern "C" fn bloom_inject_gamepad_button_up(button: f64) {
1394
1394
  #[no_mangle]
1395
1395
  pub extern "C" fn bloom_get_platform() -> f64 { 5.0 }
1396
1396
 
1397
- /// Preferred OS language packed as `c0*256+c1`. TODO: real per-OS detection; returns "en" for now.
1398
- #[no_mangle]
1399
- pub extern "C" fn bloom_get_language() -> f64 { 25966.0 }
1397
+ /// Preferred OS language packed as `c0*256+c1` (ISO-639 primary subtag), read
1398
+ /// from the device locale system property via the NDK (no JNI). Tries the
1399
+ /// user-set locale first, then the factory defaults. Falls back to "en".
1400
+ #[no_mangle]
1401
+ pub extern "C" fn bloom_get_language() -> f64 {
1402
+ fn parse(buf: &[u8], n: i32) -> Option<f64> {
1403
+ if n < 2 { return None; }
1404
+ let lc = |b: u8| if b.is_ascii_uppercase() { b + 32 } else { b };
1405
+ let (c0, c1) = (lc(buf[0]), lc(buf[1]));
1406
+ if c0.is_ascii_alphabetic() && c1.is_ascii_alphabetic() {
1407
+ Some((c0 as f64) * 256.0 + (c1 as f64))
1408
+ } else {
1409
+ None
1410
+ }
1411
+ }
1412
+ let props: [&[u8]; 3] = [
1413
+ b"persist.sys.locale\0",
1414
+ b"ro.product.locale\0",
1415
+ b"ro.product.locale.language\0",
1416
+ ];
1417
+ for prop in props {
1418
+ let mut buf = [0u8; 92]; // PROP_VALUE_MAX
1419
+ let n = unsafe {
1420
+ libc::__system_property_get(
1421
+ prop.as_ptr() as *const libc::c_char,
1422
+ buf.as_mut_ptr() as *mut libc::c_char,
1423
+ )
1424
+ };
1425
+ if let Some(v) = parse(&buf, n) { return v; }
1426
+ }
1427
+ 25966.0
1428
+ }
1400
1429
  #[no_mangle]
1401
1430
  pub extern "C" fn bloom_is_any_input_pressed() -> f64 {
1402
1431
  if engine().input.is_any_input_pressed() { 1.0 } else { 0.0 }
@@ -1938,7 +1938,12 @@ pub fn bloom_get_platform() -> f64 {
1938
1938
  }
1939
1939
 
1940
1940
  #[wasm_bindgen]
1941
- pub fn bloom_get_language() -> f64 { 25966.0 } // TODO: navigator.language via JS host glue
1941
+ pub fn bloom_get_language() -> f64 {
1942
+ // navigator.language (e.g. "en-US" / "zh-Hans") -> packed 2-letter code.
1943
+ let lang = web_sys::window().and_then(|w| w.navigator().language()).unwrap_or_default();
1944
+ let b = lang.to_ascii_lowercase().into_bytes();
1945
+ if b.len() >= 2 { (b[0] as f64) * 256.0 + (b[1] as f64) } else { 25966.0 }
1946
+ }
1942
1947
 
1943
1948
  #[wasm_bindgen]
1944
1949
  pub fn bloom_is_any_input_pressed() -> f64 {
@@ -28,6 +28,7 @@ wgpu = "29"
28
28
  [target.'cfg(windows)'.dependencies]
29
29
  windows = { version = "0.58", features = [
30
30
  "Win32_Foundation",
31
+ "Win32_Globalization",
31
32
  "Win32_UI_WindowsAndMessaging",
32
33
  "Win32_UI_HiDpi",
33
34
  "Win32_UI_Input_KeyboardAndMouse",
@@ -1636,9 +1636,22 @@ pub extern "C" fn bloom_inject_gamepad_button_up(button: f64) {
1636
1636
  #[no_mangle]
1637
1637
  pub extern "C" fn bloom_get_platform() -> f64 { 3.0 }
1638
1638
 
1639
- /// Preferred OS language packed as `c0*256+c1`. TODO: real per-OS detection; returns "en" for now.
1640
- #[no_mangle]
1641
- pub extern "C" fn bloom_get_language() -> f64 { 25966.0 }
1639
+ /// Preferred OS language packed as `c0*256+c1` (ISO-639 primary subtag), from
1640
+ /// `GetUserDefaultLocaleName` (e.g. "en-US" -> "en"). Falls back to "en".
1641
+ #[no_mangle]
1642
+ pub extern "C" fn bloom_get_language() -> f64 {
1643
+ use windows::Win32::Globalization::GetUserDefaultLocaleName;
1644
+ let mut buf = [0u16; 85]; // LOCALE_NAME_MAX_LENGTH
1645
+ let n = unsafe { GetUserDefaultLocaleName(&mut buf) };
1646
+ if n >= 2 {
1647
+ let lc = |c: u16| -> u8 { let b = c as u8; if b.is_ascii_uppercase() { b + 32 } else { b } };
1648
+ let (c0, c1) = (lc(buf[0]), lc(buf[1]));
1649
+ if c0.is_ascii_alphabetic() && c1.is_ascii_alphabetic() {
1650
+ return (c0 as f64) * 256.0 + (c1 as f64);
1651
+ }
1652
+ }
1653
+ 25966.0
1654
+ }
1642
1655
  #[no_mangle]
1643
1656
  pub extern "C" fn bloom_is_any_input_pressed() -> f64 {
1644
1657
  if engine().input.is_any_input_pressed() { 1.0 } else { 0.0 }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bloomengine/engine",
3
- "version": "0.4.11",
3
+ "version": "0.4.12",
4
4
  "description": "Bloom Engine: native TypeScript game engine compiled by Perry",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",