MCPcopy Create free account
hub / github.com/TurningWheel/Barony / readTooltipsFromFile

Method readTooltipsFromFile

src/mod_tools.cpp:1726–2068  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1724
1725#ifndef EDITOR
1726void ItemTooltips_t::readTooltipsFromFile(bool forceLoadBaseDirectory)
1727{
1728 if ( !PHYSFS_getRealDir("/items/item_tooltips.json") )
1729 {
1730 printlog("[JSON]: Error: Could not find file: items/item_tooltips.json");
1731 return;
1732 }
1733
1734 std::string inputPath = PHYSFS_getRealDir("/items/item_tooltips.json");
1735 if ( forceLoadBaseDirectory )
1736 {
1737 inputPath = BASE_DATA_DIR;
1738 }
1739 else
1740 {
1741 if ( inputPath != BASE_DATA_DIR )
1742 {
1743 readTooltipsFromFile(true); // force load the base directory first, then modded paths later.
1744 }
1745 else
1746 {
1747 forceLoadBaseDirectory = true;
1748 }
1749 }
1750
1751 inputPath.append("/items/item_tooltips.json");
1752
1753 File* fp = FileIO::open(inputPath.c_str(), "rb");
1754 if ( !fp )
1755 {
1756 printlog("[JSON]: Error: Could not open json file %s", inputPath.c_str());
1757 return;
1758 }
1759
1760 constexpr uint32_t buffer_size = (1 << 20); // 1mb
1761 if ( fp->size() >= buffer_size )
1762 {
1763 printlog("[JSON]: Error: file size is too large to fit in buffer! %s", inputPath.c_str());
1764 FileIO::close(fp);
1765 return;
1766 }
1767
1768 static char buf[buffer_size];
1769 const int count = fp->read(buf, sizeof(buf[0]), sizeof(buf) - 1);
1770 buf[count] = '\0';
1771 //rapidjson::FileReadStream is(fp, buf, sizeof(buf)); - use this for large chunks.
1772 rapidjson::StringStream is(buf);
1773
1774 rapidjson::Document d;
1775 d.ParseStream(is);
1776 FileIO::close(fp);
1777
1778 if ( !d.IsObject() )
1779 {
1780 printlog("[JSON]: Error: json file does not define a complete object. Is there a syntax error? %s", inputPath.c_str());
1781 return;
1782 }
1783

Callers 3

ingameHudFunction · 0.80
initGameDatafilesFunction · 0.80
consolecommand.cppFile · 0.80

Calls 15

printlogFunction · 0.85
makeColorFunction · 0.85
ItemTooltipIcons_tClass · 0.85
appendMethod · 0.80
c_strMethod · 0.80
GetIntMethod · 0.80
BeginMethod · 0.80
EndMethod · 0.80
setColorHeadingMethod · 0.80
setColorDescriptionMethod · 0.80
setColorDetailsMethod · 0.80
setColorPositiveMethod · 0.80

Tested by

no test coverage detected