建档
This commit is contained in:
36
source_game/Global/Global_Enum.h
Normal file
36
source_game/Global/Global_Enum.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
// 交易类型
|
||||
enum ATTACH_TYPE
|
||||
{
|
||||
FREE, // 无限制
|
||||
SEALING, // 封装
|
||||
TRADE, // 不可交易
|
||||
ACCOUNT, // 账号绑定
|
||||
TRADE_DELETE, // 无法交易、删除
|
||||
SEALING_TRADE // 封装且不可交易
|
||||
};
|
||||
|
||||
// 控制器消息类型
|
||||
enum CONTROLLER_MSG_TYPE
|
||||
{
|
||||
// 摇杆移动(左)
|
||||
CONTROLLER_MSG_TYPE_LEFT_JOYSTICK_MOVE,
|
||||
// 摇杆移动(右)
|
||||
CONTROLLER_MSG_TYPE_RIGHT_JOYSTICK_MOVE
|
||||
};
|
||||
|
||||
// 基础状态
|
||||
enum BASE_STATE
|
||||
{
|
||||
REST, // 站立
|
||||
MOVE, // 移动
|
||||
DASH, // 冲刺
|
||||
JUMP, // 跳跃
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
37
source_game/Global/Global_Game.cpp
Normal file
37
source_game/Global/Global_Game.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#include "Global_Game.h"
|
||||
|
||||
Global_Game::Global_Game()
|
||||
{
|
||||
}
|
||||
Global_Game::~Global_Game()
|
||||
{
|
||||
}
|
||||
|
||||
void Global_Game::Init()
|
||||
{
|
||||
// 初始化ttf字体资源
|
||||
TTF_Font *FontBuf = TTF_OpenFont("Fonts/LXGWWenKai-Regular.ttf", 24);
|
||||
// TTF_Font *FontBuf = TTF_OpenFont("Fonts/Gothica-Book.ttf", 24);
|
||||
// TTF_Font *FontBuf = TTF_OpenFont("Fonts/Gasinamu.ttf", 24);
|
||||
if (!FontBuf)
|
||||
{
|
||||
SDL_LogError(0, "字体加载失败: %s", TTF_GetError());
|
||||
}
|
||||
Fonts.push_back(FontBuf);
|
||||
}
|
||||
|
||||
void Global_Game::InitGame()
|
||||
{
|
||||
// 读取角色配置文件
|
||||
CharacterConfigs = GlobalCharacterScript::InitCharacterLst();
|
||||
// 读取装备配置文件
|
||||
EquipmentPathMap = GlobalEquipmentScript::InitEquipmentLst();
|
||||
|
||||
// 初始化松鼠脚本管理器
|
||||
SquirrelManager::GetInstance().Init();
|
||||
|
||||
// 读取存档
|
||||
SavaManager::GetInstance().Init();
|
||||
// 游戏初始化完成标志
|
||||
InitFlag = true;
|
||||
}
|
||||
45
source_game/Global/Global_Game.h
Normal file
45
source_game/Global/Global_Game.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
#include "EngineCore/Game.h"
|
||||
#include "Global/Script/CharacterConfig.h"
|
||||
#include "Global/Script/EquipmentConfig.h"
|
||||
#include "Global/Save/SavaManager.h"
|
||||
#include "Asset/Squirrel/SquirrelManager.h"
|
||||
class Global_Game
|
||||
{
|
||||
|
||||
public:
|
||||
Global_Game(const Global_Game &) = delete;
|
||||
Global_Game &operator=(const Global_Game &) = delete;
|
||||
Global_Game(Global_Game &&) = delete;
|
||||
Global_Game &operator=(Global_Game &&) = delete;
|
||||
// 全局访问点
|
||||
static Global_Game &GetInstance()
|
||||
{
|
||||
static Global_Game instance; // 局部静态变量,保证只初始化一次
|
||||
return instance;
|
||||
}
|
||||
|
||||
// 游戏资源加载之前的初始化
|
||||
void Init();
|
||||
// 游戏资源加载之后的初始化
|
||||
void InitGame();
|
||||
|
||||
public:
|
||||
// 当前游戏状态 0未初始化
|
||||
int game_state = 0;
|
||||
|
||||
public:
|
||||
// 字体资源
|
||||
std::vector<TTF_Font *> Fonts;
|
||||
// 角色配置文件
|
||||
std::vector<GlobalCharacterScript::CharacterConfig> CharacterConfigs;
|
||||
// 装备路径Map
|
||||
std::map<int, std::string> EquipmentPathMap;
|
||||
|
||||
// 游戏资源初始化标志
|
||||
bool InitFlag = false;
|
||||
|
||||
private:
|
||||
Global_Game(/* args */);
|
||||
~Global_Game();
|
||||
};
|
||||
10
source_game/Global/Global_Type.h
Normal file
10
source_game/Global/Global_Type.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
#include <variant>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
// 定义变量类型变体
|
||||
using ObjectVarsType = std::variant<int, float, bool, std::string>;
|
||||
// 定义对象变量映射类型
|
||||
using ObjectVarsMap = std::map<std::string, std::vector<ObjectVarsType>>;
|
||||
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();
|
||||
};
|
||||
135
source_game/Global/Script/CharacterConfig.cpp
Normal file
135
source_game/Global/Script/CharacterConfig.cpp
Normal file
@@ -0,0 +1,135 @@
|
||||
#include "CharacterConfig.h"
|
||||
#include "Asset/AssetManager.h"
|
||||
#include "Tool/Tool_String.h"
|
||||
namespace GlobalCharacterScript
|
||||
{
|
||||
JobConfig InitJobConfig(std::string JobInfoPath)
|
||||
{
|
||||
JobConfig Config;
|
||||
ScriptData Data = AssetManager::GetInstance().GetScriptInfo(JobInfoPath);
|
||||
while (!Data.IsEnd())
|
||||
{
|
||||
std::string Segment = Data.Get();
|
||||
if (Segment == "[职业名称]")
|
||||
Config.name = Data.Get();
|
||||
else if (Segment == "[生命值上限]")
|
||||
Config.maxHP = std::stof(Data.Get());
|
||||
else if (Segment == "[魔法值上限]")
|
||||
Config.maxMP = std::stof(Data.Get());
|
||||
else if (Segment == "[生命值回复速率]")
|
||||
Config.hpRecoverRate = std::stof(Data.Get());
|
||||
else if (Segment == "[魔法值回复速率]")
|
||||
Config.mpRecoverRate = std::stof(Data.Get());
|
||||
else if (Segment == "[力量]")
|
||||
Config.strength = std::stof(Data.Get());
|
||||
else if (Segment == "[智力]")
|
||||
Config.intelligence = std::stof(Data.Get());
|
||||
else if (Segment == "[体力]")
|
||||
Config.stamina = std::stof(Data.Get());
|
||||
else if (Segment == "[精神]")
|
||||
Config.spirit = std::stof(Data.Get());
|
||||
else if (Segment == "[移动速度]")
|
||||
Config.moveSpeed = std::stof(Data.Get());
|
||||
else if (Segment == "[攻击速度]")
|
||||
Config.attackSpeed = std::stof(Data.Get());
|
||||
else if (Segment == "[释放速度]")
|
||||
Config.castSpeed = std::stof(Data.Get());
|
||||
else if (Segment == "[硬直]")
|
||||
Config.stunResist = std::stof(Data.Get());
|
||||
else if (Segment == "[跳跃力]")
|
||||
Config.jumpPower = std::stof(Data.Get());
|
||||
else if (Segment == "[跳跃速度]")
|
||||
Config.jumpSpeed = std::stof(Data.Get());
|
||||
else if (Segment == "[火属性抗性]")
|
||||
Config.fireResist = std::stof(Data.Get());
|
||||
else if (Segment == "[冰属性抗性]")
|
||||
Config.iceResist = std::stof(Data.Get());
|
||||
else if (Segment == "[光属性抗性]")
|
||||
Config.lightResist = std::stof(Data.Get());
|
||||
else if (Segment == "[暗属性抗性]")
|
||||
Config.darkResist = std::stof(Data.Get());
|
||||
else if (Segment == "[默认技能]")
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
std::string Ret = Data.Get();
|
||||
if (Ret == "[/默认技能]")
|
||||
break;
|
||||
Config.skillList.push_back(std::stoi(Ret));
|
||||
}
|
||||
}
|
||||
else if (Segment == "[默认时装]")
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
std::string Ret = Data.Get();
|
||||
if (Ret == "[/默认时装]")
|
||||
break;
|
||||
std::string Index = Data.Get();
|
||||
Config.defaultAvatarList[Ret] = std::stoi(Index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Config;
|
||||
}
|
||||
|
||||
CharacterConfig InitCharacterConfig(std::string JobInfoPath)
|
||||
{
|
||||
CharacterConfig Config;
|
||||
ScriptData Data = AssetManager::GetInstance().GetScriptInfo(std::string("character/") + JobInfoPath);
|
||||
while (!Data.IsEnd())
|
||||
{
|
||||
std::string Segment = Data.Get();
|
||||
if (Segment == "[职业标签]")
|
||||
{
|
||||
std::string JobTab = Data.Get();
|
||||
Config.jobTag = JobTab.substr(1, JobTab.size() - 2);
|
||||
}
|
||||
else if (Segment == "[基础职业属性]")
|
||||
{
|
||||
Config.baseGrowtypePath = Data.Get();
|
||||
Config.baseJobConfig = InitJobConfig(Tool_toLowerCase(Config.baseGrowtypePath));
|
||||
}
|
||||
else if (Segment == "[转职职业属性]")
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
std::string Ret = Data.Get();
|
||||
if (Ret == "[/转职职业属性]")
|
||||
break;
|
||||
Config.growtypePath.push_back(Ret);
|
||||
Config.growtypeJobConfig.push_back(InitJobConfig(Tool_toLowerCase(Ret)));
|
||||
}
|
||||
}
|
||||
else if (Segment == "[动作动画]")
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
std::string Ret = Data.Get();
|
||||
if (Ret == "[/动作动画]")
|
||||
break;
|
||||
std::string path = Data.Get();
|
||||
Config.animationPath[Ret] = path;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Config;
|
||||
}
|
||||
|
||||
std::vector<CharacterConfig> InitCharacterLst()
|
||||
{
|
||||
std::vector<CharacterConfig> Config;
|
||||
// 先读取角色职业lst
|
||||
ScriptData Data = AssetManager::GetInstance().GetScriptInfo("character/character.lst");
|
||||
while (!Data.IsEnd())
|
||||
{
|
||||
std::string Index = Data.Get();
|
||||
std::string JobInfoPath = Data.Get();
|
||||
// 读取职业 //TODO 现在只有鬼剑士更改了文件 其他职业读了会炸
|
||||
if (std::stoi(Index) <= 0)
|
||||
Config.push_back(InitCharacterConfig(Tool_toLowerCase(JobInfoPath)));
|
||||
}
|
||||
return Config;
|
||||
}
|
||||
}
|
||||
79
source_game/Global/Script/CharacterConfig.h
Normal file
79
source_game/Global/Script/CharacterConfig.h
Normal file
@@ -0,0 +1,79 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
namespace GlobalCharacterScript
|
||||
{
|
||||
|
||||
// 职业配置
|
||||
struct JobConfig
|
||||
{
|
||||
// 职业名称
|
||||
std::string name;
|
||||
// HP最大值
|
||||
float maxHP;
|
||||
// MP最大值
|
||||
float maxMP;
|
||||
// HP恢复速率
|
||||
float hpRecoverRate;
|
||||
// MP恢复速率
|
||||
float mpRecoverRate;
|
||||
// 力量
|
||||
float strength;
|
||||
// 智力
|
||||
float intelligence;
|
||||
// 体力
|
||||
float stamina;
|
||||
// 精神
|
||||
float spirit;
|
||||
// 移动速度
|
||||
float moveSpeed;
|
||||
// 攻击速度
|
||||
float attackSpeed;
|
||||
// 释放速度
|
||||
float castSpeed;
|
||||
// 硬直
|
||||
float stunResist;
|
||||
// 跳跃力
|
||||
float jumpPower;
|
||||
// 跳跃速度
|
||||
float jumpSpeed;
|
||||
// 火属性抗性
|
||||
float fireResist;
|
||||
// 冰属性抗性
|
||||
float iceResist;
|
||||
// 光属性抗性
|
||||
float lightResist;
|
||||
// 暗属性抗性
|
||||
float darkResist;
|
||||
|
||||
// 初始技能列表
|
||||
std::vector<int> skillList;
|
||||
// 默认时装列表
|
||||
std::map<std::string, int> defaultAvatarList;
|
||||
};
|
||||
|
||||
// 角色类信息
|
||||
struct CharacterConfig
|
||||
{
|
||||
// 基础职业标识
|
||||
std::string jobTag;
|
||||
// 基础职业路径
|
||||
std::string baseGrowtypePath;
|
||||
// 基础职业配置
|
||||
JobConfig baseJobConfig;
|
||||
// 转职配置路径
|
||||
std::vector<std::string> growtypePath;
|
||||
// 转职职业配置
|
||||
std::vector<JobConfig> growtypeJobConfig;
|
||||
// 动画路径
|
||||
std::map<std::string, std::string> animationPath;
|
||||
};
|
||||
|
||||
// 读取角色Lst信息
|
||||
std::vector<CharacterConfig> InitCharacterLst();
|
||||
// 读取角色信息
|
||||
CharacterConfig InitCharacterConfig(std::string JobInfoPath);
|
||||
// 读取职业信息
|
||||
JobConfig InitJobConfig(std::string JobConfigPath);
|
||||
}
|
||||
19
source_game/Global/Script/EquipmentConfig.cpp
Normal file
19
source_game/Global/Script/EquipmentConfig.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#include "EquipmentConfig.h"
|
||||
#include "Asset/AssetManager.h"
|
||||
#include "Tool/Tool_String.h"
|
||||
namespace GlobalEquipmentScript
|
||||
{
|
||||
|
||||
std::map<int, std::string> InitEquipmentLst()
|
||||
{
|
||||
std::map<int, std::string> EquipList;
|
||||
ScriptData Data = AssetManager::GetInstance().GetScriptInfo("equipment/equipment.lst");
|
||||
while (!Data.IsEnd())
|
||||
{
|
||||
std::string Index = Data.Get();
|
||||
std::string EquipInfoPath = std::string("equipment/") + Data.Get();
|
||||
EquipList[std::stoi(Index)] = EquipInfoPath;
|
||||
}
|
||||
return EquipList;
|
||||
}
|
||||
}
|
||||
9
source_game/Global/Script/EquipmentConfig.h
Normal file
9
source_game/Global/Script/EquipmentConfig.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
namespace GlobalEquipmentScript
|
||||
{
|
||||
|
||||
std::map<int, std::string> InitEquipmentLst();
|
||||
}
|
||||
Reference in New Issue
Block a user