-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntityData.hpp
More file actions
57 lines (49 loc) · 1.53 KB
/
EntityData.hpp
File metadata and controls
57 lines (49 loc) · 1.53 KB
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
#ifndef ENTITYDATA_H
#define ENTITYDATA_H
#include <fstream>
#include "../utils.hpp"
#include "../Game/Game.hpp"
extern Game game;
void LoadEntites()
{
std::ifstream file("src/Data/entities.txt");
std::string line;
if (file.is_open()) {
std::cout << "File Openeded\n";
while (std::getline(file, line)) {
std::vector<std::string> split_line = SplitString(line, " ");
std::cout << "Line Read\n";
game.AddEntity(LoadTexture(("assets/sprites/" + split_line[1]).c_str()), std::atoi(split_line[2].c_str()), std::atoi(split_line[3].c_str()), split_line[0], split_line[1]);
}
std::cout << "Closed File\n";
file.close();
} else {
std::cerr << "Unable to open file.\n";
}
}
void SaveEntities()
{
std::ofstream file("src/Data/entities.txt", std::ios::trunc);
if (file.is_open())
{
std::cout << "File has been reset (contents cleared).\n";
file.close();
}
else
{
std::cerr << "Unable to open file.\n";
}
file.open("src/Data/entities.txt", std::ios::app);
if (file.is_open()) {
for (Entity& entity : game.entities)
{
if (entity.name != "Mouse" && !entity.in_run)
file << entity.name << " " << entity.texture_name << " " << entity.original_x << " " << entity.original_y << '\n';
}
file.close();
std::cout << "Data appended to file successfully.\n";
} else {
std::cerr << "Unable to open file for appending.\n";
}
}
#endif