Implemented EncodeURI stub function.
This commit is contained in:
parent
57f0b84dff
commit
fc9d9590d3
@ -300,6 +300,7 @@
|
|||||||
</PreBuildEvent>
|
</PreBuildEvent>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClInclude Include="..\..\..\..\Downloads\olcPixelGameEngine (1).h" />
|
||||||
<ClInclude Include="Ability.h" />
|
<ClInclude Include="Ability.h" />
|
||||||
<ClInclude Include="Animation.h" />
|
<ClInclude Include="Animation.h" />
|
||||||
<ClInclude Include="Attributable.h" />
|
<ClInclude Include="Attributable.h" />
|
||||||
|
@ -402,6 +402,9 @@
|
|||||||
<ClInclude Include="olcPGEX_SplashScreen.h">
|
<ClInclude Include="olcPGEX_SplashScreen.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\..\..\Downloads\olcPixelGameEngine (1).h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="Player.cpp">
|
<ClCompile Include="Player.cpp">
|
||||||
|
@ -64,7 +64,7 @@ public:
|
|||||||
animationTime+=game->GetElapsedTime();
|
animationTime+=game->GetElapsedTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void DrawDecal(ViewPort&window,bool focused){
|
inline void DrawDecal(ViewPort&window,bool focused)override{
|
||||||
MenuComponent::DrawDecal(window,focused);
|
MenuComponent::DrawDecal(window,focused);
|
||||||
|
|
||||||
if(playTime==-1){
|
if(playTime==-1){
|
||||||
|
@ -48,10 +48,10 @@ void Menu::InitializeMainMenuWindow(){
|
|||||||
Menu*mainMenuWindow=CreateMenu(MAIN_MENU,CENTERED,vi2d{96,96});
|
Menu*mainMenuWindow=CreateMenu(MAIN_MENU,CENTERED,vi2d{96,96});
|
||||||
|
|
||||||
mainMenuWindow->ADD("New Game Button",MenuComponent)({{12,4},{72,24}},"New Game",[&](MenuFuncData data){
|
mainMenuWindow->ADD("New Game Button",MenuComponent)({{12,4},{72,24}},"New Game",[&](MenuFuncData data){
|
||||||
|
game->TextEntryEnable(true);
|
||||||
#ifdef __EMSCRIPTEN__
|
#ifdef __EMSCRIPTEN__
|
||||||
data.menu.S(A::NEXT_MENU)="New Game";
|
data.menu.S(A::NEXT_MENU)="New Game";
|
||||||
if(SaveFile::GetUserID().length()==0){
|
if(SaveFile::GetUserID().length()==0){
|
||||||
game->TextEntryEnable(true);
|
|
||||||
Menu::OpenMenu(USER_ID);
|
Menu::OpenMenu(USER_ID);
|
||||||
}else{
|
}else{
|
||||||
Menu::OpenMenu(SAVE_FILE_NAME);
|
Menu::OpenMenu(SAVE_FILE_NAME);
|
||||||
|
@ -195,7 +195,7 @@ const vf2d&MenuComponent::GetSize()const{
|
|||||||
return rect.size;
|
return rect.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MenuComponent::GetLabel(){
|
const std::string&MenuComponent::GetLabel()const{
|
||||||
return label;
|
return label;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,7 +142,7 @@ public:
|
|||||||
virtual bool HandleOutsideDisabledButtonSelection(MenuComponent*disabledButton);
|
virtual bool HandleOutsideDisabledButtonSelection(MenuComponent*disabledButton);
|
||||||
//Called whenever equipment and base stats are updated, notifying a component that numbers that may be displayed have changed.
|
//Called whenever equipment and base stats are updated, notifying a component that numbers that may be displayed have changed.
|
||||||
virtual void OnEquipStatsUpdate();
|
virtual void OnEquipStatsUpdate();
|
||||||
std::string GetLabel();
|
virtual const std::string&GetLabel()const;
|
||||||
std::string GetName();
|
std::string GetName();
|
||||||
virtual void SetSelected(bool selected)final;
|
virtual void SetSelected(bool selected)final;
|
||||||
virtual void SetSelectionType(SelectionType selectionType)final;
|
virtual void SetSelectionType(SelectionType selectionType)final;
|
||||||
|
@ -209,7 +209,25 @@ const std::string SaveFile::CreateServerRequest(const SaveFileOperation::Operati
|
|||||||
auto CalculateChecksum=[](std::string_view operation,std::string_view data){
|
auto CalculateChecksum=[](std::string_view operation,std::string_view data){
|
||||||
return username.length()*8+data.length()*2+operation.length();
|
return username.length()*8+data.length()*2+operation.length();
|
||||||
};
|
};
|
||||||
std::string dataString=std::format("?username={}",username);
|
auto EncodeURI=[](std::string str){
|
||||||
|
return std::accumulate(str.begin(),str.end(),""s,[](std::string str,const char&c){
|
||||||
|
/*
|
||||||
|
* Implementation Source: https://262.ecma-international.org/5.1/#sec-15.1.3.4
|
||||||
|
uriReserved ::: one of
|
||||||
|
; / ? : @ & = + $ ,
|
||||||
|
uriMark ::: one of
|
||||||
|
- _ . ! ~ * ' ( )
|
||||||
|
Let unescapedURISet be a String containing one instance of each character valid in uriReserved and uriUnescaped plus “#”.
|
||||||
|
*/
|
||||||
|
const std::array uriReserved={';','/','?',':','@','&','=','+','$',',','-','_','.','!','~','*','\'','(',')','#'};
|
||||||
|
if(c>='A'&&c<='Z'||c>='a'&&c<='z'||c>='0'&&c<='9'||std::find(uriReserved.begin(),uriReserved.end(),c)!=uriReserved.end())return std::move(str)+c;
|
||||||
|
|
||||||
|
std::string convertedChar=std::format("%{:02x}",c);
|
||||||
|
std::for_each(convertedChar.begin(),convertedChar.end(),[](char&c){c=char(std::toupper(c));});
|
||||||
|
return std::move(str)+convertedChar;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
std::string dataString=std::format("\"username\":\"{}\"",EncodeURI(username));
|
||||||
std::string operationName="";
|
std::string operationName="";
|
||||||
switch(operation){
|
switch(operation){
|
||||||
case SaveFileOperation::GET_LOAD_FILES:{
|
case SaveFileOperation::GET_LOAD_FILES:{
|
||||||
@ -229,35 +247,41 @@ const std::string SaveFile::CreateServerRequest(const SaveFileOperation::Operati
|
|||||||
//Data should contain the entire contents of our metadata save file.
|
//Data should contain the entire contents of our metadata save file.
|
||||||
}break;
|
}break;
|
||||||
}
|
}
|
||||||
dataString+="&operation="+operationName;
|
dataString+=",\"operation\":\""+EncodeURI(operationName)+"\"";
|
||||||
dataString+="&checksum="+std::to_string(CalculateChecksum(operationName,data));
|
dataString+=",\"checksum\":\""+EncodeURI(std::to_string(CalculateChecksum(operationName,data)))+"\"";
|
||||||
dataString+="&data="+std::string(data);
|
dataString+=",\"data\":\""+EncodeURI(std::string(data))+"\"";
|
||||||
return "save_server"_S+dataString;
|
return "{"+dataString+"}";
|
||||||
}
|
}
|
||||||
const void SaveFile::Server_GetLoadInfo(std::function<void(std::string_view)>respCallbackFunc){
|
const void SaveFile::Server_GetLoadInfo(std::function<void(std::string_view)>respCallbackFunc){
|
||||||
game->SendRequest(CreateServerRequest(SaveFileOperation::GET_LOAD_FILES,"0"),"");
|
game->SendRequest("save_server"_S,CreateServerRequest(SaveFileOperation::GET_LOAD_FILES,"0"));
|
||||||
game->responseCallback=respCallbackFunc;
|
game->responseCallback=respCallbackFunc;
|
||||||
}
|
}
|
||||||
const void SaveFile::Server_GetFile(std::function<void(std::string_view)>respCallbackFunc){
|
const void SaveFile::Server_GetFile(std::function<void(std::string_view)>respCallbackFunc){
|
||||||
game->SendRequest(CreateServerRequest(SaveFileOperation::GET_FILE,std::to_string(saveFileID)),"");
|
game->SendRequest("save_server"_S,CreateServerRequest(SaveFileOperation::GET_FILE,std::to_string(saveFileID)));
|
||||||
game->responseCallback=respCallbackFunc;
|
game->responseCallback=respCallbackFunc;
|
||||||
}
|
}
|
||||||
const void SaveFile::Server_SaveFile(std::function<void(std::string_view)>respCallbackFunc){
|
const void SaveFile::Server_SaveFile(std::function<void(std::string_view)>respCallbackFunc){
|
||||||
std::stringstream fileContents;
|
std::stringstream fileContents;
|
||||||
std::ifstream file("save_file_path"_S+std::format("save.{:04}",saveFileID));
|
std::ifstream file("save_file_path"_S+std::format("save.{:04}",saveFileID));
|
||||||
while(file.good()){
|
while(file.good()){
|
||||||
fileContents<<char(file.get());
|
int val=file.get();
|
||||||
|
if(val!=-1){
|
||||||
|
fileContents<<char(val);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
game->SendRequest(CreateServerRequest(SaveFileOperation::SAVE_FILE,std::to_string(saveFileID)+"|"+fileContents.str()),"");
|
game->SendRequest("save_server"_S,CreateServerRequest(SaveFileOperation::SAVE_FILE,std::to_string(saveFileID)+"|"+fileContents.str()));
|
||||||
game->responseCallback=respCallbackFunc;
|
game->responseCallback=respCallbackFunc;
|
||||||
}
|
}
|
||||||
const void SaveFile::Server_SaveMetadataFile(std::function<void(std::string_view)>respCallbackFunc){
|
const void SaveFile::Server_SaveMetadataFile(std::function<void(std::string_view)>respCallbackFunc){
|
||||||
std::stringstream fileContents;
|
std::stringstream fileContents;
|
||||||
std::ifstream file("save_file_path"_S+"metadata.dat");
|
std::ifstream file("save_file_path"_S+"metadata.dat");
|
||||||
while(file.good()){
|
while(file.good()){
|
||||||
fileContents<<char(file.get());
|
int val=file.get();
|
||||||
|
if(val!=-1){
|
||||||
|
fileContents<<char(val);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
game->SendRequest(CreateServerRequest(SaveFileOperation::SAVE_METADATA_FILE,fileContents.str()),"");
|
game->SendRequest("save_server"_S,CreateServerRequest(SaveFileOperation::SAVE_METADATA_FILE,fileContents.str()));
|
||||||
game->responseCallback=respCallbackFunc;
|
game->responseCallback=respCallbackFunc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,4 +76,12 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline const std::string&GetLabel()const override{
|
||||||
|
if(censored){
|
||||||
|
return game->TextEntryGetString();
|
||||||
|
}else{
|
||||||
|
MenuLabel::GetLabel();
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
@ -39,7 +39,7 @@ All rights reserved.
|
|||||||
#define VERSION_MAJOR 0
|
#define VERSION_MAJOR 0
|
||||||
#define VERSION_MINOR 2
|
#define VERSION_MINOR 2
|
||||||
#define VERSION_PATCH 1
|
#define VERSION_PATCH 1
|
||||||
#define VERSION_BUILD 5287
|
#define VERSION_BUILD 5293
|
||||||
|
|
||||||
#define stringify(a) stringify_(a)
|
#define stringify(a) stringify_(a)
|
||||||
#define stringify_(a) #a
|
#define stringify_(a) #a
|
||||||
|
@ -1205,7 +1205,7 @@ namespace olc
|
|||||||
|
|
||||||
// Text Entry Routines
|
// Text Entry Routines
|
||||||
void TextEntryEnable(const bool bEnable, const std::string& sText = "");
|
void TextEntryEnable(const bool bEnable, const std::string& sText = "");
|
||||||
std::string TextEntryGetString() const;
|
const std::string&TextEntryGetString() const;
|
||||||
int32_t TextEntryGetCursor() const;
|
int32_t TextEntryGetCursor() const;
|
||||||
bool IsTextEntryEnabled() const;
|
bool IsTextEntryEnabled() const;
|
||||||
void TextEntrySetCharLimit(const uint8_t charLimit);
|
void TextEntrySetCharLimit(const uint8_t charLimit);
|
||||||
@ -4294,7 +4294,7 @@ namespace olc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string PixelGameEngine::TextEntryGetString() const
|
const std::string&PixelGameEngine::TextEntryGetString() const
|
||||||
{ return sTextEntryString; }
|
{ return sTextEntryString; }
|
||||||
|
|
||||||
int32_t PixelGameEngine::TextEntryGetCursor() const
|
int32_t PixelGameEngine::TextEntryGetCursor() const
|
||||||
@ -7217,14 +7217,18 @@ namespace olc
|
|||||||
virtual olc::rcode SendRequest(std::string_view url,std::string_view data)override{
|
virtual olc::rcode SendRequest(std::string_view url,std::string_view data)override{
|
||||||
EM_ASM({
|
EM_ASM({
|
||||||
requestResp="";
|
requestResp="";
|
||||||
fetch(UTF8ToString($0)).then((resp)=>{
|
fetch(UTF8ToString($0),{
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
method: "POST",body:UTF8ToString($1)}).then((resp)=>{
|
||||||
if(resp.ok){
|
if(resp.ok){
|
||||||
resp.text();
|
resp.text();
|
||||||
}
|
}
|
||||||
throw new Error(resp.text());
|
throw new Error(resp.text());
|
||||||
}).then((data)=>{requestResp=data;})
|
}).then((data)=>{requestResp=data;})
|
||||||
.catch((err)=>{requestResp="ERR";});
|
.catch((err)=>{requestResp="ERR";});
|
||||||
},std::string(url).c_str());
|
},std::string(url).c_str(),std::string(data).c_str());
|
||||||
return olc::rcode::OK;
|
return olc::rcode::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user