clang-format

This commit is contained in:
aMannus
2025-06-30 11:40:20 +02:00
parent ae17e572a0
commit abe682e0f2
11 changed files with 227 additions and 210 deletions

View File

@@ -355,7 +355,7 @@ void Context::AddReceivedArchipelagoItem(const RandomizerGet item) {
GetItemEntry Context::GetArchipelagoGIEntry() { GetItemEntry Context::GetArchipelagoGIEntry() {
ArchipelagoConsole_SendMessage("[LOG] Trying to get Item Entry", true); ArchipelagoConsole_SendMessage("[LOG] Trying to get Item Entry", true);
if(mAPreceiveQueue.empty()) { if (mAPreceiveQueue.empty()) {
// something must have gone wrong here, just give a rupee // something must have gone wrong here, just give a rupee
return ItemTableManager::Instance->RetrieveItemEntry(MOD_NONE, GI_HEART); return ItemTableManager::Instance->RetrieveItemEntry(MOD_NONE, GI_HEART);
} }
@@ -707,17 +707,17 @@ void Context::ParseArchipelagoItemsLocations(const std::vector<ArchipelagoClient
const std::string SlotName = ArchipelagoClient::GetInstance().GetSlotName(); const std::string SlotName = ArchipelagoClient::GetInstance().GetSlotName();
// Zero out the location table first // Zero out the location table first
for(int rc = 1; rc < RC_MAX; rc++) { for (int rc = 1; rc < RC_MAX; rc++) {
itemLocationTable[rc].SetPlacedItem(RG_NONE); itemLocationTable[rc].SetPlacedItem(RG_NONE);
} }
for(const ArchipelagoClient::ApItem& ap_item: scouted_items) { for (const ArchipelagoClient::ApItem& ap_item : scouted_items) {
//const RandomizerCheck rc = StaticData::APcheckToSoh.find(ap_item.locationName)->second; // const RandomizerCheck rc = StaticData::APcheckToSoh.find(ap_item.locationName)->second;
const RandomizerCheck rc = StaticData::locationNameToEnum[ap_item.locationName]; const RandomizerCheck rc = StaticData::locationNameToEnum[ap_item.locationName];
itemLocationTable[rc].SetCustomPrice(10); itemLocationTable[rc].SetCustomPrice(10);
if(SlotName == ap_item.playerName) { if (SlotName == ap_item.playerName) {
// our item // our item
SPDLOG_TRACE("Populated item {} at location {}", ap_item.itemName, ap_item.locationName); SPDLOG_TRACE("Populated item {} at location {}", ap_item.itemName, ap_item.locationName);
const RandomizerGet item = StaticData::itemNameToEnum[ap_item.itemName]; const RandomizerGet item = StaticData::itemNameToEnum[ap_item.itemName];

View File

@@ -290,15 +290,15 @@ void RandomizerOnExternalCheckHandler(uint32_t randomizerCheck) {
SceneID scene = loc->GetScene(); SceneID scene = loc->GetScene();
bool inSameArea = false; bool inSameArea = false;
if(gPlayState != nullptr) { if (gPlayState != nullptr) {
inSameArea = scene == gPlayState->sceneNum; inSameArea = scene == gPlayState->sceneNum;
} }
std::string logMessage = ""; std::string logMessage = "";
switch(loc->GetCollectionCheck().type) { switch (loc->GetCollectionCheck().type) {
case SPOILER_CHK_CHEST: case SPOILER_CHK_CHEST:
if(inSameArea) { if (inSameArea) {
Flags_SetTreasure(gPlayState, flagID); Flags_SetTreasure(gPlayState, flagID);
} else { } else {
gSaveContext.sceneFlags[scene].chest |= 1 << flagID; gSaveContext.sceneFlags[scene].chest |= 1 << flagID;
@@ -306,7 +306,7 @@ void RandomizerOnExternalCheckHandler(uint32_t randomizerCheck) {
} }
break; break;
case SPOILER_CHK_COLLECTABLE: case SPOILER_CHK_COLLECTABLE:
if(inSameArea) { if (inSameArea) {
Flags_SetCollectible(gPlayState, flagID); Flags_SetCollectible(gPlayState, flagID);
} else { } else {
gSaveContext.sceneFlags[scene].collect |= 1 << flagID; gSaveContext.sceneFlags[scene].collect |= 1 << flagID;
@@ -325,11 +325,12 @@ void RandomizerOnExternalCheckHandler(uint32_t randomizerCheck) {
Flags_SetInfTable(flagID); Flags_SetInfTable(flagID);
break; break;
case SPOILER_CHK_GOLD_SKULLTULA: case SPOILER_CHK_GOLD_SKULLTULA:
logMessage = "[LOG] Externaly checked golden skultulla: " + std::to_string(loc->GetActorParams()) + ", " + std::to_string(flagID); logMessage = "[LOG] Externaly checked golden skultulla: " + std::to_string(loc->GetActorParams()) + ", " +
std::to_string(flagID);
ArchipelagoConsole_SendMessage(logMessage.c_str(), true); ArchipelagoConsole_SendMessage(logMessage.c_str(), true);
SET_GS_FLAGS((flagID & 0x1F00) >> 8, flagID & 0xFF); SET_GS_FLAGS((flagID & 0x1F00) >> 8, flagID & 0xFF);
break; break;
case SPOILER_CHK_GRAVEDIGGER: //This enum is used nowhere in code, so i'll leave it as nothing for now case SPOILER_CHK_GRAVEDIGGER: // This enum is used nowhere in code, so i'll leave it as nothing for now
case SPOILER_CHK_NONE: case SPOILER_CHK_NONE:
// do Nothing // do Nothing
break; break;

View File

@@ -133,7 +133,7 @@ bool ItemLocation::HasObtained() const {
} }
void ItemLocation::SetCheckStatus(RandomizerCheckStatus status_) { void ItemLocation::SetCheckStatus(RandomizerCheckStatus status_) {
if(rc == RC_ARCHIPELAGO_RECEIVED_ITEM) // never count the AP receive trigger as 'collected' if (rc == RC_ARCHIPELAGO_RECEIVED_ITEM) // never count the AP receive trigger as 'collected'
return; return;
status = status_; status = status_;
} }

View File

@@ -5352,7 +5352,8 @@ void CreateArchipelagoItemMessage() {
customMessageManager->AddCustomMessageTable(Randomizer::archipelagoItemsTableID); customMessageManager->AddCustomMessageTable(Randomizer::archipelagoItemsTableID);
customMessageManager->CreateMessage( customMessageManager->CreateMessage(
Randomizer::archipelagoItemsTableID, 0, Randomizer::archipelagoItemsTableID, 0,
CustomMessage("You found [[apcolor]][[apitem]]%w for %r[[applayer]]%w!", "You found \x05\x06[[apitem]]\x05\x00 for \x05\x05[[applayer]]\x05\x00!", CustomMessage("You found [[apcolor]][[apitem]]%w for %r[[applayer]]%w!",
"You found \x05\x06[[apitem]]\x05\x00 for \x05\x05[[applayer]]\x05\x00!",
"You found \x05\x06[[apitem]]\x05\x00 for \x05\x05[[applayer]]\x05\x00!")); "You found \x05\x06[[apitem]]\x05\x00 for \x05\x05[[applayer]]\x05\x00!"));
} }
@@ -5370,7 +5371,8 @@ CustomMessage Randomizer::GetArchipelagoItemMessage(int16_t randomizerGet, uint3
} }
messageEntry.Replace("[[apcolor]]", itemColor); messageEntry.Replace("[[apcolor]]", itemColor);
messageEntry.Replace("[[apitem]]", std::string(gSaveContext.ship.quest.data.archipelago.locations[randomizerCheck].itemName)); messageEntry.Replace("[[apitem]]",
std::string(gSaveContext.ship.quest.data.archipelago.locations[randomizerCheck].itemName));
messageEntry.Replace("[[applayer]]", messageEntry.Replace("[[applayer]]",
std::string(gSaveContext.ship.quest.data.archipelago.locations[randomizerCheck].playerName)); std::string(gSaveContext.ship.quest.data.archipelago.locations[randomizerCheck].playerName));
messageEntry.AutoFormat(); messageEntry.AutoFormat();

View File

@@ -38,7 +38,7 @@ ArchipelagoClient& ArchipelagoClient::GetInstance() {
} }
bool ArchipelagoClient::StartClient() { bool ArchipelagoClient::StartClient() {
if(apClient != NULL) { if (apClient != NULL) {
apClient.reset(); apClient.reset();
} }
@@ -51,8 +51,7 @@ bool ArchipelagoClient::StartClient() {
std::list<std::string> tags; std::list<std::string> tags;
// tags.push_back("DeathLink"); // todo, implement deathlink // tags.push_back("DeathLink"); // todo, implement deathlink
apClient->ConnectSlot(CVarGetString(CVAR_REMOTE_ARCHIPELAGO("SlotName"), ""), apClient->ConnectSlot(CVarGetString(CVAR_REMOTE_ARCHIPELAGO("SlotName"), ""),
CVarGetString(CVAR_REMOTE_ARCHIPELAGO("Password"), ""), CVarGetString(CVAR_REMOTE_ARCHIPELAGO("Password"), ""), 0b001, tags);
0b001, tags);
}); });
apClient->set_slot_connected_handler([&](const nlohmann::json data) { apClient->set_slot_connected_handler([&](const nlohmann::json data) {
@@ -63,8 +62,8 @@ bool ArchipelagoClient::StartClient() {
// if we are already in game when we connect // if we are already in game when we connect
// we won't have to request an itemSynch // we won't have to request an itemSynch
if(GameInteractor::IsSaveLoaded(true)) { if (GameInteractor::IsSaveLoaded(true)) {
if(!isRightSaveLoaded()) { if (!isRightSaveLoaded()) {
disconnecting = true; disconnecting = true;
ArchipelagoConsole_SendMessage("[ERROR] Connected to incorrect slot, disconnecting..."); ArchipelagoConsole_SendMessage("[ERROR] Connected to incorrect slot, disconnecting...");
return; return;
@@ -76,11 +75,11 @@ bool ArchipelagoClient::StartClient() {
}); });
apClient->set_items_received_handler([&](const std::list<APClient::NetworkItem>& items) { apClient->set_items_received_handler([&](const std::list<APClient::NetworkItem>& items) {
if(disconnecting) { if (disconnecting) {
return; return;
} }
for(const APClient::NetworkItem& item : items) { for (const APClient::NetworkItem& item : items) {
ApItem apItem; ApItem apItem;
const std::string game = apClient->get_player_game(item.player); const std::string game = apClient->get_player_game(item.player);
apItem.itemName = apClient->get_item_name(item.item, AP_Client_consts::AP_GAME_NAME); apItem.itemName = apClient->get_item_name(item.item, AP_Client_consts::AP_GAME_NAME);
@@ -93,13 +92,13 @@ bool ArchipelagoClient::StartClient() {
}); });
apClient->set_location_info_handler([&](const std::list<APClient::NetworkItem>& items) { apClient->set_location_info_handler([&](const std::list<APClient::NetworkItem>& items) {
if(disconnecting) { if (disconnecting) {
return; return;
} }
scoutedItems.clear(); scoutedItems.clear();
for(const APClient::NetworkItem& item: items) { for (const APClient::NetworkItem& item : items) {
ApItem apItem; ApItem apItem;
const std::string game = apClient->get_player_game(item.player); const std::string game = apClient->get_player_game(item.player);
apItem.itemName = apClient->get_item_name(item.item, game); apItem.itemName = apClient->get_item_name(item.item, game);
@@ -112,7 +111,8 @@ bool ArchipelagoClient::StartClient() {
const std::string itemName = apItem.itemName; const std::string itemName = apItem.itemName;
const std::string playerName = apItem.playerName; const std::string playerName = apItem.playerName;
const std::string locationName = apItem.locationName; const std::string locationName = apItem.locationName;
std::string logMessage = "[LOG] Location scouted: " + itemName + " for " + playerName + " in location " + locationName; std::string logMessage =
"[LOG] Location scouted: " + itemName + " for " + playerName + " in location " + locationName;
ArchipelagoConsole_SendMessage(logMessage.c_str(), true); ArchipelagoConsole_SendMessage(logMessage.c_str(), true);
} }
@@ -120,53 +120,66 @@ bool ArchipelagoClient::StartClient() {
}); // todo maybe move these functions to a lambda, since they don't have to be static anymore }); // todo maybe move these functions to a lambda, since they don't have to be static anymore
apClient->set_location_checked_handler([&](const std::list<int64_t> locations) { apClient->set_location_checked_handler([&](const std::list<int64_t> locations) {
if(disconnecting) { if (disconnecting) {
return; return;
} }
for(const int64_t apLoc : locations) { for (const int64_t apLoc : locations) {
QueueExternalCheck(apLoc); QueueExternalCheck(apLoc);
} }
}); });
apClient->set_print_json_handler([&](const APClient::PrintJSONArgs& arg) { apClient->set_print_json_handler([&](const APClient::PrintJSONArgs& arg) {
if(disconnecting) { if (disconnecting) {
return; return;
} }
std::vector<ColoredTextNode> coloredNodes; std::vector<ColoredTextNode> coloredNodes;
for(const APClient::TextNode& node : arg.data) { for (const APClient::TextNode& node : arg.data) {
APClient* client = apClient.get(); APClient* client = apClient.get();
std::string color; std::string color;
std::string text; std::string text;
if(node.type == "player_id") { if (node.type == "player_id") {
int id = std::stoi(node.text); int id = std::stoi(node.text);
if (color.empty() && id == client->get_player_number()) color = "magenta"; if (color.empty() && id == client->get_player_number())
else if(color.empty()) color = "yellow"; color = "magenta";
else if (color.empty())
color = "yellow";
text = client->get_player_alias(id); text = client->get_player_alias(id);
} else if (node.type == "item_id") { } else if (node.type == "item_id") {
int64_t id = std::stoll(node.text); int64_t id = std::stoll(node.text);
if(color.empty()) { if (color.empty()) {
if (node.flags & APClient::ItemFlags::FLAG_ADVANCEMENT) color = "plum"; if (node.flags & APClient::ItemFlags::FLAG_ADVANCEMENT)
else if (node.flags & APClient::ItemFlags::FLAG_NEVER_EXCLUDE) color = "slateblue"; color = "plum";
else if (node.flags & APClient::ItemFlags::FLAG_TRAP) color = "salmon"; else if (node.flags & APClient::ItemFlags::FLAG_NEVER_EXCLUDE)
else color = "cyan"; color = "slateblue";
else if (node.flags & APClient::ItemFlags::FLAG_TRAP)
color = "salmon";
else
color = "cyan";
} }
text = client->get_item_name(id, client->get_player_game(node.player)); text = client->get_item_name(id, client->get_player_game(node.player));
} else if (node.type == "location_id") { } else if (node.type == "location_id") {
int64_t id = std::stoll(node.text); int64_t id = std::stoll(node.text);
if (color.empty()) color = "blue"; if (color.empty())
color = "blue";
text = client->get_location_name(id, client->get_player_game(node.player)); text = client->get_location_name(id, client->get_player_game(node.player));
} else if (node.type == "hint_status") { } else if (node.type == "hint_status") {
text = node.text; text = node.text;
if (node.hintStatus == APClient::HINT_FOUND) color = "green"; if (node.hintStatus == APClient::HINT_FOUND)
else if (node.hintStatus == APClient::HINT_UNSPECIFIED) color = "grey"; color = "green";
else if (node.hintStatus == APClient::HINT_NO_PRIORITY) color = "slateblue"; else if (node.hintStatus == APClient::HINT_UNSPECIFIED)
else if (node.hintStatus == APClient::HINT_AVOID) color = "salmon"; color = "grey";
else if (node.hintStatus == APClient::HINT_PRIORITY) color = "plum"; else if (node.hintStatus == APClient::HINT_NO_PRIORITY)
else color = "red"; // unknown status -> red color = "slateblue";
else if (node.hintStatus == APClient::HINT_AVOID)
color = "salmon";
else if (node.hintStatus == APClient::HINT_PRIORITY)
color = "plum";
else
color = "red"; // unknown status -> red
} else if (node.type == "ERROR") { } else if (node.type == "ERROR") {
color = "ERROR"; color = "ERROR";
text = node.text; text = node.text;
@@ -191,18 +204,18 @@ bool ArchipelagoClient::StartClient() {
} }
void ArchipelagoClient::GameLoaded() { void ArchipelagoClient::GameLoaded() {
if(apClient == nullptr) { if (apClient == nullptr) {
return; return;
} }
// if its not an AP save, disconnect // if its not an AP save, disconnect
if(!IS_ARCHIPELAGO) { if (!IS_ARCHIPELAGO) {
ArchipelagoConsole_SendMessage("[ERROR] Loaded save is not not an archipelago save, disconnecting..."); ArchipelagoConsole_SendMessage("[ERROR] Loaded save is not not an archipelago save, disconnecting...");
disconnecting = true; disconnecting = true;
return; return;
} }
if(!isRightSaveLoaded()) { if (!isRightSaveLoaded()) {
ArchipelagoConsole_SendMessage("[ERROR] Loaded save is not associated with connected slot, disconnecting..."); ArchipelagoConsole_SendMessage("[ERROR] Loaded save is not associated with connected slot, disconnecting...");
disconnecting = true; disconnecting = true;
return; return;
@@ -219,10 +232,10 @@ void ArchipelagoClient::StartLocationScouts() {
std::set<int64_t> missing_loc_set = apClient->get_missing_locations(); std::set<int64_t> missing_loc_set = apClient->get_missing_locations();
std::set<int64_t> found_loc_set = apClient->get_checked_locations(); std::set<int64_t> found_loc_set = apClient->get_checked_locations();
std::list<int64_t> location_list; std::list<int64_t> location_list;
for(const int64_t loc_id : missing_loc_set) { for (const int64_t loc_id : missing_loc_set) {
location_list.emplace_back(loc_id); location_list.emplace_back(loc_id);
} }
for(const int64_t loc_id : found_loc_set) { for (const int64_t loc_id : found_loc_set) {
location_list.emplace_back(loc_id); location_list.emplace_back(loc_id);
} }
apClient->LocationScouts(location_list); apClient->LocationScouts(location_list);
@@ -237,14 +250,15 @@ void ArchipelagoClient::SynchItems() {
void ArchipelagoClient::SynchSentLocations() { void ArchipelagoClient::SynchSentLocations() {
// send already checked locations // send already checked locations
std::list<int64_t> checkedLocations; std::list<int64_t> checkedLocations;
for(const auto& loc : Rando::StaticData::GetLocationTable()) { for (const auto& loc : Rando::StaticData::GetLocationTable()) {
const RandomizerCheck rc = loc.GetRandomizerCheck(); const RandomizerCheck rc = loc.GetRandomizerCheck();
if(Rando::Context::GetInstance()->GetItemLocation(rc)->HasObtained()) { if (Rando::Context::GetInstance()->GetItemLocation(rc)->HasObtained()) {
const int64_t apLocation = apClient->get_location_id(loc.GetName()); const int64_t apLocation = apClient->get_location_id(loc.GetName());
checkedLocations.emplace_back(apLocation); checkedLocations.emplace_back(apLocation);
} }
} }
std::string locationLog = "[LOG] Synching " + std::to_string(checkedLocations.size())+ " checks already found in game"; std::string locationLog =
"[LOG] Synching " + std::to_string(checkedLocations.size()) + " checks already found in game";
ArchipelagoConsole_SendMessage(locationLog.c_str(), true); ArchipelagoConsole_SendMessage(locationLog.c_str(), true);
apClient->LocationChecks(checkedLocations); apClient->LocationChecks(checkedLocations);
@@ -252,7 +266,7 @@ void ArchipelagoClient::SynchSentLocations() {
void ArchipelagoClient::SynchReceivedLocations() { void ArchipelagoClient::SynchReceivedLocations() {
// Open checks that have been found previously but went unsaved // Open checks that have been found previously but went unsaved
for(const int64_t apLoc : apClient->get_checked_locations()) { for (const int64_t apLoc : apClient->get_checked_locations()) {
QueueExternalCheck(apLoc); QueueExternalCheck(apLoc);
} }
} }
@@ -261,13 +275,13 @@ void ArchipelagoClient::QueueExternalCheck(const int64_t apLocation) {
const std::string checkName = apClient->get_location_name(apLocation, AP_Client_consts::AP_GAME_NAME); const std::string checkName = apClient->get_location_name(apLocation, AP_Client_consts::AP_GAME_NAME);
const uint32_t RC = static_cast<uint32_t>(Rando::StaticData::locationNameToEnum[checkName]); const uint32_t RC = static_cast<uint32_t>(Rando::StaticData::locationNameToEnum[checkName]);
if(RC == RC_UNKNOWN_CHECK) { if (RC == RC_UNKNOWN_CHECK) {
ArchipelagoConsole_SendMessage("[ERROR] Attempting to queue RC_UNKOWN_CHECK, skipping", false); ArchipelagoConsole_SendMessage("[ERROR] Attempting to queue RC_UNKOWN_CHECK, skipping", false);
return; return;
} }
// Don't queue checks we already have // Don't queue checks we already have
if(Rando::Context::GetInstance()->GetItemLocation(RC)->HasObtained()) { if (Rando::Context::GetInstance()->GetItemLocation(RC)->HasObtained()) {
return; return;
} }
@@ -278,7 +292,7 @@ void ArchipelagoClient::QueueExternalCheck(const int64_t apLocation) {
} }
bool ArchipelagoClient::IsConnected() { bool ArchipelagoClient::IsConnected() {
if(apClient == nullptr) { if (apClient == nullptr) {
return false; return false;
} }
@@ -286,12 +300,12 @@ bool ArchipelagoClient::IsConnected() {
} }
void ArchipelagoClient::CheckLocation(RandomizerCheck sohCheckId) { void ArchipelagoClient::CheckLocation(RandomizerCheck sohCheckId) {
if(sohCheckId == RC_UNKNOWN_CHECK) { if (sohCheckId == RC_UNKNOWN_CHECK) {
ArchipelagoConsole_SendMessage("[ERROR] trying to send RC_UNKNOWN_CHECK, skipping", false); ArchipelagoConsole_SendMessage("[ERROR] trying to send RC_UNKNOWN_CHECK, skipping", false);
return; return;
} }
if(!IsConnected()) { if (!IsConnected()) {
return; return;
} }
@@ -308,7 +322,7 @@ void ArchipelagoClient::CheckLocation(RandomizerCheck sohCheckId) {
} }
void ArchipelagoClient::OnItemReceived(const ApItem apItem) { void ArchipelagoClient::OnItemReceived(const ApItem apItem) {
if(!GameInteractor::IsSaveLoaded(true)) { if (!GameInteractor::IsSaveLoaded(true)) {
// Don't queue up any items when we aren't in game // Don't queue up any items when we aren't in game
// Any Items missed this way will get synched when we load the save // Any Items missed this way will get synched when we load the save
return; return;
@@ -317,7 +331,7 @@ void ArchipelagoClient::OnItemReceived(const ApItem apItem) {
std::string logMessage = "[LOG] Received " + apItem.itemName; std::string logMessage = "[LOG] Received " + apItem.itemName;
ArchipelagoConsole_SendMessage(logMessage.c_str(), true); ArchipelagoConsole_SendMessage(logMessage.c_str(), true);
if(apItem.index < gSaveContext.ship.quest.data.archipelago.lastReceivedItemIndex) { if (apItem.index < gSaveContext.ship.quest.data.archipelago.lastReceivedItemIndex) {
// Skip queueing any items we already have // Skip queueing any items we already have
std::string logMessage = "[LOG] Skipping giving " + apItem.itemName + ". We received this previously."; std::string logMessage = "[LOG] Skipping giving " + apItem.itemName + ". We received this previously.";
ArchipelagoConsole_SendMessage(logMessage.c_str(), true); ArchipelagoConsole_SendMessage(logMessage.c_str(), true);
@@ -332,7 +346,7 @@ void ArchipelagoClient::QueueItem(const ApItem item) {
std::string logMessage = "[LOG] Giving " + item.itemName; std::string logMessage = "[LOG] Giving " + item.itemName;
ArchipelagoConsole_SendMessage(logMessage.c_str(), true); ArchipelagoConsole_SendMessage(logMessage.c_str(), true);
const RandomizerGet RG = Rando::StaticData::itemNameToEnum[item.itemName]; const RandomizerGet RG = Rando::StaticData::itemNameToEnum[item.itemName];
if(RG == RG_NONE) { if (RG == RG_NONE) {
return; return;
} }
@@ -341,7 +355,7 @@ void ArchipelagoClient::QueueItem(const ApItem item) {
} }
void ArchipelagoClient::SendGameWon() { void ArchipelagoClient::SendGameWon() {
if(!gameWon) { if (!gameWon) {
apClient->StatusUpdate(APClient::ClientStatus::GOAL); apClient->StatusUpdate(APClient::ClientStatus::GOAL);
gameWon = true; gameWon = true;
} }
@@ -349,12 +363,14 @@ void ArchipelagoClient::SendGameWon() {
void ArchipelagoClient::SendMessageToConsole(const std::string message) { void ArchipelagoClient::SendMessageToConsole(const std::string message) {
// local commands not implemented yet // local commands not implemented yet
if(message.starts_with("/")) { if (message.starts_with("/")) {
ArchipelagoConsole_SendMessage("Ship of Harkinian does not have any local commands yet.\nUse \"!help\" to see server commands instead", false); ArchipelagoConsole_SendMessage(
"Ship of Harkinian does not have any local commands yet.\nUse \"!help\" to see server commands instead",
false);
return; return;
} }
if(apClient == nullptr) { if (apClient == nullptr) {
ArchipelagoConsole_SendMessage("[ERROR] Could not send message. Please Connect to your slot.", false); ArchipelagoConsole_SendMessage("[ERROR] Could not send message. Please Connect to your slot.", false);
return; return;
} }
@@ -363,18 +379,18 @@ void ArchipelagoClient::SendMessageToConsole(const std::string message) {
} }
void ArchipelagoClient::Poll() { void ArchipelagoClient::Poll() {
if(apClient == nullptr) { if (apClient == nullptr) {
return; return;
} }
if(disconnecting) { if (disconnecting) {
apClient->reset(); apClient->reset();
apClient = nullptr; apClient = nullptr;
return; return;
} }
// queue another item to be received // queue another item to be received
if(!itemQueued && receiveQueue.size() > 0) { if (!itemQueued && receiveQueue.size() > 0) {
const ApItem item = receiveQueue.front(); const ApItem item = receiveQueue.front();
receiveQueue.pop(); receiveQueue.pop();
@@ -391,7 +407,7 @@ bool ArchipelagoClient::isRightSaveLoaded() const {
} }
const std::string ArchipelagoClient::GetSlotName() const { const std::string ArchipelagoClient::GetSlotName() const {
if(apClient == NULL) { if (apClient == NULL) {
return ""; return "";
} }
@@ -472,8 +488,7 @@ void LoadArchipelagoData() {
ARRAY_COUNT(gSaveContext.ship.quest.data.archipelago.slotName)); ARRAY_COUNT(gSaveContext.ship.quest.data.archipelago.slotName));
SaveManager::Instance->LoadArray( SaveManager::Instance->LoadArray(
"locations", ARRAY_COUNT(gSaveContext.ship.quest.data.archipelago.locations), "locations", ARRAY_COUNT(gSaveContext.ship.quest.data.archipelago.locations), [](size_t i) {
[](size_t i) {
SaveManager::Instance->LoadStruct("", [&i]() { SaveManager::Instance->LoadStruct("", [&i]() {
SaveManager::Instance->LoadCharArray( SaveManager::Instance->LoadCharArray(
"itemName", gSaveContext.ship.quest.data.archipelago.locations[i].itemName, "itemName", gSaveContext.ship.quest.data.archipelago.locations[i].itemName,
@@ -529,9 +544,11 @@ void RegisterArchipelago() {
CVarSetInteger(CVAR_REMOTE_ARCHIPELAGO("Connected"), 0); CVarSetInteger(CVAR_REMOTE_ARCHIPELAGO("Connected"), 0);
COND_HOOK(GameInteractor::OnGameFrameUpdate, true, [](){ArchipelagoClient::GetInstance().Poll();}); COND_HOOK(GameInteractor::OnGameFrameUpdate, true, []() { ArchipelagoClient::GetInstance().Poll(); });
COND_HOOK(GameInteractor::PostLoadGame, true, [](int32_t file_id){ArchipelagoClient::GetInstance().GameLoaded();}); COND_HOOK(GameInteractor::PostLoadGame, true,
COND_HOOK(GameInteractor::OnRandomizerItemGivenHooks, IS_ARCHIPELAGO, [](int32_t file_id) { ArchipelagoClient::GetInstance().GameLoaded(); });
COND_HOOK(
GameInteractor::OnRandomizerItemGivenHooks, IS_ARCHIPELAGO,
[](uint32_t rc, GetItemEntry gi, uint8_t isGiSkipped) { [](uint32_t rc, GetItemEntry gi, uint8_t isGiSkipped) {
if (rc == RC_ARCHIPELAGO_RECEIVED_ITEM) { if (rc == RC_ARCHIPELAGO_RECEIVED_ITEM) {
gSaveContext.ship.quest.data.archipelago.lastReceivedItemIndex++; gSaveContext.ship.quest.data.archipelago.lastReceivedItemIndex++;
@@ -556,12 +573,11 @@ void RegisterArchipelago() {
break; break;
} }
Notification::Emit({ Notification::Emit(
.itemIcon = itemIcon, { .itemIcon = itemIcon,
.prefix = std::string(gSaveContext.ship.quest.data.archipelago.locations[rc].itemName), .prefix = std::string(gSaveContext.ship.quest.data.archipelago.locations[rc].itemName),
.message = " for ", .message = " for ",
.suffix = std::string(gSaveContext.ship.quest.data.archipelago.locations[rc].playerName) .suffix = std::string(gSaveContext.ship.quest.data.archipelago.locations[rc].playerName) });
});
} }
} }
}); });

View File

@@ -10,14 +10,14 @@
class APClient; class APClient;
namespace AP_Client_consts { namespace AP_Client_consts {
static constexpr int MAX_ADDRESS_LENGTH = 64; static constexpr int MAX_ADDRESS_LENGTH = 64;
static constexpr int MAX_PLAYER_NAME_LENGHT = 17; static constexpr int MAX_PLAYER_NAME_LENGHT = 17;
static constexpr int MAX_PASSWORD_LENGTH = 32; static constexpr int MAX_PASSWORD_LENGTH = 32;
static constexpr char const* AP_GAME_NAME = "Ship of Harkinian"; static constexpr char const* AP_GAME_NAME = "Ship of Harkinian";
} } // namespace AP_Client_consts
class ArchipelagoClient{ class ArchipelagoClient {
public: public:
struct ApItem { struct ApItem {
std::string itemName; std::string itemName;
@@ -69,8 +69,8 @@ class ArchipelagoClient{
ArchipelagoClient(); ArchipelagoClient();
private: private:
ArchipelagoClient(ArchipelagoClient &) = delete; ArchipelagoClient(ArchipelagoClient&) = delete;
void operator=(const ArchipelagoClient &) = delete; void operator=(const ArchipelagoClient&) = delete;
bool isRightSaveLoaded() const; bool isRightSaveLoaded() const;

View File

@@ -47,8 +47,8 @@ void ArchipelagoConsoleWindow::DrawElement() {
if (ImGui::BeginChild("ScrollingRegion", ImVec2(0, 400), ImGuiChildFlags_AlwaysUseWindowPadding, if (ImGui::BeginChild("ScrollingRegion", ImVec2(0, 400), ImGuiChildFlags_AlwaysUseWindowPadding,
ImGuiWindowFlags_HorizontalScrollbar)) { ImGuiWindowFlags_HorizontalScrollbar)) {
for(const std::vector<ArchipelagoClient::ColoredTextNode>& line : Items) { for (const std::vector<ArchipelagoClient::ColoredTextNode>& line : Items) {
for(const ArchipelagoClient::ColoredTextNode& node : line) { for (const ArchipelagoClient::ColoredTextNode& node : line) {
ImGui::PushStyleColor(ImGuiCol_Text, getColorVal(node.color)); ImGui::PushStyleColor(ImGuiCol_Text, getColorVal(node.color));
ImGui::TextUnformatted(node.text.c_str()); ImGui::TextUnformatted(node.text.c_str());
ImGui::SameLine(); ImGui::SameLine();
@@ -69,24 +69,23 @@ void ArchipelagoConsoleWindow::DrawElement() {
static char textEntryBuf[1024]; static char textEntryBuf[1024];
static bool keepFocus = false; static bool keepFocus = false;
if(keepFocus) { if (keepFocus) {
ImGui::SetKeyboardFocusHere(); ImGui::SetKeyboardFocusHere();
keepFocus = false; keepFocus = false;
} }
if(ImGui::InputText("##AP_MessageField", textEntryBuf, 1023, ImGuiInputTextFlags_EnterReturnsTrue)) { if (ImGui::InputText("##AP_MessageField", textEntryBuf, 1023, ImGuiInputTextFlags_EnterReturnsTrue)) {
ArchipelagoClient::GetInstance().SendMessageToConsole(std::string(textEntryBuf)); ArchipelagoClient::GetInstance().SendMessageToConsole(std::string(textEntryBuf));
textEntryBuf[0] = '\0'; textEntryBuf[0] = '\0';
keepFocus = true; keepFocus = true;
} }
//keepFocus = ImGui::IsItemActive(); // keepFocus = ImGui::IsItemActive();
ImGui::SameLine(); ImGui::SameLine();
if(ImGui::Button("Send")) { if (ImGui::Button("Send")) {
ArchipelagoClient::GetInstance().SendMessageToConsole(std::string(textEntryBuf)); ArchipelagoClient::GetInstance().SendMessageToConsole(std::string(textEntryBuf));
textEntryBuf[0] = '\0'; textEntryBuf[0] = '\0';
keepFocus = true; keepFocus = true;
} }
ImGui::PopStyleColor(); ImGui::PopStyleColor();
ImGui::PopStyleVar(4); ImGui::PopStyleVar(4);
}; };
@@ -94,31 +93,31 @@ void ArchipelagoConsoleWindow::DrawElement() {
ImVec4 getColorVal(const std::string& color) { // TODO change color strings to an enum ImVec4 getColorVal(const std::string& color) { // TODO change color strings to an enum
if (color == "ERROR") { if (color == "ERROR") {
return ImVec4(1.0f, 0.4f, 0.4f, 1.0f); return ImVec4(1.0f, 0.4f, 0.4f, 1.0f);
} else if(color =="LOG") { } else if (color == "LOG") {
return ImVec4(0.7f, 0.7f, 1.0f, 1.0f); return ImVec4(0.7f, 0.7f, 1.0f, 1.0f);
} else if(color == "black") { } else if (color == "black") {
return ImVec4(0.000f, 0.000f, 0.000f, 1.00f); return ImVec4(0.000f, 0.000f, 0.000f, 1.00f);
} else if(color == "red") { } else if (color == "red") {
return ImVec4(0.933f, 0.000f, 0.000f, 1.00f); return ImVec4(0.933f, 0.000f, 0.000f, 1.00f);
} else if(color == "green") { } else if (color == "green") {
return ImVec4(0.000f, 1.000f, 0.498f, 1.00f); return ImVec4(0.000f, 1.000f, 0.498f, 1.00f);
} else if(color == "yellow") { } else if (color == "yellow") {
return ImVec4(0.980f, 0.980f, 0.824f, 1.00f); return ImVec4(0.980f, 0.980f, 0.824f, 1.00f);
} else if(color == "blue") { } else if (color == "blue") {
return ImVec4(0.392f, 0.584f, 0.929f, 1.00f); return ImVec4(0.392f, 0.584f, 0.929f, 1.00f);
} else if(color == "cyan") { } else if (color == "cyan") {
return ImVec4(0.000f, 0.933f, 0.933f, 1.00f); return ImVec4(0.000f, 0.933f, 0.933f, 1.00f);
} else if(color == "magenta") { } else if (color == "magenta") {
return ImVec4(0.933f, 0.000f, 0.933f, 1.00f); return ImVec4(0.933f, 0.000f, 0.933f, 1.00f);
} else if(color == "slateblue") { } else if (color == "slateblue") {
return ImVec4(0.427f, 0.545f, 0.910f, 1.00f); return ImVec4(0.427f, 0.545f, 0.910f, 1.00f);
} else if(color == "plum") { } else if (color == "plum") {
return ImVec4(0.686f, 0.600f, 0.937f, 1.00f); return ImVec4(0.686f, 0.600f, 0.937f, 1.00f);
} else if(color == "salmon") { } else if (color == "salmon") {
return ImVec4(0.980f, 0.502f, 0.447f, 1.00f); return ImVec4(0.980f, 0.502f, 0.447f, 1.00f);
} else if(color == "white") { } else if (color == "white") {
return ImVec4(0.93f, 0.93f, 0.93f, 1.00f); return ImVec4(0.93f, 0.93f, 0.93f, 1.00f);
} else if(color == "orange") { } else if (color == "orange") {
return ImVec4(1.000, 0.467f, 0.000f, 1.000f); return ImVec4(1.000, 0.467f, 0.000f, 1.000f);
} }
return ImVec4(0.93f, 0.93f, 0.93f, 1.00f); return ImVec4(0.93f, 0.93f, 0.93f, 1.00f);

View File

@@ -10,12 +10,12 @@
class ArchipelagoConsoleWindow final : public Ship::GuiWindow { class ArchipelagoConsoleWindow final : public Ship::GuiWindow {
public: public:
using GuiWindow::GuiWindow; using GuiWindow::GuiWindow;
~ArchipelagoConsoleWindow() {}; ~ArchipelagoConsoleWindow(){};
protected: protected:
void InitElement() override {}; void InitElement() override{};
void DrawElement() override; void DrawElement() override;
void UpdateElement() override {}; void UpdateElement() override{};
}; };
void ArchipelagoConsole_SendMessage(const char* fmt, bool debugMessage = false, ...); void ArchipelagoConsole_SendMessage(const char* fmt, bool debugMessage = false, ...);

View File

@@ -72,11 +72,11 @@ void ArchipelagoSettingsWindow::DrawElement() {
ArchipelagoClient::GetInstance().OnItemReceived(apItem); ArchipelagoClient::GetInstance().OnItemReceived(apItem);
} }
ImGui::SameLine(); ImGui::SameLine();
if (UIWidgets::Button("Send Game Won", if (UIWidgets::Button("Send Game Won", UIWidgets::ButtonOptions().Color(THEME_COLOR).Size(ImVec2(0.0, 0.0)))) {
UIWidgets::ButtonOptions().Color(THEME_COLOR).Size(ImVec2(0.0, 0.0)))) {
ArchipelagoClient::GetInstance().SendGameWon(); ArchipelagoClient::GetInstance().SendGameWon();
} }
if (UIWidgets::Button("Get Mido br chest", UIWidgets::ButtonOptions().Color(THEME_COLOR).Size(ImVec2(0.0, 0.0)))) { if (UIWidgets::Button("Get Mido br chest",
UIWidgets::ButtonOptions().Color(THEME_COLOR).Size(ImVec2(0.0, 0.0)))) {
ArchipelagoClient::GetInstance().QueueExternalCheck(16711707); ArchipelagoClient::GetInstance().QueueExternalCheck(16711707);
} }
} }
@@ -96,7 +96,6 @@ void ArchipelagoSettingsWindow::DrawElement() {
void ArchipelagoSettingsWindow::InitElement() { void ArchipelagoSettingsWindow::InitElement() {
SaveManager::Instance->AddLoadFunction("archipelagoData", 1, LoadArchipelagoData); SaveManager::Instance->AddLoadFunction("archipelagoData", 1, LoadArchipelagoData);
SaveManager::Instance->AddSaveFunction("archipelagoData", 1, SaveArchipelagoData, true, SaveManager::Instance->AddSaveFunction("archipelagoData", 1, SaveArchipelagoData, true, SECTION_PARENT_NONE);
SECTION_PARENT_NONE);
SaveManager::Instance->AddInitFunction(InitArchipelagoData); SaveManager::Instance->AddInitFunction(InitArchipelagoData);
} }

View File

@@ -7,12 +7,12 @@
class ArchipelagoSettingsWindow final : public Ship::GuiWindow { class ArchipelagoSettingsWindow final : public Ship::GuiWindow {
public: public:
using GuiWindow::GuiWindow; using GuiWindow::GuiWindow;
~ArchipelagoSettingsWindow() {}; ~ArchipelagoSettingsWindow(){};
protected: protected:
void InitElement() override; void InitElement() override;
void DrawElement() override; void DrawElement() override;
void UpdateElement() override {}; void UpdateElement() override{};
}; };
#endif // ARCHIPELAGO_SETTINGS_WINDOW_H #endif // ARCHIPELAGO_SETTINGS_WINDOW_H