1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
/*
* Copyright (C) 2002-2019 by the Widelands Development Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "game_io/game_map_packet.h"
#include <memory>
#include "io/filesystem/filesystem.h"
#include "logic/game.h"
#include "logic/game_data_error.h"
#include "map_io/map_saver.h"
#include "map_io/widelands_map_loader.h"
namespace Widelands {
GameMapPacket::~GameMapPacket() {
delete wms_;
delete wml_;
}
void GameMapPacket::read(FileSystem& fs, Game& game, MapObjectLoader* const) {
if (!fs.file_exists("map") || !fs.is_directory("map"))
throw GameDataError("no map");
// Now Load the map as it would be a normal map saving.
delete wml_;
wml_ = new WidelandsMapLoader(fs.make_sub_file_system("map"), game.mutable_map());
wml_->preload_map(true);
// DONE, mapfs gets deleted by WidelandsMapLoader.
return;
}
void GameMapPacket::read_complete(Game& game) {
wml_->load_map_complete(game, MapLoader::LoadType::kScenario);
mol_ = wml_->get_map_object_loader();
}
void GameMapPacket::write(FileSystem& fs, Game& game, MapObjectSaver* const) {
std::unique_ptr<FileSystem> mapfs(fs.create_sub_file_system("map", FileSystem::DIR));
// Now Write the map as it would be a normal map saving.
delete wms_;
wms_ = new MapSaver(*mapfs, game);
wms_->save();
mos_ = wms_->get_map_object_saver();
}
} // namespace Widelands
|