audio.d 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. module scripts.lua.audio;
  2. import bindbc.lua;
  3. import raylib;
  4. import variables;
  5. import graphics.effects;
  6. import std.conv;
  7. import system.abstraction;
  8. import system.config;
  9. import std.string;
  10. import std.algorithm;
  11. import system.init;
  12. import graphics.playback;
  13. import std.file;
  14. import graphics.collision;
  15. import audio.sfx;
  16. extern (C) nothrow int luaL_loadMusic(lua_State* L)
  17. {
  18. try
  19. {
  20. char* musicPath = cast(char*)luaL_checkstring(L, 1);
  21. music = LoadMusicStream(musicPath);
  22. }
  23. catch (Exception e)
  24. {
  25. debugWriteln(e.msg);
  26. }
  27. return 0;
  28. }
  29. extern (C) nothrow int luaL_playMusic(lua_State* L)
  30. {
  31. PlayMusicStream(music);
  32. return 0;
  33. }
  34. extern (C) nothrow int luaL_stopMusic(lua_State* L)
  35. {
  36. StopMusicStream(music);
  37. return 0;
  38. }
  39. extern (C) nothrow int luaL_unloadMusic(lua_State* L)
  40. {
  41. UnloadMusicStream(music);
  42. music = Music();
  43. return 0;
  44. }
  45. extern (C) nothrow int luaL_setMusicVolume(lua_State *L) {
  46. SetMusicVolume(music, luaL_checknumber(L, 1));
  47. return 0;
  48. }
  49. extern (C) nothrow int luaL_playSfx(lua_State *L) {
  50. try {
  51. playSfx(to!string(luaL_checkstring(L, 1)));
  52. } catch (Exception e) {
  53. debugWriteln(e.msg);
  54. }
  55. return 0;
  56. }
  57. extern (C) nothrow int luaL_stopSfx(lua_State *L) {
  58. StopSound(sfx);
  59. return 0;
  60. }