set playerName in localStorage as well

This commit is contained in:
Moros Smith 2024-08-28 14:40:41 -04:00
parent 88958298a8
commit 7724d3a653
2 changed files with 12 additions and 0 deletions

View File

@ -420,6 +420,12 @@ 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;
// set playerName in localStorage as well
EM_ASM({
window.localStorage.setItem("playerName", UTF8ToString($0));
}, rawMetadata.c_str());
*((std::string*)(arg))=rawMetadata.substr(0,length);
std::cout<<std::format("Success! Loaded Player Name {}",*((std::string*)(arg)))<<std::endl;
HamsterGame::Game().net.SetName(*((std::string*)(arg)));

View File

@ -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){