metaforce/DataSpec/DNAMP3/STRG.hpp

87 lines
2.3 KiB
C++
Raw Normal View History

#ifndef __DNAMP3_STRG_HPP__
#define __DNAMP3_STRG_HPP__
#include <unordered_map>
2015-08-22 01:58:41 +00:00
#include "../DNACommon/PAK.hpp"
#include "../DNACommon/STRG.hpp"
2017-12-29 08:08:12 +00:00
namespace DataSpec::DNAMP3
{
2015-08-09 03:55:11 +00:00
struct STRG : ISTRG
{
2015-08-09 03:55:11 +00:00
DECL_YAML
Delete expl;
2016-03-04 23:04:53 +00:00
void _read(athena::io::IStreamReader& reader);
2015-08-23 06:42:29 +00:00
std::vector<std::pair<DNAFourCC, std::vector<std::string>>> langs;
std::unordered_map<DNAFourCC, std::vector<std::string>*> langMap;
std::map<std::string, int32_t> names;
2017-11-13 06:19:18 +00:00
int32_t lookupIdx(std::string_view name) const
{
2017-11-13 06:19:18 +00:00
auto search = names.find(name.data());
if (search == names.end())
return -1;
return search->second;
}
size_t count() const
{
size_t retval = 0;
2015-07-16 01:57:34 +00:00
for (const auto& item : langs)
{
size_t sz = item.second.size();
if (sz > retval)
retval = sz;
}
return retval;
}
std::string getUTF8(const FourCC& lang, size_t idx) const
{
auto search = langMap.find(lang);
if (search != langMap.end())
return search->second->at(idx);
return std::string();
}
std::u16string getUTF16(const FourCC& lang, size_t idx) const
{
auto search = langMap.find(lang);
if (search != langMap.end())
2017-01-24 07:41:33 +00:00
return hecl::UTF8ToChar16(search->second->at(idx));
return std::u16string();
}
hecl::SystemString getSystemString(const FourCC& lang, size_t idx) const
{
auto search = langMap.find(lang);
if (search != langMap.end())
#if HECL_UCS2
2016-03-04 23:04:53 +00:00
return hecl::UTF8ToWide(search->second->at(idx));
#else
return search->second->at(idx);
#endif
2016-03-04 23:04:53 +00:00
return hecl::SystemString();
}
2015-07-16 01:57:34 +00:00
2016-03-04 23:04:53 +00:00
static bool Extract(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath)
{
2015-08-09 03:55:11 +00:00
std::unique_ptr<ISTRG> strg = LoadSTRG(rs);
2017-01-27 02:22:52 +00:00
athena::io::TransactionalFileWriter writer(outPath.getAbsolutePath());
2016-08-22 03:47:48 +00:00
strg->toYAMLStream(writer);
return true;
}
2015-07-22 19:05:18 +00:00
2016-03-04 23:04:53 +00:00
static bool Cook(const hecl::ProjectPath& inPath, const hecl::ProjectPath& outPath)
2015-07-22 19:05:18 +00:00
{
2015-08-09 03:55:11 +00:00
STRG strg;
2016-08-22 03:47:48 +00:00
athena::io::FileReader reader(inPath.getAbsolutePath());
strg.fromYAMLStream(reader);
2017-01-27 02:22:52 +00:00
athena::io::TransactionalFileWriter ws(outPath.getAbsolutePath());
2015-08-09 03:55:11 +00:00
strg.write(ws);
2015-07-22 19:05:18 +00:00
return true;
}
};
}
#endif // __DNAMP2_STRG_HPP__