mirror of
https://github.com/motajs/template.git
synced 2026-10-17 11:40:16 +08:00
test(08-09): align data-state integration and perf tests to shipped shapes
- dataClosure: local CoreState helper, Record equip.value, ReplayCommandResult/Active commands, natural sandbox step
- enemyCombination: local CoreState helper
- perf: CoreState loadStarter assembly, Record equip.value, addLayer('event')
This commit is contained in:
parent
827e11c7a4
commit
ff9fd77880
@ -1,4 +1,5 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { WebLoadStarter } from '@motajs/loader';
|
||||
import {
|
||||
IEnemyAttr,
|
||||
IReplaySandbox,
|
||||
@ -6,16 +7,26 @@ import {
|
||||
IItemRawData,
|
||||
ItemCategory,
|
||||
ReplaySystem,
|
||||
ReplayCommandResult,
|
||||
ReplayCommandType,
|
||||
SaveCompression,
|
||||
ReplayCode,
|
||||
TileType
|
||||
} from '@user/data-common';
|
||||
import { IEnemy, IReadonlyHeroAttribute } from '@user/data-base';
|
||||
import { IReadonlyEnemyHandler } from '@user/data-system';
|
||||
import { createCoreState, CoreState } from '../src/core';
|
||||
import { CoreState } from '../src/core';
|
||||
import { MainDamageCalculator } from '../src/enemy/calculator';
|
||||
import { createClosedLoopFixture } from './fixtures/closed-loop';
|
||||
|
||||
/** 按 08-08 约定的 CoreState 装配创建一个独立状态实例 */
|
||||
function createCoreState(): CoreState {
|
||||
return new CoreState({
|
||||
loadStarter: new WebLoadStarter(),
|
||||
coreURL: 'placeholder'
|
||||
});
|
||||
}
|
||||
|
||||
/** 供测试读取的稳定指令码顺序 */
|
||||
export const REPLAY_COMMAND_ORDER: readonly ReplayCode[] = [
|
||||
ReplayCode.Up,
|
||||
@ -52,11 +63,6 @@ vi.hoisted(() => {
|
||||
};
|
||||
});
|
||||
|
||||
interface IManualReplaySandbox extends IReplaySandbox {
|
||||
pausing: boolean;
|
||||
playing: boolean;
|
||||
}
|
||||
|
||||
function createEnemy(): IEnemy<IEnemyAttr> {
|
||||
let attrs: IEnemyAttr = {
|
||||
hp: 20,
|
||||
@ -138,8 +144,8 @@ function equipAtkItem(state: CoreState): number {
|
||||
equip: {
|
||||
slots: [0],
|
||||
animate: 'sword',
|
||||
value: new Map(value),
|
||||
percentage: new Map(),
|
||||
value: Object.fromEntries(value),
|
||||
percentage: {},
|
||||
loadEvent: null,
|
||||
unloadEvent: null
|
||||
}
|
||||
@ -281,11 +287,15 @@ describe('DATA-01 closure', () => {
|
||||
|
||||
const replay = new ReplaySystem();
|
||||
let laterExecuted = false;
|
||||
replay.registerCommand(0, { execute: async () => false });
|
||||
replay.registerCommand(0, {
|
||||
type: ReplayCommandType.Active,
|
||||
execute: async () => ReplayCommandResult.Failed
|
||||
});
|
||||
replay.registerCommand(1, {
|
||||
type: ReplayCommandType.Active,
|
||||
execute: async () => {
|
||||
laterExecuted = true;
|
||||
return true;
|
||||
return ReplayCommandResult.Success;
|
||||
}
|
||||
});
|
||||
replay.record(0);
|
||||
@ -293,12 +303,10 @@ describe('DATA-01 closure', () => {
|
||||
const sandbox = replay.createReplaySandbox({
|
||||
route: replay.array,
|
||||
reseter: { reset: () => {} }
|
||||
}) as IManualReplaySandbox;
|
||||
sandbox.pausing = false;
|
||||
sandbox.playing = true;
|
||||
});
|
||||
|
||||
await expect(sandbox.step()).resolves.toBe(false);
|
||||
expect(sandbox.getReplayed()).toBe(1);
|
||||
expect(sandbox.getReplayed()).toBe(2);
|
||||
expect(laterExecuted).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
// 测试顶层伤害组合:单特殊属性 / 单光环基线,以及多特殊属性与系统层光环效果组合
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { FullRange, logger, type ITileLocator } from '@motajs/common';
|
||||
import { WebLoadStarter } from '@motajs/loader';
|
||||
import { type IEnemyAttr, type IHeroAttr } from '@user/data-common';
|
||||
import {
|
||||
Enemy,
|
||||
@ -17,12 +18,20 @@ import {
|
||||
type IEnemySpecialQueryEffect,
|
||||
type IReadonlyEnemyHandler
|
||||
} from '@user/data-system';
|
||||
import { createCoreState, type CoreState } from '../src/core';
|
||||
import { CoreState } from '../src/core';
|
||||
import { MainDamageCalculator } from '../src/enemy/calculator';
|
||||
import { CommonAuraConverter, GuardAuraConverter } from '../src/enemy/aura';
|
||||
import { MainEnemyFinalEffect } from '../src/enemy/final';
|
||||
import { type IHaloValue, type IVampireValue } from '../src/enemy/special';
|
||||
|
||||
/** 按 08-08 约定的 CoreState 装配创建一个独立状态实例 */
|
||||
function createCoreState(): CoreState {
|
||||
return new CoreState({
|
||||
loadStarter: new WebLoadStarter(),
|
||||
coreURL: 'placeholder'
|
||||
});
|
||||
}
|
||||
|
||||
vi.hoisted(() => {
|
||||
Map.prototype.getOrInsert ??= function <K, V>(
|
||||
this: Map<K, V>,
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
// 性能测量:13 张真实地图拼接的单一大图下怪物上下文构建与地图伤害构建耗时,只记录不断言
|
||||
import { afterAll, describe, it, vi } from 'vitest';
|
||||
import { WebLoadStarter } from '@motajs/loader';
|
||||
import {
|
||||
type IEnemyAttr,
|
||||
type IHeroAttr,
|
||||
@ -13,10 +14,18 @@ import {
|
||||
type ISpecial
|
||||
} from '@user/data-base';
|
||||
import { type IDamageSystem, type IMapDamage } from '@user/data-system';
|
||||
import { CoreState, createCoreState } from '../src/core';
|
||||
import { CoreState } from '../src/core';
|
||||
import { type IHaloValue, type IZoneValue } from '../src/enemy/special';
|
||||
import floorDataset from './fixtures/floors.json';
|
||||
|
||||
/** 按 08-08 约定的 CoreState 装配创建一个独立状态实例 */
|
||||
function createCoreState(): CoreState {
|
||||
return new CoreState({
|
||||
loadStarter: new WebLoadStarter(),
|
||||
coreURL: 'placeholder'
|
||||
});
|
||||
}
|
||||
|
||||
vi.hoisted(() => {
|
||||
vi.stubGlobal('main', { replayChecking: true });
|
||||
vi.stubGlobal('location', { origin: 'http://localhost' });
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
// 性能测量:CoreState 整体存读档随件数与压缩档的耗时,只记录不断言
|
||||
import { afterAll, describe, it, vi } from 'vitest';
|
||||
import { WebLoadStarter } from '@motajs/loader';
|
||||
import {
|
||||
type IEnemyAttr,
|
||||
type IHeroAttr,
|
||||
@ -9,7 +10,15 @@ import {
|
||||
TileType
|
||||
} from '@user/data-common';
|
||||
import { Enemy } from '@user/data-base';
|
||||
import { CoreState, createCoreState } from '../src/core';
|
||||
import { CoreState } from '../src/core';
|
||||
|
||||
/** 按 08-08 约定的 CoreState 装配创建一个独立状态实例 */
|
||||
function createCoreState(): CoreState {
|
||||
return new CoreState({
|
||||
loadStarter: new WebLoadStarter(),
|
||||
coreURL: 'placeholder'
|
||||
});
|
||||
}
|
||||
|
||||
vi.hoisted(() => {
|
||||
vi.stubGlobal('main', { replayChecking: true });
|
||||
@ -161,8 +170,8 @@ function createItemRaw(
|
||||
equip: {
|
||||
slots: [0],
|
||||
animate: 'sword',
|
||||
value: new Map(),
|
||||
percentage: new Map(),
|
||||
value: {},
|
||||
percentage: {},
|
||||
loadEvent: null,
|
||||
unloadEvent: null
|
||||
}
|
||||
@ -195,7 +204,7 @@ function registerItem(state: CoreState, item: IItemRawData<IHeroAttr>): void {
|
||||
function createSaveablesFixture(count: number): CoreState {
|
||||
const state = createCoreState();
|
||||
const map = state.maps.createMap('F1', 2, 2);
|
||||
map.addLayer();
|
||||
map.addLayer('event');
|
||||
state.maps.compareWith(
|
||||
new Map([['F1', new Map([[0, new Uint32Array(4)]])]])
|
||||
);
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
// 性能测量:真实 13×13 魔塔地图下 CoreState 存读档耗时,只记录不断言
|
||||
import { afterAll, describe, it, vi } from 'vitest';
|
||||
import { WebLoadStarter } from '@motajs/loader';
|
||||
import {
|
||||
type IEnemyAttr,
|
||||
type IHeroAttr,
|
||||
@ -10,9 +11,17 @@ import {
|
||||
TileType
|
||||
} from '@user/data-common';
|
||||
import { Enemy, ValueModifier } from '@user/data-base';
|
||||
import { CoreState, createCoreState } from '../src/core';
|
||||
import { CoreState } from '../src/core';
|
||||
import floorDataset from './fixtures/floors.json';
|
||||
|
||||
/** 按 08-08 约定的 CoreState 装配创建一个独立状态实例 */
|
||||
function createCoreState(): CoreState {
|
||||
return new CoreState({
|
||||
loadStarter: new WebLoadStarter(),
|
||||
coreURL: 'placeholder'
|
||||
});
|
||||
}
|
||||
|
||||
vi.hoisted(() => {
|
||||
vi.stubGlobal('main', { replayChecking: true });
|
||||
vi.stubGlobal('location', { origin: 'http://localhost' });
|
||||
@ -267,8 +276,8 @@ function createItemRaw(
|
||||
equip: {
|
||||
slots: [...EQUIPPED_SLOTS],
|
||||
animate: 'sword',
|
||||
value: new Map(value),
|
||||
percentage: new Map(),
|
||||
value: Object.fromEntries(value),
|
||||
percentage: {},
|
||||
loadEvent: null,
|
||||
unloadEvent: null
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user