Function renames

This commit is contained in:
aMannus
2025-05-19 11:16:13 +02:00
parent 1bf399658c
commit 959b7dd433
12 changed files with 127 additions and 127 deletions

View File

@@ -783,7 +783,7 @@ void RegisterBossDefeatTimestamps() {
case ACTOR_BOSS_GANON2:
gSaveContext.ship.stats.itemTimestamp[TIMESTAMP_DEFEAT_GANON] = GAMEPLAYSTAT_TOTAL_TIME;
gSaveContext.ship.stats.gameComplete = true;
ArchipelagoClient::getInstance().send_game_won();
ArchipelagoClient::GetInstance().SendGameWon();
break;
case ACTOR_BOSS_GANONDROF:
gSaveContext.ship.stats.itemTimestamp[TIMESTAMP_DEFEAT_PHANTOM_GANON] = GAMEPLAYSTAT_TOTAL_TIME;

View File

@@ -441,9 +441,9 @@ void Context::ParseArchipelago() {
mSeedGenerated = false;
mSpoilerLoaded = false;
ArchipelagoClient& ap_client = ArchipelagoClient::getInstance();
Rando::Settings::GetInstance()->ParseArchipelago(ap_client.get_slot_data());
ParseArchipelagoItemsLocations(ap_client.get_scouted_items());
ArchipelagoClient& ap_client = ArchipelagoClient::GetInstance();
Rando::Settings::GetInstance()->ParseArchipelago(ap_client.GetSlotData());
ParseArchipelagoItemsLocations(ap_client.GetScoutedItems());
// lets see if counting AP_loaded as spoiler loaded does the trick
mSpoilerLoaded = true;
@@ -484,7 +484,7 @@ void Context::ParseItemLocationsJson(nlohmann::json spoilerFileJson) {
}
void Context::ParseArchipelagoItemsLocations(const std::vector<ArchipelagoClient::ApItem>& scouted_items) {
const std::string SlotName = ArchipelagoClient::getInstance().get_slot_name();
const std::string SlotName = ArchipelagoClient::GetInstance().GetSlotName();
// init the item table with regular items first
for(int rc = 1; rc <= RC_MAX; rc++) {

View File

@@ -383,7 +383,7 @@ void RandomizerOnItemReceiveHandler(GetItemEntry receivedItemEntry) {
// todo maybe move to seperate function
// let arhipelago know we got this check
if(randomizerQueuedCheck != RC_ARCHIPELAGO_RECIEVED_ITEM) {
ArchipelagoClient& ap_client = ArchipelagoClient::getInstance();
ArchipelagoClient& ap_client = ArchipelagoClient::GetInstance();
ap_client.check_location(randomizerQueuedCheck);
}
@@ -2445,7 +2445,7 @@ void RandomizerRegisterHooks() {
GameInteractor::Instance->UnregisterGameHook<GameInteractor::OnVanillaBehavior>(
shuffleFreestandingOnVanillaBehaviorHook);
ArchipelagoClient::getInstance().removeItemRecievedCallback(ArchipelagoOnRecieveItem);
ArchipelagoClient::GetInstance().RemoveItemRecievedCallback(ArchipelagoOnRecieveItem);
onFlagSetHook = 0;
onSceneFlagSetHook = 0;
@@ -2562,6 +2562,6 @@ void RandomizerRegisterHooks() {
ShuffleFairies_RegisterHooks();
}
ArchipelagoClient::getInstance().addItemRecievedCallback(ArchipelagoOnRecieveItem);
ArchipelagoClient::GetInstance().AddItemRecievedCallback(ArchipelagoOnRecieveItem);
});
}

View File

@@ -5885,7 +5885,7 @@ extern "C" u16 Randomizer_Item_Give(PlayState* play, GetItemEntry giEntry) {
(OTRGlobals::Instance->gRandomizer->GetRandoSettingValue(RSK_TRIFORCE_HUNT_PIECES_REQUIRED) + 1)) {
gSaveContext.ship.stats.itemTimestamp[TIMESTAMP_TRIFORCE_COMPLETED] = GAMEPLAYSTAT_TOTAL_TIME;
gSaveContext.ship.stats.gameComplete = 1;
ArchipelagoClient::getInstance().send_game_won();
ArchipelagoClient::GetInstance().SendGameWon();
Flags_SetRandomizerInf(RAND_INF_GRANT_GANONS_BOSSKEY);
Play_PerformSave(play);
Notification::Emit({

View File

@@ -352,7 +352,7 @@ void HandleDragAndDrop(std::vector<SplitObject>& objectList, int targetIndex, co
void TimeSplitCompleteSplits() {
gSaveContext.ship.stats.itemTimestamp[TIMESTAMP_DEFEAT_GANON] = GAMEPLAYSTAT_TOTAL_TIME;
gSaveContext.ship.stats.gameComplete = true;
ArchipelagoClient::getInstance().send_game_won();
ArchipelagoClient::GetInstance().SendGameWon();
}
void TimeSplitsSkipSplit(uint32_t index) {

View File

@@ -19,50 +19,50 @@ ArchipelagoClient::ArchipelagoClient() {
game_won = false;
namespace apc = AP_Client_consts;
CVarSetInteger("archipelago_connected", 0);
strncpy(server_address, CVarGetString(apc::SETTING_ADDRESS, apc::DEFAULT_SERVER_NAME), apc::MAX_ADDRESS_LENGTH);
strncpy(slot_name, CVarGetString(apc::SETTING_NAME, ""), apc::MAX_PLAYER_NAME_LENGHT);
CVarSetInteger("ArchipelagoConnected", 0);
strncpy(serverAddress, CVarGetString(apc::SETTING_ADDRESS, apc::DEFAULT_SERVER_NAME), apc::MAX_ADDRESS_LENGTH);
strncpy(slotName, CVarGetString(apc::SETTING_NAME, ""), apc::MAX_PLAYER_NAME_LENGHT);
// call poll every frame
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnGameFrameUpdate>([](){ArchipelagoClient::getInstance().poll();});
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnGameFrameUpdate>([](){ArchipelagoClient::GetInstance().Poll();});
}
ArchipelagoClient& ArchipelagoClient::getInstance() {
ArchipelagoClient& ArchipelagoClient::GetInstance() {
static ArchipelagoClient Client;
return Client;
}
bool ArchipelagoClient::start_client() {
if(apclient != NULL) {
apclient.reset();
bool ArchipelagoClient::StartClient() {
if(apClient != NULL) {
apClient.reset();
}
apclient = std::unique_ptr<APClient>(new APClient(uuid, AP_Client_consts::AP_GAME_NAME, server_address));
apClient = std::unique_ptr<APClient>(new APClient(uuid, AP_Client_consts::AP_GAME_NAME, serverAddress));
apclient->set_room_info_handler([&]() {
apClient->set_room_info_handler([&]() {
std::list<std::string> tags;
// tags.push_back("DeathLink"); // todo, implement deathlink
apclient->ConnectSlot(slot_name, password, 0b001, tags);
apClient->ConnectSlot(slotName, password, 0b001, tags);
});
apclient->set_items_received_handler([&](const std::list<APClient::NetworkItem>& items) {
apClient->set_items_received_handler([&](const std::list<APClient::NetworkItem>& items) {
for(const APClient::NetworkItem& item : items) {
on_item_recieved(item.item, false); // todo get rid of notify, since it doesn't work for us right now anyway
OnItemReceived(item.item, false); // todo get rid of notify, since it doesn't work for us right now anyway
}
});
apclient->set_location_info_handler([&](const std::list<APClient::NetworkItem>& items) {
scouted_items.clear();
apClient->set_location_info_handler([&](const std::list<APClient::NetworkItem>& items) {
scoutedItems.clear();
for(const APClient::NetworkItem& item: items) {
ApItem apItem;
const std::string game = apclient->get_player_game(item.player);
apItem.itemName = apclient->get_item_name(item.item, game);
apItem.locationName = apclient->get_location_name(item.location, game);
apItem.playerName = apclient->get_player_alias(item.player);
const std::string game = apClient->get_player_game(item.player);
apItem.itemName = apClient->get_item_name(item.item, game);
apItem.locationName = apClient->get_location_name(item.location, game);
apItem.playerName = apClient->get_player_alias(item.player);
apItem.flags = item.flags;
apItem.index = item.index;
scouted_items.push_back(apItem);
scoutedItems.push_back(apItem);
const std::string itemName = apItem.itemName;
const std::string playerName = apItem.playerName;
@@ -72,17 +72,17 @@ bool ArchipelagoClient::start_client() {
}
}); // 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) {
// todo implement me
});
save_data();
SaveData();
return true;
}
void ArchipelagoClient::start_location_scouts() {
std::set<int64_t> missing_loc_set = apclient->get_missing_locations();
std::set<int64_t> found_loc_set = apclient->get_checked_locations();
void ArchipelagoClient::StartLocationScouts() {
std::set<int64_t> missing_loc_set = apClient->get_missing_locations();
std::set<int64_t> found_loc_set = apClient->get_checked_locations();
std::list<int64_t> location_list;
for(const int64_t loc_id : missing_loc_set) {
location_list.emplace_back(loc_id);
@@ -90,16 +90,16 @@ void ArchipelagoClient::start_location_scouts() {
for(const int64_t loc_id : found_loc_set) {
location_list.emplace_back(loc_id);
}
apclient->LocationScouts(location_list);
apClient->LocationScouts(location_list);
}
void ArchipelagoClient::save_data() {
CVarSetString(AP_Client_consts::SETTING_ADDRESS, server_address);
CVarSetString(AP_Client_consts::SETTING_NAME, slot_name);
void ArchipelagoClient::SaveData() {
CVarSetString(AP_Client_consts::SETTING_ADDRESS, serverAddress);
CVarSetString(AP_Client_consts::SETTING_NAME, slotName);
}
bool ArchipelagoClient::isConnected() {
return apclient->get_state() == APClient::State::SLOT_CONNECTED;
bool ArchipelagoClient::IsConnected() {
return apClient->get_state() == APClient::State::SLOT_CONNECTED;
}
void ArchipelagoClient::check_location(RandomizerCheck SoH_check_id) {
@@ -108,26 +108,26 @@ void ArchipelagoClient::check_location(RandomizerCheck SoH_check_id) {
if(ap_name.empty()) {
return;
}
int64_t ap_item_id = apclient->get_location_id(std::string(ap_name));
int64_t ap_item_id = apClient->get_location_id(std::string(ap_name));
std::string logMessage = "[LOG] Checked: " + ap_name + "(" + std::to_string(ap_item_id) + "), sending to AP server";
ArchipelagoConsole_SendMessage(logMessage.c_str());
// currently not sending, because i only get so many real chances
if(!isConnected()) {
if(!IsConnected()) {
return;
}
apclient->LocationChecks({ap_item_id});
apClient->LocationChecks({ap_item_id});
}
void ArchipelagoClient::addItemRecievedCallback(std::function<void(const std::string&)> callback) {
void ArchipelagoClient::AddItemRecievedCallback(std::function<void(const std::string&)> callback) {
ItemRecievedCallback = callback;
}
void ArchipelagoClient::removeItemRecievedCallback(std::function<void(const std::string&)> old_callback) {
void ArchipelagoClient::RemoveItemRecievedCallback(std::function<void(const std::string&)> old_callback) {
ItemRecievedCallback = nullptr;
}
void ArchipelagoClient::on_connected() {
void ArchipelagoClient::OnConnected() {
// todo implement me
ArchipelagoConsole_SendMessage("[LOG] AP Connected!");
}
@@ -135,10 +135,10 @@ void ArchipelagoClient::on_connected() {
// // todo implement me
//}
void ArchipelagoClient::on_item_recieved(int64_t recieved_item_id, bool notify_player) {
void ArchipelagoClient::OnItemReceived(int64_t recieved_item_id, bool notify_player) {
// call each callback
const std::string item_name = apclient->get_item_name(recieved_item_id, AP_Client_consts::AP_GAME_NAME);
ArchipelagoClient& ap_client = ArchipelagoClient::getInstance();
const std::string item_name = apClient->get_item_name(recieved_item_id, AP_Client_consts::AP_GAME_NAME);
ArchipelagoClient& ap_client = ArchipelagoClient::GetInstance();
if(ap_client.ItemRecievedCallback) {
std::string logMessage = "[LOG] Item recieved: " + item_name + ". Notify: " + std::to_string(notify_player);
ArchipelagoConsole_SendMessage(logMessage.c_str());
@@ -146,53 +146,53 @@ void ArchipelagoClient::on_item_recieved(int64_t recieved_item_id, bool notify_p
}
}
void ArchipelagoClient::send_game_won() {
void ArchipelagoClient::SendGameWon() {
if(!game_won) {
apclient->StatusUpdate(APClient::ClientStatus::GOAL);
apClient->StatusUpdate(APClient::ClientStatus::GOAL);
game_won = true;
}
}
void ArchipelagoClient::poll() {
if(apclient == nullptr) {
void ArchipelagoClient::Poll() {
if(apClient == nullptr) {
return;
}
apclient->poll();
apClient->poll();
}
const std::string& ArchipelagoClient::get_slot_name() const {
if(apclient == NULL) {
const std::string& ArchipelagoClient::GetSlotName() const {
if(apClient == NULL) {
return "";
}
return apclient->get_slot();
return apClient->get_slot();
}
char* ArchipelagoClient::get_server_address_buff() {
return server_address;
char* ArchipelagoClient::GetServerAddressBuffer() {
return serverAddress;
}
char* ArchipelagoClient::get_slot_name_buff() {
return slot_name;
char* ArchipelagoClient::GetSlotNameBuffer() {
return slotName;
}
char* ArchipelagoClient::get_password_buff() {
char* ArchipelagoClient::GetPasswordBuffer() {
return password;
}
const std::map<std::string, int>& ArchipelagoClient::get_slot_data() {
return slot_data;
const std::map<std::string, int>& ArchipelagoClient::GetSlotData() {
return slotData;
}
const std::vector<ArchipelagoClient::ApItem>& ArchipelagoClient::get_scouted_items() {
return scouted_items;
const std::vector<ArchipelagoClient::ApItem>& ArchipelagoClient::GetScoutedItems() {
return scoutedItems;
}
const char* ArchipelagoClient::get_connection_status() {
if (!apclient) {
const char* ArchipelagoClient::GetConnectionStatus() {
if (!apClient) {
return "";
}
APClient::State clientStatus = apclient->get_state();
APClient::State clientStatus = apClient->get_state();
switch (clientStatus) {
case APClient::State::DISCONNECTED: {

View File

@@ -28,39 +28,38 @@ class ArchipelagoClient{
int index;
};
static ArchipelagoClient& getInstance();
static ArchipelagoClient& GetInstance();
bool start_client();
bool stop_client();
bool StartClient();
bool StopClient();
void start_location_scouts();
void StartLocationScouts();
// getters
const std::string& get_slot_name() const;
const std::string& GetSlotName() const;
char* get_server_address_buff();
char* get_slot_name_buff();
char* get_password_buff();
const char* get_connection_status();
const std::map<std::string, int>& get_slot_data();
const std::vector<ApItem>& get_scouted_items();
char* GetServerAddressBuffer();
char* GetSlotNameBuffer();
char* GetPasswordBuffer();
const char* GetConnectionStatus();
const std::map<std::string, int>& GetSlotData();
const std::vector<ApItem>& GetScoutedItems();
bool isConnected();
bool IsConnected();
void check_location(RandomizerCheck SoH_check_id);
// callback slots
void addItemRecievedCallback(std::function<void(const std::string&)> callback);
void removeItemRecievedCallback(std::function<void(const std::string&)> old_callback);
void AddItemRecievedCallback(std::function<void(const std::string&)> callback);
void RemoveItemRecievedCallback(std::function<void(const std::string&)> old_callback);
// todo move me back down when done testing
void on_item_recieved(int64_t recieved_item_id, bool notify_player);
void OnItemReceived(int64_t recieved_item_id, bool notify_player);
void send_game_won();
void SendGameWon();
void poll();
void Poll();
std::unique_ptr<APClient> apclient;
std::unique_ptr<APClient> apClient;
protected:
ArchipelagoClient();
@@ -73,23 +72,23 @@ class ArchipelagoClient{
static std::shared_ptr<ArchipelagoClient> instance; // is this even used?
static bool initialized;
char server_address[AP_Client_consts::MAX_ADDRESS_LENGTH];
char slot_name[AP_Client_consts::MAX_PLAYER_NAME_LENGHT];
char serverAddress[AP_Client_consts::MAX_ADDRESS_LENGTH];
char slotName[AP_Client_consts::MAX_PLAYER_NAME_LENGHT];
char password[AP_Client_consts::MAX_PLAYER_NAME_LENGHT];
bool game_won;
std::map<std::string, int> slot_data;
std::map<std::string, int> slotData;
std::set<int64_t> locations;
std::vector<ApItem> scouted_items;
std::vector<ApItem> scoutedItems;
void save_data();
void SaveData();
// callback functions
void on_connected();
void OnConnected();
void on_location_checked(int64_t location_id);
void on_deathlink_recieved() { }; // TODO: implement me
void OnLocationChecked(int64_t location_id);
void OnDeathLinkReceived() { }; // TODO: implement me
// callbacks
std::function<void(const std::string&)> ItemRecievedCallback;

View File

@@ -18,10 +18,9 @@ void ArchipelagoConsole_SendMessage(const char* fmt, ...) IM_FMTARGS(2) {
}
void ArchipelagoConsoleWindow::DrawElement() {
// Reserve enough left-over height for 1 separator + 1 input text
const float footer_height_to_reserve = ImGui::GetStyle().ItemSpacing.y + ImGui::GetFrameHeightWithSpacing();
if (ImGui::Button("Add line to log")) {
ArchipelagoConsole_SendMessage("[LOG] Hello World");
ArchipelagoConsole_SendMessage("[ERROR] Hello World");
ArchipelagoConsole_SendMessage("Hello World");
}
@@ -36,18 +35,21 @@ void ArchipelagoConsoleWindow::DrawElement() {
// Normally you would store more information in your item than just a string.
// (e.g. make Items[] an array of structure, store color/type etc.)
ImVec4 color;
bool has_color = false;
if (strstr(item, "[error]")) {
bool hasColor = false;
if (strstr(item, "[ERROR]")) {
color = ImVec4(1.0f, 0.4f, 0.4f, 1.0f);
has_color = true;
hasColor = true;
} else if (strstr(item, "[LOG]")) {
color = ImVec4(0.7f, 0.7f, 1.0f, 1.0f);
hasColor = true;
} else if (strncmp(item, "# ", 2) == 0) {
color = ImVec4(1.0f, 0.8f, 0.6f, 1.0f);
has_color = true;
hasColor = true;
}
if (has_color)
if (hasColor)
ImGui::PushStyleColor(ImGuiCol_Text, color);
ImGui::TextUnformatted(item);
if (has_color)
if (hasColor)
ImGui::PopStyleColor();
}

View File

@@ -6,32 +6,32 @@
#include "soh/Network/Archipelago/ArchipelagoConsoleWindow.h"
void ArchipelagoSettingsWindow::DrawElement() {
ArchipelagoClient& AP_client = ArchipelagoClient::getInstance();
ArchipelagoClient& AP_client = ArchipelagoClient::GetInstance();
ImGui::SeparatorText("Connection info");
ImGui::InputText("Server Address", AP_client.get_server_address_buff(), AP_Client_consts::MAX_ADDRESS_LENGTH);
ImGui::InputText("Slot Name", AP_client.get_slot_name_buff(), AP_Client_consts::MAX_PLAYER_NAME_LENGHT);
ImGui::InputText("Password (leave blank for no password)", AP_client.get_password_buff(),
ImGui::InputText("Server Address", AP_client.GetServerAddressBuffer(), AP_Client_consts::MAX_ADDRESS_LENGTH);
ImGui::InputText("Slot Name", AP_client.GetSlotNameBuffer(), AP_Client_consts::MAX_PLAYER_NAME_LENGHT);
ImGui::InputText("Password (leave blank for no password)", AP_client.GetPasswordBuffer(),
AP_Client_consts::MAX_PASSWORD_LENGTH, ImGuiInputTextFlags_Password);
if (ImGui::Button("Connect")) {
bool success = AP_client.start_client();
bool success = AP_client.StartClient();
ArchipelagoConsole_SendMessage("[LOG] Trying to connect...");
}
ImGui::SameLine();
ImGui::Text(ArchipelagoClient::getInstance().get_connection_status());
ImGui::Text(ArchipelagoClient::GetInstance().GetConnectionStatus());
if (ImGui::Button("scout")) {
AP_client.start_location_scouts();
if (ImGui::Button("Scout")) {
AP_client.StartLocationScouts();
}
ImGui::SameLine();
if (ImGui::Button("link up")) {
CVarSetInteger("archipelago_connected", 1);
if (ImGui::Button("Link up")) {
CVarSetInteger("ArchipelagoConnected", 1);
}
UIWidgets::PaddedSeparator();
if(ImGui::Button("give blue ruppie")) {
ArchipelagoClient::getInstance().on_item_recieved(66077, true);
if(ImGui::Button("Give Blue Rupee")) {
ArchipelagoClient::GetInstance().OnItemReceived(66077, true);
}
};

View File

@@ -2594,7 +2594,7 @@ void SoH_ProcessDroppedFiles(std::string filePath) {
}
}
extern "C" void parse_archipelago() {
extern "C" void ParseArchipelago() {
OTRGlobals::Instance->gRandoContext->ParseArchipelago();
}
// #endregion

View File

@@ -166,7 +166,7 @@ void CheckTracker_OnMessageClose();
GetItemID RetrieveGetItemIDFromItemID(ItemID itemID);
RandomizerGet RetrieveRandomizerGetFromItemID(ItemID itemID);
void parse_archipelago();
void ParseArchipelago();
#endif
#ifdef __cplusplus

View File

@@ -1030,7 +1030,7 @@ void DrawSeedHashSprites(FileChooseContext* this) {
u8 generating;
int retries = 0;
bool fileSelectSpoilerFileLoaded = false;
bool fileSelectarchipelagoloaded = false;
bool fileSelectArchipelagoLoaded = false;
void FileChoose_UpdateRandomizer() {
if (CVarGetInteger(CVAR_GENERAL("RandoGenerating"), 0) != 0 && generating == 0) {
@@ -1075,11 +1075,10 @@ void FileChoose_UpdateRandomizer() {
}
}
if (CVarGetInteger("archipelago_connected", 0) != 0
&& !fileSelectarchipelagoloaded) {
parse_archipelago();
fileSelectarchipelagoloaded = true;
Audio_PlayFanfare(NA_BGM_HORSE_GOAL);
if (CVarGetInteger("ArchipelagoConnected", 0) && !fileSelectArchipelagoLoaded) {
ParseArchipelago();
fileSelectArchipelagoLoaded = true;
Audio_PlayFanfare(NA_BGM_HORSE_GOAL);
}
}
@@ -3939,7 +3938,7 @@ void FileChoose_Init(GameState* thisx) {
this->questType[1] = MIN_QUEST;
this->questType[2] = MIN_QUEST;
fileSelectSpoilerFileLoaded = false;
fileSelectarchipelagoloaded = false;
fileSelectArchipelagoLoaded = false;
CVarSetInteger(CVAR_GENERAL("OnFileSelectNameEntry"), 0);
SREG(30) = 1;