Files
DNF_DEV/source_game/Global/Save/SavaManager.cpp
2025-10-06 04:18:49 +08:00

60 lines
1.2 KiB
C++

#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();
}