-
Notifications
You must be signed in to change notification settings - Fork 0
/
Loader.cpp
127 lines (103 loc) · 2.44 KB
/
Loader.cpp
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include "stdafx.h"
#include "Loader.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include "ImageManager.h"
#include "Material.h"
#include "Grid.h"
Loader::Loader():pathManipuler()
{
tile_dir = pathManipuler.FindDirectory("tile");
}
ImageManager Loader::LoadImages()
{
ImageManager imMgr;
std::vector<fs::path> image_files = pathManipuler.FindFiles(tile_dir, ".jpg");
BOOST_FOREACH(const fs::path& p, image_files)
{
imMgr.Add(p);
}
return imMgr;
}
MaterialManager Loader::LoadMaterials(const ImageManager& imgMgr, const fs::path& mat_file_name) const
{
MaterialManager matMgr;
fs::path math_path = pathManipuler.FindDirectory("material");
fs::path mat_file = math_path / mat_file_name;
std::ifstream file(mat_file.string().c_str());
if(file)
{
std::string s;
while(std::getline(file, s))
{
char short_name_material;
std::string name_material, name_image;
float speed_factor;
std::stringstream ss;
ss << s;
if(ss >> name_material >> short_name_material >> speed_factor >> name_image)
{
const sf::Image* image = imgMgr.Get(name_image);
if(image != NULL)
{
Material m(name_material, short_name_material, speed_factor, image);
matMgr.Add(m);
}
}
}
}
return matMgr;
}
Grid Loader::LoadGrid(const MaterialManager& matMgr, const fs::path& grid_file_name, int widthscreen, int heightScreen) const
{
fs::path grid_path = pathManipuler.FindDirectory("grid");
fs::path grid_file = grid_path / grid_file_name;
std::ifstream file(grid_file.string().c_str());
if(file)
{
std::string s;
std::getline(file, s);
int nbCol, nbRow = 0;
std::stringstream ss;
ss << s;
if(ss >> nbCol >> nbRow)
{
Grid grid(nbCol, nbRow, widthscreen, heightScreen);
int y = 0;
while(std::getline(file, s) && (y < nbRow))
{
std::stringstream ss;
ss << s;
for(int x = 0 ; x < nbCol ; x++)
{
char mat;
ss >> mat;
Box& box = grid.GetBoxByRank(x, y);
box.BindMaterial(matMgr.GetByShortName(mat));
}
y++;
}
return grid;
}
/*
while(std::getline(file, s))
{
std::string name_material, name_image;
float speed_factor;
std::stringstream ss;
ss << s;
if(ss >> name_material >> speed_factor >> name_image)
{
const sf::Image* image = imgMgr.Get(name_image);
if(image != NULL)
{
Material m(speed_factor, image);
matMgr.Add(name_material, m);
}
}
}
*/
}
return Grid(0, 0, 0, 0);
}