-
Notifications
You must be signed in to change notification settings - Fork 5
/
MeguSerialize.h
45 lines (43 loc) · 1.14 KB
/
MeguSerialize.h
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
#pragma once
#include<string>
#include<fstream>
#include<sstream>
#include<iostream>
#include <SDL2/SDL.h>
#include"MeguStructs.h"
class MeguSerialize{
friend class MeguEngine;
public:
static void serializePlayer(const std::string &path, Megu::megu_sprites &player){
std::ofstream file;
file.open(path.c_str());
if (file.is_open()){
file << player.owner_name << "/n";
file << player.pet_name << "/n";
file << player.id << "/n";
file.close();
}
else{
std::cerr << "error opening file" << std::endl;
}
}
static void deserializePlayer(const std::string &path, const int id, SDL_Renderer *renderer){
std::ifstream file;
std::string line;
file.open(path.c_str());
int megu_id;
std::string owner_name;
std::string pet_name;
if (file.is_open()){
file >> owner_name;
file >> pet_name;
file >> megu_id;
file.close();
}
else{
std::cerr << "error opening file" << std::endl;
}
}
static void serializeHouse(const std::string &path, std::vector<Megu::scene_objects> &objects_list);
static void deserializeHouse(const std::string &path, std::vector<Megu::scene_objects> &objects_list, SDL_Renderer *renderer);
};