chore(03): checkpoint data layer structure

This commit is contained in:
AncTe committed 2026-09-10 13:30:53 +08:00
1 parent 848f9b6328
commit 7f19773477
16 files changed
+659 -79

No files matched your search

@@ -1,10 +1,5 @@
// 测试事件 trigger 过滤、来源环境、执行顺序、await、cut/reduce 和移动钩子
import { beforeAll, describe, expect, it, vi } from 'vitest';
import {
BlockEventType,
type IBlockEventEnv,
type IGameEventInvocation
} from '@user/data-base';
import {
type IDataCommon,
type IGameEventStore,
@@ -13,8 +8,15 @@ import {
EventTrigger
} from '@user/data-common';
import { type IStateSystem } from '../types';
import { EventExecuteMode, EventReduceMode } from './types';
import {
EventExecuteMode,
EventReduceMode,
BlockEventType,
type IBlockEventEnv,
type IGameEventInvocation
} from './types';
import { AnonTokyoInterpreter } from 'anon-tokyo';
import { IStateBase } from '@user/data-base';
vi.hoisted(() => {
vi.stubGlobal('main', { replayChecking: true });
@@ -215,10 +217,11 @@ function addEvent(
function invocation(id: string, trigger: EventTrigger): IGameEventInvocation {
const env: IBlockEventEnv = {
state: {} as IDataCommon,
state: {} as IStateBase,
type: BlockEventType.CommonEvent,
trigger,
heroLocator: { x: 0, y: 0 },
heroFloor: 'Unknown',
triggerLocator: null,
tile: null,
layer: null,
@@ -1,12 +1,14 @@
import { logger } from '@motajs/common';
import { IGameEventStore } from '@user/data-common';
import { AnonTokyoInterpreter } from 'anon-tokyo';
import {
EventExecuteMode,
EventReduceMode,
IGameEventExecutor,
IBlockEventEnv,
IBlockEventParam,
IGameEventInvocation
} from '@user/data-base';
import { IGameEventStore } from '@user/data-common';
import { AnonTokyoInterpreter } from 'anon-tokyo';
import { EventExecuteMode, EventReduceMode, IGameEventExecutor } from './types';
} from './types';
export class EventExecutor implements IGameEventExecutor {
mode: EventExecuteMode = EventExecuteMode.Normal;
+62 -4
View File
@@ -1,12 +1,70 @@
import { ITileLocator } from '@motajs/common';
import {
IBlockEventEnv,
IBlockEventParam,
IDataBaseExtended,
IGameEventInvocation
IGameMap,
IMapLayer,
IReadonlyTileBase
} from '@user/data-base';
import { IGameEventStore } from '@user/data-common';
import {
EventTrigger,
IGameEvent,
IGameEventStore,
IReadonlyGameEvent
} from '@user/data-common';
import { AnonTokyoInterpreter } from 'anon-tokyo';
export const enum BlockEventType {
/** 普通事件类型,一般是手动触发的 */
CommonEvent,
/** 点事件类型 */
PointEvent,
/** 图块事件类型 */
TileEvent
}
export interface IBlockEventParam {
/** 自定义参数 */
readonly custom: Record<string, any>;
}
export interface IBlockEventEnv extends IDataBaseExtended {
/** 事件类型 */
readonly type: BlockEventType;
/** 本次事件的触发器类型 */
readonly trigger: EventTrigger;
/** 触发事件时玩家的位置 */
readonly heroLocator: Readonly<ITileLocator>;
/** 触发事件时玩家的位置 */
readonly heroFloor: string;
/** 触发事件时触发者的位置,有可能不存在 */
readonly triggerLocator: Readonly<ITileLocator> | null;
/** 触发事件的图块,有可能不存在 */
readonly tile: IReadonlyTileBase | null;
/** 触发事件的图层,有可能不存在 */
readonly layer: IMapLayer | null;
/** 触发事件的地图,有可能不存在 */
readonly map: IGameMap | null;
}
export interface IGameEventInvocation {
/** 事件在 `IGameEventStore` 中的 id */
readonly id: string;
/** 此次调用对应的真实来源环境 */
readonly env: IBlockEventEnv;
}
export interface IReadonlyBlockEvent<R = void> extends IReadonlyGameEvent<
IBlockEventParam,
IBlockEventEnv,
R
> {}
export interface IBlockEvent<R = void> extends IGameEvent<
IBlockEventParam,
IBlockEventEnv,
R
> {}
export const enum EventExecuteMode {
/** 正常顺序执行,执行完前一个后执行后一个 */
Normal,