From 36775982a6da96cd1d94dc2de538b68df51433c5 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Fri, 29 Mar 2024 21:04:55 -0500 Subject: [PATCH] Emscripten compatibility fixes. --- .../AdventuresInLestoria.cpp | 8 +-- .../CharacterMenuWindow.cpp | 10 ++-- Adventures in Lestoria/Item.cpp | 50 +++++++++---------- Adventures in Lestoria/Monster.cpp | 6 +-- Adventures in Lestoria/Player.cpp | 6 +-- Adventures in Lestoria/State_MainMenu.cpp | 2 +- Adventures in Lestoria/Unlock.cpp | 11 ++-- Adventures in Lestoria/emscripten_compat.h | 2 + 8 files changed, 49 insertions(+), 46 deletions(-) diff --git a/Adventures in Lestoria/AdventuresInLestoria.cpp b/Adventures in Lestoria/AdventuresInLestoria.cpp index 0324f789..4810fb5e 100644 --- a/Adventures in Lestoria/AdventuresInLestoria.cpp +++ b/Adventures in Lestoria/AdventuresInLestoria.cpp @@ -2513,7 +2513,9 @@ void AiL::_PrepareLevel(MapName map,MusicChange changeMusic){ }); LoadingScreen::AddPhase([&](){ - if(SteamUserStats())SteamUserStats()->StoreStats(); + STEAMUSERSTATS( + SteamUserStats()->StoreStats(); + ) ClearGarbage(); return true; }); @@ -2746,9 +2748,9 @@ bool Steam_Init(){ LOG(std::format("STEAM[{}]: {}",severity,std::string(message))); }); } - if(SteamUserStats()){ + STEAMUSERSTATS( SteamUserStats()->RequestCurrentStats(); - } + ) return true; } #endif diff --git a/Adventures in Lestoria/CharacterMenuWindow.cpp b/Adventures in Lestoria/CharacterMenuWindow.cpp index 5f11987c..e26707e3 100644 --- a/Adventures in Lestoria/CharacterMenuWindow.cpp +++ b/Adventures in Lestoria/CharacterMenuWindow.cpp @@ -51,7 +51,7 @@ All rights reserved. #include "ProgressBar.h" #include "MenuItemLabel.h" #ifndef __EMSCRIPTEN__ - #include + #include "steam/isteamuserstats.h" #endif INCLUDE_game @@ -103,16 +103,14 @@ namespace CharacterMenuWindow{ if(SelectedEquipIsDifferent(comp)){ //If we find that the opposite ring slot is equipped to us, this would be an item swap or the exact same ring, therefore no stat calculations apply. Inventory::EquipItem(comp.lock()->GetItem(),EquipSlot(comp.lock()->I(Attribute::EQUIP_TYPE))); - #pragma region Achievement Stuff - if(SteamUserStats()){ - #pragma region Fully Decked Out Achievement + #pragma region Fully Decked Out Achievement + STEAMUSERSTATS( datafile&unlock=DATA.GetProperty("Achievement.Equip Unlocks.Fully Decked Out"); if(Inventory::EquipsFullyMaxedOut(unlock["Weapon Max Level"].GetInt(),unlock["Armor Max Level"].GetInt())){ SteamUserStats()->SetAchievement(unlock["API Name"].GetString().c_str()); SteamUserStats()->StoreStats(); } - #pragma endregion - } + ) #pragma endregion if(Menu::IsCurrentlyActive(data.menu.GetType())){ diff --git a/Adventures in Lestoria/Item.cpp b/Adventures in Lestoria/Item.cpp index 6d125899..27da8b4c 100644 --- a/Adventures in Lestoria/Item.cpp +++ b/Adventures in Lestoria/Item.cpp @@ -48,7 +48,7 @@ All rights reserved. #include "ClassInfo.h" #include "RowInventoryScrollableWindowComponent.h" #ifndef __EMSCRIPTEN__ - #include + #include "steam/isteamuserstats.h" #endif INCLUDE_game @@ -929,32 +929,32 @@ void Item::EnhanceItem(uint8_t qty){ enhancementLevel++; - if(SteamUserStats()){ - #pragma region Fully Decked Out Achievement - datafile&unlock=DATA.GetProperty("Achievement.Equip Unlocks.Fully Decked Out"); - if(Inventory::EquipsFullyMaxedOut(unlock["Weapon Max Level"].GetInt(),unlock["Armor Max Level"].GetInt())){ - SteamUserStats()->SetAchievement(unlock["API Name"].GetString().c_str()); - SteamUserStats()->StoreStats(); - } - #pragma endregion - #pragma region Equipment achievement unlocks - for(auto&[key,size]:DATA.GetProperty("Achievement.Equip Unlocks")){ - datafile&unlock=DATA.GetProperty(std::format("Achievement.Equip Unlocks.{}",key)); - if(!(unlock.HasProperty("Upgrade Requirement")&&unlock.HasProperty("Equip Slot")))continue; //Ignore any achievements that don't have an upgrade requirement/equipment slot defined. - if(EnhancementLevel()>=unlock["Upgrade Requirement"].GetInt()){ - EquipSlot validSlots=EquipSlot::NONE; - for(const std::string&slot:unlock["Equip Slot"].GetValues()){ - validSlots|=ItemInfo::StringToEquipSlot(slot); //Collect all the bits that this equipment can fall under. - } - if(GetEquipSlot()&validSlots){ - //This piece of gear matches one of the provided slots. - SteamUserStats()->SetAchievement(unlock["API Name"].GetString().c_str()); - SteamUserStats()->StoreStats(); + #pragma region Achievements + STEAMUSERSTATS( + // Fully Decked Out Achievement + datafile&unlock=DATA.GetProperty("Achievement.Equip Unlocks.Fully Decked Out"); + if(Inventory::EquipsFullyMaxedOut(unlock["Weapon Max Level"].GetInt(),unlock["Armor Max Level"].GetInt())){ + SteamUserStats()->SetAchievement(unlock["API Name"].GetString().c_str()); + SteamUserStats()->StoreStats(); + } + // Equipment achievement unlocks + for(auto&[key,size]:DATA.GetProperty("Achievement.Equip Unlocks")){ + datafile&unlock=DATA.GetProperty(std::format("Achievement.Equip Unlocks.{}",key)); + if(!(unlock.HasProperty("Upgrade Requirement")&&unlock.HasProperty("Equip Slot")))continue; //Ignore any achievements that don't have an upgrade requirement/equipment slot defined. + if(EnhancementLevel()>=unlock["Upgrade Requirement"].GetInt()){ + EquipSlot validSlots=EquipSlot::NONE; + for(const std::string&slot:unlock["Equip Slot"].GetValues()){ + validSlots|=ItemInfo::StringToEquipSlot(slot); //Collect all the bits that this equipment can fall under. + } + if(GetEquipSlot()&validSlots){ + //This piece of gear matches one of the provided slots. + SteamUserStats()->SetAchievement(unlock["API Name"].GetString().c_str()); + SteamUserStats()->StoreStats(); + } } } - } - #pragma endregion - } + ) + #pragma endregion const CraftingRequirement&consumedResources=GetEnhancementInfo()[EnhancementLevel()].craftingRequirement; diff --git a/Adventures in Lestoria/Monster.cpp b/Adventures in Lestoria/Monster.cpp index e7be0f10..3c63d982 100644 --- a/Adventures in Lestoria/Monster.cpp +++ b/Adventures in Lestoria/Monster.cpp @@ -49,7 +49,7 @@ All rights reserved. #include "SoundEffect.h" #include "Unlock.h" #ifndef __EMSCRIPTEN__ - #include + #include "steam/isteamuserstats.h" #endif INCLUDE_ANIMATION_DATA @@ -729,7 +729,7 @@ void Monster::OnDeath(){ Unlock::IncreaseKillCount(); - if(SteamUserStats()){ + STEAMUSERSTATS( for(auto&[key,size]:DATA.GetProperty("Achievement.Kill Unlocks")){ //Monster-specific achievement unlocks. datafile&unlock=DATA.GetProperty(std::format("Achievement.Kill Unlocks.{}",key)); @@ -746,7 +746,7 @@ void Monster::OnDeath(){ } } } - } + ) if(hasStrategyDeathFunction){ GameEvent::AddEvent(std::make_unique(strategyDeathFunc,*this,MONSTER_DATA[name].GetAIStrategy())); diff --git a/Adventures in Lestoria/Player.cpp b/Adventures in Lestoria/Player.cpp index 4b7ed822..f3b1875e 100644 --- a/Adventures in Lestoria/Player.cpp +++ b/Adventures in Lestoria/Player.cpp @@ -58,7 +58,7 @@ All rights reserved. #include "Unlock.h" #include "Tutorial.h" #ifndef __EMSCRIPTEN__ - #include + #include "steam/isteamuserstats.h" #endif INCLUDE_MONSTER_DATA @@ -1327,7 +1327,7 @@ void Player::OnLevelUp(){ stats.SetBaseStat("Attack",GetBaseStat("Attack")+atkGrowthRate); Heal(GetBaseStat("Health")); - if(SteamUserStats()){ + STEAMUSERSTATS( for(auto&[key,size]:DATA.GetProperty("Achievement.Class Unlocks")){ datafile&unlock=DATA.GetProperty(std::format("Achievement.Class Unlocks.{}",key)); if(classutils::StringToClass(unlock["Class Requirement"].GetString())==GetClass()&& @@ -1337,7 +1337,7 @@ void Player::OnLevelUp(){ SteamUserStats()->StoreStats(); } } - } + ) } const uint8_t Player::LevelCap()const{ return levelCap; diff --git a/Adventures in Lestoria/State_MainMenu.cpp b/Adventures in Lestoria/State_MainMenu.cpp index 6b29014d..1005bff9 100644 --- a/Adventures in Lestoria/State_MainMenu.cpp +++ b/Adventures in Lestoria/State_MainMenu.cpp @@ -43,7 +43,7 @@ All rights reserved. #include "ItemDrop.h" #include "util.h" #ifndef __EMSCRIPTEN__ - #include + #include "steam/isteamuserstats.h" #endif INCLUDE_game diff --git a/Adventures in Lestoria/Unlock.cpp b/Adventures in Lestoria/Unlock.cpp index 5ade3e85..cd5a550e 100644 --- a/Adventures in Lestoria/Unlock.cpp +++ b/Adventures in Lestoria/Unlock.cpp @@ -40,8 +40,9 @@ All rights reserved. #include "config.h" #include "olcUTIL_DataFile.h" #include "DEFINES.h" +#include "emscripten_compat.h" #ifndef __EMSCRIPTEN__ - #include + #include "steam/isteamuserstats.h" #endif INCLUDE_DATA @@ -57,13 +58,13 @@ void Unlock::Initialize(){ void Unlock::UnlockArea(std::string mapName){ if(mapName=="NPCs.Sherman.Potion Crafting Unlock Condition"_S&& //When we beat the bonus chapter 1 fight, before sherman's potion crafting is unlocked, if the current map we just unlocked for is the bonus boss stage we will notify the Hub connection point and reset it so the player has a notification to go there again. !Unlock::IsUnlocked("NPCs.Sherman.Potion Crafting Unlock Condition"_S))State_OverworldMap::ConnectionPointFromString("HUB").value()->ResetVisitedFlag(); - if(SteamUserStats()){ + STEAMUSERSTATS( datafile&areaUnlocks=DATA.GetProperty("Achievement.Area Unlocks"); for(auto&[key,size]:areaUnlocks){ datafile&unlock = areaUnlocks[key]; if(mapName==unlock["Unlock Name"].GetString())SteamUserStats()->SetAchievement(unlock["API Name"].GetString().c_str()); } - } + ) unlocks.insert(mapName); } bool Unlock::IsUnlocked(std::string mapName){ @@ -80,7 +81,7 @@ void Unlock::UnlockCurrentMap(){ void Unlock::IncreaseKillCount(){ monsterKillCount++; - if(SteamUserStats()){ + STEAMUSERSTATS( SteamUserStats()->SetStat("Achievement.Kill Unlocks.Total Kill API Name"_S.c_str(),Unlock::monsterKillCount); datafile&killUnlocks=DATA.GetProperty("Achievement.Kill Unlocks"); for(auto&[key,size]:killUnlocks){ @@ -92,5 +93,5 @@ void Unlock::IncreaseKillCount(){ } } } - } + ) } \ No newline at end of file diff --git a/Adventures in Lestoria/emscripten_compat.h b/Adventures in Lestoria/emscripten_compat.h index 78dd0604..e0b20641 100644 --- a/Adventures in Lestoria/emscripten_compat.h +++ b/Adventures in Lestoria/emscripten_compat.h @@ -15,7 +15,9 @@ inline void SteamAPI_RunCallbacks(){}; #define STEAMINPUT(statement) if(false){} #define STEAMUTILS(statement) if(false){} +#define STEAMUSERSTATS(statement) if(false){} #else #define STEAMINPUT(statement) if(SteamInput()){statement} #define STEAMUTILS(statement) if(SteamUtils()){statement} +#define STEAMUSERSTATS(statement) if(SteamUserStats()){statement} #endif