mirror of
https://github.com/sigonasr2/hamster.git
synced 2025-04-16 05:49:17 -05:00
Merge pull request #22 from sigonasr2/add-playerName-to-localStorage
set playerName in localStorage as well
This commit is contained in:
commit
689b3b891f
@ -420,7 +420,14 @@ bool HamsterGame::OnUserUpdate(float fElapsedTime){
|
||||
emscripten_idb_async_load("hamster",Game().playerNameLabel.c_str(),&Game().playerName,[](void*arg,void*data,int length){
|
||||
std::string rawMetadata=(char*)data;
|
||||
std::cout<<rawMetadata<<std::endl;
|
||||
|
||||
*((std::string*)(arg))=rawMetadata.substr(0,length);
|
||||
|
||||
// set playerName in localStorage as well
|
||||
EM_ASM({
|
||||
window.localStorage.setItem("playerName", UTF8ToString($0));
|
||||
}, rawMetadata.substr(0,length).c_str());
|
||||
|
||||
std::cout<<std::format("Success! Loaded Player Name {}",*((std::string*)(arg)))<<std::endl;
|
||||
HamsterGame::Game().net.SetName(*((std::string*)(arg)));
|
||||
},
|
||||
@ -867,4 +874,4 @@ int main()
|
||||
game.Start();
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -750,6 +750,12 @@ void Menu::OnTextEntryComplete(const std::string&text){
|
||||
HamsterGame::Game().emscripten_temp_val=HamsterGame::Game().playerName;
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_idb_async_store("hamster",HamsterGame::Game().playerNameLabel.c_str(),HamsterGame::Game().emscripten_temp_val.data(),HamsterGame::Game().emscripten_temp_val.length(),0,[](void*args){
|
||||
|
||||
// set playerName in localStorage as well
|
||||
EM_ASM({
|
||||
window.localStorage.setItem("playerName", UTF8ToString($0));
|
||||
}, HamsterGame::Game().playerName.c_str());
|
||||
|
||||
std::cout<<"Success!"<<std::endl;
|
||||
},
|
||||
[](void*args){
|
||||
|
Loading…
x
Reference in New Issue
Block a user