DaFuWeng/assets/Tool/NPKImage.ts

122 lines
4.1 KiB
TypeScript
Raw Normal View History

/*
* @Author: WoNiu
* @Date: 2024-03-10 20:00:57
* @LastEditTime: 2024-03-29 12:57:23
* @LastEditors: WoNiu
* @Description:
*/
import { SpriteFrame, Texture2D, v2 } from "cc";
import { ImagePack } from "../GlobalScript/ImagePack/ImagePack";
import { ImgInfo } from "../GlobalScript/GlobalInterface/GlobalInterface";
/** interface2/event/chn_event_2020/200922_dnf_marble/ */
export const NpkImagePath =
"interface2/event/chn_event_2020/200922_dnf_marble/";
2024-03-11 17:37:03 +08:00
export enum NpkImage {
main = NpkImagePath + "00_main.img",
ingame = NpkImagePath + "01_ingame.img",
board = NpkImagePath + "02_board.img",
gauge = NpkImagePath + "03_gauge.img",
character_sd = NpkImagePath + "04_character_sd.img",
monsternotice = NpkImagePath + "05_monsternotice.img",
specialplace = NpkImagePath + "06_specialplace.img",
conditionsofvictory = NpkImagePath + "07_conditionsofvictory.img",
calendar = NpkImagePath + "08_calendar.img",
bankruptcy = NpkImagePath + "bankruptcy.img",
character_loop = NpkImagePath + "character_loop.img",
count_font = NpkImagePath + "count_font.img",
dice_1x1_db = NpkImagePath + "dice_1x1_db.img",
dice_1x2 = NpkImagePath + "dice_1x2.img",
dice_1x3 = NpkImagePath + "dice_1x3.img",
dice_2x2_db = NpkImagePath + "dice_2x2_db.img",
dice_2x3 = NpkImagePath + "dice_2x3.img",
dice_2x4 = NpkImagePath + "dice_2x4.img",
dice_3x3_db = NpkImagePath + "dice_3x3_db.img",
dice_3x4 = NpkImagePath + "dice_3x4.img",
dice_3x5 = NpkImagePath + "dice_3x5.img",
dice_4x4_db = NpkImagePath + "dice_4x4_db.img",
dice_4x5 = NpkImagePath + "dice_4x5.img",
dice_4x6 = NpkImagePath + "dice_4x6.img",
dice_5x5 = NpkImagePath + "dice_5x5.img",
dice_5x6 = NpkImagePath + "dice_5x6.img",
dice_6x6_db = NpkImagePath + "dice_6x6_db.img",
dice_font = NpkImagePath + "dice_font.img",
dungeonbg = NpkImagePath + "dungeonbg.img",
fire_loop = NpkImagePath + "fire_loop.img",
light01 = NpkImagePath + "light01.img",
light02 = NpkImagePath + "light02.img",
loading_loop = NpkImagePath + "loading_loop.img",
luckycoin = NpkImagePath + "luckycoin.img",
luckycoin_bg = NpkImagePath + "luckycoin_bg.img",
point_loop = NpkImagePath + "point_loop.img",
table_back = NpkImagePath + "table_back.img",
table_dodge = NpkImagePath + "table_dodge.img",
table_front = NpkImagePath + "table_front.img",
title_loop = NpkImagePath + "title_loop.img",
win = NpkImagePath + "win.img",
}
interface NpkImageCallback{
/**
* @param {number} frameCount
* @param {Map<number, SpriteFrame>} frameMapMap
*/
(frameCount: number, frameMap: Map<number, SpriteFrame>): void;
}
export class NpkImageTool {
/**
* @description: Npk path路径下的所有
* @param {string} path
* @param {Function} callBack((frameCount, frameMap)number, Map<number, SpriteFrame>
*/
static GetNpkImageAll(path: string, callBack: NpkImageCallback) {
// 精灵帧总数
let frameCount = 0;
// 精灵帧缓存
let frameMap: Map<number, SpriteFrame> = new Map<number, SpriteFrame>();
ImagePack.getInstance().ReadNpkTable(
"sprite/" + path.toLocaleLowerCase(),
(ImgObj: { Png_List: [ImgInfo]; Png_Count: number; }) => {
const Pngs = ImgObj.Png_List;
// 总数量
frameCount = ImgObj.Png_Count;
for (let i = 0; i < Pngs.length; i++) {
const png = Pngs[i];
const spriteFrame = NpkImageTool.initSpriteFrame(png);
frameMap.set(i, spriteFrame);
}
callBack(frameCount, frameMap);
}
);
}
/**
* @description:
* @param {ImgInfo} Png: 动画数据
*/
static initSpriteFrame(Png: ImgInfo): SpriteFrame {
const spriteFrame = new SpriteFrame();
let tex = new Texture2D();
tex.reset({
width: Png.Width,
height: Png.Height,
format: Texture2D.PixelFormat.RGBA8888,
mipmapLevel: 0,
});
tex.uploadData(Png.PNGdata);
// 更新 0 级 Mipmap。
tex.updateImage();
spriteFrame.texture = tex;
spriteFrame.offset = v2(Png.Xpos, -Png.Ypos);
return spriteFrame;
}
}