Jump to content

TablePlusPlus Loading and saving


reepblue
 Share

Go to solution Solved by Josh,

Recommended Posts

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

 

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

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);
    }

 

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

  • 2 weeks later...

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}"

 

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

  • Solution
	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;
	}

 

  • Like 1

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

The false argument should prevent the null character from being written at the end.

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

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...