64 lines
1.7 KiB
C++
64 lines
1.7 KiB
C++
#pragma once
|
|
#include "Sqr_CommonFunc.hpp"
|
|
#include "Asset/Asset_ImagePack.h"
|
|
|
|
static SQInteger SQR_GetImg(HSQUIRRELVM v)
|
|
{
|
|
const SQChar *ImgPath;
|
|
sq_getstring(v, 2, &ImgPath);
|
|
Asset_ImagePack::IMG *Info = Asset_ImagePack::GetInstance().GetIMG(ImgPath);
|
|
|
|
sq_newtable(v);
|
|
sq_pushstring(v, _SC("PngCount"), -1);
|
|
sq_pushfloat(v, Info->png_sum);
|
|
sq_newslot(v, 3, SQFalse);
|
|
sq_pushstring(v, _SC("NpkName"), -1);
|
|
sq_pushstring(v, Info->lpBelongsFile.c_str(), -1);
|
|
sq_newslot(v, 3, SQFalse);
|
|
return 1;
|
|
}
|
|
|
|
static SQInteger SQR_GetPng(HSQUIRRELVM v)
|
|
{
|
|
const SQChar *ImgPath;
|
|
sq_getstring(v, 2, &ImgPath);
|
|
SQInteger Index;
|
|
sq_getinteger(v, 3, &Index);
|
|
Asset_ImagePack::IMG *Info = Asset_ImagePack::GetInstance().GetIMG(ImgPath);
|
|
Asset_ImagePack::ImgInfo PngInfo = Info->lp_lplist[Index];
|
|
|
|
sq_newtable(v);
|
|
struct TableEntry
|
|
{
|
|
const SQChar *key;
|
|
SQInteger value;
|
|
} entries[] = {
|
|
{_SC("Format"), PngInfo.Type},
|
|
{_SC("CompressType"), PngInfo.CmpType},
|
|
{_SC("Width"), PngInfo.Width},
|
|
{_SC("Height"), PngInfo.Height},
|
|
{_SC("XPos"), PngInfo.Xpos},
|
|
{_SC("YPos"), PngInfo.Ypos},
|
|
{_SC("FrameXPos"), PngInfo.FrameXpos},
|
|
{_SC("FrameYPos"), PngInfo.FrameYpos}};
|
|
|
|
for (const auto &entry : entries)
|
|
{
|
|
sq_pushstring(v, entry.key, -1);
|
|
sq_pushinteger(v, entry.value);
|
|
sq_newslot(v, -3, SQFalse);
|
|
}
|
|
|
|
return 1;
|
|
}
|
|
|
|
static void RegisterAsset()
|
|
{
|
|
HSQUIRRELVM v = SquirrelEx::GetInstance().GetSquirrelVM();
|
|
|
|
// 获取Img数据
|
|
RegisterNutApi(_SC("sq_GetImg"), SQR_GetImg, v);
|
|
// 获取Png数据
|
|
RegisterNutApi(_SC("sq_GetPng"), SQR_GetPng, v);
|
|
}
|