fix(njhub): falling tiles play their sounds as live did

Shaking once stepped on, landing at waypoint 1 (the shaking stops), rising when sent back, stopped at waypoint 0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aaron Kimbrell
2026-11-28 11:07:55 -06:00
parent ab589ef276
commit 908d1954bd
2 changed files with 57 additions and 0 deletions

View File

@@ -3,6 +3,13 @@
#include "GameMessages.h"
#include "EffectsMessages.h"
namespace {
// The sounds live played on the tile: shaking once stepped on, landing, and rising back
constexpr const char* ShakeSound = "{b7b848ad-7db0-4d51-a664-e38b386607dc}";
constexpr const char* LandSound = "{7665b557-a611-4718-8bb1-9bb1fb0f8f0f}";
constexpr const char* RiseSound = "{6f07abbd-1710-4047-8d54-e772c22a970f}";
}
void FallingTile::OnStartup(Entity* self) {
auto* movingPlatfromComponent = self->GetComponent<MovingPlatformComponent>();
@@ -18,6 +25,8 @@ void FallingTile::OnCollisionPhantom(Entity* self, Entity* target) {
return;
}
GameMessages::PlayNDAudioEmitter(self->GetObjectID(), ShakeSound).Send(UNASSIGNED_SYSTEM_ADDRESS);
self->AddTimer("flipTime", 0.75f);
self->SetVar<bool>(u"AboutToFall", true);
@@ -27,7 +36,10 @@ void FallingTile::OnCollisionPhantom(Entity* self, Entity* target) {
void FallingTile::OnWaypointReached(Entity* self, uint32_t waypointIndex) {
if (waypointIndex == 1) {
GameMessages::PlayNDAudioEmitter(self->GetObjectID(), LandSound).Send(UNASSIGNED_SYSTEM_ADDRESS);
GameMessages::StopNDAudioEmitter(self->GetObjectID(), ShakeSound).Send(UNASSIGNED_SYSTEM_ADDRESS);
} else if (waypointIndex == 0) {
GameMessages::StopNDAudioEmitter(self->GetObjectID(), RiseSound).Send(UNASSIGNED_SYSTEM_ADDRESS);
}
}
@@ -52,5 +64,6 @@ void FallingTile::OnTimerDone(Entity* self, std::string timerName) {
movingPlatfromComponent->GotoWaypoint(0);
GameMessages::PlayFXEffect(self->GetObjectID(), -1, u"up", "up").Send(UNASSIGNED_SYSTEM_ADDRESS);
GameMessages::PlayNDAudioEmitter(self->GetObjectID(), RiseSound).Send(UNASSIGNED_SYSTEM_ADDRESS);
}
}

View File

@@ -12,6 +12,8 @@
#include "Entity.h"
#include "GameMessages.h"
#include "02_server/Map/njhub/FireTransRocks.h"
#include "02_server/Map/njhub/FallingTile.h"
#include "EffectsMessages.h"
#include "LDFFormat.h"
#include "MovementMessages.h"
#include "MovingPlatformComponent.h"
@@ -92,6 +94,7 @@ TEST_F(MovingPlatformComponentTest, SubcomponentTypeFromLevelConfig) {
info.settings.Insert<bool>(u"platformIsMover", false);
Entity none(288300744895900106, info);
EXPECT_EQ(ChooseMoverSubComponentType(41, none), eMoverSubComponentType::none);
info.settings.values.clear();
}
@@ -1323,3 +1326,44 @@ TEST_F(MovingPlatformComponentTest, ShootingGalleryTargetWritesItsTimeScore) {
EXPECT_EQ(SgTarget::GetActivityPoints(&noData), 0);
EXPECT_FALSE(otherActivity->PlayerHasActivityData(LWOOBJID_EMPTY));
}
// The NJ falling tile's sounds in the live captures: shaking when stepped on, landing at waypoint 1 (then the shaking
// stops), rising when sent back, and the rising stops at waypoint 0
TEST_F(MovingPlatformComponentTest, FallingTileSoundsLikeLive) {
const std::string shake = "{b7b848ad-7db0-4d51-a664-e38b386607dc}";
const std::string land = "{7665b557-a611-4718-8bb1-9bb1fb0f8f0f}";
const std::string rise = "{6f07abbd-1710-4047-8d54-e772c22a970f}";
Entity entity(288300744895900110, info);
FallingTile script;
auto* const mock = static_cast<dServerMock*>(Game::server);
// The bytes of each message sent since the last call
const auto sent = [&]() {
std::vector<std::vector<uint8_t>> out;
for (const auto& packet : mock->GetSentPackets()) out.push_back(packet.bytes);
mock->ClearSentPackets();
return out;
};
const auto bytes = [&](const GameMessages::NetGameMsg& msg) {
msg.Send(UNASSIGNED_SYSTEM_ADDRESS);
auto out = sent();
return out.empty() ? std::vector<uint8_t>{} : out.back();
};
const auto id = entity.GetObjectID();
mock->ClearSentPackets();
script.OnCollisionPhantom(&entity, &entity);
auto got = sent();
const auto playShake = bytes(GameMessages::PlayNDAudioEmitter(id, shake));
EXPECT_NE(std::ranges::find(got, playShake), got.end());
script.OnWaypointReached(&entity, 1);
got = sent();
ASSERT_EQ(got.size(), 2u);
EXPECT_EQ(got[0], bytes(GameMessages::PlayNDAudioEmitter(id, land)));
EXPECT_EQ(got[1], bytes(GameMessages::StopNDAudioEmitter(id, shake)));
script.OnWaypointReached(&entity, 0);
got = sent();
ASSERT_EQ(got.size(), 1u);
EXPECT_EQ(got[0], bytes(GameMessages::StopNDAudioEmitter(id, rise)));
}