diff --git a/audio/13925__adcbicycle__21.ogg b/audio/13925__adcbicycle__21.ogg new file mode 100644 index 0000000..5b76eaa --- /dev/null +++ b/audio/13925__adcbicycle__21.ogg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b9d30306535105c1070730f40aba8894d7c4b19d702bb95ef5ff2c78471b3cd5 +size 7662 diff --git a/audio/255571__stradie__flipping-paper.ogg b/audio/255571__stradie__flipping-paper.ogg new file mode 100644 index 0000000..cae74b7 --- /dev/null +++ b/audio/255571__stradie__flipping-paper.ogg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9442ccf84f7f2e856c16519b0cb060e1b36f4096db7c0a07889c94dd826a77bc +size 45403 diff --git a/audio/398751__anthousai__door-lock-01.ogg b/audio/398751__anthousai__door-lock-01.ogg new file mode 100644 index 0000000..f79dd21 --- /dev/null +++ b/audio/398751__anthousai__door-lock-01.ogg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:659d78850496656075215ccd50ae62a64b4de7e4dc13c3c0191a964822481255 +size 10364 diff --git a/audio/459618__n-lerche__blow.ogg b/audio/459618__n-lerche__blow.ogg new file mode 100644 index 0000000..957b415 --- /dev/null +++ b/audio/459618__n-lerche__blow.ogg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4a55d5a4968a28ae948b72d0092b6a64beeb2d14bda4c2010a12890a0a4cec03 +size 42794 diff --git a/audio/537061__imafoley__message-pop-sound.ogg b/audio/537061__imafoley__message-pop-sound.ogg new file mode 100644 index 0000000..c431da3 --- /dev/null +++ b/audio/537061__imafoley__message-pop-sound.ogg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:624b696ed4ffa4e72cbcbc2a7005c7f282b4baaec921bb2be1f6853c3e15b097 +size 7916 diff --git a/audio/547041__cogfirestudios__hit-swing-sword-small-3.ogg b/audio/547041__cogfirestudios__hit-swing-sword-small-3.ogg new file mode 100644 index 0000000..f1be8e0 --- /dev/null +++ b/audio/547041__cogfirestudios__hit-swing-sword-small-3.ogg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fd6b8506121e1ac9807a8fb2689f7c0cfca48777c08810b613ba761fc33d76c4 +size 19353 diff --git a/audio/587036__antoineromo__bed-sheets.ogg b/audio/587036__antoineromo__bed-sheets.ogg new file mode 100644 index 0000000..ed0d4cb --- /dev/null +++ b/audio/587036__antoineromo__bed-sheets.ogg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:12d04399abfe2441f51dc8b5e268aebc734ba707de161239aa90b808ade630da +size 35946 diff --git a/audio/656126__itsthegoodstuff__paging-through-book.ogg b/audio/656126__itsthegoodstuff__paging-through-book.ogg new file mode 100644 index 0000000..0f64f91 --- /dev/null +++ b/audio/656126__itsthegoodstuff__paging-through-book.ogg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ad3034bc469fba569d8569881676c27f5bbec40533d5255291bef6d379bfe4c9 +size 21567 diff --git a/audio/702171__foxfire__door-opening.ogg b/audio/702171__foxfire__door-opening.ogg new file mode 100644 index 0000000..2c7c861 --- /dev/null +++ b/audio/702171__foxfire__door-opening.ogg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9e725a730b1387a9df7bb0125f3dd7ccba1ca27e8422ee3c55b3bde4d8ce4124 +size 17136 diff --git a/audio/751089__smallconfusion__mechanical-plastic-click-11.ogg b/audio/751089__smallconfusion__mechanical-plastic-click-11.ogg new file mode 100644 index 0000000..2ca58ce --- /dev/null +++ b/audio/751089__smallconfusion__mechanical-plastic-click-11.ogg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6a548df89a87919e3fd4bde3fa8eb2da883c402b7feeae7c0603d7d98d35399a +size 5105 diff --git a/audio/78564__joedeshon__alarm_clock_ticking_02.ogg b/audio/78564__joedeshon__alarm_clock_ticking_02.ogg new file mode 100644 index 0000000..4d0cee4 --- /dev/null +++ b/audio/78564__joedeshon__alarm_clock_ticking_02.ogg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c1756c0ece8080c799cb6ca4911a2c610800089ec6a65c45ba69e990942b7af9 +size 104191 diff --git a/audio/831642__ienba__generic-game-pick-up.ogg b/audio/831642__ienba__generic-game-pick-up.ogg new file mode 100644 index 0000000..44d62da --- /dev/null +++ b/audio/831642__ienba__generic-game-pick-up.ogg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c79391d1f26978900194f9d5af1a0dc59eb62a1572f4f9011d1538a6bf09ffab +size 16067 diff --git a/audio/sound_bag001.ogg b/audio/sound_bag001.ogg new file mode 100644 index 0000000..be0d04b --- /dev/null +++ b/audio/sound_bag001.ogg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e64ea00f0355371d2e1b93818b0c686da6e699e1cdb4de26a1c9dac5640bd0fb +size 16054 diff --git a/audio/sound_bag_close.ogg b/audio/sound_bag_close.ogg new file mode 100644 index 0000000..217533a --- /dev/null +++ b/audio/sound_bag_close.ogg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bcb99f3aa14d4f53ae636fab8fadb0ed19a4be17e994088e7e41e4872002c0be +size 18569 diff --git a/audio/sound_bag_open.ogg b/audio/sound_bag_open.ogg new file mode 100644 index 0000000..1080147 --- /dev/null +++ b/audio/sound_bag_open.ogg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e17ae2d18d36892cbc634cca6b5523293c2737e97e0a94b577a8709823a5db04 +size 17077 diff --git a/resources/start_dorm.lua b/resources/start_dorm.lua index 6485245..0a76f90 100644 --- a/resources/start_dorm.lua +++ b/resources/start_dorm.lua @@ -76,6 +76,7 @@ function on_bed_sleep() local day = game_api.getIntValue("day") game_api.setIntValue("day", day + 1) print("Setting to day 1----x") + game_api.play_sound("audio/587036__antoineromo__bed-sheets.ogg") end end @@ -85,6 +86,8 @@ end function on_locked_door_click() game_api.start_dialogue("door_locked_dialog001") + game_api.play_sound("audio/398751__anthousai__door-lock-01.ogg") + --game_api.play_sound("audio/702171__foxfire__door-opening.ogg") end function on_sleep_cutscene() @@ -118,6 +121,8 @@ function alik_door_open_callback() else game_api.switch_navigation(4) --b end + + game_api.play_sound("audio/702171__foxfire__door-opening.ogg") end end @@ -156,6 +161,8 @@ function on_player_bathroom_click() else game_api.switch_navigation(1) --ca end + + game_api.play_sound("audio/702171__foxfire__door-opening.ogg") end end @@ -186,7 +193,9 @@ function on_player_door_click() else game_api.switch_navigation(2) --ba end + game_api.play_sound("audio/702171__foxfire__door-opening.ogg") end + end end diff --git a/resources/start_uni_exterior.lua b/resources/start_uni_exterior.lua index aa4a36e..98710e1 100644 --- a/resources/start_uni_exterior.lua +++ b/resources/start_uni_exterior.lua @@ -63,6 +63,14 @@ game_api.set_darklands_callbacks( end ) +game_api.set_enter_night_callback( + function() + game_api.deactivate_interactive_object("car001") + game_api.deactivate_interactive_object("car001wheels") + game_api.switch_navigation(1) + end +) + game_api.set_location_callbacks( function() diff --git a/resources/start_uni_interior.lua b/resources/start_uni_interior.lua index 43cad6a..0de0017 100644 --- a/resources/start_uni_interior.lua +++ b/resources/start_uni_interior.lua @@ -257,25 +257,6 @@ function on_npc_interact(npc_index) game_api.start_dialogue("teacher_dialog007") end end - --[[ - if (player_ghost_aware == 1) then - --game_api.setIntValue("player_has_coursework", 1) - local player_has_coursework = game_api.getIntValue("player_has_coursework") - local player_has_report_card = game_api.getIntValue("player_has_report_card") - local report_card_signed = game_api.getIntValue("report_card_signed") - - if (report_card_signed == 1) then - game_api.start_dialogue("teacher_dialog004") - elseif (player_has_coursework == 1 and player_has_report_card == 1) then - game_api.start_dialogue("teacher_dialog005") - game_api.remove_item("coursework") - game_api.setIntValue("report_card_signed", 1) - else - game_api.start_dialogue("teacher_dialog007") - end - else - game_api.start_dialogue("teacher_dialog001") - end]] end if npc_index == 2 then local report_card_signed = game_api.getIntValue("report_card_signed") @@ -320,12 +301,17 @@ function on_library_door_click() if (day == 0) then if game_api.is_dawn() then - game_api.start_dialogue("door_dialog007") + if not (morning_did_open_door_index == 5) then + game_api.start_dialogue("door_dialog007") + game_api.play_sound("audio/398751__anthousai__door-lock-01.ogg") + end elseif game_api.is_night() then game_api.start_dialogue("door_night_dialog001") + game_api.play_sound("audio/398751__anthousai__door-lock-01.ogg") else if (lection_is_over == 0) then game_api.start_dialogue("door_dialog003") + game_api.play_sound("audio/398751__anthousai__door-lock-01.ogg") end end else @@ -366,9 +352,11 @@ function on_teachers_door_click() game_api.deactivate_interactive_object("Room_Cover_South_3_001") end) game_api.switch_navigation(3) + game_api.play_sound("audio/702171__foxfire__door-opening.ogg") end else game_api.start_dialogue("door_dialog004") + game_api.play_sound("audio/398751__anthousai__door-lock-01.ogg") end else if (game_api.is_dawn()) then @@ -384,6 +372,7 @@ function on_teachers_door_click() game_api.deactivate_interactive_object("Room_Cover_Corridor_001") end) game_api.switch_navigation(10) + game_api.play_sound("audio/702171__foxfire__door-opening.ogg") else if (morning_did_open_door_index == 1) then --s1 + s3 @@ -393,6 +382,7 @@ function on_teachers_door_click() game_api.deactivate_interactive_object("Room_Cover_South_3_001") end) game_api.switch_navigation(11) + game_api.play_sound("audio/702171__foxfire__door-opening.ogg") elseif (morning_did_open_door_index == 2) then --s2 + s3 @@ -401,6 +391,7 @@ function on_teachers_door_click() game_api.deactivate_interactive_object("Room_Cover_South_3_001") end) game_api.switch_navigation(15) + game_api.play_sound("audio/702171__foxfire__door-opening.ogg") elseif (morning_did_open_door_index == 5) then --n3 + s3 @@ -409,6 +400,7 @@ function on_teachers_door_click() game_api.deactivate_interactive_object("Room_Cover_South_3_001") end) game_api.switch_navigation(13) + game_api.play_sound("audio/702171__foxfire__door-opening.ogg") elseif (morning_did_open_door_index == 4) then --n2 + s3 @@ -417,6 +409,7 @@ function on_teachers_door_click() game_api.deactivate_interactive_object("Room_Cover_South_3_001") end) game_api.switch_navigation(14) + game_api.play_sound("audio/702171__foxfire__door-opening.ogg") elseif (morning_did_open_door_index == 6) then --hall + s3 @@ -425,6 +418,7 @@ function on_teachers_door_click() game_api.deactivate_interactive_object("Room_Cover_South_3_001") end) game_api.switch_navigation(12) + game_api.play_sound("audio/702171__foxfire__door-opening.ogg") else --Player was in corridor, but tries to open the teacher's door --s3 only @@ -433,6 +427,7 @@ function on_teachers_door_click() game_api.deactivate_interactive_object("Room_Cover_South_3_001") end) game_api.switch_navigation(10) + game_api.play_sound("audio/702171__foxfire__door-opening.ogg") end end end @@ -454,6 +449,7 @@ function on_teachers_door_click() end game_api.switch_navigation(10) + game_api.play_sound("audio/702171__foxfire__door-opening.ogg") end end end @@ -466,7 +462,10 @@ function on_hall_door_click() if (day == 0) then if (game_api.is_dawn()) then - game_api.start_dialogue("door_dialog007") + if not (morning_did_open_door_index == 6) then + game_api.start_dialogue("door_dialog007") + game_api.play_sound("audio/398751__anthousai__door-lock-01.ogg") + end else if (not hall_door_opened) then hall_door_opened = true @@ -478,12 +477,14 @@ function on_hall_door_click() game_api.set_npc_enabled(0, true) game_api.set_npc_enabled(6, true) game_api.npc_rotate_to(6, 180) + game_api.play_sound("audio/702171__foxfire__door-opening.ogg") end end else if (game_api.is_night()) then if not (morning_did_open_door_index == 6) then game_api.start_dialogue("door_dialog001") + game_api.play_sound("audio/398751__anthousai__door-lock-01.ogg") end end end @@ -492,14 +493,19 @@ end function on_s1_door_click() local day = game_api.getIntValue("day") if (day == 0) and(game_api.is_dawn()) then - game_api.start_dialogue("door_dialog007") + if not (morning_did_open_door_index == 1) then + game_api.start_dialogue("door_dialog007") + game_api.play_sound("audio/398751__anthousai__door-lock-01.ogg") + end else if (game_api.is_night()) then if not (morning_did_open_door_index == 1) then game_api.start_dialogue("door_dialog001") + game_api.play_sound("audio/398751__anthousai__door-lock-01.ogg") end else game_api.start_dialogue("door_dialog006") + game_api.play_sound("audio/398751__anthousai__door-lock-01.ogg") end end end @@ -507,14 +513,19 @@ end function on_s2_door_click() local day = game_api.getIntValue("day") if (day == 0) and(game_api.is_dawn()) then - game_api.start_dialogue("door_dialog007") + if not (morning_did_open_door_index == 2) then + game_api.start_dialogue("door_dialog007") + game_api.play_sound("audio/398751__anthousai__door-lock-01.ogg") + end else if (game_api.is_night()) then if not (morning_did_open_door_index == 2) then game_api.start_dialogue("door_dialog001") + game_api.play_sound("audio/398751__anthousai__door-lock-01.ogg") end else game_api.start_dialogue("door_dialog006") + game_api.play_sound("audio/398751__anthousai__door-lock-01.ogg") end end end @@ -522,11 +533,15 @@ end function on_n2_door_click() local day = game_api.getIntValue("day") if (day == 0) and(game_api.is_dawn()) then - game_api.start_dialogue("door_dialog007") + if not (morning_did_open_door_index == 4) then + game_api.start_dialogue("door_dialog007") + game_api.play_sound("audio/398751__anthousai__door-lock-01.ogg") + end else if (game_api.is_night()) then if not (morning_did_open_door_index == 4) then game_api.start_dialogue("door_dialog001") + game_api.play_sound("audio/398751__anthousai__door-lock-01.ogg") end end end @@ -641,6 +656,7 @@ function on_teacher_arrived_intermediate() game_api.switch_navigation(2) game_api.npc_walk_to(0, 4.94194, 0, 6.64111, on_teacher_arrived) teacher_arrived = true + game_api.play_sound("audio/702171__foxfire__door-opening.ogg") end function on_lection_cutscene_fadein_callback() @@ -1226,6 +1242,8 @@ function on_aiperi_opens_door() game_api.start_dialogue("dialog_aiperi_morning001") end) game_api.player_walk_to(0.0, 0.0, 10.0, nil) + + game_api.play_sound("audio/702171__foxfire__door-opening.ogg") end elseif (morning_can_open_door_index == 5) then if (morning_did_open_door_index == 0) then @@ -1252,6 +1270,8 @@ function on_aiperi_opens_door() game_api.start_dialogue("dialog_aiperi_morning001") end) game_api.player_walk_to(3.52174, 0, 6.28993, nil) + + game_api.play_sound("audio/702171__foxfire__door-opening.ogg") end elseif (morning_can_open_door_index == 4) then if (morning_did_open_door_index == 0) then @@ -1278,6 +1298,8 @@ function on_aiperi_opens_door() game_api.start_dialogue("dialog_aiperi_morning001") end) game_api.player_walk_to(3.36055, 0, -2.0345, nil) + + game_api.play_sound("audio/702171__foxfire__door-opening.ogg") end elseif (morning_can_open_door_index == 2) then if (morning_did_open_door_index == 0) then @@ -1304,6 +1326,8 @@ function on_aiperi_opens_door() game_api.start_dialogue("dialog_aiperi_morning001") end) game_api.player_walk_to(-3.63363, 0, -1.50727, nil) + + game_api.play_sound("audio/702171__foxfire__door-opening.ogg") end elseif (morning_can_open_door_index == 1) then if (morning_did_open_door_index == 0) then @@ -1330,6 +1354,8 @@ function on_aiperi_opens_door() game_api.start_dialogue("dialog_aiperi_morning001") end) game_api.player_walk_to(-3.64494, 0, -9.66711, nil) + + game_api.play_sound("audio/702171__foxfire__door-opening.ogg") end end end diff --git a/src/Character.cpp b/src/Character.cpp index 9379d83..52d4d51 100644 --- a/src/Character.cpp +++ b/src/Character.cpp @@ -419,6 +419,17 @@ void Character::update(int64_t deltaMs, const CharacterResolver& resolver) { state.currentState == AnimationState::ACTION_ATTACK_2)) { if (attackTarget != nullptr) { attackTarget->applyDamage(10.f, attackDirectionToTarget()); + + if (audioPlayer) { + if (state.isPlayer) + { + audioPlayer->playSoundAsync("audio/547041__cogfirestudios__hit-swing-sword-small-3.ogg"); + } + else + { + audioPlayer->playSoundAsync("audio/13925__adcbicycle__21.ogg"); + } + } } } @@ -1176,8 +1187,8 @@ void Character::drawNightCpuWithShadow(Renderer& renderer, void Character::setupHitSparks(std::shared_ptr sparkTexture) { hitSparkEmitter.setTexture(sparkTexture); hitSparkEmitter.setShaderProgramName("spark"); - hitSparkEmitter.setMaxParticles(64); - hitSparkEmitter.setParticleSize(0.08f); + hitSparkEmitter.setMaxParticles(128); + hitSparkEmitter.setParticleSize(0.02f); hitSparkEmitter.setBiasX(0.0f); hitSparkEmitter.setEmissionRate(1.0e9f); hitSparkEmitter.setSpeedRange(2.0f, 4.0f); diff --git a/src/Character.h b/src/Character.h index f537725..20544ad 100644 --- a/src/Character.h +++ b/src/Character.h @@ -12,6 +12,7 @@ #include #include #include "dialogue/TranslationDatabase.h" +#include "AudioPlayerAsync.h" namespace ZL { @@ -107,6 +108,7 @@ public: std::string weaponAttachBoneName = "RightHand"; SparkEmitter hitSparkEmitter; + AudioPlayerAsync* audioPlayer; static Dialogue::TranslationDatabase nameTranslations; diff --git a/src/Game.cpp b/src/Game.cpp index 3d704ee..aada736 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -16,7 +16,6 @@ #include #endif - #ifdef EMSCRIPTEN #include #endif @@ -258,10 +257,12 @@ namespace ZL menuManager.onItemPickedUp(itemId); const Item* item = ItemRegistry::instance().findById(itemId); if (item) menuManager.showToast(menuManager.toastTextureItemAdded, item->name); + audioPlayer->playSoundAsync("audio/831642__ienba__generic-game-pick-up.ogg"); }; gameState.inventory.onItemRemoved = [this](const std::string& itemId) { const Item* item = ItemRegistry::instance().findById(itemId); if (item) menuManager.showToast(menuManager.toastTextureItemRemoved, item->name); + audioPlayer->playSoundAsync("audio/831642__ienba__generic-game-pick-up.ogg"); }; // Wire phone dialogue start function so MenuManager can trigger dialogues. @@ -433,7 +434,7 @@ namespace ZL uniInteriorParams.playerPosition = Eigen::Vector3f(0.942694, 0, -9.63104); gameState.locations["uni_interior"] = std::make_shared(renderer, gameState.inventory); - gameState.locations["uni_interior"]->setup(uniInteriorParams, &gameState.questJournal); + gameState.locations["uni_interior"]->setup(uniInteriorParams, &gameState.questJournal, audioPlayer.get()); gameState.locations["uni_interior"]->scriptEngine.setGlobalStore(&gameState.globalInts); gameState.locations["uni_interior"]->scriptEngine.setGlobalFloatStore(&gameState.globalFloats); gameState.locations["uni_interior"]->requestNightDayTransition = [this](bool isNight, bool isDawn) { gameState.isNight = isNight; gameState.isDawn = isDawn; }; @@ -487,7 +488,7 @@ namespace ZL gameState.locations["uni_exterior"] = std::make_shared(renderer, gameState.inventory); - gameState.locations["uni_exterior"]->setup(uniExteriorParams, &gameState.questJournal); + gameState.locations["uni_exterior"]->setup(uniExteriorParams, &gameState.questJournal, audioPlayer.get()); gameState.locations["uni_exterior"]->scriptEngine.setGlobalStore(&gameState.globalInts); gameState.locations["uni_exterior"]->scriptEngine.setGlobalFloatStore(&gameState.globalFloats); gameState.locations["uni_exterior"]->requestNightDayTransition = [this](bool isNight, bool isDawn) { @@ -547,7 +548,7 @@ namespace ZL params_dorm.playerPosition = Eigen::Vector3f(6.76345, 0, -14.6022); gameState.locations["location_dorm"] = std::make_shared(renderer, gameState.inventory); - gameState.locations["location_dorm"]->setup(params_dorm, &gameState.questJournal); + gameState.locations["location_dorm"]->setup(params_dorm, &gameState.questJournal, audioPlayer.get()); gameState.locations["location_dorm"]->scriptEngine.setGlobalStore(&gameState.globalInts); gameState.locations["location_dorm"]->scriptEngine.setGlobalFloatStore(&gameState.globalFloats); gameState.locations["location_dorm"]->requestNightDayTransition = [this](bool isNight, bool isDawn) { gameState.isNight = isNight; gameState.isDawn = isDawn; }; @@ -1482,6 +1483,7 @@ namespace ZL bool Game::startDarklandsTransition() { + audioPlayer->playSoundAsync("audio/459618__n-lerche__blow.ogg"); if (!gameState.isNight) { currentLocation()->dialogueSystem.startDialogue("darklands_day_dialog001"); diff --git a/src/Location.cpp b/src/Location.cpp index d929574..b441005 100644 --- a/src/Location.cpp +++ b/src/Location.cpp @@ -83,7 +83,7 @@ namespace ZL // ---- Setup ---- - void Location::setup(const LocationSetup& params, Quest::QuestJournal* journal) + void Location::setup(const LocationSetup& params, Quest::QuestJournal* journal, AudioPlayerAsync* audioPlayer) { // Load static game objects @@ -138,6 +138,7 @@ namespace ZL player->state.position = params.playerPosition; player->setTarget(params.playerPosition); player->setupHitSparks(sparkTexture); + player->audioPlayer = audioPlayer; std::cout << "Load resurces step 9" << std::endl; // Load NPCs from JSON. Aggressive (canAttack) NPCs need a player target @@ -149,6 +150,7 @@ namespace ZL npc->state.homePosition = Eigen::Vector3f(npc->state.position.x(), 0.f, npc->state.position.z()); if (npc->state.canAttack) { npc->setupHitSparks(sparkTexture); + npc->audioPlayer = audioPlayer; npc->state.attackTargetIndex = CharacterState::kPlayerIndex; } } @@ -179,7 +181,7 @@ namespace ZL npcNameText.reset(); } - scriptEngine.init(this, &inventory, params.scriptPath); + scriptEngine.init(this, &inventory, audioPlayer, params.scriptPath); scriptEngine.setQuestJournal(journal); dialogueSystem.setOnCutsceneFinished([this](const std::string& cutsceneId) { diff --git a/src/Location.h b/src/Location.h index a9b570f..d7f8a82 100644 --- a/src/Location.h +++ b/src/Location.h @@ -133,7 +133,7 @@ namespace ZL bool playBattleMusic = false; - void setup(const LocationSetup& params, Quest::QuestJournal* journal); + void setup(const LocationSetup& params, Quest::QuestJournal* journal, AudioPlayerAsync* audioPlayer); void setupNavigation(const std::vector& paths); bool switchNavigation(int index); InteractiveObject* raycastInteractiveObjects(const Eigen::Vector3f& rayOrigin, const Eigen::Vector3f& rayDir); @@ -170,6 +170,7 @@ namespace ZL friend class LocationEditor; Renderer& renderer; Inventory& inventory; + AudioPlayerAsync* audioPlayer; private: // ---- Pointer-to-index helpers ---- diff --git a/src/MenuManager.cpp b/src/MenuManager.cpp index 0750176..1eb9f5d 100644 --- a/src/MenuManager.cpp +++ b/src/MenuManager.cpp @@ -331,25 +331,32 @@ namespace ZL { uiManager.replaceRoot(mainMenuRoot); uiManager.setTextButtonCallback("menuStartButton", [this](const std::string&) { + audioPlayer_.playSoundAsync("audio/751089__smallconfusion__mechanical-plastic-click-11.ogg"); enterGameplay(); + }); uiManager.setTextButtonCallback("menuAboutButton", [this](const std::string&) { showAboutScreen(); + audioPlayer_.playSoundAsync("audio/751089__smallconfusion__mechanical-plastic-click-11.ogg"); }); uiManager.setTextButtonCallback("menuSettingsButton", [this](const std::string&) { showSettingsScreen(); + audioPlayer_.playSoundAsync("audio/751089__smallconfusion__mechanical-plastic-click-11.ogg"); }); uiManager.setTextButtonCallback("menuLanguageButton", [this](const std::string&) { showLanguageScreen(); + audioPlayer_.playSoundAsync("audio/751089__smallconfusion__mechanical-plastic-click-11.ogg"); }); uiManager.setTextButtonCallback("menuLoadButton", [this](const std::string&) { showLoadGameScreen(); + audioPlayer_.playSoundAsync("audio/751089__smallconfusion__mechanical-plastic-click-11.ogg"); }); #ifndef EMSCRIPTEN uiManager.setTextButtonCallback("menuExitButton", [this](const std::string&) { + audioPlayer_.playSoundAsync("audio/751089__smallconfusion__mechanical-plastic-click-11.ogg"); Environment::exitGameLoop = true; }); #else @@ -362,6 +369,7 @@ namespace ZL { uiManager.setTextButtonCallback("aboutBackButton", [this](const std::string&) { uiManager.popMenu(); uiManager.updateAllLayouts(); + audioPlayer_.playSoundAsync("audio/751089__smallconfusion__mechanical-plastic-click-11.ogg"); }); } @@ -371,6 +379,7 @@ namespace ZL { saveSettings(); uiManager.popMenu(); uiManager.updateAllLayouts(); + audioPlayer_.playSoundAsync("audio/751089__smallconfusion__mechanical-plastic-click-11.ogg"); }); // Set initial slider positions before registering callbacks so @@ -456,6 +465,7 @@ namespace ZL { uiManager.setTextButtonColor("musicToggleButton", on ? std::array{ 0.2f, 0.9f, 0.2f, 1.0f } : std::array{ 0.9f, 0.2f, 0.2f, 1.0f }); + audioPlayer_.playSoundAsync("audio/751089__smallconfusion__mechanical-plastic-click-11.ogg"); }); uiManager.setTextButtonCallback("soundToggleButton", [this](const std::string&) { audioPlayer_.setSoundEnabled(!audioPlayer_.isSoundEnabled()); @@ -464,10 +474,12 @@ namespace ZL { uiManager.setTextButtonColor("soundToggleButton", on ? std::array{ 0.2f, 0.9f, 0.2f, 1.0f } : std::array{ 0.9f, 0.2f, 0.2f, 1.0f }); + audioPlayer_.playSoundAsync("audio/751089__smallconfusion__mechanical-plastic-click-11.ogg"); }); uiManager.setTextButtonCallback("fullScreenToggleButton", [this, refreshFullscreenToggle](const std::string&) { Environment::setFullscreen(!Environment::isFullscreen); refreshFullscreenToggle(); + audioPlayer_.playSoundAsync("audio/751089__smallconfusion__mechanical-plastic-click-11.ogg"); }); } @@ -477,14 +489,17 @@ namespace ZL { saveSettings(); uiManager.popMenu(); uiManager.updateAllLayouts(); + audioPlayer_.playSoundAsync("audio/751089__smallconfusion__mechanical-plastic-click-11.ogg"); }); uiManager.setTextButtonCallback("languageRussianButton", [this](const std::string&) { + audioPlayer_.playSoundAsync("audio/751089__smallconfusion__mechanical-plastic-click-11.ogg"); ZL::g_currentLanguage = ZL::Language::Russian; reloadLocalizedGameContent(); saveSettings(); }); uiManager.setTextButtonCallback("languageEnglishButton", [this](const std::string&) { + audioPlayer_.playSoundAsync("audio/751089__smallconfusion__mechanical-plastic-click-11.ogg"); ZL::g_currentLanguage = ZL::Language::English; reloadLocalizedGameContent(); saveSettings(); @@ -528,6 +543,7 @@ namespace ZL { uiManager.setTextButtonCallback("loadBackButton", [this](const std::string&) { uiManager.popMenu(); uiManager.updateAllLayouts(); + audioPlayer_.playSoundAsync("audio/751089__smallconfusion__mechanical-plastic-click-11.ogg"); }); static const char* kSlotButtons[4] = { @@ -543,6 +559,7 @@ namespace ZL { uiManager.setTextButtonText(kSlotButtons[i], label); } uiManager.setTextButtonCallback(kSlotButtons[i], [this, slot](const std::string&) { + audioPlayer_.playSoundAsync("audio/751089__smallconfusion__mechanical-plastic-click-11.ogg"); if (onLoadGame) onLoadGame(slot); enterGameplay(true); }); @@ -555,6 +572,7 @@ namespace ZL { uiManager.setTextButtonCallback("saveBackButton", [this](const std::string&) { uiManager.popMenu(); uiManager.updateAllLayouts(); + audioPlayer_.playSoundAsync("audio/751089__smallconfusion__mechanical-plastic-click-11.ogg"); }); static const char* kSlotButtons[4] = { @@ -578,6 +596,7 @@ namespace ZL { ? "Empty" : localizedLocationName[info.locationName][ZL::g_currentLanguage] + "\n" + info.savedAt; uiManager.setTextButtonText(buttonName, label); + audioPlayer_.playSoundAsync("audio/751089__smallconfusion__mechanical-plastic-click-11.ogg"); } }); } @@ -607,6 +626,7 @@ namespace ZL { } uiManager.setButtonCallback(btnName, [this, i](const std::string&) { selectInventoryItem(i); + audioPlayer_.playSoundAsync("audio/sound_bag001.ogg"); }); } else { uiManager.setNodeVisible(btnName, false); @@ -617,6 +637,8 @@ namespace ZL { if (!portrait && !items.empty()) { selectInventoryItem(0); } + + audioPlayer_.playSoundAsync("audio/sound_bag_open.ogg"); } void MenuManager::selectInventoryItem(int index) { @@ -668,6 +690,7 @@ namespace ZL { for (int i = 0; i < inventoryMenuStackDepth_; ++i) uiManager.popMenu(); inventoryMenuStackDepth_ = 0; uiManager.updateAllLayouts(); + audioPlayer_.playSoundAsync("audio/sound_bag_close.ogg"); } void MenuManager::openQuestJournal() { @@ -683,6 +706,7 @@ namespace ZL { uiManager.setButtonCallback("journalExitButton", [this](const std::string&) { closeQuestJournal(); + audioPlayer_.playSoundAsync("audio/656126__itsthegoodstuff__paging-through-book.ogg"); }); static const char* kItemNames[9] = { @@ -693,6 +717,7 @@ namespace ZL { for (int i = 0; i < 9; ++i) { uiManager.setTextButtonCallback(kItemNames[i], [this, i](const std::string&) { selectQuestByIndex(i); + audioPlayer_.playSoundAsync("audio/255571__stradie__flipping-paper.ogg"); }); } @@ -700,6 +725,8 @@ namespace ZL { if (!portrait && !visibleQuestIds.empty()) { selectQuestByIndex(0); } + + audioPlayer_.playSoundAsync("audio/255571__stradie__flipping-paper.ogg"); } void MenuManager::closeQuestJournal() { @@ -750,19 +777,24 @@ namespace ZL { uiManager.setButtonCallback("phoneExitButton", [this](const std::string&) { closePhoneEntirely(); + audioPlayer_.playSoundAsync("audio/537061__imafoley__message-pop-sound.ogg"); }); uiManager.setButtonCallback("phoneMain", [this](const std::string&) {}); uiManager.setButtonCallback("phoneMessenger", [this](const std::string&) { openPhoneMessenger(); + audioPlayer_.playSoundAsync("audio/537061__imafoley__message-pop-sound.ogg"); }); uiManager.setButtonCallback("phoneBank", [this](const std::string&) { openPhoneBank(); + audioPlayer_.playSoundAsync("audio/537061__imafoley__message-pop-sound.ogg"); }); uiManager.setButtonCallback("phoneVideo", [this](const std::string&) { openPhoneVideo(); + audioPlayer_.playSoundAsync("audio/537061__imafoley__message-pop-sound.ogg"); }); uiManager.setButtonCallback("phoneTaxi", [this](const std::string&) { openPhoneTaxi(); + audioPlayer_.playSoundAsync("audio/537061__imafoley__message-pop-sound.ogg"); }); if (gameState_.isNight) @@ -786,6 +818,8 @@ namespace ZL { uiManager.setNodeVisible("phoneTimeNight", false); uiManager.setNodeVisible("phoneTimeDawn", false); } + + audioPlayer_.playSoundAsync("audio/537061__imafoley__message-pop-sound.ogg"); } void MenuManager::openPhoneMessenger() { @@ -803,19 +837,23 @@ namespace ZL { uiManager.setButtonCallback("phoneExitButton", [this](const std::string&) { closePhoneEntirely(); + audioPlayer_.playSoundAsync("audio/537061__imafoley__message-pop-sound.ogg"); }); uiManager.setButtonCallback("phoneMain", [this](const std::string&) {}); uiManager.setTextButtonCallback("chat1button", [this](const std::string&) { gameState_.chatUnread[0] = false; openPhoneChatFromList(0, isPortraitMode() ? verticalPhoneChat1Root : phoneChat1Root); + audioPlayer_.playSoundAsync("audio/537061__imafoley__message-pop-sound.ogg"); }); uiManager.setTextButtonCallback("chat2button", [this](const std::string&) { gameState_.chatUnread[1] = false; openPhoneChatFromList(1, isPortraitMode() ? verticalPhoneChat2Root : phoneChat2Root); + audioPlayer_.playSoundAsync("audio/537061__imafoley__message-pop-sound.ogg"); }); uiManager.setTextButtonCallback("chat3button", [this](const std::string&) { gameState_.chatUnread[2] = false; openPhoneChatFromList(2, isPortraitMode() ? verticalPhoneChat3Root : phoneChat3Root); + audioPlayer_.playSoundAsync("audio/537061__imafoley__message-pop-sound.ogg"); }); } @@ -851,11 +889,13 @@ namespace ZL { uiManager.setButtonCallback("phoneExitButton", [this](const std::string&) { closePhoneEntirely(); + audioPlayer_.playSoundAsync("audio/537061__imafoley__message-pop-sound.ogg"); }); uiManager.setButtonCallback("phoneMain", [this](const std::string&) {}); uiManager.setButtonCallback("buttonBack", [this](const std::string&) { uiManager.popMenu(); uiManager.updateAllLayouts(); + audioPlayer_.playSoundAsync("audio/537061__imafoley__message-pop-sound.ogg"); }); } @@ -865,15 +905,16 @@ namespace ZL { uiManager.setButtonCallback("phoneExitButton", [this](const std::string&) { closePhoneEntirely(); + audioPlayer_.playSoundAsync("audio/537061__imafoley__message-pop-sound.ogg"); }); uiManager.setButtonCallback("phoneMain", [this](const std::string&) {}); uiManager.setButtonCallback("buttonBack", [this](const std::string&) { uiManager.popMenu(); uiManager.updateAllLayouts(); + audioPlayer_.playSoundAsync("audio/537061__imafoley__message-pop-sound.ogg"); }); uiManager.setButtonCallback("videoSkip", [this](const std::string&) { closePhoneEntirely(); - if (gameState_.isNight) { startDialogueFunc("dialog_video002"); @@ -887,6 +928,7 @@ namespace ZL { } else { + audioPlayer_.playSoundAsync("audio/78564__joedeshon__alarm_clock_ticking_02.ogg"); startNightTransitionFunc(); } } @@ -911,11 +953,13 @@ namespace ZL { uiManager.setButtonCallback("phoneExitButton", [this](const std::string&) { closePhoneEntirely(); + audioPlayer_.playSoundAsync("audio/537061__imafoley__message-pop-sound.ogg"); }); uiManager.setButtonCallback("phoneMain", [this](const std::string&) {}); uiManager.setButtonCallback("buttonBack", [this](const std::string&) { uiManager.popMenu(); uiManager.updateAllLayouts(); + audioPlayer_.playSoundAsync("audio/537061__imafoley__message-pop-sound.ogg"); }); uiManager.setButtonCallback("mapGo", [this](const std::string&) { gameState_.tutorialNeedOpenTaxiScreen = false; @@ -927,7 +971,10 @@ namespace ZL { gameState_.money -= 500; closePhoneEntirely(); if (startDialogueFunc) startDialogueFunc("dialog_taxi002"); + audioPlayer_.playSoundAsync("audio/537061__imafoley__message-pop-sound.ogg"); }); + + audioPlayer_.playSoundAsync("audio/537061__imafoley__message-pop-sound.ogg"); } void MenuManager::openPhoneChatFromList(int chatIndex, std::shared_ptr chatRoot) { @@ -967,10 +1014,12 @@ namespace ZL { uiManager.setButtonCallback("phoneExitButton", [this](const std::string&) { closePhoneScreenFromChat(); + audioPlayer_.playSoundAsync("audio/537061__imafoley__message-pop-sound.ogg"); }); uiManager.setButtonCallback("phoneMain", [this](const std::string&) {}); uiManager.setTextButtonCallback("chatTitleButton", [this](const std::string&) { returnToPhoneChatList(); + audioPlayer_.playSoundAsync("audio/537061__imafoley__message-pop-sound.ogg"); }); if (chatOpenCallback) { @@ -1054,30 +1103,37 @@ namespace ZL { } void MenuManager::showModalMenuScreen() { + audioPlayer_.playSoundAsync("audio/751089__smallconfusion__mechanical-plastic-click-11.ogg"); uiManager.pushMenuFromSavedRoot(modalMenuRoot); uiManager.setButtonCallback("modalExitButton", [this](const std::string&) { + audioPlayer_.playSoundAsync("audio/751089__smallconfusion__mechanical-plastic-click-11.ogg"); uiManager.popMenu(); uiManager.updateAllLayouts(); }); uiManager.setButtonCallback("menuCloseButton", [this](const std::string&) { + audioPlayer_.playSoundAsync("audio/751089__smallconfusion__mechanical-plastic-click-11.ogg"); uiManager.popMenu(); uiManager.updateAllLayouts(); }); uiManager.setButtonCallback("menuSaveButton", [this](const std::string&) { showSaveGameScreen(); + audioPlayer_.playSoundAsync("audio/751089__smallconfusion__mechanical-plastic-click-11.ogg"); }); uiManager.setButtonCallback("menuLoadButton", [this](const std::string&) { showLoadGameScreen(); + audioPlayer_.playSoundAsync("audio/751089__smallconfusion__mechanical-plastic-click-11.ogg"); }); uiManager.setButtonCallback("menuSettingsButton", [this](const std::string&) { showSettingsScreen(); + audioPlayer_.playSoundAsync("audio/751089__smallconfusion__mechanical-plastic-click-11.ogg"); }); uiManager.setButtonCallback("menuExitButton", [this](const std::string&) { + audioPlayer_.playSoundAsync("audio/751089__smallconfusion__mechanical-plastic-click-11.ogg"); uiManager.popMenu(); showMainMenu(); }); @@ -1441,6 +1497,7 @@ namespace ZL { uiManager.setButtonCallback("inventoryExitButton", [this](const std::string&) { closePortraitInventoryItem(); + audioPlayer_.playSoundAsync("audio/sound_bag001.ogg"); }); const auto& item = items[index]; @@ -1468,6 +1525,7 @@ namespace ZL { uiManager.setButtonCallback("journalItemExitButton", [this](const std::string&) { closePortraitJournalItem(); + audioPlayer_.playSoundAsync("audio/255571__stradie__flipping-paper.ogg"); }); Quest::QuestState* quest = gameState_.questJournal.findQuest(visibleQuestIds[index]); @@ -1656,6 +1714,7 @@ namespace ZL { recomputePhoneChatPositions(); } chatUiManager.startPopIn(nodeName, 300.0f); + audioPlayer_.playSoundAsync("audio/537061__imafoley__message-pop-sound.ogg"); } void MenuManager::setDarklandsMode(bool enabled) diff --git a/src/ScriptEngine.cpp b/src/ScriptEngine.cpp index ba54566..7bad805 100644 --- a/src/ScriptEngine.cpp +++ b/src/ScriptEngine.cpp @@ -33,7 +33,7 @@ namespace ZL { ScriptEngine::ScriptEngine() = default; ScriptEngine::~ScriptEngine() = default; - void ScriptEngine::init(Location* loc, Inventory* inventory, const std::string& scriptPath) { + void ScriptEngine::init(Location* loc, Inventory* inventory, AudioPlayerAsync* audioPlayer, const std::string& scriptPath) { impl = std::make_unique(); sol::state& lua = impl->lua; @@ -773,6 +773,14 @@ namespace ZL { } }); + api.set_function("play_sound", + [audioPlayer](const std::string& soundPath) -> void { + if (audioPlayer) + { + audioPlayer->playSoundAsync(soundPath); + } + }); + lua.script_file(scriptPath); } diff --git a/src/ScriptEngine.h b/src/ScriptEngine.h index 6ad34ef..4cbfe2c 100644 --- a/src/ScriptEngine.h +++ b/src/ScriptEngine.h @@ -5,6 +5,7 @@ #include "quest/QuestJournal.h" #include "external/nlohmann/json.hpp" #include "ISaveable.h" +#include "AudioPlayerAsync.h" namespace ZL { @@ -17,7 +18,7 @@ public: ~ScriptEngine(); // Must be called once, after the Game's NPCs are ready. - void init(Location* game, Inventory* inventory, const std::string& scriptPath); + void init(Location* game, Inventory* inventory, AudioPlayerAsync* audioPlayer, const std::string& scriptPath); // Execute a Lua script file. Logs errors to stderr. void runScript(const std::string& path);