Added emscripten compatiblity fix for all Steam API changes. Fix bug where walking direction took priority over manual aim when using controller aiming. Release Build 8465.

mac-build
sigonasr2 8 months ago
parent 68ed4d2b5d
commit 05abf6c3e9
  1. 1
      Adventures in Lestoria/Adventures in Lestoria.vcxproj
  2. 3
      Adventures in Lestoria/Adventures in Lestoria.vcxproj.filters
  3. 64
      Adventures in Lestoria/AdventuresInLestoria.cpp
  4. 6
      Adventures in Lestoria/ClassSelectionWindow.cpp
  5. 6
      Adventures in Lestoria/Error.h
  6. 2
      Adventures in Lestoria/InputHelper.cpp
  7. 287
      Adventures in Lestoria/Key.cpp
  8. 7
      Adventures in Lestoria/Key.h
  9. 47
      Adventures in Lestoria/Player.cpp
  10. 4
      Adventures in Lestoria/SettingsWindow.cpp
  11. 35
      Adventures in Lestoria/SteamKeyboardCallbackHandler.cpp
  12. 6
      Adventures in Lestoria/SteamKeyboardCallbackHandler.h
  13. 3
      Adventures in Lestoria/TODO.txt
  14. 16
      Adventures in Lestoria/Tutorial.h
  15. 2
      Adventures in Lestoria/Version.h
  16. 21
      Adventures in Lestoria/emscripten_compat.h
  17. BIN
      x64/Release/Adventures in Lestoria.exe

@ -329,6 +329,7 @@
</ClInclude>
<ClInclude Include="Effect.h" />
<ClInclude Include="Emitter.h" />
<ClInclude Include="emscripten_compat.h" />
<ClInclude Include="EncountersSpawnListScrollableWindowComponent.h" />
<ClInclude Include="EnhancementStatsLabel.h">
<SubType>

@ -624,6 +624,9 @@
<ClInclude Include="SteamKeyboardCallbackHandler.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="emscripten_compat.h">
<Filter>Header Files\steam</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Player.cpp">

