| 757 | } |
| 758 | |
| 759 | void NetworkedAnimator::update(float dt, DynamicTarget* dynamicTarget) { |
| 760 | dt *= m_animationRate.get(); |
| 761 | |
| 762 | m_animatedParts.update(dt); |
| 763 | |
| 764 | m_animatedParts.forEachActiveState([&](String const& stateTypeName, AnimatedPartSet::ActiveStateInformation const& activeState) { |
| 765 | if (dynamicTarget) { |
| 766 | dynamicTarget->clearFinishedAudio(); |
| 767 | |
| 768 | Json persistentSound = activeState.properties.value("persistentSound", ""); |
| 769 | String persistentSoundFile; |
| 770 | |
| 771 | if (persistentSound.isType(Json::Type::String)) |
| 772 | persistentSoundFile = persistentSound.toString(); |
| 773 | else if (persistentSound.isType(Json::Type::Array)) |
| 774 | persistentSoundFile = Random::randValueFrom(persistentSound.toArray(), "").toString(); |
| 775 | |
| 776 | if (!persistentSoundFile.empty()) |
| 777 | persistentSoundFile = AssetPath::relativeTo(m_relativePath, persistentSoundFile); |
| 778 | |
| 779 | auto& activePersistentSound = dynamicTarget->statePersistentSounds[stateTypeName]; |
| 780 | |
| 781 | bool changedPersistentSound = persistentSound != activePersistentSound.sound; |
| 782 | if (changedPersistentSound || !activePersistentSound.audio) { |
| 783 | activePersistentSound.sound = std::move(persistentSound); |
| 784 | if (activePersistentSound.audio) |
| 785 | activePersistentSound.audio->stop(activePersistentSound.stopRampTime); |
| 786 | |
| 787 | if (!persistentSoundFile.empty()) { |
| 788 | activePersistentSound.audio = make_shared<AudioInstance>(*Root::singleton().assets()->audio(persistentSoundFile)); |
| 789 | activePersistentSound.audio->setRangeMultiplier(activeState.properties.value("persistentSoundRangeMultiplier", 1.0f).toFloat()); |
| 790 | activePersistentSound.audio->setLoops(-1); |
| 791 | activePersistentSound.audio->setPosition(globalTransformation().transformVec2(Vec2F())); |
| 792 | activePersistentSound.stopRampTime = activeState.properties.value("persistentSoundStopTime", 0.0f).toFloat(); |
| 793 | dynamicTarget->pendingAudios.append(activePersistentSound.audio); |
| 794 | } else { |
| 795 | dynamicTarget->statePersistentSounds.remove(stateTypeName); |
| 796 | } |
| 797 | } |
| 798 | |
| 799 | Json immediateSound = activeState.properties.value("immediateSound", ""); |
| 800 | String immediateSoundFile = ""; |
| 801 | |
| 802 | if (immediateSound.isType(Json::Type::String)) |
| 803 | immediateSoundFile = immediateSound.toString(); |
| 804 | else if (immediateSound.isType(Json::Type::Array)) |
| 805 | immediateSoundFile = Random::randValueFrom(immediateSound.toArray(), "").toString(); |
| 806 | |
| 807 | if (!immediateSoundFile.empty()) |
| 808 | immediateSoundFile = AssetPath::relativeTo(m_relativePath, immediateSoundFile); |
| 809 | |
| 810 | auto& activeImmediateSound = dynamicTarget->stateImmediateSounds[stateTypeName]; |
| 811 | |
| 812 | bool changedImmediateSound = immediateSound != activeImmediateSound.sound; |
| 813 | if (changedImmediateSound) { |
| 814 | activeImmediateSound.sound = std::move(immediateSound); |
| 815 | if (!immediateSoundFile.empty()) { |
| 816 | activeImmediateSound.audio = make_shared<AudioInstance>(*Root::singleton().assets()->audio(immediateSoundFile)); |
nothing calls this directly
no test coverage detected