| 486 | } |
| 487 | |
| 488 | WorldStorage::TileSectorStore WorldStorage::readTileSector(ByteArray const& data) { |
| 489 | auto& root = Root::singleton(); |
| 490 | auto matDatabase = root.materialDatabase(); |
| 491 | auto liqDatabase = root.liquidsDatabase(); |
| 492 | auto storageConfig = root.assets()->json("/worldstorage.config"); |
| 493 | |
| 494 | DataStreamBuffer ds(uncompressData(data)); |
| 495 | TileSectorStore store; |
| 496 | ds.vuread(store.generationLevel); |
| 497 | ds.vuread(store.tileSerializationVersion); |
| 498 | |
| 499 | store.tiles.reset(new TileArray()); |
| 500 | for (size_t y = 0; y < WorldSectorSize; ++y) { |
| 501 | for (size_t x = 0; x < WorldSectorSize; ++x) { |
| 502 | ServerTile tile; |
| 503 | tile.read(ds, store.tileSerializationVersion); |
| 504 | |
| 505 | if (!matDatabase->isValidMaterialId(tile.foreground)) |
| 506 | tile.foreground = storageConfig.getUInt("replacementMaterialId"); |
| 507 | if (!matDatabase->isValidMaterialId(tile.background)) |
| 508 | tile.background = storageConfig.getUInt("replacementMaterialId"); |
| 509 | if (!matDatabase->isValidModId(tile.foregroundMod)) |
| 510 | tile.foregroundMod = storageConfig.getUInt("replacementModId"); |
| 511 | if (!matDatabase->isValidModId(tile.backgroundMod)) |
| 512 | tile.backgroundMod = storageConfig.getUInt("replacementModId"); |
| 513 | if (!liqDatabase->isValidLiquidId(tile.liquid.liquid)) { |
| 514 | LiquidId replacementLiquid = storageConfig.getUInt("replacementLiquidId"); |
| 515 | if (replacementLiquid == EmptyLiquidId) |
| 516 | tile.liquid = LiquidStore(); |
| 517 | else |
| 518 | tile.liquid.liquid = replacementLiquid; |
| 519 | } |
| 520 | |
| 521 | (*store.tiles)(x, y) = tile; |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | return store; |
| 526 | } |
| 527 | |
| 528 | ByteArray WorldStorage::writeTileSector(TileSectorStore const& store) { |
| 529 | DataStreamBuffer ds; |
nothing calls this directly
no test coverage detected