Skip to main content

gizmo_scripting/
api_audio.rs

1//! Audio API — Lua'ya sunulan ses yönetim fonksiyonları
2
3use crate::commands::{CommandQueue, ScriptCommand};
4use gizmo_math::Vec3;
5use mlua::prelude::*;
6use std::sync::Arc;
7
8/// Audio API fonksiyonlarını Lua'ya kaydeder
9pub fn register_audio_api(lua: &Lua, command_queue: Arc<CommandQueue>) -> Result<(), LuaError> {
10    let audio_table = lua.create_table()?;
11
12    // === SES ÇALMA ===
13    {
14        let cq = command_queue.clone();
15        audio_table.set(
16            "play",
17            lua.create_function(move |_, sound_name: String| {
18                cq.push(ScriptCommand::PlaySound(sound_name));
19                Ok(())
20            })?,
21        )?;
22    }
23
24    // === 3D SES ÇALMA ===
25    {
26        let cq = command_queue.clone();
27        audio_table.set(
28            "play_3d",
29            lua.create_function(move |_, (sound_name, x, y, z): (String, f32, f32, f32)| {
30                cq.push(ScriptCommand::PlaySound3D(sound_name, Vec3::new(x, y, z)));
31                Ok(())
32            })?,
33        )?;
34    }
35
36    // === SES DURDURMA ===
37    {
38        let cq = command_queue.clone();
39        audio_table.set(
40            "stop",
41            lua.create_function(move |_, sound_name: String| {
42                cq.push(ScriptCommand::StopSound(sound_name));
43                Ok(())
44            })?,
45        )?;
46    }
47
48    lua.globals().set("audio", audio_table)?;
49    Ok(())
50}