| 3 | #include <fstream> |
| 4 | |
| 5 | BlockData::BlockData(const std::string &fileName) |
| 6 | { |
| 7 | std::ifstream inFile("Res/Blocks/" + fileName + ".block"); |
| 8 | |
| 9 | if (!inFile.is_open()) { |
| 10 | throw std::runtime_error("Unable to open block file: " + fileName + |
| 11 | "!"); |
| 12 | } |
| 13 | |
| 14 | std::string line; |
| 15 | while (std::getline(inFile, line)) { |
| 16 | if (line == "TexTop") { |
| 17 | int x, y; |
| 18 | inFile >> x >> y; |
| 19 | m_data.texTopCoord = {x, y}; |
| 20 | } |
| 21 | else if (line == "TexSide") { |
| 22 | int x, y; |
| 23 | inFile >> x >> y; |
| 24 | m_data.texSideCoord = {x, y}; |
| 25 | } |
| 26 | else if (line == "TexBottom") { |
| 27 | int x, y; |
| 28 | inFile >> x >> y; |
| 29 | m_data.texBottomCoord = {x, y}; |
| 30 | } |
| 31 | else if (line == "TexAll") { |
| 32 | int x, y; |
| 33 | inFile >> x >> y; |
| 34 | m_data.texTopCoord = {x, y}; |
| 35 | m_data.texSideCoord = {x, y}; |
| 36 | m_data.texBottomCoord = {x, y}; |
| 37 | } |
| 38 | else if (line == "Id") { |
| 39 | int id; |
| 40 | inFile >> id; |
| 41 | m_data.id = static_cast<BlockId>(id); |
| 42 | } |
| 43 | else if (line == "Opaque") { |
| 44 | inFile >> m_data.isOpaque; |
| 45 | } |
| 46 | else if (line == "Collidable") { |
| 47 | inFile >> m_data.isCollidable; |
| 48 | } |
| 49 | else if (line == "MeshType") { |
| 50 | int id; |
| 51 | inFile >> id; |
| 52 | m_data.meshType = static_cast<BlockMeshType>(id); |
| 53 | } |
| 54 | else if (line == "ShaderType") { |
| 55 | int id; |
| 56 | inFile >> id; |
| 57 | m_data.shaderType = static_cast<BlockShaderType>(id); |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | const BlockDataHolder &BlockData::getBlockData() const |
nothing calls this directly
no outgoing calls
no test coverage detected