推
This commit is contained in:
@@ -72,9 +72,12 @@ void Global_Game::InitGame()
|
||||
EquipmentPathMap = GlobalEquipmentScript::InitEquipmentLst();
|
||||
// 读取怪物配置文件
|
||||
MonsterPathMap = GlobalMonsterScript::InitMonsterLst();
|
||||
// 读取城镇配置文件
|
||||
TownPathMap = GlobalTownScript::InitTownLst();
|
||||
|
||||
// 初始化松鼠脚本管理器
|
||||
SquirrelManager::GetInstance().Init();
|
||||
SquirrelManager::GetInstance()
|
||||
.Init();
|
||||
// 读取存档
|
||||
SavaManager::GetInstance().Init();
|
||||
|
||||
@@ -105,6 +108,30 @@ GlobalMonsterScript::MonsterConfig Global_Game::GetMonsterInfo(int id)
|
||||
return MonsterConfig;
|
||||
}
|
||||
|
||||
const std::map<int, std::string> &Global_Game::GetTownMap() const
|
||||
{
|
||||
return TownPathMap;
|
||||
}
|
||||
|
||||
GlobalTownScript::TownConfig *Global_Game::GetTownInfo(int id)
|
||||
{
|
||||
if (TownInfoMap.count(id))
|
||||
return TownInfoMap[id];
|
||||
if (!TownPathMap.count(id))
|
||||
{
|
||||
SDL_LogError(0, "城镇ID不存在");
|
||||
return nullptr;
|
||||
}
|
||||
std::string path = TownPathMap[id];
|
||||
GlobalTownScript::TownConfig *TownConfig = GlobalTownScript::GetTownConfig(path);
|
||||
if (TownConfig)
|
||||
{
|
||||
TownInfoMap[id] = TownConfig;
|
||||
return TownConfig;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<GameCamera> Global_Game::GetCamera()
|
||||
{
|
||||
return _GameCamera;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "Global/Script/CharacterConfig.h"
|
||||
#include "Global/Script/EquipmentConfig.h"
|
||||
#include "Global/Script/MonsterConfig.h"
|
||||
#include "Global/Script/TownConfig.h"
|
||||
#include "Global/Save/SavaManager.h"
|
||||
#include "Global/GameCamera.h"
|
||||
class Global_Game
|
||||
@@ -43,6 +44,12 @@ public:
|
||||
std::map<int, GlobalMonsterScript::MonsterConfig> MonsterInfoMap; // 信息
|
||||
GlobalMonsterScript::MonsterConfig GetMonsterInfo(int id); // 获取怪物信息
|
||||
|
||||
// 城镇相关
|
||||
std::map<int, std::string> TownPathMap; // 路径
|
||||
std::map<int, GlobalTownScript::TownConfig *> TownInfoMap; // 信息
|
||||
const std::map<int, std::string>& GetTownMap() const; // 获取城镇路径
|
||||
GlobalTownScript::TownConfig *GetTownInfo(int id); // 获取城镇信息
|
||||
|
||||
// 游戏摄像机
|
||||
RefPtr<GameCamera> _GameCamera = nullptr;
|
||||
|
||||
|
||||
58
source_game/Global/Script/TownConfig.cpp
Normal file
58
source_game/Global/Script/TownConfig.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
#include "TownConfig.h"
|
||||
#include "Asset/AssetManager.h"
|
||||
#include "Tool/Tool_String.h"
|
||||
namespace GlobalTownScript
|
||||
{
|
||||
std::map<int, std::string> InitTownLst()
|
||||
{
|
||||
std::map<int, std::string> TownList;
|
||||
ScriptData Data = AssetManager::GetInstance().GetScriptInfo("town/town.lst");
|
||||
while (!Data.IsEnd())
|
||||
{
|
||||
std::string Index = Data.Get();
|
||||
std::string MonsterPath = std::string("town/") + Tool_toLowerCase(Data.Get());
|
||||
TownList[std::stoi(Index)] = MonsterPath;
|
||||
}
|
||||
return TownList;
|
||||
}
|
||||
|
||||
TownConfig *GetTownConfig(std::string TownPath)
|
||||
{
|
||||
TownConfig *Config = new TownConfig();
|
||||
ScriptData Data = AssetManager::GetInstance().GetScriptInfo(TownPath);
|
||||
while (!Data.IsEnd())
|
||||
{
|
||||
std::string Segment = Data.Get();
|
||||
|
||||
if (Segment == "[entering title]")
|
||||
{
|
||||
Config->Entering_Title = "sprite/" + Tool_toLowerCase(Data.Get());
|
||||
}
|
||||
else if (Segment == "[cutscene image]")
|
||||
{
|
||||
Config->Entering_Cutscene = "sprite/" + Tool_toLowerCase(Data.Get());
|
||||
}
|
||||
else if (Segment == "[area]")
|
||||
{
|
||||
int Index = std::stoi(Data.Get());
|
||||
std::string MapPath = "map/" + Tool_toLowerCase(Data.Get());
|
||||
std::string TypeBuffer = Data.Get();
|
||||
std::string Type = TypeBuffer.substr(1, TypeBuffer.size() - 2);
|
||||
int GenerateXPos = -1;
|
||||
int GenerateYPos = -1;
|
||||
|
||||
if (Type == "gate")
|
||||
{
|
||||
GenerateXPos = std::stoi(Data.Get());
|
||||
GenerateYPos = std::stoi(Data.Get());
|
||||
}
|
||||
Config->AreaLst[Index] = AreaConfig{MapPath, Type, GenerateXPos, GenerateYPos};
|
||||
}
|
||||
else if (Segment == "[name]")
|
||||
{
|
||||
Config->TownName = Data.Get();
|
||||
}
|
||||
}
|
||||
return Config;
|
||||
}
|
||||
}
|
||||
41
source_game/Global/Script/TownConfig.h
Normal file
41
source_game/Global/Script/TownConfig.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
namespace GlobalTownScript
|
||||
{
|
||||
struct AreaConfig
|
||||
{
|
||||
/**地图路径 */
|
||||
std::string MapPath;
|
||||
/**地图类型 */
|
||||
std::string MapType;
|
||||
/**生成坐标X */
|
||||
int GenerateXPos = 0;
|
||||
/**生成坐标Y */
|
||||
int GenerateYPos = 0;
|
||||
};
|
||||
|
||||
/**城镇配置 */
|
||||
struct TownConfig
|
||||
{
|
||||
/**城镇名称 */
|
||||
std::string TownName;
|
||||
/**进入城镇时的标题Img */
|
||||
std::string Entering_Title;
|
||||
/**进入城镇时的过场Img */
|
||||
std::string Entering_Cutscene;
|
||||
/**需要的任务进入条件 */
|
||||
int NeedQuestID = -1;
|
||||
/**需要的等级进入条件 */
|
||||
int NeedLevel = -1;
|
||||
/**区域 */
|
||||
std::map<int, AreaConfig> AreaLst;
|
||||
};
|
||||
|
||||
// 读取城镇列表
|
||||
std::map<int, std::string> InitTownLst();
|
||||
|
||||
// 读取城镇配置
|
||||
TownConfig *GetTownConfig(std::string TownPath);
|
||||
}
|
||||
Reference in New Issue
Block a user