mirror of
https://github.com/motajs/template.git
synced 2026-10-17 03:10:17 +08:00
wip(event): scaffold EventSetBlock class, utils helpers, anon-tokyo workspace dep
- data-state: add @motajs/anon-tokyo workspace dependency - map.ts: new EventSetBlock BuiltInFunction class (reference style) - utils.ts: getPossibleMap/getPossibleLayer helpers (not yet wired) Checkpoint of user-authored in-progress event refactor.
This commit is contained in:
parent
b86a060759
commit
5a05eecad1
@ -3,6 +3,7 @@
|
||||
"dependencies": {
|
||||
"@motajs/types": "workspace:*",
|
||||
"@motajs/common": "workspace:*",
|
||||
"@motajs/anon-tokyo": "workspace:*",
|
||||
"@user/data-common": "workspace:*",
|
||||
"@user/data-base": "workspace:*",
|
||||
"@user/data-system": "workspace:*"
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { BuiltInFunction } from 'anon-tokyo';
|
||||
import { BuiltInFunction } from '@motajs/anon-tokyo';
|
||||
import { IBlockEventEnv } from '@user/data-system';
|
||||
import {
|
||||
EventBuiltinName,
|
||||
@ -10,6 +10,28 @@ import { isNil } from 'lodash-es';
|
||||
import { logger } from '@motajs/common';
|
||||
import { appendMoveSteps, getPossibleLayer } from './hero';
|
||||
|
||||
export class EventSetBlock implements BuiltInFunction<
|
||||
ISetBlockEventParam,
|
||||
IBlockEventEnv
|
||||
> {
|
||||
name: string = 'setBlock';
|
||||
|
||||
func(param: ISetBlockEventParam, env: IBlockEventEnv) {
|
||||
const layer = getPossibleLayer(env);
|
||||
if (!layer) return;
|
||||
|
||||
if (!layer.inMap(param.x, param.y)) return;
|
||||
|
||||
const num = env.state.tileStore.num(param.tile);
|
||||
if (isNil(num)) {
|
||||
logger.warn(1001);
|
||||
return;
|
||||
}
|
||||
|
||||
layer.setBlock(num, param.x, param.y);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 在解析出的目标图层设置静态图块,目标或图块缺失时安全返回
|
||||
*/
|
||||
|
||||
27
packages-user/data-state/src/event/utils.ts
Normal file
27
packages-user/data-state/src/event/utils.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import { IGameMap, IMapLayer } from '@user/data-base';
|
||||
import { IBlockEventEnv } from '@user/data-system';
|
||||
|
||||
/**
|
||||
* 通过环境参量获取可能的地图对象
|
||||
*/
|
||||
export function getPossibleMap(env: IBlockEventEnv): IGameMap | null {
|
||||
if (env.map) return env.map;
|
||||
if (env.layer) return env.layer.map;
|
||||
|
||||
const map = env.state.maps.getMap(env.heroFloor);
|
||||
if (map) return map;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过环境参量获取可能的事件图层
|
||||
*/
|
||||
export function getPossibleLayer(env: IBlockEventEnv): IMapLayer | null {
|
||||
if (env.layer) return env.layer;
|
||||
|
||||
const map = getPossibleMap(env);
|
||||
if (map?.eventLayer) return map.eventLayer;
|
||||
|
||||
return null;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user