feat: WASMビルド完全対応+finiシステム修正 🎉
## WASMビルド対応 - TimerBox、AudioBox等の問題のあるBoxをWASM環境では条件付きコンパイルで除外 - WebBox (WebDisplayBox, WebConsoleBox, WebCanvasBox) にas_anyメソッド追加 - プラグイン関連コードに#[cfg]ガードを追加 - web-sysフィーチャーを追加(Performance、MouseEvent等) - projects/nyash-wasmのビルドが完全に通るように! ## finiシステム修正 - フィールド差し替え時の自動fini削除(Nyashの明示的哲学に従う) - スコープ離脱時のみfini実行(meは除外) - ドキュメント更新で正しいfiniルールを明記 ## その他 - CLAUDE.mdにWASMビルド方法を追記(wasm-pack build --target web) - 開発サーバー起動方法を記載(python3 -m http.server 8010) - cargo testで全テスト成功を確認 これでNyashがブラウザで動作可能に!🐱✨ 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -66,38 +66,14 @@ use web_sys::{
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct AudioBox {
|
||||
base: BoxBase,
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
context: Option<AudioContext>,
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
gain_node: Option<GainNode>,
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
analyser_node: Option<AnalyserNode>,
|
||||
volume: f64,
|
||||
is_playing: bool,
|
||||
}
|
||||
|
||||
impl AudioBox {
|
||||
pub fn new() -> Self {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
let context = AudioContext::new().ok();
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
let (gain_node, analyser_node) = if let Some(ctx) = &context {
|
||||
let gain = ctx.create_gain().ok();
|
||||
let analyser = ctx.create_analyser().ok();
|
||||
(gain, analyser)
|
||||
} else {
|
||||
(None, None)
|
||||
};
|
||||
|
||||
Self {
|
||||
base: BoxBase::new(),
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
context,
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
gain_node,
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
analyser_node,
|
||||
volume: 1.0,
|
||||
is_playing: false,
|
||||
}
|
||||
|
||||
@ -60,10 +60,16 @@ pub mod math_box;
|
||||
pub mod time_box;
|
||||
pub mod debug_box;
|
||||
pub mod random_box;
|
||||
// These boxes use web APIs that require special handling in WASM
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub mod timer_box;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub mod canvas_event_box;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub mod canvas_loop_box;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub mod audio_box;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub mod qr_box;
|
||||
pub mod sound_box;
|
||||
pub mod map_box;
|
||||
@ -85,10 +91,15 @@ pub use math_box::{MathBox, FloatBox};
|
||||
pub use time_box::{TimeBox, DateTimeBox};
|
||||
pub use debug_box::DebugBox;
|
||||
pub use random_box::RandomBox;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub use timer_box::TimerBox;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub use canvas_event_box::CanvasEventBox;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub use canvas_loop_box::CanvasLoopBox;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub use audio_box::AudioBox;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub use qr_box::QRBox;
|
||||
pub use sound_box::SoundBox;
|
||||
pub use map_box::MapBox;
|
||||
|
||||
@ -52,25 +52,18 @@ use std::any::Any;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use web_sys::{window, Performance};
|
||||
use web_sys::window;
|
||||
|
||||
/// タイマー管理Box
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct TimerBox {
|
||||
base: BoxBase,
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
performance: Option<Performance>,
|
||||
}
|
||||
|
||||
impl TimerBox {
|
||||
pub fn new() -> Self {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
let performance = window().and_then(|w| w.performance().ok());
|
||||
|
||||
Self {
|
||||
base: BoxBase::new(),
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
performance,
|
||||
}
|
||||
}
|
||||
|
||||
@ -78,8 +71,12 @@ impl TimerBox {
|
||||
pub fn now(&self) -> f64 {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
{
|
||||
if let Some(perf) = &self.performance {
|
||||
perf.now()
|
||||
if let Some(window) = window() {
|
||||
if let Ok(perf) = window.performance() {
|
||||
perf.now()
|
||||
} else {
|
||||
js_sys::Date::now()
|
||||
}
|
||||
} else {
|
||||
js_sys::Date::now()
|
||||
}
|
||||
|
||||
@ -275,6 +275,9 @@ impl BoxCore for WebCanvasBox {
|
||||
write!(f, "WebCanvasBox({}, {}x{})", self.canvas_id, self.width, self.height)
|
||||
}
|
||||
|
||||
fn as_any(&self) -> &dyn Any {
|
||||
self
|
||||
}
|
||||
|
||||
fn as_any_mut(&mut self) -> &mut dyn Any {
|
||||
self
|
||||
|
||||
@ -152,6 +152,9 @@ impl BoxCore for WebConsoleBox {
|
||||
write!(f, "WebConsoleBox({})", self.target_element_id)
|
||||
}
|
||||
|
||||
fn as_any(&self) -> &dyn Any {
|
||||
self
|
||||
}
|
||||
|
||||
fn as_any_mut(&mut self) -> &mut dyn Any {
|
||||
self
|
||||
|
||||
@ -145,6 +145,9 @@ impl BoxCore for WebDisplayBox {
|
||||
write!(f, "WebDisplayBox({})", self.target_element_id)
|
||||
}
|
||||
|
||||
fn as_any(&self) -> &dyn Any {
|
||||
self
|
||||
}
|
||||
|
||||
fn as_any_mut(&mut self) -> &mut dyn Any {
|
||||
self
|
||||
|
||||
Reference in New Issue
Block a user