|
11 | 11 | #include "../screen/Color.h" |
12 | 12 | #include "../screen/Styles.h" |
13 | 13 | #include <Core/TextIO.h> |
| 14 | +#include <Core/StringHelper.h> |
14 | 15 | #include <sstream> |
15 | 16 |
|
16 | 17 |
|
@@ -55,6 +56,7 @@ namespace t8 |
55 | 56 |
|
56 | 57 | struct Texture |
57 | 58 | { |
| 59 | + int ver = 0; |
58 | 60 | RC size; |
59 | 61 | int area = 0; |
60 | 62 | std::vector<char> characters; |
@@ -251,15 +253,49 @@ namespace t8 |
251 | 253 | { |
252 | 254 | if (section == 0) |
253 | 255 | { |
254 | | - std::istringstream iss(l); |
255 | | - iss >> size.r >> size.c; |
256 | | - area = size.r * size.c; |
257 | | - characters.resize(area, ' '); |
258 | | - fg_colors.resize(area, Color::Default); |
259 | | - bg_colors.resize(area, Color::Transparent2); |
260 | | - materials.resize(area, -1); |
261 | | - section = 1; |
262 | | - r = 0; |
| 256 | + if (!l.empty()) |
| 257 | + { |
| 258 | + if (l.starts_with("VER")) |
| 259 | + { |
| 260 | + auto tokens = str::tokenize(l, { ' ' }); |
| 261 | + if (tokens.size() == 2) |
| 262 | + { |
| 263 | + // Absence of VER line means it is version 1. |
| 264 | + int ver_parsed = std::stoi(tokens[1]); |
| 265 | + // Change from 1 to current version for making sure it is future-incompatible. |
| 266 | + static const int compatible_version_until_and_including = 1; |
| 267 | + if (ver_parsed <= compatible_version_until_and_including) |
| 268 | + ver = ver_parsed; |
| 269 | + else |
| 270 | + { |
| 271 | + std::cerr << "ERROR in Texture::load() : Incompatible texture version: version = " + tokens[1] << '\n'; |
| 272 | + return false; |
| 273 | + } |
| 274 | + } |
| 275 | + else |
| 276 | + ver = 1; // Absence of VER line means it is version 1. |
| 277 | + } |
| 278 | + else |
| 279 | + { |
| 280 | + std::istringstream iss(l); |
| 281 | + iss >> size.r >> size.c; |
| 282 | + area = size.r * size.c; |
| 283 | + characters.resize(area, ' '); |
| 284 | + fg_colors.resize(area, Color::Default); |
| 285 | + bg_colors.resize(area, Color::Transparent2); |
| 286 | + materials.resize(area, -1); |
| 287 | + } |
| 288 | + r++; |
| 289 | + } |
| 290 | + else if (r == 1 || r == 2) // 2 if there is a VER line. |
| 291 | + { |
| 292 | + section = 1; |
| 293 | + r = 0; |
| 294 | + } |
| 295 | + else if (r > 2) |
| 296 | + { |
| 297 | + std::cerr << "ERROR in Texture::parse() : Incorrect number of header lines.\n"; |
| 298 | + } |
263 | 299 | } |
264 | 300 | else if (section == 1) |
265 | 301 | { |
|
0 commit comments