DarkflameServer/dDatabase/CDClientDatabase/CDClientTables/CDRailActivatorComponent.cpp
David Markowitz d2aeebcd46
chore: Move database storage containers to be translation unit local to allow for safe references (#1434)
* Move CDClientManager to be a namespace

Tested that worlds still load data as expected.  Had no use being a singleton anyways.

* Move cdclient data storage to tu local containers

Allows some data from these containers to be saved on object by reference instead of always needing to copy.

iteration 2

- move all unnamed namespace containers to a singular spot
- use macro for template specialization and variable declaration
- use templates to allow for as little copy paste of types and functions as possible

* remember to use typename!

compiler believes T::StorageType is accessing a member, not a type.

* Update CDClientManager.cpp

* move to cpp?
2024-02-09 07:37:58 -06:00

65 lines
2.3 KiB
C++

#include "CDRailActivatorComponent.h"
#include "GeneralUtils.h"
void CDRailActivatorComponentTable::LoadValuesFromDatabase() {
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM RailActivatorComponent;");
auto& entries = GetEntriesMutable();
while (!tableData.eof()) {
CDRailActivatorComponent entry;
entry.id = tableData.getIntField("id", 0);
entry.startAnimation = GeneralUtils::ASCIIToUTF16(tableData.getStringField("startAnim", ""));
entry.loopAnimation = GeneralUtils::ASCIIToUTF16(tableData.getStringField("loopAnim", ""));
entry.stopAnimation = GeneralUtils::ASCIIToUTF16(tableData.getStringField("stopAnim", ""));
entry.startSound = GeneralUtils::ASCIIToUTF16(tableData.getStringField("startSound", ""));
entry.loopSound = GeneralUtils::ASCIIToUTF16(tableData.getStringField("loopSound", ""));
entry.stopSound = GeneralUtils::ASCIIToUTF16(tableData.getStringField("stopSound", ""));
std::string loopEffectString(tableData.getStringField("effectIDs", ""));
entry.loopEffectID = EffectPairFromString(loopEffectString);
entry.preconditions = tableData.getStringField("preconditions", "-1");
entry.playerCollision = tableData.getIntField("playerCollision", 0);
entry.cameraLocked = tableData.getIntField("cameraLocked", 0);
std::string startEffectString(tableData.getStringField("StartEffectID", ""));
entry.startEffectID = EffectPairFromString(startEffectString);
std::string stopEffectString(tableData.getStringField("StopEffectID", ""));
entry.stopEffectID = EffectPairFromString(stopEffectString);
entry.damageImmune = tableData.getIntField("DamageImmune", 0);
entry.noAggro = tableData.getIntField("NoAggro", 0);
entry.showNameBillboard = tableData.getIntField("ShowNameBillboard", 0);
entries.push_back(entry);
tableData.nextRow();
}
tableData.finalize();
}
CDRailActivatorComponent CDRailActivatorComponentTable::GetEntryByID(int32_t id) const {
for (const auto& entry : GetEntries()) {
if (entry.id == id)
return entry;
}
return {};
}
std::pair<uint32_t, std::u16string> CDRailActivatorComponentTable::EffectPairFromString(std::string& str) {
const auto split = GeneralUtils::SplitString(str, ':');
if (split.size() == 2) {
return { std::stoi(split.at(0)), GeneralUtils::ASCIIToUTF16(split.at(1)) };
}
return {};
}