Merge pull request #71 from jeromkiller/AddArchipelagoClientLib

Add archipelago client lib
This commit is contained in:
aMannus
2025-06-06 08:50:36 +02:00
committed by GitHub
4 changed files with 69 additions and 9 deletions

View File

@@ -285,7 +285,56 @@ void RandomizerOnSceneFlagSetHandler(int16_t sceneNum, int16_t flagType, int16_t
}
void RandomizerOnExternalCheckHandler(uint32_t randomizerCheck) {
randomizerQueuedChecks.push(static_cast<RandomizerCheck>(randomizerCheck));
RandomizerCheck rc = static_cast<RandomizerCheck>(randomizerCheck);
Rando::Location* loc = Rando::StaticData::GetLocation(rc);
s32 flagID = loc->GetCollectionCheck().flag;
SceneID scene = loc->GetScene();
bool inSameArea = false;
if(gPlayState != nullptr) {
inSameArea = scene == gPlayState->sceneNum;
}
std::string logMessage = "";
switch(loc->GetCollectionCheck().type) {
case SPOILER_CHK_CHEST:
if(inSameArea) {
Flags_SetTreasure(gPlayState, flagID);
} else {
gSaveContext.sceneFlags[scene].chest |= 1 << flagID;
randomizerQueuedChecks.push(rc);
}
break;
case SPOILER_CHK_COLLECTABLE:
if(inSameArea) {
Flags_SetCollectible(gPlayState, flagID);
} else {
gSaveContext.sceneFlags[scene].collect |= 1 << flagID;
randomizerQueuedChecks.push(rc);
}
break;
case SPOILER_CHK_RANDOMIZER_INF:
Flags_SetRandomizerInf(static_cast<RandomizerInf>(flagID));
case SPOILER_CHK_EVENT_CHK_INF:
Flags_SetEventChkInf(flagID);
break;
case SPOILER_CHK_ITEM_GET_INF:
Flags_SetItemGetInf(flagID);
break;
case SPOILER_CHK_INF_TABLE:
Flags_SetInfTable(flagID);
break;
case SPOILER_CHK_GOLD_SKULLTULA:
logMessage = "[LOG] Externaly checked golden skultulla: " + std::to_string(loc->GetActorParams()) + ", " + std::to_string(flagID);
ArchipelagoConsole_SendMessage(logMessage.c_str(), true);
SET_GS_FLAGS((flagID & 0x1F00) >> 8, flagID & 0xFF);
break;
case SPOILER_CHK_GRAVEDIGGER: //This enum is used nowhere in code, so i'll leave it as nothing for now
case SPOILER_CHK_NONE:
// do Nothing
break;
}
}
static Vec3f spawnPos = { 0.0f, -999.0f, 0.0f };

View File

@@ -83,7 +83,7 @@ bool ArchipelagoClient::StartClient() {
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.itemName = apClient->get_item_name(item.item, AP_Client_consts::AP_GAME_NAME);
apItem.locationName = apClient->get_location_name(item.location, game);
apItem.playerName = apClient->get_player_alias(item.player);
apItem.flags = item.flags;
@@ -103,7 +103,7 @@ bool ArchipelagoClient::StartClient() {
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.locationName = apClient->get_location_name(item.location, AP_Client_consts::AP_GAME_NAME);
apItem.playerName = apClient->get_player_alias(item.player);
apItem.flags = item.flags;
apItem.index = item.index;
@@ -278,6 +278,10 @@ void ArchipelagoClient::QueueExternalCheck(const int64_t apLocation) {
}
bool ArchipelagoClient::IsConnected() {
if(apClient == nullptr) {
return false;
}
return apClient->get_state() == APClient::State::SLOT_CONNECTED;
}
@@ -287,6 +291,10 @@ void ArchipelagoClient::CheckLocation(RandomizerCheck sohCheckId) {
return;
}
if(!IsConnected()) {
return;
}
std::string apName = Rando::StaticData::GetLocation(sohCheckId)->GetName();
if (apName.empty()) {
return;
@@ -296,9 +304,6 @@ void ArchipelagoClient::CheckLocation(RandomizerCheck sohCheckId) {
std::string logMessage = "[LOG] Checked: " + apName + "(" + std::to_string(apItemId) + "), sending to AP server";
ArchipelagoConsole_SendMessage(logMessage.c_str(), true);
if(!IsConnected()) {
return;
}
apClient->LocationChecks({ apItemId });
}
@@ -345,7 +350,7 @@ void ArchipelagoClient::SendGameWon() {
void ArchipelagoClient::SendMessageToConsole(const std::string message) {
// local commands not implemented yet
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;
}

View File

@@ -64,8 +64,7 @@ void ArchipelagoConsoleWindow::DrawElement() {
}
}
ImGui::EndChild();
ImGui::PopStyleColor();
ImGui::PopStyleVar(3);
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 8.0f);
static char textEntryBuf[1024];
static bool keepFocus = false;
@@ -86,6 +85,10 @@ void ArchipelagoConsoleWindow::DrawElement() {
textEntryBuf[0] = '\0';
keepFocus = true;
}
ImGui::PopStyleColor();
ImGui::PopStyleVar(4);
};
ImVec4 getColorVal(const std::string& color) { // TODO change color strings to an enum

View File

@@ -76,6 +76,9 @@ void ArchipelagoSettingsWindow::DrawElement() {
UIWidgets::ButtonOptions().Color(THEME_COLOR).Size(ImVec2(0.0, 0.0)))) {
ArchipelagoClient::GetInstance().SendGameWon();
}
if (UIWidgets::Button("Get Mido br chest", UIWidgets::ButtonOptions().Color(THEME_COLOR).Size(ImVec2(0.0, 0.0)))) {
ArchipelagoClient::GetInstance().QueueExternalCheck(16711707);
}
}
static bool sArchipelagoTexturesLoaded = false;