建档
This commit is contained in:
59
source_game/Global/Save/SavaManager.cpp
Normal file
59
source_game/Global/Save/SavaManager.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
#include "SavaManager.h"
|
||||
#include <json.hpp>
|
||||
#include <dirent.h>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <SDL.h>
|
||||
SavaManager::SavaManager()
|
||||
{
|
||||
}
|
||||
|
||||
SavaManager::~SavaManager()
|
||||
{
|
||||
}
|
||||
|
||||
void SavaManager::Init()
|
||||
{
|
||||
DIR *dir;
|
||||
struct dirent *ent;
|
||||
std::string path = "Save/";
|
||||
dir = opendir(path.c_str());
|
||||
|
||||
while ((ent = readdir(dir)))
|
||||
{
|
||||
// 跳过.和..目录
|
||||
if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0)
|
||||
continue;
|
||||
std::string RealPath = path + ent->d_name;
|
||||
SDL_Log("RealPath: %s", RealPath.c_str());
|
||||
}
|
||||
|
||||
Save();
|
||||
}
|
||||
|
||||
void SavaManager::Save()
|
||||
{
|
||||
int Level = 1;
|
||||
int Job = 0;
|
||||
int GrowType = -1;
|
||||
int Exp = 0;
|
||||
int Fatigue = 0;
|
||||
|
||||
nlohmann::json SaveJson;
|
||||
SaveJson["Level"] = Level;
|
||||
SaveJson["Job"] = Job;
|
||||
SaveJson["GrowType"] = GrowType;
|
||||
SaveJson["Exp"] = Exp;
|
||||
SaveJson["Fatigue"] = Fatigue;
|
||||
|
||||
SaveJson["WearEquipment"] = nlohmann::json::object();
|
||||
|
||||
nlohmann::json weapon;
|
||||
weapon["id"] = 26058;
|
||||
|
||||
SaveJson["WearEquipment"]["weapon"] = weapon;
|
||||
|
||||
std::ofstream OutFile("Save/Save_0.sav");
|
||||
OutFile << SaveJson.dump(4);
|
||||
OutFile.close();
|
||||
}
|
||||
29
source_game/Global/Save/SavaManager.h
Normal file
29
source_game/Global/Save/SavaManager.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
class SavaManager
|
||||
{
|
||||
public:
|
||||
// 删除拷贝构造和赋值运算符,确保无法复制
|
||||
SavaManager(const SavaManager &) = delete;
|
||||
SavaManager &operator=(const SavaManager &) = delete;
|
||||
|
||||
// 移动构造和赋值也删除,避免意外转移
|
||||
SavaManager(SavaManager &&) = delete;
|
||||
SavaManager &operator=(SavaManager &&) = delete;
|
||||
|
||||
// 全局访问点
|
||||
static SavaManager &GetInstance()
|
||||
{
|
||||
static SavaManager instance; // 局部静态变量,保证只初始化一次
|
||||
return instance;
|
||||
}
|
||||
|
||||
private:
|
||||
// 构造函数和析构函数设为私有,防止外部创建和销毁
|
||||
SavaManager();
|
||||
~SavaManager();
|
||||
|
||||
public:
|
||||
void Init();
|
||||
void Save();
|
||||
};
|
||||
Reference in New Issue
Block a user