mirror of https://github.com/AxioDL/metaforce.git
Merge pull request #260 from lioncash/array2
CPlayerState: Make g_typeNameMap a compile-time array
This commit is contained in:
commit
dc6954491b
|
@ -390,7 +390,8 @@ void CPlayerState::InitializeScanTimes() {
|
||||||
|
|
||||||
u32 CPlayerState::GetPowerUpMaxValue(EItemType type) { return PowerUpMaxValues[size_t(type)]; }
|
u32 CPlayerState::GetPowerUpMaxValue(EItemType type) { return PowerUpMaxValues[size_t(type)]; }
|
||||||
|
|
||||||
const std::unordered_map<std::string_view, CPlayerState::EItemType> CPlayerState::g_TypeNameMap = {
|
CPlayerState::EItemType CPlayerState::ItemNameToType(std::string_view name) {
|
||||||
|
static constexpr std::array<std::pair<std::string_view, EItemType>, 46> typeNameMap{{
|
||||||
{"powerbeam"sv, EItemType::PowerBeam},
|
{"powerbeam"sv, EItemType::PowerBeam},
|
||||||
{"icebeam"sv, EItemType::IceBeam},
|
{"icebeam"sv, EItemType::IceBeam},
|
||||||
{"wavebeam"sv, EItemType::WaveBeam},
|
{"wavebeam"sv, EItemType::WaveBeam},
|
||||||
|
@ -437,15 +438,18 @@ const std::unordered_map<std::string_view, CPlayerState::EItemType> CPlayerState
|
||||||
{"world"sv, EItemType::World},
|
{"world"sv, EItemType::World},
|
||||||
{"spirit"sv, EItemType::Spirit},
|
{"spirit"sv, EItemType::Spirit},
|
||||||
{"newborn"sv, EItemType::Newborn},
|
{"newborn"sv, EItemType::Newborn},
|
||||||
};
|
}};
|
||||||
|
|
||||||
CPlayerState::EItemType CPlayerState::ItemNameToType(std::string_view name) {
|
std::string lowName{name};
|
||||||
std::string lowName = name.data();
|
|
||||||
athena::utility::tolower(lowName);
|
athena::utility::tolower(lowName);
|
||||||
if (g_TypeNameMap.find(lowName) == g_TypeNameMap.end())
|
|
||||||
return EItemType::Invalid;
|
|
||||||
|
|
||||||
return g_TypeNameMap.find(lowName)->second;
|
const auto iter = std::find_if(typeNameMap.cbegin(), typeNameMap.cend(),
|
||||||
|
[&lowName](const auto& entry) { return entry.first == lowName; });
|
||||||
|
if (iter == typeNameMap.cend()) {
|
||||||
|
return EItemType::Invalid;
|
||||||
|
}
|
||||||
|
|
||||||
|
return iter->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace urde
|
} // namespace urde
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <unordered_map>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "Runtime/CStaticInterference.hpp"
|
#include "Runtime/CStaticInterference.hpp"
|
||||||
|
@ -89,7 +88,6 @@ public:
|
||||||
enum class EBeamId : s32 { Invalid = -1, Power, Ice, Wave, Plasma, Phazon, Phazon2 = 27 };
|
enum class EBeamId : s32 { Invalid = -1, Power, Ice, Wave, Plasma, Phazon, Phazon2 = 27 };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const std::unordered_map<std::string_view, EItemType> g_TypeNameMap;
|
|
||||||
struct CPowerUp {
|
struct CPowerUp {
|
||||||
u32 x0_amount = 0;
|
u32 x0_amount = 0;
|
||||||
u32 x4_capacity = 0;
|
u32 x4_capacity = 0;
|
||||||
|
|
Loading…
Reference in New Issue