@ -74,7 +74,7 @@ All rights reserved.
#include "InventoryScrollableWindowComponent.h"
#ifndef __EMSCRIPTEN__
#include "discord.h"
#include <steam_api.h>
#include "steam/steam_api.h"
#endif
#include "GameSettings.h"
#include "LoadingScreen.h"
@ -323,15 +323,17 @@ bool AiL::OnUserCreate(){
#endif
State_OverworldMap::SetStageMarker("starting_map_name"_S);
if(SteamInput()!=nullptr){
STEAMINPUT(
SteamInput()->Init(false);
Input::LoadSteamButtonIcons();
Input::ingameControlsHandle=SteamInput()->GetActionSetHandle("InGameControls");
}
)
if(steamKeyboardCallbackListener==nullptr){
steamKeyboardCallbackListener=new SteamKeyboardCallbackHandler();
}
#ifndef __EMSCRIPTEN__
if(steamKeyboardCallbackListener==nullptr){
steamKeyboardCallbackListener=new SteamKeyboardCallbackHandler();
}
#endif
utils::datafile::INITIAL_SETUP_COMPLETE=true;
@ -353,10 +355,10 @@ bool AiL::OnUserCreate(){
bool AiL::OnUserUpdate(float fElapsedTime){
levelTime+=fElapsedTime;
SteamAPI_RunCallbacks();
if(SteamInput()){
STEAMINPUT(
ActivateActionSetForAllControllers(Input::ingameControlsHandle);
Input::UpdateSteamInput();
}
)
if(GetMousePos()!=lastMousePos){
lastMouseMovement=0.f;
@ -2127,10 +2129,10 @@ void AiL::_PrepareLevel(MapName map,MusicChange changeMusic){
GetPlayer()->SetInvisible(false);
GetPlayer()->ResetVelocity();
if(SteamInput()){ //This is kind of a hack to refresh the in-game controls handle and button icons if for some reason it's not setup correctly.
STEAMINPUT( //This is kind of a hack to refresh the in-game controls handle and button icons if for some reason it's not setup correctly.
Input::LoadSteamButtonIcons();
Input::ingameControlsHandle=SteamInput()->GetActionSetHandle("InGameControls");
}
)
ZONE_LIST=game->MAP_DATA[game->GetCurrentLevel()].ZoneData;
return true;
@ -2683,25 +2685,29 @@ datafiledoubledata AiL::GetDoubleList(std::string key){
}
bool Steam_Init(){
if(SteamAPI_Init()){
if(SteamUtils()!=nullptr){
SteamUtils()->SetWarningMessageHook([](int severity,const char*message){
LOG(std::format("STEAM[{}]: {}",severity,std::string(message)));
});
#ifndef __EMSCRIPTEN__
if(SteamAPI_Init()){
if(SteamUtils()!=nullptr){
SteamUtils()->SetWarningMessageHook([](int severity,const char*message){
LOG(std::format("STEAM[{}]: {}",severity,std::string(message)));
});
}
return true;
}
return true;
}
#endif
return false;
}
int main()
{
if(SteamAPI_RestartAppIfNecessary(2895980U))return false; //Immediately quit if steam is detected and can be started through it.
if(Steam_Init()){
LOG("Steam API Initialized successfully!");
}else{
LOG("Steam API failed to initialize!");
}
#ifndef __EMSCRIPTEN__
if(SteamAPI_RestartAppIfNecessary(2895980U))return false; //Immediately quit if steam is detected and can be started through it.
if(Steam_Init()){
LOG("Steam API Initialized successfully!");
}else{
LOG("Steam API failed to initialize!");
}
#endif
{
AiL demo;
@ -2870,7 +2876,9 @@ bool AiL::IsReflectiveTile(TilesheetData tileSheet,int tileID){
}
bool AiL::OnUserDestroy(){
SteamAPI_Shutdown();
#ifndef __EMSCRIPTEN__
SteamAPI_Shutdown();
#endif
GFX.Reset();
for(auto&[key,value]:MAP_DATA){
if(MAP_DATA[key].optimizedTile!=nullptr){
@ -3871,7 +3879,9 @@ int AiL::GetLoadoutSize()const{
}
void AiL::ActivateActionSetForAllControllers(InputActionSetHandle_t actionSetHandle){
for(int i=0;i<Input::controllerCount;i++){
SteamInput()->ActivateActionSet(Input::steamControllers[i],actionSetHandle);
}
STEAMINPUT(
for(int i=0;i<Input::controllerCount;i++){
SteamInput()->ActivateActionSet(Input::steamControllers[i],actionSetHandle);
}
)
}

@ -46,7 +46,7 @@ All rights reserved.
#include "TextEntryLabel.h"
#include "Checkbox.h"
#ifndef __EMSCRIPTEN__
#include <isteamutils.h>
#include "steam/isteamutils.h"
#endif
INCLUDE_game
@ -74,9 +74,9 @@ void Menu::InitializeClassSelectionWindow(){
vf2d textboxWindowPos=data.component.lock()->rect.pos*game->GetPixelSize();
vf2d textboxWindowSize=data.component.lock()->rect.size*game->GetPixelSize();
if(SteamUtils()){
STEAMUTILS(
SteamUtils()->ShowGamepadTextInput(k_EGamepadTextInputModeNormal,k_EGamepadTextInputLineModeSingleLine,"Character Name:",16U,std::string(SaveFile::GetSaveFileName()).c_str());
}
)
return true;
},vf2d{2.f,2.f})END;

@ -91,11 +91,15 @@ inline std::ofstream debugLogger;
std::stringstream errStream; \
errStream<<err; \
Error::log(errStream,std::source_location::current());}
#define LOG(err) { \
std::stringstream errStream; \
errStream<<err; \
Error::log(errStream,std::source_location::current());}
class Error{
public:
inline static void log(std::stringstream&str,std::source_location loc){
LOG(loc.file_name()<<"("<<loc.line()<<":"<<loc.column()<<") "<<loc.function_name()<<": "<<str.str());
std::cout<<loc.file_name()<<"("<<loc.line()<<":"<<loc.column()<<") "<<loc.function_name()<<": "<<str.str();
#ifdef __DEBUG__
throw;
#endif

@ -64,7 +64,7 @@ const InputType InputHelper::InputMode()const{
void InputHelper::Draw(){
InputType mode=InputMode();
if(mode==CONTROLLER&&SteamInput())mode=STEAM;
STEAMINPUT(if(mode==CONTROLLER){mode=STEAM;})
if(mode==MOUSE)mode=KEY; //We're going to make it so the keyboard controls always show up when navigating using a mouse.
auto OriginalGameIcon=[](std::optional<Input>input)->bool{

@ -60,85 +60,87 @@ uint8_t Input::controllerCount{0};
std::vector<Steam::SteamInput>Input::leftStickActionSets{Steam::MOVE};
std::vector<Steam::SteamInput>Input::rightStickActionSets{Steam::SCROLL};
std::array<std::unordered_map<Steam::SteamInput,std::pair<std::string,HWButton>>,16>Input::enumToActionName;
std::array<std::unordered_map<Steam::SteamInput,std::pair<std::string,HWButton>>,STEAM_INPUT_MAX_COUNT>Input::enumToActionName;
std::unordered_map<EInputActionOrigin,std::string>Input::steamIconToGameIcon{
{k_EInputActionOrigin_SteamController_A,"themes/button_d_xb.png"},
{k_EInputActionOrigin_XBoxOne_A,"themes/button_d_xb.png"},
{k_EInputActionOrigin_XBox360_A,"themes/button_d_xb.png"},
{k_EInputActionOrigin_Switch_A,"themes/button_d_xb.png"},
{k_EInputActionOrigin_Switch_JoyConButton_S,"themes/button_d_xb.png"},
{k_EInputActionOrigin_SteamDeck_A,"themes/button_d_xb.png"},
{k_EInputActionOrigin_SteamController_B,"themes/button_r_xb.png"},
{k_EInputActionOrigin_XBoxOne_B,"themes/button_r_xb.png"},
{k_EInputActionOrigin_XBox360_B,"themes/button_r_xb.png"},
{k_EInputActionOrigin_Switch_B,"themes/button_r_xb.png"},
{k_EInputActionOrigin_Switch_JoyConButton_W,"themes/button_r_xb.png"},
{k_EInputActionOrigin_SteamDeck_B,"themes/button_r_xb.png"},
{k_EInputActionOrigin_SteamController_X,"themes/button_l_xb.png"},
{k_EInputActionOrigin_XBoxOne_X,"themes/button_l_xb.png"},
{k_EInputActionOrigin_XBox360_X,"themes/button_l_xb.png"},
{k_EInputActionOrigin_Switch_X,"themes/button_l_xb.png"},
{k_EInputActionOrigin_Switch_JoyConButton_E,"themes/button_l_xb.png"},
{k_EInputActionOrigin_SteamDeck_X,"themes/button_l_xb.png"},
{k_EInputActionOrigin_SteamController_Y,"themes/button_u_xb.png"},
{k_EInputActionOrigin_XBoxOne_Y,"themes/button_u_xb.png"},
{k_EInputActionOrigin_XBox360_Y,"themes/button_u_xb.png"},
{k_EInputActionOrigin_Switch_Y,"themes/button_u_xb.png"},
{k_EInputActionOrigin_Switch_JoyConButton_N,"themes/button_u_xb.png"},
{k_EInputActionOrigin_SteamDeck_Y,"themes/button_u_xb.png"},
{k_EInputActionOrigin_SteamController_LeftBumper,"themes/button_l1.png"},
{k_EInputActionOrigin_PS4_LeftBumper,"themes/button_l1.png"},
{k_EInputActionOrigin_XBoxOne_LeftBumper,"themes/button_l1.png"},
{k_EInputActionOrigin_XBox360_LeftBumper,"themes/button_l1.png"},
{k_EInputActionOrigin_Switch_LeftBumper,"themes/button_l1.png"},
{k_EInputActionOrigin_SteamDeck_L1,"themes/button_l1.png"},
{k_EInputActionOrigin_SteamController_RightBumper,"themes/button_r1.png"},
{k_EInputActionOrigin_PS4_RightBumper,"themes/button_r1.png"},
{k_EInputActionOrigin_XBoxOne_RightBumper,"themes/button_r1.png"},
{k_EInputActionOrigin_XBox360_RightBumper,"themes/button_r1.png"},
{k_EInputActionOrigin_Switch_RightBumper,"themes/button_r1.png"},
{k_EInputActionOrigin_SteamDeck_R1,"themes/button_r1.png"},
{k_EInputActionOrigin_SteamController_RightTrigger_Pull,"themes/button_r2.png"},
{k_EInputActionOrigin_PS4_RightTrigger_Pull,"themes/button_r2.png"},
{k_EInputActionOrigin_XBoxOne_RightTrigger_Pull,"themes/button_r2.png"},
{k_EInputActionOrigin_XBox360_RightTrigger_Pull,"themes/button_r2.png"},
{k_EInputActionOrigin_Switch_RightTrigger_Pull,"themes/button_r2.png"},
{k_EInputActionOrigin_SteamDeck_R2_SoftPull,"themes/button_r2.png"},
{k_EInputActionOrigin_SteamController_RightTrigger_Click,"themes/button_r2.png"},
{k_EInputActionOrigin_PS4_RightTrigger_Click,"themes/button_r2.png"},
{k_EInputActionOrigin_XBoxOne_RightTrigger_Click,"themes/button_r2.png"},
{k_EInputActionOrigin_XBox360_RightTrigger_Click,"themes/button_r2.png"},
{k_EInputActionOrigin_Switch_RightTrigger_Click,"themes/button_r2.png"},
{k_EInputActionOrigin_SteamDeck_R2,"themes/button_r2.png"},
{k_EInputActionOrigin_SteamController_LeftTrigger_Pull,"themes/button_l2.png"},
{k_EInputActionOrigin_PS4_LeftTrigger_Pull,"themes/button_l2.png"},
{k_EInputActionOrigin_XBoxOne_LeftTrigger_Pull,"themes/button_l2.png"},
{k_EInputActionOrigin_XBox360_LeftTrigger_Pull,"themes/button_l2.png"},
{k_EInputActionOrigin_Switch_LeftTrigger_Pull,"themes/button_l2.png"},
{k_EInputActionOrigin_SteamDeck_L2_SoftPull,"themes/button_l2.png"},
{k_EInputActionOrigin_SteamController_LeftTrigger_Click,"themes/button_l2.png"},
{k_EInputActionOrigin_PS4_LeftTrigger_Click,"themes/button_l2.png"},
{k_EInputActionOrigin_XBoxOne_LeftTrigger_Click,"themes/button_l2.png"},
{k_EInputActionOrigin_XBox360_LeftTrigger_Click,"themes/button_l2.png"},
{k_EInputActionOrigin_Switch_LeftTrigger_Click,"themes/button_l2.png"},
{k_EInputActionOrigin_SteamDeck_L2,"themes/button_l2.png"},
{k_EInputActionOrigin_PS4_X,"themes/button_d_ps.png"},
{k_EInputActionOrigin_PS4_Circle,"themes/button_r_ps.png"},
{k_EInputActionOrigin_PS4_Triangle,"themes/button_u_ps.png"},
{k_EInputActionOrigin_PS4_Square,"themes/button_l_ps.png"},
{k_EInputActionOrigin_SteamController_LeftStick_Move,"themes/button_analogstick.png"},
{k_EInputActionOrigin_PS4_LeftStick_Move,"themes/button_analogstick.png"},
{k_EInputActionOrigin_PS4_RightStick_Move,"themes/button_analogstick.png"},
{k_EInputActionOrigin_XBoxOne_LeftStick_Move,"themes/button_analogstick.png"},
{k_EInputActionOrigin_XBoxOne_RightStick_Move,"themes/button_analogstick.png"},
{k_EInputActionOrigin_XBox360_LeftStick_Move,"themes/button_analogstick.png"},
{k_EInputActionOrigin_XBox360_RightStick_Move,"themes/button_analogstick.png"},
{k_EInputActionOrigin_Switch_LeftStick_Move,"themes/button_analogstick.png"},
{k_EInputActionOrigin_Switch_RightStick_Move,"themes/button_analogstick.png"},
{k_EInputActionOrigin_PS5_LeftStick_Move,"themes/button_analogstick.png"},
{k_EInputActionOrigin_PS5_RightStick_Move,"themes/button_analogstick.png"},
{k_EInputActionOrigin_SteamDeck_LeftStick_Move,"themes/button_analogstick.png"},
{k_EInputActionOrigin_SteamDeck_RightStick_Move,"themes/button_analogstick.png"},
#ifndef __EMSCRIPTEN__
{k_EInputActionOrigin_SteamController_A,"themes/button_d_xb.png"},
{k_EInputActionOrigin_XBoxOne_A,"themes/button_d_xb.png"},
{k_EInputActionOrigin_XBox360_A,"themes/button_d_xb.png"},
{k_EInputActionOrigin_Switch_A,"themes/button_d_xb.png"},
{k_EInputActionOrigin_Switch_JoyConButton_S,"themes/button_d_xb.png"},
{k_EInputActionOrigin_SteamDeck_A,"themes/button_d_xb.png"},
{k_EInputActionOrigin_SteamController_B,"themes/button_r_xb.png"},
{k_EInputActionOrigin_XBoxOne_B,"themes/button_r_xb.png"},
{k_EInputActionOrigin_XBox360_B,"themes/button_r_xb.png"},
{k_EInputActionOrigin_Switch_B,"themes/button_r_xb.png"},
{k_EInputActionOrigin_Switch_JoyConButton_W,"themes/button_r_xb.png"},
{k_EInputActionOrigin_SteamDeck_B,"themes/button_r_xb.png"},
{k_EInputActionOrigin_SteamController_X,"themes/button_l_xb.png"},
{k_EInputActionOrigin_XBoxOne_X,"themes/button_l_xb.png"},
{k_EInputActionOrigin_XBox360_X,"themes/button_l_xb.png"},
{k_EInputActionOrigin_Switch_X,"themes/button_l_xb.png"},
{k_EInputActionOrigin_Switch_JoyConButton_E,"themes/button_l_xb.png"},
{k_EInputActionOrigin_SteamDeck_X,"themes/button_l_xb.png"},
{k_EInputActionOrigin_SteamController_Y,"themes/button_u_xb.png"},
{k_EInputActionOrigin_XBoxOne_Y,"themes/button_u_xb.png"},
{k_EInputActionOrigin_XBox360_Y,"themes/button_u_xb.png"},
{k_EInputActionOrigin_Switch_Y,"themes/button_u_xb.png"},
{k_EInputActionOrigin_Switch_JoyConButton_N,"themes/button_u_xb.png"},
{k_EInputActionOrigin_SteamDeck_Y,"themes/button_u_xb.png"},
{k_EInputActionOrigin_SteamController_LeftBumper,"themes/button_l1.png"},
{k_EInputActionOrigin_PS4_LeftBumper,"themes/button_l1.png"},
{k_EInputActionOrigin_XBoxOne_LeftBumper,"themes/button_l1.png"},
{k_EInputActionOrigin_XBox360_LeftBumper,"themes/button_l1.png"},
{k_EInputActionOrigin_Switch_LeftBumper,"themes/button_l1.png"},
{k_EInputActionOrigin_SteamDeck_L1,"themes/button_l1.png"},
{k_EInputActionOrigin_SteamController_RightBumper,"themes/button_r1.png"},
{k_EInputActionOrigin_PS4_RightBumper,"themes/button_r1.png"},
{k_EInputActionOrigin_XBoxOne_RightBumper,"themes/button_r1.png"},
{k_EInputActionOrigin_XBox360_RightBumper,"themes/button_r1.png"},
{k_EInputActionOrigin_Switch_RightBumper,"themes/button_r1.png"},
{k_EInputActionOrigin_SteamDeck_R1,"themes/button_r1.png"},
{k_EInputActionOrigin_SteamController_RightTrigger_Pull,"themes/button_r2.png"},
{k_EInputActionOrigin_PS4_RightTrigger_Pull,"themes/button_r2.png"},
{k_EInputActionOrigin_XBoxOne_RightTrigger_Pull,"themes/button_r2.png"},
{k_EInputActionOrigin_XBox360_RightTrigger_Pull,"themes/button_r2.png"},
{k_EInputActionOrigin_Switch_RightTrigger_Pull,"themes/button_r2.png"},
{k_EInputActionOrigin_SteamDeck_R2_SoftPull,"themes/button_r2.png"},
{k_EInputActionOrigin_SteamController_RightTrigger_Click,"themes/button_r2.png"},
{k_EInputActionOrigin_PS4_RightTrigger_Click,"themes/button_r2.png"},
{k_EInputActionOrigin_XBoxOne_RightTrigger_Click,"themes/button_r2.png"},
{k_EInputActionOrigin_XBox360_RightTrigger_Click,"themes/button_r2.png"},
{k_EInputActionOrigin_Switch_RightTrigger_Click,"themes/button_r2.png"},
{k_EInputActionOrigin_SteamDeck_R2,"themes/button_r2.png"},
{k_EInputActionOrigin_SteamController_LeftTrigger_Pull,"themes/button_l2.png"},
{k_EInputActionOrigin_PS4_LeftTrigger_Pull,"themes/button_l2.png"},
{k_EInputActionOrigin_XBoxOne_LeftTrigger_Pull,"themes/button_l2.png"},
{k_EInputActionOrigin_XBox360_LeftTrigger_Pull,"themes/button_l2.png"},
{k_EInputActionOrigin_Switch_LeftTrigger_Pull,"themes/button_l2.png"},
{k_EInputActionOrigin_SteamDeck_L2_SoftPull,"themes/button_l2.png"},
{k_EInputActionOrigin_SteamController_LeftTrigger_Click,"themes/button_l2.png"},
{k_EInputActionOrigin_PS4_LeftTrigger_Click,"themes/button_l2.png"},
{k_EInputActionOrigin_XBoxOne_LeftTrigger_Click,"themes/button_l2.png"},
{k_EInputActionOrigin_XBox360_LeftTrigger_Click,"themes/button_l2.png"},
{k_EInputActionOrigin_Switch_LeftTrigger_Click,"themes/button_l2.png"},
{k_EInputActionOrigin_SteamDeck_L2,"themes/button_l2.png"},
{k_EInputActionOrigin_PS4_X,"themes/button_d_ps.png"},
{k_EInputActionOrigin_PS4_Circle,"themes/button_r_ps.png"},
{k_EInputActionOrigin_PS4_Triangle,"themes/button_u_ps.png"},
{k_EInputActionOrigin_PS4_Square,"themes/button_l_ps.png"},
{k_EInputActionOrigin_SteamController_LeftStick_Move,"themes/button_analogstick.png"},
{k_EInputActionOrigin_PS4_LeftStick_Move,"themes/button_analogstick.png"},
{k_EInputActionOrigin_PS4_RightStick_Move,"themes/button_analogstick.png"},
{k_EInputActionOrigin_XBoxOne_LeftStick_Move,"themes/button_analogstick.png"},
{k_EInputActionOrigin_XBoxOne_RightStick_Move,"themes/button_analogstick.png"},
{k_EInputActionOrigin_XBox360_LeftStick_Move,"themes/button_analogstick.png"},
{k_EInputActionOrigin_XBox360_RightStick_Move,"themes/button_analogstick.png"},
{k_EInputActionOrigin_Switch_LeftStick_Move,"themes/button_analogstick.png"},
{k_EInputActionOrigin_Switch_RightStick_Move,"themes/button_analogstick.png"},
{k_EInputActionOrigin_PS5_LeftStick_Move,"themes/button_analogstick.png"},
{k_EInputActionOrigin_PS5_RightStick_Move,"themes/button_analogstick.png"},
{k_EInputActionOrigin_SteamDeck_LeftStick_Move,"themes/button_analogstick.png"},
{k_EInputActionOrigin_SteamDeck_RightStick_Move,"themes/button_analogstick.png"},
#endif
};
Input::Input(InputType type,int key)
@ -174,24 +176,26 @@ void Input::Initialize(){
void Input::LoadSteamButtonIcons(){
GFX.Unlock();
for(int i=1;i<k_EInputActionOrigin_Count;i++){
const char*imageName{SteamInput()->GetGlyphPNGForActionOrigin(EInputActionOrigin(i),k_ESteamInputGlyphSize_Small,0U)};
if(imageName!=nullptr){
std::string loadImage{imageName};
if(loadImage.length()>0&&(!GFX.count(loadImage)||GFX.at(loadImage).Decal()==nullptr)){
LOG(std::format("Loading steam image {}",loadImage));
if(!GFX.count(loadImage))GFX[loadImage];
if(GFX.at(loadImage).Load(loadImage)!=rcode::OK){
LOG(std::format("WARNING! Failed to load steam image {}!",loadImage));
#ifndef __EMSCRIPTEN__
for(int i=1;i<k_EInputActionOrigin_Count;i++){
const char*imageName{SteamInput()->GetGlyphPNGForActionOrigin(EInputActionOrigin(i),k_ESteamInputGlyphSize_Small,0U)};
if(imageName!=nullptr){
std::string loadImage{imageName};
if(loadImage.length()>0&&(!GFX.count(loadImage)||GFX.at(loadImage).Decal()==nullptr)){
LOG(std::format("Loading steam image {}",loadImage));
if(!GFX.count(loadImage))GFX[loadImage];
if(GFX.at(loadImage).Load(loadImage)!=rcode::OK){
LOG(std::format("WARNING! Failed to load steam image {}!",loadImage));
}
}
}
}
}
#endif
GFX.SetInitialized();
}
void Input::UpdateSteamInput(){
if(SteamInput()){
STEAMINPUT(
uint8_t prevControllerCount=controllerCount;
controllerCount=SteamInput()->GetConnectedControllers(steamControllers.data());
if(controllerCount<prevControllerCount&&Menu::stack.size()==0&&GameState::STATE==GameState::states[States::GAME_RUN])Menu::OpenMenu(MenuType::PAUSE); //We unplugged a controller so we will automatically pause the game.
@ -224,7 +228,7 @@ void Input::UpdateSteamInput(){
steamGameInputToAnalogOrigin[input].first=SteamInput()->GetAnalogActionOrigins(steamControllers[activeSteamControllerIndex],ingameControlsHandle,analogInputHnd,steamGameInputToAnalogOrigin[input].second.data());
}
}
}
)
}
bool Input::Pressed(){
@ -238,14 +242,16 @@ bool Input::Pressed(){
inputPressed=game->GetMouse(key).bPressed;
}break;
case CONTROLLER:{
if(!SteamInput()){
STEAMINPUT()else{
for(GamePad*gamepad:GamePad::getGamepads()){
if(gamepad->stillConnected&&gamepad->getButton(static_cast<GPButtons>(key)).bPressed)inputPressed=true;
}
}
}break;
case STEAM:{
if(enumToActionName[activeSteamControllerIndex][Steam::SteamInput(key)].second.bPressed)inputPressed=true;
STEAMINPUT(
if(enumToActionName[activeSteamControllerIndex][Steam::SteamInput(key)].second.bPressed)inputPressed=true;
)
}break;
case ANALOG:{
//An analog input can never be "pressed". No-op.
@ -255,7 +261,7 @@ bool Input::Pressed(){
}
}
if(inputPressed){
usingGamepad=type==CONTROLLER||type==STEAM;
SetUsingGamepad(type==CONTROLLER||type==STEAM);
return true;
}
return false;
@ -272,14 +278,16 @@ bool Input::Held(){
inputHeld|=game->GetMouse(key).bHeld;
}break;
case CONTROLLER:{
if(!SteamInput()){
STEAMINPUT()else{
for(GamePad*gamepad:GamePad::getGamepads()){
if(gamepad->stillConnected)inputHeld|=gamepad->getButton(static_cast<GPButtons>(key)).bHeld;
}
}
}break;
case STEAM:{
inputHeld|=enumToActionName[activeSteamControllerIndex][Steam::SteamInput(key)].second.bHeld;
STEAMINPUT(
inputHeld|=enumToActionName[activeSteamControllerIndex][Steam::SteamInput(key)].second.bHeld;
)
}break;
case ANALOG:{
//An analog input can never be "held". No-op.
@ -289,7 +297,7 @@ bool Input::Held(){
}
}
if(inputHeld){
usingGamepad=type==CONTROLLER||type==STEAM;
SetUsingGamepad(type==CONTROLLER||type==STEAM);
return true;
}
return false;
@ -306,14 +314,16 @@ bool Input::Released(){
inputReleased|=game->GetMouse(key).bReleased;
}break;
case CONTROLLER:{
if(!SteamInput()){
STEAMINPUT()else{
for(GamePad*gamepad:GamePad::getGamepads()){
if(gamepad->stillConnected)inputReleased|=gamepad->getButton(static_cast<GPButtons>(key)).bReleased;
}
}
}break;
case STEAM:{
inputReleased|=enumToActionName[activeSteamControllerIndex][Steam::SteamInput(key)].second.bReleased;
STEAMINPUT(
inputReleased|=enumToActionName[activeSteamControllerIndex][Steam::SteamInput(key)].second.bReleased;
)
}break;
case ANALOG:{
//An analog input can never be "released". No-op.
@ -323,7 +333,7 @@ bool Input::Released(){
}
}
if(inputReleased){
usingGamepad=type==CONTROLLER||type==STEAM;
SetUsingGamepad(type==CONTROLLER||type==STEAM);
return true;
}
return false;
@ -333,18 +343,7 @@ float Input::Analog(){
if(!game->IsFocused())return false;
switch(type){
case ANALOG:{
if(!SteamInput()){
for(GamePad*gamepad:GamePad::getGamepads()){
if(gamepad->stillConnected){
float axisVal=gamepad->getAxis(static_cast<GPAxes>(key));
if(axisVal!=0.f){
usingGamepad=true;
return axisVal;
}
}
}
}else{
STEAMINPUT(
auto GetAnalogStickVal=[&](uint8_t controller,Steam::SteamInput input,Axis axis){
InputAnalogActionHandle_t inputHnd=SteamInput()->GetAnalogActionHandle(enumToActionName[controller][input].first.c_str());
InputAnalogActionData_t data=SteamInput()->GetAnalogActionData(steamControllers[controller],inputHnd);
@ -412,6 +411,16 @@ float Input::Analog(){
case GPAxes::DY:{}break;//Unused. No-op
}
}
)else{
for(GamePad*gamepad:GamePad::getGamepads()){
if(gamepad->stillConnected){
float axisVal=gamepad->getAxis(static_cast<GPAxes>(key));
if(axisVal!=0.f){
usingGamepad=true;
return axisVal;
}
}
}
}
}break;
case KEY:
@ -702,10 +711,10 @@ void InputGroup::DrawPrimaryInput(const std::variant<AiL*const,TileTransformedVi
switch(type){
case CONTROLLER:{
if(SteamInput()){
STEAMINPUT(
primaryKey=GetPrimaryKey(STEAM);
type=STEAM;
}else{
)else{
primaryKey=GetPrimaryKey(CONTROLLER);
}
}break;
@ -879,24 +888,26 @@ const bool Input::HasExtendedIcons()const{
}
const Renderable&Input::GetIcon()const{
if(type==STEAM){
EInputActionOrigin action=Input::steamGameInputToOrigin.at(Steam::SteamInput(key)).second[0];
EInputActionOrigin analogAction=Input::steamGameInputToAnalogOrigin.at(Steam::SteamInput(key)).second[0];
if(Input::steamGameInputToOrigin.count(Steam::SteamInput(key))&&
Input::steamGameInputToOrigin.at(Steam::SteamInput(key)).first>0){
if(steamIconToGameIcon.count(action)){
return GFX.at(GetProperIconName(steamIconToGameIcon[action]));
}else{
return GFX.at(SteamInput()->GetGlyphPNGForActionOrigin(action,k_ESteamInputGlyphSize_Small,0));
}
}else
if(Input::steamGameInputToAnalogOrigin.count(Steam::SteamInput(key))&&
Input::steamGameInputToAnalogOrigin.at(Steam::SteamInput(key)).first>0){
if(steamIconToGameIcon.count(analogAction)){
return GFX.at(GetProperIconName(steamIconToGameIcon[analogAction]));
}else{
return GFX.at(SteamInput()->GetGlyphPNGForActionOrigin(analogAction,k_ESteamInputGlyphSize_Small,0));
#ifndef __EMSCRIPTEN__
EInputActionOrigin action=Input::steamGameInputToOrigin.at(Steam::SteamInput(key)).second[0];
EInputActionOrigin analogAction=Input::steamGameInputToAnalogOrigin.at(Steam::SteamInput(key)).second[0];
if(Input::steamGameInputToOrigin.count(Steam::SteamInput(key))&&
Input::steamGameInputToOrigin.at(Steam::SteamInput(key)).first>0){
if(steamIconToGameIcon.count(action)){
return GFX.at(GetProperIconName(steamIconToGameIcon[action]));
}else{
return GFX.at(SteamInput()->GetGlyphPNGForActionOrigin(action,k_ESteamInputGlyphSize_Small,0));
}
}else
if(Input::steamGameInputToAnalogOrigin.count(Steam::SteamInput(key))&&
Input::steamGameInputToAnalogOrigin.at(Steam::SteamInput(key)).first>0){
if(steamIconToGameIcon.count(analogAction)){
return GFX.at(GetProperIconName(steamIconToGameIcon[analogAction]));
}else{
return GFX.at(SteamInput()->GetGlyphPNGForActionOrigin(analogAction,k_ESteamInputGlyphSize_Small,0));
}
}
}
#endif
}
return GFX.at(GenericKey::keyLiteral.at({type,key}).iconName);
}
@ -1060,14 +1071,14 @@ const bool Input::UsingGamepad(){
const bool Input::AxesActive(){
float xAxis=0.f,yAxis=0.f;
if(SteamInput()){
STEAMINPUT(
if(fabs(game->KEY_SCROLLHORZ_R.Analog())>0.f){
return true;
}
if(fabs(game->KEY_SCROLLVERT_R.Analog())>0.f){
return true;
}
}else{
)else{
for(GamePad*gamepad:GamePad::getGamepads()){
if(gamepad->stillConnected){
if(fabs(gamepad->getAxis(GPAxes::RX))>0.f){
@ -1085,9 +1096,9 @@ const bool Input::AxesActive(){
void Input::StartVibration(const bool override){
if(!GameSettings::RumbleEnabled(override))return;
if(UsingGamepad()){
if(SteamInput()){
STEAMINPUT(
SteamInput()->TriggerVibration(steamControllers[activeSteamControllerIndex],std::numeric_limits<unsigned short>::max(),std::numeric_limits<unsigned short>::max());
}else{
)else{
for(GamePad*gamepad:GamePad::getGamepads()){
if(gamepad->stillConnected){
gamepad->startVibration();
@ -1097,11 +1108,11 @@ void Input::StartVibration(const bool override){
}
}
void Input::StopVibration(){
if(SteamInput()){
STEAMINPUT(
for(int i=0;i<controllerCount;i++){
SteamInput()->TriggerVibration(steamControllers[i],0U,0U);
}
}else{
)else{
for(GamePad*gamepad:GamePad::getGamepads()){
if(gamepad->stillConnected){
gamepad->stopVibration();
@ -1224,9 +1235,9 @@ const bool InputEngageGroup::GetLabelVisible()const{
}
void Input::SetLightbar(const Pixel col){
if(SteamInput()){
STEAMINPUT(
for(int i=0;i<controllerCount;i++){
SteamInput()->SetLEDColor(steamControllers[i],col.r,col.g,col.b,0);
}
}
)
}

@ -46,7 +46,10 @@ All rights reserved.
#include "IconType.h"
#include "olcPGEX_ViewPort.h"
#include "UndefKeys.h"
#include <isteaminput.h>
#ifndef __EMSCRIPTEN__
#include "steam/isteaminput.h"
#endif
#include "emscripten_compat.h"
class AiL;
@ -111,7 +114,7 @@ class Input{
static std::unordered_map<Steam::SteamInput,std::pair<NumOfOrigins,std::array<EInputActionOrigin,STEAM_INPUT_MAX_ORIGINS>>>steamGameInputToAnalogOrigin;
static void Initialize();
static void UpdateSteamInput();
static std::array<InputHandle_t,16>steamControllers;
static std::array<InputHandle_t,STEAM_INPUT_MAX_COUNT>steamControllers;
static uint8_t activeSteamControllerIndex;
static uint8_t controllerCount;
static std::vector<Steam::SteamInput>leftStickActionSets;

@ -1389,20 +1389,15 @@ const vf2d Player::GetAimingLocation(bool useWalkDir,bool invert){
if(UsingAutoAim()){
float xAxis=0.f,yAxis=0.f;
if(useWalkDir&&movementVelocity!=vf2d{0,0}){
xAxis=aimingAngle.cart().x;
yAxis=aimingAngle.cart().y;
}
#pragma region Manual Aiming
if(SteamInput()){
STEAMINPUT(
if(fabs(game->KEY_SCROLLHORZ_R.Analog())>0.f){
xAxis=game->KEY_SCROLLHORZ_R.Analog();
}
if(fabs(game->KEY_SCROLLVERT_R.Analog())>0.f){
yAxis=game->KEY_SCROLLVERT_R.Analog();
}
}else{
)else{
for(GamePad*gamepad:GamePad::getGamepads()){
if(gamepad->stillConnected){
if(fabs(gamepad->getAxis(GPAxes::RX))>0.f){
@ -1421,23 +1416,33 @@ const vf2d Player::GetAimingLocation(bool useWalkDir,bool invert){
if(xAxis!=0.f||yAxis!=0.f){
return {(game->ScreenWidth()*xAxis)/2+game->ScreenWidth()/2,(game->ScreenHeight()*yAxis)/2+game->ScreenHeight()/2};
}else{
//Find the closest monster target.
vf2d closestPoint={std::numeric_limits<float>::max(),std::numeric_limits<float>::max()};
for(Monster&m:MONSTER_LIST){
if(m.IsAlive()){
float distToMonster=geom2d::line<float>(GetPos(),m.GetPos()).length();
geom2d::line<float>aimingLine=geom2d::line<float>(GetPos(),m.GetPos());
vf2d aimingPoint=aimingLine.rpoint((invert?-1.f:1.f)*operator""_Pixels("Player.Aiming Cursor Max Distance"_F));
float distToClosestPoint=geom2d::line<float>(GetPos(),closestPoint).length();
if(distToClosestPoint>distToMonster&&distToMonster<=operator""_Pixels("Player.Auto Aim Detection Distance"_F)){
closestPoint=aimingPoint;
if(useWalkDir&&movementVelocity!=vf2d{0,0}){
xAxis=aimingAngle.cart().x;
yAxis=aimingAngle.cart().y;
}
if(xAxis!=0.f||yAxis!=0.f){
return {(game->ScreenWidth()*xAxis)/2+game->ScreenWidth()/2,(game->ScreenHeight()*yAxis)/2+game->ScreenHeight()/2};
}else{
//Find the closest monster target.
vf2d closestPoint={std::numeric_limits<float>::max(),std::numeric_limits<float>::max()};
for(Monster&m:MONSTER_LIST){
if(m.IsAlive()){
float distToMonster=geom2d::line<float>(GetPos(),m.GetPos()).length();
geom2d::line<float>aimingLine=geom2d::line<float>(GetPos(),m.GetPos());
vf2d aimingPoint=aimingLine.rpoint((invert?-1.f:1.f)*operator""_Pixels("Player.Aiming Cursor Max Distance"_F));
float distToClosestPoint=geom2d::line<float>(GetPos(),closestPoint).length();
if(distToClosestPoint>distToMonster&&distToMonster<=operator""_Pixels("Player.Auto Aim Detection Distance"_F)){
closestPoint=aimingPoint;
}
}
}
if(closestPoint!=vf2d{std::numeric_limits<float>::max(),std::numeric_limits<float>::max()}){
return game->GetScreenSize()/2+closestPoint-GetPos();
}else
return game->GetScreenSize()/2+vf2d{float(operator""_Pixels("Player.Aiming Cursor Max Distance"_F)),aimingAngle.y}.cart();
}
if(closestPoint!=vf2d{std::numeric_limits<float>::max(),std::numeric_limits<float>::max()}){
return game->GetScreenSize()/2+closestPoint-GetPos();
}else
return game->GetScreenSize()/2+vf2d{float(operator""_Pixels("Player.Aiming Cursor Max Distance"_F)),aimingAngle.y}.cart();
}
}else{
return game->GetMousePos();

@ -224,9 +224,9 @@ void Menu::InitializeSettingsWindow(){
settingsList->ADD("Controller Bindings Button",MenuComponent)(geom2d::rect<float>{{28,168.f},vf2d{settingsList->rect.size.x-12-56,24}},"Controller Bindings",[&](MenuFuncData data){
ChangeKeybindDisplayType(CONTROLLER);
Component<MenuLabel>(INPUT_KEY_DISPLAY,"Keyboard Mapping Label")->SetLabel("Controller Mappings");
if(SteamInput()){
STEAMINPUT(
SteamInput()->ShowBindingPanel(Input::steamControllers[Input::activeSteamControllerIndex]);
}else{
)else{
Menu::OpenMenu(INPUT_KEY_DISPLAY);
}
return true;

@ -37,19 +37,22 @@ All rights reserved.
#pragma endregion
#include "SteamKeyboardCallbackHandler.h"
void SteamKeyboardCallbackHandler::TextEntryComplete( GamepadTextInputDismissed_t* pCallback ){
if(SteamUtils()){
if(pCallback->m_bSubmitted){
char enteredText[17];
SteamUtils()->GetEnteredGamepadTextInput(enteredText,16);
Component<TextEntryLabel>(SAVE_FILE_NAME,"Save File Name Text Entry")->SetInput(std::string(enteredText));
if(std::string(enteredText).length()>0){
Component<MenuComponent>(SAVE_FILE_NAME,"Continue Button")->SetGrayedOut(false);
Component<MenuComponent>(SAVE_FILE_NAME,"Continue Button")->Click();
}else{
Component<MenuComponent>(SAVE_FILE_NAME,"Back Button")->Click();
}
}else Component<MenuComponent>(SAVE_FILE_NAME,"Back Button")->Click();
}
};
#include "emscripten_compat.h"
#ifndef __EMSCRIPTEN__
void SteamKeyboardCallbackHandler::TextEntryComplete( GamepadTextInputDismissed_t* pCallback ){
STEAMUTILS(
if(pCallback->m_bSubmitted){
char enteredText[17];
SteamUtils()->GetEnteredGamepadTextInput(enteredText,16);
Component<TextEntryLabel>(SAVE_FILE_NAME,"Save File Name Text Entry")->SetInput(std::string(enteredText));
if(std::string(enteredText).length()>0){
Component<MenuComponent>(SAVE_FILE_NAME,"Continue Button")->SetGrayedOut(false);
Component<MenuComponent>(SAVE_FILE_NAME,"Continue Button")->Click();
}else{
Component<MenuComponent>(SAVE_FILE_NAME,"Back Button")->Click();
}
}else Component<MenuComponent>(SAVE_FILE_NAME,"Back Button")->Click();
)
};
#endif

@ -37,11 +37,13 @@ All rights reserved.
#pragma endregion
#pragma once
#ifndef __EMSCRIPTEN__
#include <steam_api.h>
#include "steam/steam_api.h"
#endif
#include <string>
#include "TextEntryLabel.h"
#ifndef __EMSCRIPTEN__
class SteamKeyboardCallbackHandler{
STEAM_CALLBACK(SteamKeyboardCallbackHandler,TextEntryComplete,GamepadTextInputDismissed_t);
};
};
#endif

@ -1,5 +1,6 @@
Equip Gear using Start menu tutorial
Add in vsync system option
Manual aim does not override movement choice.
============================================

@ -183,9 +183,9 @@ private:
virtual inline void OnComplete()override final{}
virtual inline void Draw()const override final{
if(Input::UsingGamepad()){
if(SteamInput()){
STEAMINPUT(
attackGroup.DrawInput(game,{game->ScreenWidth()/2.f,48.f},"Attack",180,InputType::STEAM);
}else{
)else{
attackGroup.DrawInput(game,{game->ScreenWidth()/2.f,48.f},"Attack",180,InputType::CONTROLLER);
}
}else{
@ -217,9 +217,9 @@ private:
virtual inline void OnComplete()override final{}
virtual inline void Draw()const override final{
if(Input::UsingGamepad()){
if(SteamInput()){
STEAMINPUT(
abilityGroup.DrawInput(game,{game->ScreenWidth()/2.f,48.f},"Use Abilities",180,InputType::STEAM);
}else{
)else{
abilityGroup.DrawInput(game,{game->ScreenWidth()/2.f,48.f},"Use Abilities",180,InputType::CONTROLLER);
}
}else{
@ -245,9 +245,9 @@ private:
virtual inline void OnComplete()override final{}
virtual inline void Draw()const override final{
if(Input::UsingGamepad()){
if(SteamInput()){
STEAMINPUT(
defensiveGroup.DrawInput(game,{game->ScreenWidth()/2.f,48.f},"Defensive Ability",180,InputType::STEAM);
}else{
)else{
defensiveGroup.DrawInput(game,{game->ScreenWidth()/2.f,48.f},"Defensive Ability",180,InputType::CONTROLLER);
}
}else{
@ -285,9 +285,9 @@ private:
virtual inline void OnComplete()override final{}
virtual inline void Draw()const override final{
if(Input::UsingGamepad()){
if(SteamInput()){
STEAMINPUT(
itemsGroup.DrawInput(game,{game->ScreenWidth()/2.f,48.f},"Use Consumables",180,InputType::STEAM);
}else{
)else{
itemsGroup.DrawInput(game,{game->ScreenWidth()/2.f,48.f},"Use Consumables",180,InputType::CONTROLLER);
}
}else{

@ -39,7 +39,7 @@ All rights reserved.
#define VERSION_MAJOR 1
#define VERSION_MINOR 0
#define VERSION_PATCH 0
#define VERSION_BUILD 8464
#define VERSION_BUILD 8465
#define stringify(a) stringify_(a)
#define stringify_(a) #a

@ -0,0 +1,21 @@
#pragma once
#include "olcPixelGameEngine.h"
#ifdef __EMSCRIPTEN__
#define STEAM_INPUT_MAX_COUNT 0
#define STEAM_INPUT_MAX_ORIGINS 0
#define STEAM_CALLBACK(arg1,arg2,arg3)
enum EInputActionOrigin{};
using InputHandle_t=uint64_t;
using InputActionSetHandle_t=uint64_t;
class GamepadTextInputDismissed_t{};
inline void SteamAPI_RunCallbacks(){};
#define STEAMINPUT(statement) if(false){}
#define STEAMUTILS(statement) if(false){}
#else
#define STEAMINPUT(statement) if(SteamInput()){statement}
#define STEAMUTILS(statement) if(SteamUtils()){statement}
#endif
Loading…
Cancel
Save