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

Method readModelLimbsFromFile

src/mod_tools.cpp:18752–18986  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18750}
18751
18752void Compendium_t::readModelLimbsFromFile(std::string section)
18753{
18754 std::string fullpath = "data/compendium/" + section + "_models/";
18755 for ( auto& f : directoryContents(fullpath.c_str(), false, true) )
18756 {
18757 std::string inputPath = fullpath + f;
18758 std::string path = PHYSFS_getRealDir(inputPath.c_str()) ? PHYSFS_getRealDir(inputPath.c_str()) : "";
18759 if ( path != "" )
18760 {
18761 path += PHYSFS_getDirSeparator();
18762 inputPath = path + inputPath;
18763 File* fp = FileIO::open(inputPath.c_str(), "rb");
18764 if ( !fp )
18765 {
18766 printlog("[JSON]: Error: Could not locate json file %s", inputPath.c_str());
18767 return;
18768 }
18769 static char buf[65536];
18770 int count = fp->read(buf, sizeof(buf[0]), sizeof(buf) - 1);
18771 buf[count] = '\0';
18772 rapidjson::StringStream is(buf);
18773 FileIO::close(fp);
18774
18775 rapidjson::Document d;
18776 d.ParseStream(is);
18777 if ( !d.IsObject() || !d.HasMember("version") || !d.HasMember("limbs") )
18778 {
18779 printlog("[JSON]: Error: No 'version' value in json file, or JSON syntax incorrect! %s", inputPath.c_str());
18780 return;
18781 }
18782 int version = d["version"].GetInt();
18783
18784 std::string filename = f.substr(0, f.find(".json"));
18785 auto& entry = compendiumObjectLimbs[filename];
18786 entry.entities.clear();
18787 entry.baseCamera = CompendiumView_t();
18788
18789 compendiumObjectMapTiles.erase(filename);
18790 int w = 0;
18791 int h = 0;
18792 int index = 0;
18793 if ( d.HasMember("map_tiles") )
18794 {
18795 auto& m = compendiumObjectMapTiles[filename];
18796 if ( d["map_tiles"].HasMember("floor")
18797 && d["map_tiles"].HasMember("mid")
18798 && d["map_tiles"].HasMember("top")
18799 && d["map_tiles"].HasMember("width")
18800 && d["map_tiles"].HasMember("height") )
18801 {
18802 if ( d["map_tiles"]["floor"].IsArray()
18803 && d["map_tiles"]["mid"].IsArray()
18804 && d["map_tiles"]["top"].IsArray() )
18805 {
18806 auto floor = d["map_tiles"]["floor"].GetArray();
18807 auto mid = d["map_tiles"]["mid"].GetArray();
18808 auto top = d["map_tiles"]["top"].GetArray();
18809 w = d["map_tiles"]["width"].GetInt();

Callers 2

initGameDatafilesFunction · 0.80
consolecommand.cppFile · 0.80

Calls 12

directoryContentsFunction · 0.85
printlogFunction · 0.85
CompendiumView_tClass · 0.85
c_strMethod · 0.80
GetIntMethod · 0.80
BeginMethod · 0.80
EndMethod · 0.80
EntityClass · 0.70
readMethod · 0.45
clearMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected