mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-22 12:47:53 -05:00
Add ZoneScriptString class to store zone script strings
This commit is contained in:
@ -2,13 +2,14 @@
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "Zone/ZoneTypes.h"
|
||||
#include "Pool/ZoneAssetPools.h"
|
||||
#include "Game/IGame.h"
|
||||
#include "Game/GameLanguage.h"
|
||||
#include "ZoneMemory.h"
|
||||
#include "ZoneScriptStrings.h"
|
||||
|
||||
class IGame;
|
||||
class ZoneAssetPools;
|
||||
@ -24,7 +25,7 @@ public:
|
||||
zone_priority_t m_priority;
|
||||
GameLanguage m_language;
|
||||
IGame* m_game;
|
||||
std::vector<std::string> m_script_strings;
|
||||
ZoneScriptStrings m_script_strings;
|
||||
std::unique_ptr<ZoneAssetPools> m_pools;
|
||||
|
||||
Zone(std::string name, zone_priority_t priority, IGame* game);
|
||||
@ -36,5 +37,5 @@ public:
|
||||
|
||||
void Register();
|
||||
|
||||
ZoneMemory* GetMemory() const;
|
||||
_NODISCARD ZoneMemory* GetMemory() const;
|
||||
};
|
||||
|
57
src/ZoneCommon/Zone/ZoneScriptStrings.cpp
Normal file
57
src/ZoneCommon/Zone/ZoneScriptStrings.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
#include "ZoneScriptStrings.h"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <sstream>
|
||||
|
||||
scr_string_t ZoneScriptStrings::AddScriptString(const std::string& value)
|
||||
{
|
||||
if(m_scr_strings.empty())
|
||||
{
|
||||
m_scr_strings.emplace_back("");
|
||||
m_scr_string_lookup[""] = static_cast<scr_string_t>(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto existingScriptString = m_scr_string_lookup.find(value);
|
||||
if (existingScriptString != m_scr_string_lookup.end())
|
||||
return existingScriptString->second;
|
||||
}
|
||||
|
||||
const auto newScrStringIndex = static_cast<scr_string_t>(m_scr_strings.size());
|
||||
m_scr_strings.emplace_back(value);
|
||||
m_scr_string_lookup[value] = newScrStringIndex;
|
||||
|
||||
return newScrStringIndex;
|
||||
}
|
||||
|
||||
size_t ZoneScriptStrings::Count() const
|
||||
{
|
||||
return m_scr_strings.size();
|
||||
}
|
||||
|
||||
bool ZoneScriptStrings::Empty() const
|
||||
{
|
||||
return m_scr_strings.empty();
|
||||
}
|
||||
|
||||
const std::string& ZoneScriptStrings::operator[](const size_t index) const
|
||||
{
|
||||
if(index > m_scr_strings.size())
|
||||
{
|
||||
std::ostringstream str;
|
||||
str << "Script string index '" << index << "' is not inside range of zone script strings (count: " << m_scr_strings.size() << ")";
|
||||
throw std::runtime_error(str.str());
|
||||
}
|
||||
|
||||
return m_scr_strings[index];
|
||||
}
|
||||
|
||||
std::vector<std::string>::const_iterator ZoneScriptStrings::begin() const
|
||||
{
|
||||
return m_scr_strings.cbegin();
|
||||
}
|
||||
|
||||
std::vector<std::string>::const_iterator ZoneScriptStrings::end() const
|
||||
{
|
||||
return m_scr_strings.end();
|
||||
}
|
24
src/ZoneCommon/Zone/ZoneScriptStrings.h
Normal file
24
src/ZoneCommon/Zone/ZoneScriptStrings.h
Normal file
@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "Zone/ZoneTypes.h"
|
||||
|
||||
class ZoneScriptStrings
|
||||
{
|
||||
std::vector<std::string> m_scr_strings;
|
||||
std::unordered_map<std::string, scr_string_t> m_scr_string_lookup;
|
||||
|
||||
public:
|
||||
scr_string_t AddScriptString(const std::string& value);
|
||||
_NODISCARD size_t Count() const;
|
||||
_NODISCARD bool Empty() const;
|
||||
|
||||
_NODISCARD const std::string& operator[](size_t index) const;
|
||||
_NODISCARD std::vector<std::string>::const_iterator begin() const;
|
||||
_NODISCARD std::vector<std::string>::const_iterator end() const;
|
||||
};
|
Reference in New Issue
Block a user