mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2025-08-20 05:13:39 -07:00
tts: use RawJson
resource + add SpeechLogger
(#3998)
* moved `tts.cpp` away from using `LoadFileRaw` by creating a new `RawJson` resource type * added `SpeechLogger`
This commit is contained in:
parent
402a4db593
commit
9fb2f26f1b
10 changed files with 122 additions and 18 deletions
16
soh/soh/Enhancements/speechsynthesizer/SpeechLogger.cpp
Normal file
16
soh/soh/Enhancements/speechsynthesizer/SpeechLogger.cpp
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
#include "SpeechLogger.h"
|
||||||
|
#include <libultraship/libultraship.h>
|
||||||
|
|
||||||
|
SpeechLogger::SpeechLogger() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void SpeechLogger::Speak(const char* text, const char* language) {
|
||||||
|
lusprintf(__FILE__, __LINE__, 2, "Spoken Text (%s): %s", language, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SpeechLogger::DoInit() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SpeechLogger::DoUninitialize() {
|
||||||
|
}
|
17
soh/soh/Enhancements/speechsynthesizer/SpeechLogger.h
Normal file
17
soh/soh/Enhancements/speechsynthesizer/SpeechLogger.h
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
#ifndef SOHSpeechLogger_h
|
||||||
|
#define SOHSpeechLogger_h
|
||||||
|
|
||||||
|
#include "SpeechSynthesizer.h"
|
||||||
|
|
||||||
|
class SpeechLogger : public SpeechSynthesizer {
|
||||||
|
public:
|
||||||
|
SpeechLogger();
|
||||||
|
|
||||||
|
void Speak(const char* text, const char* language);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool DoInit(void);
|
||||||
|
void DoUninitialize(void);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -36,3 +36,5 @@ class SpeechSynthesizer {
|
||||||
#elif defined(__APPLE__)
|
#elif defined(__APPLE__)
|
||||||
#include "DarwinSpeechSynthesizer.h"
|
#include "DarwinSpeechSynthesizer.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "SpeechLogger.h"
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
#include "message_data_static.h"
|
#include "message_data_static.h"
|
||||||
#include "overlays/gamestates/ovl_file_choose/file_choose.h"
|
#include "overlays/gamestates/ovl_file_choose/file_choose.h"
|
||||||
#include "soh/Enhancements/boss-rush/BossRush.h"
|
#include "soh/Enhancements/boss-rush/BossRush.h"
|
||||||
|
#include "soh/resource/type/SohResourceType.h"
|
||||||
|
#include "soh/resource/type/RawJson.h"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
extern MapData* gMapData;
|
extern MapData* gMapData;
|
||||||
|
@ -1037,25 +1039,22 @@ void InitTTSBank() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto sceneFile = LUS::Context::GetInstance()->GetResourceManager()->GetArchiveManager()->LoadFileRaw("accessibility/texts/scenes" + languageSuffix);
|
auto initData = std::make_shared<LUS::ResourceInitData>();
|
||||||
if (sceneFile != nullptr) {
|
initData->Format = RESOURCE_FORMAT_BINARY;
|
||||||
sceneMap = nlohmann::json::parse(*sceneFile->Buffer.get(), nullptr, true, true);
|
initData->Type = static_cast<uint32_t>(SOH::ResourceType::SOH_RawJson);
|
||||||
}
|
initData->ResourceVersion = 0;
|
||||||
|
|
||||||
auto miscFile = LUS::Context::GetInstance()->GetResourceManager()->GetArchiveManager()->LoadFileRaw("accessibility/texts/misc" + languageSuffix);
|
sceneMap = std::static_pointer_cast<SOH::RawJson>(
|
||||||
if (miscFile != nullptr) {
|
LUS::Context::GetInstance()->GetResourceManager()->LoadResource("accessibility/texts/scenes" + languageSuffix, true, initData))->Data;
|
||||||
miscMap = nlohmann::json::parse(*miscFile->Buffer.get(), nullptr, true, true);
|
|
||||||
}
|
miscMap = std::static_pointer_cast<SOH::RawJson>(
|
||||||
|
LUS::Context::GetInstance()->GetResourceManager()->LoadResource("accessibility/texts/misc" + languageSuffix, true, initData))->Data;
|
||||||
auto kaleidoFile = LUS::Context::GetInstance()->GetResourceManager()->GetArchiveManager()->LoadFileRaw("accessibility/texts/kaleidoscope" + languageSuffix);
|
|
||||||
if (kaleidoFile != nullptr) {
|
kaleidoMap = std::static_pointer_cast<SOH::RawJson>(
|
||||||
kaleidoMap = nlohmann::json::parse(*kaleidoFile->Buffer.get(), nullptr, true, true);
|
LUS::Context::GetInstance()->GetResourceManager()->LoadResource("accessibility/texts/kaleidoscope" + languageSuffix, true, initData))->Data;
|
||||||
}
|
|
||||||
|
fileChooseMap = std::static_pointer_cast<SOH::RawJson>(
|
||||||
auto fileChooseFile = LUS::Context::GetInstance()->GetResourceManager()->GetArchiveManager()->LoadFileRaw("accessibility/texts/filechoose" + languageSuffix);
|
LUS::Context::GetInstance()->GetResourceManager()->LoadResource("accessibility/texts/filechoose" + languageSuffix, true, initData))->Data;
|
||||||
if (fileChooseFile != nullptr) {
|
|
||||||
fileChooseMap = nlohmann::json::parse(*fileChooseFile->Buffer.get(), nullptr, true, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegisterOnSetGameLanguageHook() {
|
void RegisterOnSetGameLanguageHook() {
|
||||||
|
|
|
@ -118,6 +118,7 @@ GameInteractorSail* GameInteractorSail::Instance;
|
||||||
#include "soh/resource/importer/SkeletonLimbFactory.h"
|
#include "soh/resource/importer/SkeletonLimbFactory.h"
|
||||||
#include "soh/resource/importer/TextFactory.h"
|
#include "soh/resource/importer/TextFactory.h"
|
||||||
#include "soh/resource/importer/BackgroundFactory.h"
|
#include "soh/resource/importer/BackgroundFactory.h"
|
||||||
|
#include "soh/resource/importer/RawJsonFactory.h"
|
||||||
|
|
||||||
#include "soh/config/ConfigUpdaters.h"
|
#include "soh/config/ConfigUpdaters.h"
|
||||||
|
|
||||||
|
@ -341,6 +342,7 @@ OTRGlobals::OTRGlobals() {
|
||||||
loader->RegisterResourceFactory(std::make_shared<SOH::ResourceFactoryBinaryAudioSoundFontV2>(), RESOURCE_FORMAT_BINARY, "AudioSoundFont", static_cast<uint32_t>(SOH::ResourceType::SOH_AudioSoundFont), 2);
|
loader->RegisterResourceFactory(std::make_shared<SOH::ResourceFactoryBinaryAudioSoundFontV2>(), RESOURCE_FORMAT_BINARY, "AudioSoundFont", static_cast<uint32_t>(SOH::ResourceType::SOH_AudioSoundFont), 2);
|
||||||
loader->RegisterResourceFactory(std::make_shared<SOH::ResourceFactoryBinaryAudioSequenceV2>(), RESOURCE_FORMAT_BINARY, "AudioSequence", static_cast<uint32_t>(SOH::ResourceType::SOH_AudioSequence), 2);
|
loader->RegisterResourceFactory(std::make_shared<SOH::ResourceFactoryBinaryAudioSequenceV2>(), RESOURCE_FORMAT_BINARY, "AudioSequence", static_cast<uint32_t>(SOH::ResourceType::SOH_AudioSequence), 2);
|
||||||
loader->RegisterResourceFactory(std::make_shared<SOH::ResourceFactoryBinaryBackgroundV0>(), RESOURCE_FORMAT_BINARY, "Background", static_cast<uint32_t>(SOH::ResourceType::SOH_Background), 0);
|
loader->RegisterResourceFactory(std::make_shared<SOH::ResourceFactoryBinaryBackgroundV0>(), RESOURCE_FORMAT_BINARY, "Background", static_cast<uint32_t>(SOH::ResourceType::SOH_Background), 0);
|
||||||
|
loader->RegisterResourceFactory(std::make_shared<SOH::ResourceFactoryBinaryRawJsonV0>(), RESOURCE_FORMAT_BINARY, "RawJson", static_cast<uint32_t>(SOH::ResourceType::SOH_RawJson), 0);
|
||||||
|
|
||||||
gSaveStateMgr = std::make_shared<SaveStateMgr>();
|
gSaveStateMgr = std::make_shared<SaveStateMgr>();
|
||||||
gRandomizer = std::make_shared<Randomizer>();
|
gRandomizer = std::make_shared<Randomizer>();
|
||||||
|
@ -1109,6 +1111,9 @@ extern "C" void InitOTR() {
|
||||||
#elif defined(_WIN32)
|
#elif defined(_WIN32)
|
||||||
SpeechSynthesizer::Instance = new SAPISpeechSynthesizer();
|
SpeechSynthesizer::Instance = new SAPISpeechSynthesizer();
|
||||||
SpeechSynthesizer::Instance->Init();
|
SpeechSynthesizer::Instance->Init();
|
||||||
|
#else
|
||||||
|
SpeechSynthesizer::Instance = new SpeechLogger();
|
||||||
|
SpeechSynthesizer::Instance->Init();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENABLE_REMOTE_CONTROL
|
#ifdef ENABLE_REMOTE_CONTROL
|
||||||
|
|
19
soh/soh/resource/importer/RawJsonFactory.cpp
Normal file
19
soh/soh/resource/importer/RawJsonFactory.cpp
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
#include "soh/resource/importer/RawJsonFactory.h"
|
||||||
|
#include "soh/resource/type/RawJson.h"
|
||||||
|
#include "spdlog/spdlog.h"
|
||||||
|
|
||||||
|
namespace SOH {
|
||||||
|
std::shared_ptr<LUS::IResource> ResourceFactoryBinaryRawJsonV0::ReadResource(std::shared_ptr<LUS::File> file) {
|
||||||
|
if (!FileHasValidFormatAndReader(file)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto rawJson = std::make_shared<RawJson>(file->InitData);
|
||||||
|
auto reader = std::get<std::shared_ptr<LUS::BinaryReader>>(file->Reader);
|
||||||
|
|
||||||
|
rawJson->DataSize = file->Buffer->size();
|
||||||
|
rawJson->Data = nlohmann::json::parse(reader->ReadCString(), nullptr, true, true);
|
||||||
|
|
||||||
|
return rawJson;
|
||||||
|
}
|
||||||
|
} // namespace SOH
|
11
soh/soh/resource/importer/RawJsonFactory.h
Normal file
11
soh/soh/resource/importer/RawJsonFactory.h
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "resource/Resource.h"
|
||||||
|
#include "resource/ResourceFactoryBinary.h"
|
||||||
|
|
||||||
|
namespace SOH {
|
||||||
|
class ResourceFactoryBinaryRawJsonV0 : public LUS::ResourceFactoryBinary {
|
||||||
|
public:
|
||||||
|
std::shared_ptr<LUS::IResource> ReadResource(std::shared_ptr<LUS::File> file) override;
|
||||||
|
};
|
||||||
|
}; // namespace SOH
|
14
soh/soh/resource/type/RawJson.cpp
Normal file
14
soh/soh/resource/type/RawJson.cpp
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
#include "RawJson.h"
|
||||||
|
|
||||||
|
namespace SOH {
|
||||||
|
RawJson::RawJson() : Resource(std::shared_ptr<LUS::ResourceInitData>()) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void* RawJson::GetPointer() {
|
||||||
|
return &Data;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t RawJson::GetPointerSize() {
|
||||||
|
return DataSize * sizeof(char);
|
||||||
|
}
|
||||||
|
} // namespace SOH
|
20
soh/soh/resource/type/RawJson.h
Normal file
20
soh/soh/resource/type/RawJson.h
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "resource/Resource.h"
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
namespace SOH {
|
||||||
|
|
||||||
|
class RawJson : public LUS::Resource<void> {
|
||||||
|
public:
|
||||||
|
using Resource::Resource;
|
||||||
|
|
||||||
|
RawJson();
|
||||||
|
|
||||||
|
void* GetPointer() override;
|
||||||
|
size_t GetPointerSize() override;
|
||||||
|
|
||||||
|
nlohmann::json Data;
|
||||||
|
size_t DataSize;
|
||||||
|
};
|
||||||
|
}; // namespace SOH
|
|
@ -17,5 +17,6 @@ enum class ResourceType {
|
||||||
SOH_AudioSequence = 0x4F534551, // OSEQ
|
SOH_AudioSequence = 0x4F534551, // OSEQ
|
||||||
SOH_Background = 0x4F424749, // OBGI
|
SOH_Background = 0x4F424749, // OBGI
|
||||||
SOH_SceneCommand = 0x4F52434D, // ORCM
|
SOH_SceneCommand = 0x4F52434D, // ORCM
|
||||||
|
SOH_RawJson = 0x4A534F4E, // JSON
|
||||||
};
|
};
|
||||||
} // namespace SOH
|
} // namespace SOH
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue