reepblue Posted April 20 Share Posted April 20 This is for a Leadwerks project and over the few months I've fell in love with tableplusplus and I've used it for my input system in Ultra Engine. I'm trying to port it to Leadwerks but it seems my implementation of the loading and saving isn't correct. My JSON parsers work fine but no data loads, and tables don't save as pretty as when using the json library alone. Anything I'm doing wrong? #ifdef __TABLE_PLUS_PLUS table Table::Load(const std::string& path) { auto j3 = JSON::Load(path); table t(j3); return t; } table Table::Load(Stream* stream) { auto j3 = JSON::Load(stream); table t(j3); return t; } bool Table::Save(table& t, const std::string& path) { nlohmann::json j3 = t.to_json(); return JSON::Save(j3, path); } table Table::Load(const std::wstring& path) { auto j3 = JSON::Load(path); table t(j3); return t; } table Table::Load(shared_ptr<FileStream> stream) { auto j3 = JSON::Load(stream); table t(j3); return t; } bool Table::Save(table& t, const std::wstring& path) { nlohmann::json j3 = t.to_json(); return JSON::Save(j3, path); } #endif Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
reepblue Posted April 21 Author Share Posted April 21 Nevermind, loading is fine, saving is the remaining issue. For the record, this is how I'm saving my json files. bool JSON::Save(nlohmann::json& j3, const std::string& path) { std::ofstream o(path); o << std::setw(4) << j3 << std::endl; return (bool)FileSystem::GetFileType(path); } Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
reepblue Posted May 5 Author Share Posted May 5 How would I save a table without it saving like below? "{\n\t\"Console\": 112,\n\t\"Fullscreen\": 122,\n\t\"InGameControls\":\n\t{\n\t\t\"Crouch\": 17,\n\t\t\"Jump\": 32,\n\t\t\"MoveBackward\": 83,\n\t\t\"MoveForward\": 87,\n\t\t\"MoveLeft\": 65,\n\t\t\"MoveRight\": 68,\n\t\t\"QuickSpin\": 81,\n\t\t\"Use\": 69,\n\t\t\"ZoomIn\": 257,\n\t\t\"ZoomOut\": 258,\n\t\t\"axes\":\n\t\t{\n\t\t\t\"Camera\": 0\n\t\t},\n\t\t\"mousecursor\": 0\n\t},\n\t\"Pause\": 27,\n\t\"Quick Load\": 117,\n\t\"Quick Save\": 116,\n\t\"Screenshot\": 113,\n\t\"Terminate\": 35,\n\t\"mousecursor\": 1\n}" Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Solution Josh Posted May 6 Solution Share Posted May 6 bool SaveTable(table& t, const WString& path) { std::string s = t.to_json(); auto stream = WriteFile(path); if (stream == NULL) return false; stream->WriteString(s, false); return true; } 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
reepblue Posted May 6 Author Share Posted May 6 I had to use WriteLine for Leadwerks as WriteString wrote extra data at the end. Much appreciated! Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Josh Posted May 7 Share Posted May 7 The false argument should prevent the null character from being written at the end. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
reepblue Posted May 8 Author Share Posted May 8 On 5/6/2024 at 9:35 PM, Josh said: The false argument should prevent the null character from being written at the end. The Leadwerks Stream class lacks such an override. Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.