mirror of
https://github.com/motajs/template.git
synced 2026-11-19 02:34:30 +08:00
refactor(type): material types.
This commit is contained in:
1 parent
9b51b6a1ce
commit
4e305e392a
19 files changed
+80
-87
No files matched your search
@@ -22,7 +22,7 @@ import {
|
||||
} from '@user/data-base';
|
||||
import { IMotaAudioContext, ISoundPlayer } from '@motajs/audio';
|
||||
import { loading } from '@user/data-base';
|
||||
import { IMaterialManager } from '../material';
|
||||
import { ITextureManager } from '../material';
|
||||
import { ITextureSplitter, Texture, TextureRowSplitter } from '@motajs/render';
|
||||
import { iconNames } from './data';
|
||||
import { IMotaDataLoader } from '@user/data-base';
|
||||
@@ -55,7 +55,7 @@ export class MotaAssetsLoader implements IMotaAssetsLoader {
|
||||
private readonly dataLoader: IMotaDataLoader,
|
||||
private readonly ac: IMotaAudioContext,
|
||||
private readonly sounds: ISoundPlayer<SoundIds>,
|
||||
private readonly materials: IMaterialManager
|
||||
private readonly materials: ITextureManager
|
||||
) {
|
||||
this.imageProcessor = new LoadImageProcessor();
|
||||
this.audioProcessor = new LoadAudioProcessor(ac);
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
IAutotileConnection,
|
||||
IAutotileProcessor,
|
||||
IMaterialFramedData,
|
||||
IMaterialManager
|
||||
ITextureManager
|
||||
} from './types';
|
||||
import { isNil } from 'lodash-es';
|
||||
|
||||
@@ -45,7 +45,7 @@ export class AutotileProcessor implements IAutotileProcessor {
|
||||
/** 自动元件父子关系映射,父元件 -> 子元件列表 */
|
||||
readonly childMap: Map<number, Set<number>> = new Map();
|
||||
|
||||
constructor(readonly manager: IMaterialManager) {}
|
||||
constructor(readonly manager: ITextureManager) {}
|
||||
|
||||
private ensureChildSet(num: number) {
|
||||
const set = this.childMap.get(num);
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
TextureMaxRectsStreamComposer,
|
||||
SizedCanvasImageSource
|
||||
} from '@motajs/render';
|
||||
import { IAssetBuilder, IMaterialGetter, ITrackedAssetData } from './types';
|
||||
import { IAssetBuilder, ITextureGetter, ITrackedAssetData } from './types';
|
||||
import { logger, PrivateListDirtyTracker } from '@motajs/common';
|
||||
|
||||
export class AssetBuilder implements IAssetBuilder {
|
||||
@@ -24,7 +24,7 @@ export class AssetBuilder implements IAssetBuilder {
|
||||
/** 贴图更新的 promise */
|
||||
private pending: Promise<void> = Promise.resolve();
|
||||
|
||||
constructor(readonly materials: IMaterialGetter) {
|
||||
constructor(readonly materials: ITextureGetter) {
|
||||
this.trackedData = new TrackedAssetData(materials, this);
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ class TrackedAssetData
|
||||
private promises: Set<Promise<ImageBitmap>> = new Set();
|
||||
|
||||
constructor(
|
||||
readonly materials: IMaterialGetter,
|
||||
readonly materials: ITextureGetter,
|
||||
readonly builder: AssetBuilder
|
||||
) {
|
||||
super(0);
|
||||
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
import {
|
||||
IBlockIdentifier,
|
||||
IMaterialData,
|
||||
IMaterialManager,
|
||||
ITextureManager,
|
||||
IIndexedIdentifier,
|
||||
IMaterialAssetData,
|
||||
BlockCls,
|
||||
@@ -35,7 +35,7 @@ interface TilesetCache {
|
||||
readonly texture: ITexture;
|
||||
}
|
||||
|
||||
export class MaterialManager implements IMaterialManager {
|
||||
export class MaterialManager implements ITextureManager {
|
||||
readonly tileStore: ITextureStore = new TextureStore();
|
||||
readonly tilesetStore: ITextureStore = new TextureStore();
|
||||
readonly imageStore: ITextureStore = new TextureStore();
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
ITextureStore,
|
||||
SizedCanvasImageSource
|
||||
} from '@motajs/render';
|
||||
import { ICoreStateExtended } from '@user/data-state';
|
||||
|
||||
export const enum BlockCls {
|
||||
Unknown,
|
||||
@@ -81,13 +82,6 @@ export interface IAutotileConnection {
|
||||
readonly center: number;
|
||||
}
|
||||
|
||||
export interface IBigImageReturn {
|
||||
/** 大怪物贴图在 store 中的标识符 */
|
||||
readonly identifier: number;
|
||||
/** 存储大怪物贴图的存储对象 */
|
||||
readonly store: ITextureStore;
|
||||
}
|
||||
|
||||
export interface IMaterialFramedData {
|
||||
/** 贴图对象 */
|
||||
texture: ITexture;
|
||||
@@ -107,9 +101,9 @@ export interface IMaterialAsset
|
||||
readonly data: ITextureComposedData;
|
||||
}
|
||||
|
||||
export interface IAutotileProcessor {
|
||||
export interface IAutotileProcessor extends ICoreStateExtended {
|
||||
/** 该自动元件处理器使用的素材管理器 */
|
||||
readonly manager: IMaterialManager;
|
||||
readonly manager: ITextureManager;
|
||||
|
||||
/**
|
||||
* 设置一个自动元件的特殊连接方式,设置后当前自动元件将会单方面与目标元件连接,
|
||||
@@ -199,7 +193,7 @@ export interface IAutotileProcessor {
|
||||
): Generator<ITextureRenderable, void>;
|
||||
}
|
||||
|
||||
export interface IMaterialGetter {
|
||||
export interface ITextureGetter {
|
||||
/**
|
||||
* 根据图块数字获取图块,可以获取额外素材,会自动将未缓存的额外素材缓存
|
||||
* @param identifier 图块的图块数字
|
||||
@@ -212,25 +206,6 @@ export interface IMaterialGetter {
|
||||
*/
|
||||
getBlockCls(identifier: number): BlockCls;
|
||||
|
||||
/**
|
||||
* 判断一个图块是否包含 `bigImage` 贴图,即是否是大怪物
|
||||
* @param identifier 图块标识符,即图块数字
|
||||
*/
|
||||
isBigImage(identifier: number): boolean;
|
||||
|
||||
/**
|
||||
* 根据图块标识符获取一个图块的 `bigImage` 贴图
|
||||
* @param identifier 图块标识符,即图块数字
|
||||
*/
|
||||
getBigImage(identifier: number): Readonly<IMaterialFramedData> | null;
|
||||
|
||||
/**
|
||||
* 根据图块标识符,首先判断是否是 `bigImage` 贴图,如果是,则返回 `bigImage` 贴图,
|
||||
* 否则返回普通贴图。如果图块不存在,则返回 `null`
|
||||
* @param identifier 图块标识符,即图块数字
|
||||
*/
|
||||
getIfBigImage(identifier: number): Readonly<IMaterialFramedData> | null;
|
||||
|
||||
/**
|
||||
* 根据标识符获取图集信息
|
||||
* @param identifier 图集的标识符
|
||||
@@ -250,7 +225,7 @@ export interface IMaterialGetter {
|
||||
getImage(identifier: number): ITexture | null;
|
||||
}
|
||||
|
||||
export interface IMaterialAliasGetter {
|
||||
export interface ITextureAliasGetter {
|
||||
/**
|
||||
* 根据图块 id 获取图块,可以获取额外素材,会自动将未缓存的额外素材缓存
|
||||
* @param alias 图块 id
|
||||
@@ -280,16 +255,12 @@ export interface IMaterialAliasGetter {
|
||||
* @param alias 图块别名,即图块的 id
|
||||
*/
|
||||
getBlockClsByAlias(alias: string): BlockCls;
|
||||
|
||||
/**
|
||||
* 根据图块别名获取一个图块的 `bigImage` 贴图
|
||||
* @param alias 图块别名,即图块的 id
|
||||
*/
|
||||
getBigImageByAlias(alias: string): Readonly<IMaterialFramedData> | null;
|
||||
}
|
||||
|
||||
export interface IMaterialManager
|
||||
extends IMaterialGetter, IMaterialAliasGetter {
|
||||
export interface ITextureManager
|
||||
extends ITextureGetter, ITextureAliasGetter, ICoreStateExtended {
|
||||
/** 通过加载获取的所有纹理贴图存储,包括图块、普通图片等 */
|
||||
readonly textures: ITextureStore;
|
||||
/** 贴图存储,把 terrains 等内容单独分开存储 */
|
||||
readonly tileStore: ITextureStore;
|
||||
/** tilesets 贴图存储,每个 tileset 是一个贴图对象 */
|
||||
@@ -298,8 +269,6 @@ export interface IMaterialManager
|
||||
readonly imageStore: ITextureStore;
|
||||
/** 图集存储,将常用贴图存入其中 */
|
||||
readonly assetStore: ITextureStore;
|
||||
/** bigImage 存储,存储大怪物数据 */
|
||||
readonly bigImageStore: ITextureStore;
|
||||
|
||||
/** 图集信息存储 */
|
||||
readonly assetDataStore: Iterable<[number, ITextureComposedData]>;
|
||||
@@ -445,18 +414,6 @@ export interface IMaterialManager
|
||||
*/
|
||||
getAliasByIdentifier(identifier: number): string | undefined;
|
||||
|
||||
/**
|
||||
* 设置一个图块的 `bigImage` 贴图,即大怪物贴图,但不止怪物能用
|
||||
* @param identifier 图块标识符,即图块数字
|
||||
* @param image `bigImage` 对应的贴图对象
|
||||
* @param frames `bigImage` 的帧数,即贴图有多少帧
|
||||
*/
|
||||
setBigImage(
|
||||
identifier: number,
|
||||
image: ITexture,
|
||||
frames: number
|
||||
): IBigImageReturn;
|
||||
|
||||
/**
|
||||
* 当前的所有图集中是否包含指定的贴图对象
|
||||
* @param texture 贴图对象
|
||||
@@ -470,7 +427,7 @@ export interface IMaterialManager
|
||||
getTextureAsset(texture: ITexture): number | undefined;
|
||||
}
|
||||
|
||||
export interface IAssetBuilder {
|
||||
export interface IAssetBuilder extends ICoreStateExtended {
|
||||
/**
|
||||
* 将图集打包器输出至指定贴图存储对象,只能输出到一个存储对象中,设置多个仅最后一个有效
|
||||
* @param store 贴图存储对象
|
||||
@@ -502,7 +459,8 @@ export interface IAssetBuilder {
|
||||
close(): void;
|
||||
}
|
||||
|
||||
export interface ITrackedAssetData extends IDirtyTracker<Set<number>> {
|
||||
export interface ITrackedAssetData
|
||||
extends IDirtyTracker<Set<number>>, ICoreStateExtended {
|
||||
/** 图像源列表 */
|
||||
readonly sourceList: Map<number, ImageBitmap>;
|
||||
/**
|
||||
@@ -511,7 +469,7 @@ export interface ITrackedAssetData extends IDirtyTracker<Set<number>> {
|
||||
*/
|
||||
readonly skipRef: Map<SizedCanvasImageSource, number>;
|
||||
/** 贴图数据 */
|
||||
readonly materials: IMaterialGetter;
|
||||
readonly materials: ITextureGetter;
|
||||
|
||||
/**
|
||||
* 取消使用此图集,释放相关资源
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import { ITexture } from '@motajs/render';
|
||||
import { BlockCls } from './types';
|
||||
|
||||
/**
|
||||
* @deprecated 后续理应不需要此接口
|
||||
*/
|
||||
export function getClsByString(cls: Cls): BlockCls {
|
||||
switch (cls) {
|
||||
case 'terrains':
|
||||
@@ -26,6 +29,9 @@ export function getClsByString(cls: Cls): BlockCls {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated 后续应对存储结构进行重构,每个 tile 都可以自定义帧数
|
||||
*/
|
||||
export function getTextureFrame(cls: BlockCls, texture: ITexture) {
|
||||
switch (cls) {
|
||||
case BlockCls.Animates:
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { IBGMPlayer, IMotaAudioContext, ISoundPlayer } from '@motajs/audio';
|
||||
import { ISaveSystem } from './save';
|
||||
import { ICoreState } from '@user/data-state';
|
||||
import { IAutotileProcessor, IMaterialManager } from './material';
|
||||
import { IAutotileProcessor, ITextureManager } from './material';
|
||||
import { IRenderTreeRoot } from '@motajs/render';
|
||||
import { IExcitation, IExcitationDivider } from '@motajs/animate';
|
||||
|
||||
export interface IClientBase extends ICoreState {
|
||||
/** 存档系统 */
|
||||
@@ -14,11 +15,15 @@ export interface IClientBase extends ICoreState {
|
||||
/** BGM 播放器 */
|
||||
readonly bgmPlayer: IBGMPlayer<BgmIds>;
|
||||
/** 素材管理器 */
|
||||
readonly materials: IMaterialManager;
|
||||
readonly materials: ITextureManager;
|
||||
/** 自动元件处理器 */
|
||||
readonly autotile: IAutotileProcessor;
|
||||
/** 渲染画面的根元素 */
|
||||
readonly renderer: IRenderTreeRoot;
|
||||
/** 用于渲染系统的 Raf 激励源 */
|
||||
readonly rafExcitation: IExcitation<number>;
|
||||
/** 用于渲染系统的激励源分频器 */
|
||||
readonly excitationDivider: IExcitationDivider<number>;
|
||||
}
|
||||
|
||||
export interface IClientBaseExtended {
|
||||
|
||||
Reference in new issue
Block a user