mirror of
https://github.com/motajs/template.git
synced 2026-11-17 01:24:30 +08:00
refactor: 删除 data-state 中的 legacy 文件夹
This commit is contained in:
1 parent
5f97352f94
commit
e9e9939bd8
21 files changed
+23
-1374
No files matched your search
@@ -1,18 +1,9 @@
|
||||
import { logger } from '@motajs/common';
|
||||
import {
|
||||
IItemLegacyConverter,
|
||||
IItemRawData,
|
||||
IItemStore,
|
||||
ItemCategory
|
||||
} from './types';
|
||||
import { IItemRawData, IItemStore, ItemCategory } from './types';
|
||||
|
||||
export class ItemStore<THero, TLegacy> implements IItemStore<THero, TLegacy> {
|
||||
export class ItemStore<THero> implements IItemStore<THero> {
|
||||
/** 以道具图块数字为键的原始道具定义表 */
|
||||
private readonly dataMap: Map<number, IItemRawData<THero>> = new Map();
|
||||
|
||||
/** 当前挂载的旧样板道具转换器 */
|
||||
private converter: IItemLegacyConverter<THero, TLegacy> | null = null;
|
||||
|
||||
getData(num: number): IItemRawData<THero> | null {
|
||||
return this.dataMap.get(num) ?? null;
|
||||
}
|
||||
@@ -24,21 +15,4 @@ export class ItemStore<THero, TLegacy> implements IItemStore<THero, TLegacy> {
|
||||
addItem(data: IItemRawData<THero>): void {
|
||||
this.dataMap.set(data.num, data);
|
||||
}
|
||||
|
||||
attachLegacyConverter(
|
||||
converter: IItemLegacyConverter<THero, TLegacy>
|
||||
): void {
|
||||
this.converter = converter;
|
||||
}
|
||||
|
||||
fromLegacy(num: number, legacy: TLegacy): IItemRawData<THero> {
|
||||
const converter = this.converter;
|
||||
if (!converter) {
|
||||
logger.error(57);
|
||||
throw new Error('Expected a item legacy converter.');
|
||||
}
|
||||
const data = converter.fromLegacy(num, legacy);
|
||||
this.addItem(data);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,8 @@
|
||||
import { isNil } from 'lodash-es';
|
||||
import { logger } from '@motajs/common';
|
||||
import {
|
||||
ITileLegacyConverter,
|
||||
ITileRawData,
|
||||
ITileStore,
|
||||
TileType
|
||||
} from './types';
|
||||
import { ITileRawData, ITileStore, TileType } from './types';
|
||||
|
||||
export class TileStore<TLegacy = unknown> implements ITileStore<TLegacy> {
|
||||
export class TileStore implements ITileStore {
|
||||
/** 以图块数字为键的原始图块定义表 */
|
||||
private readonly dataMap: Map<number, ITileRawData> = new Map();
|
||||
|
||||
@@ -20,9 +15,6 @@ export class TileStore<TLegacy = unknown> implements ITileStore<TLegacy> {
|
||||
/** 由图块数字保存的默认事件映射 */
|
||||
private readonly eventMap: Map<number, Map<number, string>> = new Map();
|
||||
|
||||
/** 当前挂载的旧样板图块转换器 */
|
||||
private legacyConverter: ITileLegacyConverter<TLegacy> | null = null;
|
||||
|
||||
getData(num: number): ITileRawData | null {
|
||||
return this.dataMap.get(num) ?? null;
|
||||
}
|
||||
@@ -83,21 +75,6 @@ export class TileStore<TLegacy = unknown> implements ITileStore<TLegacy> {
|
||||
}
|
||||
}
|
||||
|
||||
attachLegacyConverter(converter: ITileLegacyConverter<TLegacy>): void {
|
||||
this.legacyConverter = converter;
|
||||
}
|
||||
|
||||
fromLegacy(num: number, legacy: TLegacy): ITileRawData {
|
||||
const converter = this.legacyConverter;
|
||||
if (!converter) {
|
||||
logger.error(56);
|
||||
throw new Error('Expected a tile legacy converter.');
|
||||
}
|
||||
const data = converter.fromLegacy(num, legacy);
|
||||
this.addTile(data);
|
||||
return data;
|
||||
}
|
||||
|
||||
/** 删除一组旧的图块定义及其双向索引 */
|
||||
private deleteBy(num: number, id: string): void {
|
||||
this.dataMap.delete(num);
|
||||
|
||||
@@ -62,16 +62,7 @@ export interface ITileRawData {
|
||||
readonly eventPass: boolean;
|
||||
}
|
||||
|
||||
export interface ITileLegacyConverter<TLegacy> {
|
||||
/**
|
||||
* 将旧样板图块定义转换为新的图块原始数据
|
||||
* @param num 图块数字
|
||||
* @param legacy 旧样板图块定义
|
||||
*/
|
||||
fromLegacy(num: number, legacy: TLegacy): ITileRawData;
|
||||
}
|
||||
|
||||
export interface ITileStore<TLegacy = unknown> {
|
||||
export interface ITileStore {
|
||||
/**
|
||||
* 获取指定图块数字对应的完整原始定义
|
||||
* @param num 图块数字
|
||||
@@ -119,19 +110,6 @@ export interface ITileStore<TLegacy = unknown> {
|
||||
* @param token 图块数字或 id
|
||||
*/
|
||||
id(token: number | string): string | undefined;
|
||||
|
||||
/**
|
||||
* 挂载一个旧样板转换器
|
||||
* @param converter 旧样板转换器
|
||||
*/
|
||||
attachLegacyConverter(converter: ITileLegacyConverter<TLegacy>): void;
|
||||
|
||||
/**
|
||||
* 使用当前转换器转换并写入一个旧样板图块定义
|
||||
* @param num 图块数字
|
||||
* @param legacy 旧样板图块定义
|
||||
*/
|
||||
fromLegacy(num: number, legacy: TLegacy): ITileRawData;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
@@ -208,16 +186,7 @@ export interface IItemRawData<THero> {
|
||||
readonly equip: IItemEquipData<THero>;
|
||||
}
|
||||
|
||||
export interface IItemLegacyConverter<THero, TLegacy> {
|
||||
/**
|
||||
* 将旧样板道具定义转换为新的道具原始数据
|
||||
* @param num 道具图块数字
|
||||
* @param legacy 旧样板道具定义
|
||||
*/
|
||||
fromLegacy(num: number, legacy: TLegacy): IItemRawData<THero>;
|
||||
}
|
||||
|
||||
export interface IItemStore<THero, TLegacy> {
|
||||
export interface IItemStore<THero> {
|
||||
/**
|
||||
* 获取指定图块数字对应的道具原始数据
|
||||
* @param num 道具图块数字
|
||||
@@ -235,21 +204,6 @@ export interface IItemStore<THero, TLegacy> {
|
||||
* @param data 道具原始数据
|
||||
*/
|
||||
addItem(data: IItemRawData<THero>): void;
|
||||
|
||||
/**
|
||||
* 挂载一个旧样板转换器
|
||||
* @param converter 旧样板转换器
|
||||
*/
|
||||
attachLegacyConverter(
|
||||
converter: IItemLegacyConverter<THero, TLegacy>
|
||||
): void;
|
||||
|
||||
/**
|
||||
* 使用当前转换器转换并写入一个旧样板道具定义
|
||||
* @param num 道具图块数字
|
||||
* @param legacy 旧样板道具定义
|
||||
*/
|
||||
fromLegacy(num: number, legacy: TLegacy): IItemRawData<THero>;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
@@ -45,9 +45,9 @@ export interface IHeroAttr {
|
||||
|
||||
export interface IDataCommon {
|
||||
/** 图块定义存储 */
|
||||
readonly tileStore: ITileStore<MapDataOf<keyof NumberToId>>;
|
||||
readonly tileStore: ITileStore;
|
||||
/** 道具定义存储 */
|
||||
readonly itemStore: IItemStore<IHeroAttr, Item<AllIdsOf<'items'>>>;
|
||||
readonly itemStore: IItemStore<IHeroAttr>;
|
||||
/** 地图定义存储 */
|
||||
readonly mapStore: IMapStore;
|
||||
/** 游戏事件存储 */
|
||||
|
||||
Reference in new issue
Block a user