89 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			C
		
	
	
	
		
		
			
		
	
	
			89 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			C
		
	
	
	
|  | #pragma once
 | ||
|  | #include <switch.h>
 | ||
|  | #include <stdio.h>
 | ||
|  | #include <string.h>
 | ||
|  | #include <dirent.h>
 | ||
|  | #include <SDL.h>
 | ||
|  | #include <map>
 | ||
|  | 
 | ||
|  | #include "Tool/Ifstream_NPK.h"
 | ||
|  | #include <zlib.h>
 | ||
|  | 
 | ||
|  | class Asset_ImagePack | ||
|  | { | ||
|  | public: | ||
|  |     struct NpkInfo | ||
|  |     { | ||
|  |         int Offset; | ||
|  |         int Length; | ||
|  |         std::string Path; | ||
|  |     }; | ||
|  | 
 | ||
|  |     // PNG结构体
 | ||
|  |     struct ImgInfo | ||
|  |     { | ||
|  |         // 图片格式
 | ||
|  |         int Type; | ||
|  |         // 压缩类型
 | ||
|  |         int CmpType; | ||
|  |         // 宽度
 | ||
|  |         int Width; | ||
|  |         // 高度
 | ||
|  |         int Height; | ||
|  |         // 大小
 | ||
|  |         int Size; | ||
|  |         // Xpos
 | ||
|  |         int Xpos; | ||
|  |         // Ypos
 | ||
|  |         int Ypos; | ||
|  |         // Xpos
 | ||
|  |         int XposEx = 0; | ||
|  |         // Ypos
 | ||
|  |         int YposEx = 0; | ||
|  |         // 帧域X
 | ||
|  |         int FrameXpos; | ||
|  |         // 帧域Y
 | ||
|  |         int FrameYpos; | ||
|  |         // 偏移
 | ||
|  |         int Offset; | ||
|  |         // Png位图数据
 | ||
|  |         BYTE *PNGdata; | ||
|  |     }; | ||
|  | 
 | ||
|  |     struct IMG // npk的img的结构体
 | ||
|  |     { | ||
|  |         std::string lpImgName; // img文件的路径
 | ||
|  |         int img_index;         // img文件在npk文件里的序号
 | ||
|  |         unsigned imgOffset; | ||
|  |         unsigned imgSize; | ||
|  |         std::string lpBelongsFile; // 这个img属于哪个npk文件
 | ||
|  |         int png_sum;               // 这个img文件有多少个 图片
 | ||
|  |         ImgInfo *lp_lplist;        // 图片的数组..
 | ||
|  |         Uint32 UseTime = 0; | ||
|  |     }; | ||
|  | 
 | ||
|  | public: | ||
|  |     Asset_ImagePack(const Asset_ImagePack &) = delete; | ||
|  |     Asset_ImagePack &operator=(const Asset_ImagePack &) = delete; | ||
|  |     Asset_ImagePack(Asset_ImagePack &&) = delete; | ||
|  |     Asset_ImagePack &operator=(Asset_ImagePack &&) = delete; | ||
|  |     // 全局访问点
 | ||
|  |     static Asset_ImagePack &GetInstance() | ||
|  |     { | ||
|  |         static Asset_ImagePack instance; // 局部静态变量,保证只初始化一次
 | ||
|  |         return instance; | ||
|  |     } | ||
|  | 
 | ||
|  | public: | ||
|  |     void Init(); | ||
|  |     void ParseColor(BYTE *Tab, int Type, BYTE *SaveByte, int Offset); | ||
|  |     void LoadImgToMem(IMG *p); | ||
|  |     IMG *GetIMG(std::string imgName); | ||
|  | 
 | ||
|  | private: | ||
|  |     Asset_ImagePack(/* args */); | ||
|  |     ~Asset_ImagePack(); | ||
|  | 
 | ||
|  |     std::map<std::string, IMG> map_npk; | ||
|  | }; |