| 446 | } |
| 447 | |
| 448 | optional<int> read_int (nbt::value& parent, const char * name) |
| 449 | { |
| 450 | try |
| 451 | { |
| 452 | auto &namedValue = parent.at(name); |
| 453 | if(namedValue.get_type() != nbt::tag_type::Int) |
| 454 | { |
| 455 | return nullopt; |
| 456 | } |
| 457 | auto & tag_str = namedValue.as<nbt::tag_int>(); |
| 458 | return tag_str.get(); |
| 459 | } |
| 460 | catch (const std::out_of_range &e) |
| 461 | { |
| 462 | // fallback for old world formats |
| 463 | qWarning() << "Int NBT tag" << name << "could not be found."; |
| 464 | return nullopt; |
| 465 | } |
| 466 | catch (const std::bad_cast &e) |
| 467 | { |
| 468 | // type mismatch |
| 469 | qWarning() << "NBT tag" << name << "could not be converted to int."; |
| 470 | return nullopt; |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | GameType read_gametype(nbt::value& parent, const char * name) { |
| 475 | return GameType(read_int(parent, name)); |
no test coverage detected