@bloomengine/engine 0.4.10 → 0.4.11

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.
@@ -1393,6 +1393,10 @@ pub extern "C" fn bloom_inject_gamepad_button_up(button: f64) {
1393
1393
  }
1394
1394
  #[no_mangle]
1395
1395
  pub extern "C" fn bloom_get_platform() -> f64 { 5.0 }
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 }
1396
1400
  #[no_mangle]
1397
1401
  pub extern "C" fn bloom_is_any_input_pressed() -> f64 {
1398
1402
  if engine().input.is_any_input_pressed() { 1.0 } else { 0.0 }
@@ -23,6 +23,6 @@ panic = "abort"
23
23
  image = { version = "0.25", default-features = false, features = ["hdr"] }
24
24
  bloom-shared = { path = "../shared", default-features = false, features = ["mp3"] }
25
25
  objc2 = "0.6"
26
- objc2-foundation = { version = "0.3", features = ["NSDate", "NSRunLoop", "NSString", "NSThread", "NSObject"] }
26
+ objc2-foundation = { version = "0.3", features = ["NSDate", "NSRunLoop", "NSString", "NSThread", "NSObject", "NSLocale", "NSArray"] }
27
27
  raw-window-handle = "0.6"
28
28
  wgpu = "29"
@@ -2078,6 +2078,14 @@ pub extern "C" fn bloom_inject_gamepad_button_up(button: f64) {
2078
2078
  }
2079
2079
  #[no_mangle]
2080
2080
  pub extern "C" fn bloom_get_platform() -> f64 { 2.0 }
2081
+
2082
+ /// Preferred OS language packed as `c0*256+c1` (ISO-639 primary subtag). See macos lib for format.
2083
+ #[no_mangle]
2084
+ pub extern "C" fn bloom_get_language() -> f64 {
2085
+ fn pack(code: &str) -> f64 { let l = code.to_ascii_lowercase(); let b = l.as_bytes(); if b.len() >= 2 { (b[0] as f64) * 256.0 + (b[1] as f64) } else { 25966.0 } }
2086
+ let langs = objc2_foundation::NSLocale::preferredLanguages();
2087
+ match langs.firstObject() { Some(s) => pack(&s.to_string()), None => 25966.0 }
2088
+ }
2081
2089
  #[no_mangle]
2082
2090
  pub extern "C" fn bloom_is_any_input_pressed() -> f64 {
2083
2091
  if engine().input.is_any_input_pressed() { 1.0 } else { 0.0 }
@@ -1846,6 +1846,14 @@ pub extern "C" fn bloom_inject_gamepad_button_up(button: f64) {
1846
1846
  }
1847
1847
  #[no_mangle]
1848
1848
  pub extern "C" fn bloom_get_platform() -> f64 { 4.0 }
1849
+
1850
+ /// Preferred OS language packed as `c0*256+c1` (ISO-639 primary subtag), from $LANG/$LC_*.
1851
+ #[no_mangle]
1852
+ pub extern "C" fn bloom_get_language() -> f64 {
1853
+ fn pack(code: &str) -> f64 { let l = code.to_ascii_lowercase(); let b = l.as_bytes(); if b.len() >= 2 { (b[0] as f64) * 256.0 + (b[1] as f64) } else { 25966.0 } }
1854
+ let v = std::env::var("LANG").or_else(|_| std::env::var("LC_ALL")).or_else(|_| std::env::var("LC_MESSAGES")).unwrap_or_default();
1855
+ if v.len() >= 2 && !v.starts_with('C') && !v.starts_with("POSIX") { pack(&v) } else { 25966.0 }
1856
+ }
1849
1857
  #[no_mangle]
1850
1858
  pub extern "C" fn bloom_is_any_input_pressed() -> f64 {
1851
1859
  if engine().input.is_any_input_pressed() { 1.0 } else { 0.0 }
@@ -27,7 +27,7 @@ panic = "abort"
27
27
  bloom-shared = { path = "../shared", default-features = false, features = ["mp3"] }
28
28
  image = { version = "0.25", default-features = false, features = ["hdr"] }
29
29
  objc2 = "0.6"
30
- objc2-foundation = { version = "0.3", features = ["NSDate", "NSRunLoop", "NSString", "NSThread"] }
30
+ objc2-foundation = { version = "0.3", features = ["NSDate", "NSRunLoop", "NSString", "NSThread", "NSLocale", "NSArray"] }
31
31
  objc2-app-kit = { version = "0.3", features = ["NSWindow", "NSView", "NSEvent", "NSApplication", "NSScreen", "NSGraphicsContext", "NSRunningApplication", "NSResponder"] }
32
32
  objc2-quartz-core = { version = "0.3", features = ["CAMetalLayer"] }
33
33
  raw-window-handle = "0.6"
@@ -2415,6 +2415,25 @@ pub extern "C" fn bloom_inject_gamepad_button_up(button: f64) {
2415
2415
  }
2416
2416
  #[no_mangle]
2417
2417
  pub extern "C" fn bloom_get_platform() -> f64 { 1.0 }
2418
+
2419
+ /// Return the user's preferred OS language as a packed 2-letter code:
2420
+ /// `c0 * 256 + c1`, where c0/c1 are the ASCII bytes of the lowercased
2421
+ /// ISO-639 primary subtag (e.g. "en-US" -> "en" -> 101*256+110). The script
2422
+ /// subtag is dropped (zh-Hans/zh-Hant both pack as "zh"); callers map that to
2423
+ /// their supported variant. Falls back to "en" when no preference is set.
2424
+ #[no_mangle]
2425
+ pub extern "C" fn bloom_get_language() -> f64 {
2426
+ fn pack(code: &str) -> f64 {
2427
+ let lower = code.to_ascii_lowercase();
2428
+ let b = lower.as_bytes();
2429
+ if b.len() >= 2 { (b[0] as f64) * 256.0 + (b[1] as f64) } else { 101.0 * 256.0 + 110.0 }
2430
+ }
2431
+ let langs = objc2_foundation::NSLocale::preferredLanguages();
2432
+ match langs.firstObject() {
2433
+ Some(s) => pack(&s.to_string()),
2434
+ None => pack("en"),
2435
+ }
2436
+ }
2418
2437
  #[no_mangle]
2419
2438
  pub extern "C" fn bloom_is_any_input_pressed() -> f64 {
2420
2439
  if engine().input.is_any_input_pressed() { 1.0 } else { 0.0 }
@@ -22,7 +22,7 @@ panic = "abort"
22
22
  [dependencies]
23
23
  bloom-shared = { path = "../shared", default-features = false, features = ["mp3"] }
24
24
  objc2 = "0.6"
25
- objc2-foundation = { version = "0.3", features = ["NSDate", "NSRunLoop", "NSString", "NSThread", "NSObject"] }
25
+ objc2-foundation = { version = "0.3", features = ["NSDate", "NSRunLoop", "NSString", "NSThread", "NSObject", "NSLocale", "NSArray"] }
26
26
  raw-window-handle = "0.6"
27
27
  wgpu = "29"
28
28
  # Needed by bloom_set_env_clear_from_hdr (HDR env-map decode); mirrors macOS.
@@ -3046,6 +3046,14 @@ pub extern "C" fn bloom_inject_gamepad_button_up(button: f64) {
3046
3046
  }
3047
3047
  #[no_mangle]
3048
3048
  pub extern "C" fn bloom_get_platform() -> f64 { 6.0 }
3049
+
3050
+ /// Preferred OS language packed as `c0*256+c1` (ISO-639 primary subtag). See macos lib for format.
3051
+ #[no_mangle]
3052
+ pub extern "C" fn bloom_get_language() -> f64 {
3053
+ fn pack(code: &str) -> f64 { let l = code.to_ascii_lowercase(); let b = l.as_bytes(); if b.len() >= 2 { (b[0] as f64) * 256.0 + (b[1] as f64) } else { 25966.0 } }
3054
+ let langs = objc2_foundation::NSLocale::preferredLanguages();
3055
+ match langs.firstObject() { Some(s) => pack(&s.to_string()), None => 25966.0 }
3056
+ }
3049
3057
  #[no_mangle]
3050
3058
  pub extern "C" fn bloom_get_crown_rotation() -> f64 {
3051
3059
  engine().input.consume_crown_rotation()
@@ -206,6 +206,10 @@ pub extern "C" fn perry_scene_will_connect(_scene: *const c_void) {}
206
206
  #[no_mangle]
207
207
  pub extern "C" fn bloom_get_platform() -> f64 { 8.0 }
208
208
 
209
+ /// Preferred OS language packed as `c0*256+c1`. TODO: real per-OS detection; returns "en" for now.
210
+ #[no_mangle]
211
+ pub extern "C" fn bloom_get_language() -> f64 { 25966.0 }
212
+
209
213
  #[no_mangle]
210
214
  pub extern "C" fn bloom_get_crown_rotation() -> f64 { consume_crown() }
211
215
 
@@ -1937,6 +1937,9 @@ pub fn bloom_get_platform() -> f64 {
1937
1937
  7.0 // Web platform ID
1938
1938
  }
1939
1939
 
1940
+ #[wasm_bindgen]
1941
+ pub fn bloom_get_language() -> f64 { 25966.0 } // TODO: navigator.language via JS host glue
1942
+
1940
1943
  #[wasm_bindgen]
1941
1944
  pub fn bloom_is_any_input_pressed() -> f64 {
1942
1945
  if engine().input.is_any_input_pressed() { 1.0 } else { 0.0 }
@@ -1635,6 +1635,10 @@ pub extern "C" fn bloom_inject_gamepad_button_up(button: f64) {
1635
1635
  }
1636
1636
  #[no_mangle]
1637
1637
  pub extern "C" fn bloom_get_platform() -> f64 { 3.0 }
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 }
1638
1642
  #[no_mangle]
1639
1643
  pub extern "C" fn bloom_is_any_input_pressed() -> f64 {
1640
1644
  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.10",
3
+ "version": "0.4.11",
4
4
  "description": "Bloom Engine: native TypeScript game engine compiled by Perry",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -251,6 +251,7 @@
251
251
  { "name": "bloom_inject_gamepad_button_down","params": ["f64"], "returns": "void" },
252
252
  { "name": "bloom_inject_gamepad_button_up","params": ["f64"], "returns": "void" },
253
253
  { "name": "bloom_get_platform", "params": [], "returns": "f64" },
254
+ { "name": "bloom_get_language", "params": [], "returns": "f64" },
254
255
  { "name": "bloom_is_any_input_pressed", "params": [], "returns": "f64" },
255
256
  { "name": "bloom_get_crown_rotation", "params": [], "returns": "f64" },
256
257
 
package/src/core/index.ts CHANGED
@@ -97,6 +97,7 @@ declare function bloom_inject_gamepad_axis(axis: number, value: number): void;
97
97
  declare function bloom_inject_gamepad_button_down(button: number): void;
98
98
  declare function bloom_inject_gamepad_button_up(button: number): void;
99
99
  declare function bloom_get_platform(): number;
100
+ declare function bloom_get_language(): number;
100
101
  declare function bloom_is_any_input_pressed(): number;
101
102
  declare function bloom_get_crown_rotation(): number;
102
103
 
@@ -822,6 +823,11 @@ export const Platform = { UNKNOWN: 0, MACOS: 1, IOS: 2, WINDOWS: 3, LINUX: 4, AN
822
823
 
823
824
  export function getPlatform(): number { return bloom_get_platform(); }
824
825
 
826
+ /// User's preferred OS language as a packed 2-letter code (`c0 * 256 + c1`,
827
+ /// ASCII of the lowercased ISO-639 primary subtag, e.g. "en" = 101*256+110).
828
+ /// Script subtags are dropped (zh-Hans -> "zh"); callers map to their variant.
829
+ export function getLanguage(): number { return bloom_get_language(); }
830
+
825
831
  export function isMobile(): boolean {
826
832
  const p = bloom_get_platform();
827
833
  return p === 2 || p === 5;