265 lines
7.3 KiB
C++
265 lines
7.3 KiB
C++
|
|
#include "AssetManager.h"
|
||
|
|
#include "EngineCore/Asset_Script.h"
|
||
|
|
#include "Tool/Blob.hpp"
|
||
|
|
#include "Tool/Tool_String.hpp"
|
||
|
|
|
||
|
|
AssetManager::AssetManager()
|
||
|
|
{
|
||
|
|
}
|
||
|
|
AssetManager::~AssetManager()
|
||
|
|
{
|
||
|
|
}
|
||
|
|
|
||
|
|
AniInfo AssetManager::StructAniInfo(std::string path)
|
||
|
|
{
|
||
|
|
AniInfo Info;
|
||
|
|
std::vector<BYTE> Data = Asset_Script::GetInstance().GetFileContentByte(path);
|
||
|
|
Blob blob(Data);
|
||
|
|
|
||
|
|
int Frame_Max = blob.getUShort();
|
||
|
|
int Img_Count = blob.getUShort();
|
||
|
|
|
||
|
|
printf("Frame_Max : %d\n", Frame_Max);
|
||
|
|
printf("Img_Count : %d\n", Img_Count);
|
||
|
|
|
||
|
|
// Img的路径读取 存入数组
|
||
|
|
for (int i = 0; i < Img_Count; i++)
|
||
|
|
{
|
||
|
|
int Buf = blob.getInt();
|
||
|
|
std::string ImgPath = blob.getString(Buf);
|
||
|
|
printf("ImgPath : %s\n", ImgPath.c_str());
|
||
|
|
Info.Img_List.push_back(ImgPath);
|
||
|
|
}
|
||
|
|
|
||
|
|
// Ani头部标签数量
|
||
|
|
int Ani_H_Item_Count = blob.getUShort();
|
||
|
|
// 处理标签
|
||
|
|
for (int i = 0; i < Ani_H_Item_Count; i++)
|
||
|
|
{
|
||
|
|
int Type = blob.getUShort();
|
||
|
|
switch (Type)
|
||
|
|
{
|
||
|
|
case 0:
|
||
|
|
case 1:
|
||
|
|
{
|
||
|
|
std::string Key = AniScriptParser::Get_Ani_Flag(Type);
|
||
|
|
int Value = blob.getByte();
|
||
|
|
Info.Flag.emplace(Key, Value);
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
case 3:
|
||
|
|
case 28:
|
||
|
|
{
|
||
|
|
std::string Key = AniScriptParser::Get_Ani_Flag(Type);
|
||
|
|
int Value = blob.getUShort();
|
||
|
|
Info.Flag.emplace(Key, Value);
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
case 18:
|
||
|
|
{
|
||
|
|
blob.getByte();
|
||
|
|
blob.getInt();
|
||
|
|
blob.getInt();
|
||
|
|
blob.getInt();
|
||
|
|
blob.get256();
|
||
|
|
blob.get256();
|
||
|
|
blob.get256();
|
||
|
|
blob.get256();
|
||
|
|
blob.getUShort();
|
||
|
|
}
|
||
|
|
default:
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 读取每一个Img
|
||
|
|
for (int i = 0; i < Frame_Max; i++)
|
||
|
|
{
|
||
|
|
AniFrame FrameObject;
|
||
|
|
|
||
|
|
// 碰撞框项目数量
|
||
|
|
int Ani_Box_Item_Count = blob.getUShort();
|
||
|
|
for (int j = 0; j < Ani_Box_Item_Count; j++)
|
||
|
|
{
|
||
|
|
int Box_Type = blob.getUShort();
|
||
|
|
std::vector<int> D_Box_b;
|
||
|
|
for (int k = 0; k < 6; k++)
|
||
|
|
{
|
||
|
|
D_Box_b.push_back(blob.getInt());
|
||
|
|
}
|
||
|
|
if (Box_Type == 15)
|
||
|
|
FrameObject.AttackBox.push_back(D_Box_b);
|
||
|
|
else
|
||
|
|
FrameObject.DamageBox.push_back(D_Box_b);
|
||
|
|
}
|
||
|
|
|
||
|
|
// 调用的第几个Img
|
||
|
|
int Index_Buf = blob.getShort();
|
||
|
|
if (Index_Buf != -1)
|
||
|
|
{
|
||
|
|
FrameObject.Img_Path = Tool_toLowerCase(Info.Img_List[Index_Buf]);
|
||
|
|
FrameObject.Img_Index = blob.getUShort();
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
FrameObject.Img_Path = "";
|
||
|
|
FrameObject.Img_Index = 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 坐标
|
||
|
|
FrameObject.Img_Pos = SDL_Point{blob.getInt(), blob.getInt()};
|
||
|
|
|
||
|
|
// Img中的项目数量
|
||
|
|
int Img_Flag_Count = blob.getUShort();
|
||
|
|
for (int j = 0; j < Img_Flag_Count; j++)
|
||
|
|
{
|
||
|
|
int Img_Flag_Type = blob.getUShort();
|
||
|
|
std::string Key;
|
||
|
|
int Value;
|
||
|
|
switch (Img_Flag_Type)
|
||
|
|
{
|
||
|
|
case 0:
|
||
|
|
case 1:
|
||
|
|
case 10:
|
||
|
|
{
|
||
|
|
Key = AniScriptParser::Get_Ani_Flag(Img_Flag_Type);
|
||
|
|
Value = blob.getInt();
|
||
|
|
FrameObject.Flag.emplace(Key, Value);
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
case 3:
|
||
|
|
{
|
||
|
|
Key = "COORD";
|
||
|
|
Value = blob.getUShort();
|
||
|
|
FrameObject.Flag.emplace(Key, Value);
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
case 17:
|
||
|
|
{
|
||
|
|
Key = "PRELOAD";
|
||
|
|
Value = 1;
|
||
|
|
FrameObject.Flag.emplace(Key, Value);
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
case 7:
|
||
|
|
{
|
||
|
|
Key = "IMAGE_RATE";
|
||
|
|
SDL_FPoint pos{
|
||
|
|
blob.getFloat(),
|
||
|
|
blob.getFloat()};
|
||
|
|
FrameObject.Flag.emplace(Key, pos);
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
case 8:
|
||
|
|
{
|
||
|
|
Key = "IMAGE_ROTATE";
|
||
|
|
Value = blob.getFloat();
|
||
|
|
FrameObject.Flag.emplace(Key, Value);
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
case 9:
|
||
|
|
{
|
||
|
|
Key = "RGBA";
|
||
|
|
std::vector<float> RGBA = {
|
||
|
|
blob.get256(),
|
||
|
|
blob.get256(),
|
||
|
|
blob.get256(),
|
||
|
|
blob.get256()};
|
||
|
|
FrameObject.Flag.emplace(Key, RGBA);
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
case 11:
|
||
|
|
{
|
||
|
|
int Effect_Type = blob.getUShort();
|
||
|
|
Key = "GRAPHIC_EFFECT_" + AniScriptParser::Get_Ani_Effect_Type(Effect_Type);
|
||
|
|
std::vector<float> effect;
|
||
|
|
switch (Effect_Type)
|
||
|
|
{
|
||
|
|
case 5:
|
||
|
|
{
|
||
|
|
effect.push_back(blob.get256());
|
||
|
|
effect.push_back(blob.get256());
|
||
|
|
effect.push_back(blob.get256());
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
case 6:
|
||
|
|
{
|
||
|
|
effect.push_back(blob.get256());
|
||
|
|
effect.push_back(blob.get256());
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
FrameObject.Flag.emplace(Key, effect);
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
case 12:
|
||
|
|
{
|
||
|
|
Value = blob.getInt();
|
||
|
|
FrameObject.Delay = Value;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
case 13:
|
||
|
|
{
|
||
|
|
Key = "DAMAGE_TYPE";
|
||
|
|
std::string DTYPE = AniScriptParser::Get_Ani_Damage_Type(blob.getUShort());
|
||
|
|
FrameObject.Flag.emplace(Key, DTYPE);
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
case 16:
|
||
|
|
{
|
||
|
|
int SoundTempSize = blob.getInt();
|
||
|
|
Key = "PLAY_SOUND";
|
||
|
|
std::string sound = blob.getString(SoundTempSize);
|
||
|
|
FrameObject.Flag.emplace(Key, sound);
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
case 23:
|
||
|
|
{
|
||
|
|
Key = "SET_FLAG";
|
||
|
|
Value = blob.getInt();
|
||
|
|
FrameObject.Flag.emplace(Key, Value);
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
case 24:
|
||
|
|
{
|
||
|
|
Key = "FLIP_TYPE";
|
||
|
|
std::string FTYPEValue = AniScriptParser::Get_Ani_Flip_Type(blob.getUShort());
|
||
|
|
FrameObject.Flag.emplace(Key, FTYPEValue);
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
case 25:
|
||
|
|
{
|
||
|
|
Key = "LOOP_START";
|
||
|
|
FrameObject.Flag.emplace(Key, 1);
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
case 26:
|
||
|
|
{
|
||
|
|
Key = "LOOP_END";
|
||
|
|
Value = blob.getInt();
|
||
|
|
FrameObject.Flag.emplace(Key, Value);
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
case 27:
|
||
|
|
{
|
||
|
|
Key = "CLIP";
|
||
|
|
std::vector<int> ClipArr{
|
||
|
|
blob.getShort(),
|
||
|
|
blob.getShort(),
|
||
|
|
blob.getShort(),
|
||
|
|
blob.getShort(),
|
||
|
|
};
|
||
|
|
FrameObject.Flag.emplace(Key, ClipArr);
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
default:
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
Info.Frame.push_back(FrameObject);
|
||
|
|
}
|
||
|
|
|
||
|
|
return Info;
|
||
|
|
}
|