Add ListShops function
This commit is contained in:
parent
055905bffc
commit
e4611ea20d
@ -90,8 +90,7 @@ void GetShopImpl(RE::BSFixedString api_url, RE::BSFixedString api_key, uint32_t
|
|||||||
SKSE::RegistrationMap<RE::BSFixedString> failReg = SKSE::RegistrationMap<RE::BSFixedString>();
|
SKSE::RegistrationMap<RE::BSFixedString> failReg = SKSE::RegistrationMap<RE::BSFixedString>();
|
||||||
failReg.Register(quest, RE::BSFixedString("OnGetShopFail"));
|
failReg.Register(quest, RE::BSFixedString("OnGetShopFail"));
|
||||||
|
|
||||||
logger::info(FMT_STRING("GetShop api_url: {}"), api_url);
|
logger::info(FMT_STRING("GetShop api_url: {}, api_key: {}, id: {}"), api_url, api_key, id);
|
||||||
logger::info(FMT_STRING("GetShop api_key: {}"), api_key);
|
|
||||||
FFIResult<RawShop> result = get_shop(api_url.c_str(), api_key.c_str(), id);
|
FFIResult<RawShop> result = get_shop(api_url.c_str(), api_key.c_str(), id);
|
||||||
if (result.IsOk()) {
|
if (result.IsOk()) {
|
||||||
RawShop shop = result.AsOk();
|
RawShop shop = result.AsOk();
|
||||||
@ -117,3 +116,53 @@ bool GetShop(RE::StaticFunctionTag*, RE::BSFixedString api_url, RE::BSFixedStrin
|
|||||||
thread.detach();
|
thread.detach();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ListShopsImpl(RE::BSFixedString api_url, RE::BSFixedString api_key, RE::TESQuest* quest) {
|
||||||
|
logger::info("Entered ListShopsImpl");
|
||||||
|
if (!quest) {
|
||||||
|
logger::error("ListShopsImpl quest is null!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Since Papyrus arrays are single-type, the array of shops from the API needs to be decomposed into multiple arrays for each shop field
|
||||||
|
SKSE::RegistrationMap<std::vector<int>, std::vector<RE::BSFixedString>, std::vector<RE::BSFixedString>> successReg = SKSE::RegistrationMap<std::vector<int>, std::vector<RE::BSFixedString>, std::vector<RE::BSFixedString>>();
|
||||||
|
successReg.Register(quest, RE::BSFixedString("OnListShopsSuccess"));
|
||||||
|
SKSE::RegistrationMap<RE::BSFixedString> failReg = SKSE::RegistrationMap<RE::BSFixedString>();
|
||||||
|
failReg.Register(quest, RE::BSFixedString("OnListShopsFail"));
|
||||||
|
|
||||||
|
logger::info(FMT_STRING("ListShops api_url: {}, api_key: {}"), api_url, api_key);
|
||||||
|
FFIResult<RawShopVec> result = list_shops(api_url.c_str(), api_key.c_str());
|
||||||
|
|
||||||
|
if (result.IsOk()) {
|
||||||
|
RawShopVec vec = result.AsOk();
|
||||||
|
logger::info(FMT_STRING("ListShops success vec len: {:d}, cap: {:d}"), vec.len, vec.cap);
|
||||||
|
std::vector<int> id_vec = std::vector<int>();
|
||||||
|
std::vector<RE::BSFixedString> name_vec = std::vector<RE::BSFixedString>();
|
||||||
|
std::vector<RE::BSFixedString> description_vec = std::vector<RE::BSFixedString>();
|
||||||
|
for (int i = 0; i < vec.len; i++) {
|
||||||
|
RawShop shop = vec.ptr[i];
|
||||||
|
id_vec.push_back(shop.id);
|
||||||
|
name_vec.push_back(RE::BSFixedString(shop.name));
|
||||||
|
description_vec.push_back(RE::BSFixedString(shop.description));
|
||||||
|
}
|
||||||
|
successReg.SendEvent(id_vec, name_vec, description_vec);
|
||||||
|
} else {
|
||||||
|
const char* error = result.AsErr();
|
||||||
|
logger::error(FMT_STRING("ListShops failure: {}"), error);
|
||||||
|
failReg.SendEvent(RE::BSFixedString(error));
|
||||||
|
}
|
||||||
|
successReg.Unregister(quest);
|
||||||
|
failReg.Unregister(quest);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ListShops(RE::StaticFunctionTag*, RE::BSFixedString api_url, RE::BSFixedString api_key, RE::TESQuest* quest) {
|
||||||
|
logger::info("Entered ListShops");
|
||||||
|
if (!quest) {
|
||||||
|
logger::error("ListShops quest is null!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::thread thread(ListShopsImpl, api_url, api_key, quest);
|
||||||
|
thread.detach();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
@ -3,3 +3,4 @@
|
|||||||
bool CreateShop(RE::StaticFunctionTag*, RE::BSFixedString api_url, RE::BSFixedString api_key, RE::BSFixedString name, RE::BSFixedString description, RE::TESQuest* quest);
|
bool CreateShop(RE::StaticFunctionTag*, RE::BSFixedString api_url, RE::BSFixedString api_key, RE::BSFixedString name, RE::BSFixedString description, RE::TESQuest* quest);
|
||||||
bool UpdateShop(RE::StaticFunctionTag*, RE::BSFixedString api_url, RE::BSFixedString api_key, uint32_t id, RE::BSFixedString name, RE::BSFixedString description, RE::TESQuest* quest);
|
bool UpdateShop(RE::StaticFunctionTag*, RE::BSFixedString api_url, RE::BSFixedString api_key, uint32_t id, RE::BSFixedString name, RE::BSFixedString description, RE::TESQuest* quest);
|
||||||
bool GetShop(RE::StaticFunctionTag*, RE::BSFixedString api_url, RE::BSFixedString api_key, uint32_t id, RE::TESQuest* quest);
|
bool GetShop(RE::StaticFunctionTag*, RE::BSFixedString api_url, RE::BSFixedString api_key, uint32_t id, RE::TESQuest* quest);
|
||||||
|
bool ListShops(RE::StaticFunctionTag*, RE::BSFixedString api_url, RE::BSFixedString api_key, RE::TESQuest* quest);
|
||||||
|
@ -17,6 +17,7 @@ bool RegisterFuncs(RE::BSScript::IVirtualMachine* a_vm)
|
|||||||
a_vm->RegisterFunction("Create", "BRShop", CreateShop);
|
a_vm->RegisterFunction("Create", "BRShop", CreateShop);
|
||||||
a_vm->RegisterFunction("Update", "BRShop", UpdateShop);
|
a_vm->RegisterFunction("Update", "BRShop", UpdateShop);
|
||||||
a_vm->RegisterFunction("Get", "BRShop", GetShop);
|
a_vm->RegisterFunction("Get", "BRShop", GetShop);
|
||||||
|
a_vm->RegisterFunction("List", "BRShop", ListShops);
|
||||||
a_vm->RegisterFunction("Create", "BRInteriorRefList", CreateInteriorRefList);
|
a_vm->RegisterFunction("Create", "BRInteriorRefList", CreateInteriorRefList);
|
||||||
a_vm->RegisterFunction("ClearCell", "BRInteriorRefList", ClearCell);
|
a_vm->RegisterFunction("ClearCell", "BRInteriorRefList", ClearCell);
|
||||||
a_vm->RegisterFunction("Load", "BRInteriorRefList", LoadInteriorRefList);
|
a_vm->RegisterFunction("Load", "BRInteriorRefList", LoadInteriorRefList);
|
||||||
|
Loading…
Reference in New Issue
Block a user