mirror of
https://github.com/unanmed/HumanBreak.git
synced 2025-10-29 10:22:59 +08:00
feat: 将贴图转换为图集的一部分
This commit is contained in:
parent
f9b6d8271e
commit
4fd2fa168b
@ -3,6 +3,7 @@ import {
|
||||
IRect,
|
||||
ITexture,
|
||||
ITextureAnimater,
|
||||
ITextureComposedData,
|
||||
ITextureRenderable,
|
||||
ITextureSplitter,
|
||||
SizedCanvasImageSource
|
||||
@ -13,6 +14,7 @@ export class Texture<T = unknown, A = unknown> implements ITexture<T, A> {
|
||||
animater: ITextureAnimater<T, A> | null = null;
|
||||
width: number;
|
||||
height: number;
|
||||
isBitmap: boolean = false;
|
||||
|
||||
/** 裁剪矩形的左边框位置 */
|
||||
private cl: number;
|
||||
@ -59,7 +61,18 @@ export class Texture<T = unknown, A = unknown> implements ITexture<T, A> {
|
||||
|
||||
async toBitmap(): Promise<void> {
|
||||
if (this.source instanceof ImageBitmap) return;
|
||||
this.source = await createImageBitmap(this.source);
|
||||
this.source = await createImageBitmap(
|
||||
this.source,
|
||||
this.cl,
|
||||
this.ct,
|
||||
this.width,
|
||||
this.height
|
||||
);
|
||||
this.cl = 0;
|
||||
this.ct = 0;
|
||||
this.cr = this.width;
|
||||
this.cb = this.height;
|
||||
this.isBitmap = true;
|
||||
}
|
||||
|
||||
split<U>(splitter: ITextureSplitter<U>, data: U): Generator<ITexture> {
|
||||
@ -110,6 +123,23 @@ export class Texture<T = unknown, A = unknown> implements ITexture<T, A> {
|
||||
this.animater = null;
|
||||
}
|
||||
|
||||
toAsset(asset: ITextureComposedData): boolean {
|
||||
const rect = asset.assetMap.get(this);
|
||||
if (!rect) return false;
|
||||
if (this.isBitmap && this.source instanceof ImageBitmap) {
|
||||
this.source.close();
|
||||
}
|
||||
this.isBitmap = false;
|
||||
this.source = asset.texture.source;
|
||||
this.cl = rect.x;
|
||||
this.ct = rect.y;
|
||||
this.width = rect.w;
|
||||
this.height = rect.h;
|
||||
this.cr = rect.x + rect.w;
|
||||
this.cb = rect.y + rect.h;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 对贴图的动画执行偏移效果。动画效果可以不来自传入的贴图对象,
|
||||
* 输出结果的图像源会是传入的贴图对象的图像源而非动画效果对应的图像源
|
||||
|
||||
@ -98,6 +98,9 @@ export interface ITexture<T = unknown, A = unknown> {
|
||||
/** 贴图高度 */
|
||||
readonly height: number;
|
||||
|
||||
/** 当前贴图是否是完整 bitmap 图像 */
|
||||
readonly isBitmap: boolean;
|
||||
|
||||
/**
|
||||
* 将此贴图转换为 bitmap 图像,图像源也会转变成 ImageBitmap
|
||||
*/
|
||||
@ -151,6 +154,13 @@ export interface ITexture<T = unknown, A = unknown> {
|
||||
* 释放此贴图的资源,将不能再被使用
|
||||
*/
|
||||
dispose(): void;
|
||||
|
||||
/**
|
||||
* 将贴图的图像源转换为指定图集的图像源,并将范围限定至图集中对应到此贴图的矩形范围。
|
||||
* @param asset 图集信息
|
||||
* @returns 是否转换成功,如果图集信息中不包含当前贴图,那么返回 `false`
|
||||
*/
|
||||
toAsset(asset: ITextureComposedData): boolean;
|
||||
}
|
||||
|
||||
export interface ITextureStore {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user