2021-12-05 17:54:36 +00:00
|
|
|
#include "CDObjectsTable.h"
|
|
|
|
|
2024-02-09 13:37:58 +00:00
|
|
|
namespace {
|
2024-03-07 05:45:24 +00:00
|
|
|
CDObjects ObjDefault;
|
2024-02-09 13:37:58 +00:00
|
|
|
};
|
|
|
|
|
2023-08-11 04:27:40 +00:00
|
|
|
void CDObjectsTable::LoadValuesFromDatabase() {
|
2021-12-05 17:54:36 +00:00
|
|
|
// First, get the size of the table
|
2024-01-09 07:54:14 +00:00
|
|
|
uint32_t size = 0;
|
2021-12-05 17:54:36 +00:00
|
|
|
auto tableSize = CDClientDatabase::ExecuteQuery("SELECT COUNT(*) FROM Objects");
|
|
|
|
while (!tableSize.eof()) {
|
|
|
|
size = tableSize.getIntField(0, 0);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
tableSize.nextRow();
|
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
tableSize.finalize();
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
// Now get the data
|
|
|
|
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM Objects");
|
2024-02-09 13:37:58 +00:00
|
|
|
auto& entries = GetEntriesMutable();
|
2021-12-05 17:54:36 +00:00
|
|
|
while (!tableData.eof()) {
|
2024-03-07 05:45:24 +00:00
|
|
|
const uint32_t lot = tableData.getIntField("id", 0);
|
|
|
|
|
|
|
|
auto& entry = entries[lot];
|
|
|
|
entry.id = lot;
|
2023-01-07 09:48:59 +00:00
|
|
|
entry.name = tableData.getStringField("name", "");
|
2023-08-11 04:27:40 +00:00
|
|
|
UNUSED_COLUMN(entry.placeable = tableData.getIntField("placeable", -1);)
|
2023-01-07 09:48:59 +00:00
|
|
|
entry.type = tableData.getStringField("type", "");
|
2023-08-11 04:27:40 +00:00
|
|
|
UNUSED_COLUMN(entry.description = tableData.getStringField("description", "");)
|
|
|
|
UNUSED_COLUMN(entry.localize = tableData.getIntField("localize", -1);)
|
|
|
|
UNUSED_COLUMN(entry.npcTemplateID = tableData.getIntField("npcTemplateID", -1);)
|
|
|
|
UNUSED_COLUMN(entry.displayName = tableData.getStringField("displayName", "");)
|
2023-01-07 09:48:59 +00:00
|
|
|
entry.interactionDistance = tableData.getFloatField("interactionDistance", -1.0f);
|
2023-08-11 04:27:40 +00:00
|
|
|
UNUSED_COLUMN(entry.nametag = tableData.getIntField("nametag", -1);)
|
|
|
|
UNUSED_COLUMN(entry._internalNotes = tableData.getStringField("_internalNotes", "");)
|
|
|
|
UNUSED_COLUMN(entry.locStatus = tableData.getIntField("locStatus", -1);)
|
|
|
|
UNUSED_COLUMN(entry.gate_version = tableData.getStringField("gate_version", "");)
|
|
|
|
UNUSED_COLUMN(entry.HQ_valid = tableData.getIntField("HQ_valid", -1);)
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
tableData.nextRow();
|
|
|
|
}
|
|
|
|
|
2024-03-07 05:45:24 +00:00
|
|
|
ObjDefault.id = 0;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2024-03-07 05:45:24 +00:00
|
|
|
const CDObjects& CDObjectsTable::GetByID(const uint32_t lot) {
|
2024-02-09 13:37:58 +00:00
|
|
|
auto& entries = GetEntriesMutable();
|
2024-03-07 05:45:24 +00:00
|
|
|
const auto& it = entries.find(lot);
|
2024-02-09 13:37:58 +00:00
|
|
|
if (it != entries.end()) {
|
2021-12-05 17:54:36 +00:00
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
|
2023-08-11 04:27:40 +00:00
|
|
|
auto query = CDClientDatabase::CreatePreppedStmt("SELECT * FROM Objects WHERE id = ?;");
|
2024-03-07 05:45:24 +00:00
|
|
|
query.bind(1, static_cast<int32_t>(lot));
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-08-11 04:27:40 +00:00
|
|
|
auto tableData = query.execQuery();
|
2021-12-05 17:54:36 +00:00
|
|
|
if (tableData.eof()) {
|
2024-03-07 05:45:24 +00:00
|
|
|
entries.emplace(lot, ObjDefault);
|
|
|
|
return ObjDefault;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now get the data
|
|
|
|
while (!tableData.eof()) {
|
2024-03-07 05:45:24 +00:00
|
|
|
const uint32_t lot = tableData.getIntField("id", 0);
|
|
|
|
|
|
|
|
auto& entry = entries[lot];
|
|
|
|
entry.id = lot;
|
2023-01-07 09:48:59 +00:00
|
|
|
entry.name = tableData.getStringField("name", "");
|
|
|
|
UNUSED(entry.placeable = tableData.getIntField("placeable", -1));
|
|
|
|
entry.type = tableData.getStringField("type", "");
|
2021-12-05 17:54:36 +00:00
|
|
|
UNUSED(ntry.description = tableData.getStringField(4, ""));
|
2023-01-07 09:48:59 +00:00
|
|
|
UNUSED(entry.localize = tableData.getIntField("localize", -1));
|
|
|
|
UNUSED(entry.npcTemplateID = tableData.getIntField("npcTemplateID", -1));
|
|
|
|
UNUSED(entry.displayName = tableData.getStringField("displayName", ""));
|
|
|
|
entry.interactionDistance = tableData.getFloatField("interactionDistance", -1.0f);
|
|
|
|
UNUSED(entry.nametag = tableData.getIntField("nametag", -1));
|
|
|
|
UNUSED(entry._internalNotes = tableData.getStringField("_internalNotes", ""));
|
|
|
|
UNUSED(entry.locStatus = tableData.getIntField("locStatus", -1));
|
|
|
|
UNUSED(entry.gate_version = tableData.getStringField("gate_version", ""));
|
|
|
|
UNUSED(entry.HQ_valid = tableData.getIntField("HQ_valid", -1));
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
tableData.nextRow();
|
|
|
|
}
|
|
|
|
|
|
|
|
tableData.finalize();
|
|
|
|
|
2024-03-07 05:45:24 +00:00
|
|
|
const auto& it2 = entries.find(lot);
|
2021-12-05 17:54:36 +00:00
|
|
|
if (it2 != entries.end()) {
|
|
|
|
return it2->second;
|
|
|
|
}
|
|
|
|
|
2024-03-07 05:45:24 +00:00
|
|
|
return ObjDefault;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|