mirror of
https://github.com/motajs/template.git
synced 2026-10-10 06:20:16 +08:00
fix(event): finalize event reference changes
This commit is contained in:
parent
64efcf2555
commit
63d4d37ff3
@ -54,8 +54,6 @@ export class MapLayer
|
|||||||
/** 图层参考基准,用于存档压缩对比 */
|
/** 图层参考基准,用于存档压缩对比 */
|
||||||
private refArray: Uint32Array | null = null;
|
private refArray: Uint32Array | null = null;
|
||||||
|
|
||||||
//#region 点事件操作
|
|
||||||
|
|
||||||
/** 点事件视图,key = y * width + x */
|
/** 点事件视图,key = y * width + x */
|
||||||
private readonly pointEvents: Map<number, ILayerEventView> = new Map();
|
private readonly pointEvents: Map<number, ILayerEventView> = new Map();
|
||||||
|
|
||||||
@ -125,6 +123,8 @@ export class MapLayer
|
|||||||
this.posTileMap.delete(tile);
|
this.posTileMap.delete(tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//#region 点事件操作
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将动态图块的事件同步回当前静态格点
|
* 将动态图块的事件同步回当前静态格点
|
||||||
* @param tile 动态图块
|
* @param tile 动态图块
|
||||||
|
|||||||
@ -94,6 +94,11 @@ export interface IReadonlyEventView {
|
|||||||
*/
|
*/
|
||||||
get(): ReadonlyMap<number, string>;
|
get(): ReadonlyMap<number, string>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前事件的参考基准
|
||||||
|
*/
|
||||||
|
ref(): ReadonlyMap<number, string>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 当前事件是否与参考基准不同
|
* 当前事件是否与参考基准不同
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -25,10 +25,36 @@ export class EventExecutor implements IGameEventExecutor {
|
|||||||
this.reduce = reduce;
|
this.reduce = reduce;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 折叠事件的原始返回值
|
||||||
|
* @param mode 折叠模式
|
||||||
|
* @param results 原始返回值
|
||||||
|
*/
|
||||||
|
private reduceResults(mode: EventReduceMode, results: any[]): any {
|
||||||
|
if (mode === EventReduceMode.OrReduce) {
|
||||||
|
return results.reduce((prev, curr) => {
|
||||||
|
if (typeof curr !== 'boolean') {
|
||||||
|
logger.warn(172, String(curr));
|
||||||
|
}
|
||||||
|
return prev || curr;
|
||||||
|
}, false);
|
||||||
|
} else if (mode === EventReduceMode.AndReduce) {
|
||||||
|
return results.reduce((prev, curr) => {
|
||||||
|
if (typeof curr !== 'boolean') {
|
||||||
|
logger.warn(172, String(curr));
|
||||||
|
}
|
||||||
|
return prev && curr;
|
||||||
|
}, true);
|
||||||
|
} else {
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async execute<R = void>(
|
async execute<R = void>(
|
||||||
events: IGameEventInvocation[],
|
events: IGameEventInvocation[],
|
||||||
param: IBlockEventParam
|
param: IBlockEventParam
|
||||||
): Promise<R> {
|
): Promise<R> {
|
||||||
|
// 事件执行
|
||||||
const results: any[] = [];
|
const results: any[] = [];
|
||||||
for (const invocation of events) {
|
for (const invocation of events) {
|
||||||
const id = invocation.id;
|
const id = invocation.id;
|
||||||
@ -47,13 +73,9 @@ export class EventExecutor implements IGameEventExecutor {
|
|||||||
if (event.trigger !== invocation.env.trigger) continue;
|
if (event.trigger !== invocation.env.trigger) continue;
|
||||||
|
|
||||||
const result = await event.execute(param, invocation.env);
|
const result = await event.execute(param, invocation.env);
|
||||||
if (
|
|
||||||
this.reduce !== EventReduceMode.NoReduce &&
|
|
||||||
typeof result !== 'boolean'
|
|
||||||
) {
|
|
||||||
logger.warn(172, String(result));
|
|
||||||
}
|
|
||||||
results.push(result);
|
results.push(result);
|
||||||
|
|
||||||
|
// 执行模式
|
||||||
if (this.mode === EventExecuteMode.CutIfFalsy && !result) {
|
if (this.mode === EventExecuteMode.CutIfFalsy && !result) {
|
||||||
break;
|
break;
|
||||||
} else if (this.mode === EventExecuteMode.CutIfTruthy && result) {
|
} else if (this.mode === EventExecuteMode.CutIfTruthy && result) {
|
||||||
@ -61,20 +83,6 @@ export class EventExecutor implements IGameEventExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let reduced: any = results;
|
return this.reduceResults(this.reduce, results);
|
||||||
if (this.reduce === EventReduceMode.OrReduce) {
|
|
||||||
reduced = false;
|
|
||||||
for (const result of results) {
|
|
||||||
reduced ||= result;
|
|
||||||
if (reduced) break;
|
|
||||||
}
|
|
||||||
} else if (this.reduce === EventReduceMode.AndReduce) {
|
|
||||||
reduced = true;
|
|
||||||
for (const result of results) {
|
|
||||||
reduced &&= result;
|
|
||||||
if (!reduced) break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return reduced;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user