61 lines
1.6 KiB
C++
61 lines
1.6 KiB
C++
#include "Global_Game.h"
|
|
|
|
Global_Game::Global_Game()
|
|
{
|
|
}
|
|
Global_Game::~Global_Game()
|
|
{
|
|
}
|
|
|
|
void Global_Game::Init()
|
|
{
|
|
// 初始化ttf字体资源
|
|
TTF_Font *FontBuf = TTF_OpenFont("Fonts/VonwaonBitmap-12px.ttf", 24);
|
|
// TTF_Font *FontBuf = TTF_OpenFont("Fonts/NotoSansSC-Regular.otf", 24);
|
|
// TTF_Font *FontBuf = TTF_OpenFont("Fonts/calibri.ttf", 24);
|
|
|
|
if (!FontBuf)
|
|
{
|
|
SDL_LogError(0, "字体加载失败: %s", TTF_GetError());
|
|
}
|
|
Fonts.push_back(FontBuf);
|
|
}
|
|
|
|
void Global_Game::InitGame()
|
|
{
|
|
// 读取角色配置文件
|
|
CharacterConfigs = GlobalCharacterScript::InitCharacterLst();
|
|
// 读取装备配置文件
|
|
EquipmentPathMap = GlobalEquipmentScript::InitEquipmentLst();
|
|
// 读取怪物配置文件
|
|
MonsterPathMap = GlobalMonsterScript::InitMonsterLst();
|
|
|
|
// 初始化松鼠脚本管理器
|
|
SquirrelManager::GetInstance().Init();
|
|
|
|
// 读取存档
|
|
SavaManager::GetInstance().Init();
|
|
// 游戏初始化完成标志
|
|
InitFlag = true;
|
|
}
|
|
|
|
GlobalMonsterScript::MonsterConfig Global_Game::GetMonsterInfo(int id)
|
|
{
|
|
if (!InitFlag)
|
|
{
|
|
SDL_LogError(0, "游戏未初始化");
|
|
return GlobalMonsterScript::MonsterConfig();
|
|
}
|
|
if (MonsterInfoMap.count(id))
|
|
return MonsterInfoMap[id];
|
|
if (!MonsterPathMap.count(id))
|
|
{
|
|
SDL_LogError(0, "怪物ID不存在");
|
|
return GlobalMonsterScript::MonsterConfig();
|
|
}
|
|
std::string path = MonsterPathMap[id];
|
|
GlobalMonsterScript::MonsterConfig MonsterConfig = GlobalMonsterScript::ReadMonsterConfig(path);
|
|
MonsterConfig.id = id;
|
|
MonsterInfoMap[id] = MonsterConfig;
|
|
return MonsterConfig;
|
|
} |