audio.d 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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.debugwriteln;
  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. if (systemSettings.soundState != false) PlayMusicStream(music);
  32. return 0;
  33. }
  34. extern (C) nothrow int luaL_stopMusic(lua_State* L)
  35. {
  36. if (systemSettings.soundState != false) 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_loadSfx(lua_State *L) {
  50. try {
  51. int index = cast(int)luaL_checkinteger(L, 1);
  52. string filename = to!string(luaL_checkstring(L, 2));
  53. loadSfx(index, filename);
  54. } catch (Exception e) {
  55. debugWriteln(e.msg);
  56. }
  57. return 0;
  58. }
  59. extern (C) nothrow int luaL_playSfx(lua_State *L) {
  60. try {
  61. playSfx(cast(int)(luaL_checkinteger(L, 1)));
  62. } catch (Exception e) {
  63. debugWriteln(e.msg);
  64. }
  65. return 0;
  66. }
  67. extern (C) nothrow int luaL_stopSfx(lua_State *L) {
  68. int index = cast(int)luaL_checkinteger(L, 1);
  69. if (systemSettings.soundState != false) StopSound(sfx[index]);
  70. return 0;
  71. }
  72. extern (C) nothrow int luaL_setSfxVolume(lua_State *L) {
  73. int index = cast(int)luaL_checkinteger(L, 1);
  74. float volumeValue = cast(float)luaL_checknumber(L, 2);
  75. SetSoundVolume(sfx[index], volumeValue);
  76. return 0;
  77. }
  78. extern (C) nothrow int luaL_unloadSfx(lua_State *L) {
  79. int index = cast(int)luaL_checkinteger(L, 1);
  80. UnloadSound(sfx[index]);
  81. return 0;
  82. }