refactor: 存档系统应处于渲染层

This commit is contained in:
unanmed 2026-09-16 21:54:12 +08:00
parent 49aacb087a
commit fe595b7983
4 changed files with 0 additions and 44 deletions

View File

@ -1,7 +1,6 @@
import { IDirectionMapper, ITileLocator } from '@motajs/common';
import { IFaceManager, IRoleFaceBinder } from './common';
import { IGameEventStore, IItemStore, IMapStore, ITileStore } from './store';
import { ISaveSystem } from './save';
import { IReplaySystem } from './replay';
export interface IEnemyAttr {
@ -59,8 +58,6 @@ export interface IDataCommon {
readonly faceManager: IFaceManager;
/** 方向组映射器 */
readonly directionMapper: IDirectionMapper;
/** 存档系统 */
readonly saveSystem: ISaveSystem;
/** 录像系统 */
readonly replaySystem: IReplaySystem;
}

View File

@ -15,8 +15,6 @@ import {
FaceDirection,
IHeroAttr,
IEnemyAttr,
ISaveSystem,
SaveSystem,
GameEventStore,
IGameEventStore,
IItemStore,
@ -93,7 +91,6 @@ import {
export class CoreState implements ICoreState {
// Layer 0 公共层,最底层的接口,不会依赖任何其他内容,一般是工具性接口及不需要存档的数据
readonly saveSystem: ISaveSystem;
readonly roleFace: IRoleFaceBinder;
readonly faceManager: IFaceManager;
readonly tileStore: ITileStore<LegacyTileData>;
@ -131,17 +128,6 @@ export class CoreState implements ICoreState {
constructor() {
//#region L0 初始化
// 存档系统
this.saveSystem = new SaveSystem();
// 配置存档系统,一般情况下不建议动,除非你知道你在干什么
this.saveSystem.config({
autosaveLevel: SaveCompression.LowCompression,
commonSaveLevel: SaveCompression.HighCompression,
autosaveTimeTolerance: 50,
saveTimeTolerance: 100,
autosaveStackSize: 20
});
// 朝向
this.roleFace = new RoleFaceBinder();
this.faceManager = new FaceManager();
@ -250,10 +236,6 @@ export class CoreState implements ICoreState {
this.addSaveableContent('@system/maps', this.maps);
this.addSaveableContent('@system/enemy', this.enemyManager);
this.addSaveableContent('@system/replay', this.replaySystem);
// 初始化存档数据库,不要动
loading.once('coreInit', () => {
this.saveSystem.init(`@game/${core.firstData.name}`);
});
// 加载初始化,先使用兼容层实现
loading.once('loaded', () => {

View File

@ -12,7 +12,6 @@ describe('Node CoreState factory', () => {
expect(first.hero).not.toBe(second.hero);
expect(first.hero.attribute).not.toBe(second.hero.attribute);
expect(first.eventStore).not.toBe(second.eventStore);
expect(first.saveSystem).not.toBe(second.saveSystem);
first.hero.getModifiableAttribute().set('hp', 99);
expect(second.hero.attribute.getFinalAttribute('hp')).not.toBe(99);
@ -31,14 +30,4 @@ describe('Node CoreState factory', () => {
savedLayer.fullMap[0] = 99;
expect(layer.getBlock(0, 0)).toBe(7);
});
// 验证 Node 工厂路径不读取浏览器宿主并使用现有独立存档实现
it('constructs through the Node-safe path without browser globals', () => {
expect(() => createCoreState()).not.toThrow();
const state = createCoreState();
expect(state.saveSystem.constructor.name).toBe('SaveSystem');
expect(state.maps).toBeDefined();
expect(state.eventStore).toBeDefined();
});
});

View File

@ -1,19 +1,7 @@
import { describe, expect, it } from 'vitest';
import { createCoreState } from '../src/core';
import { createClosedLoopFixture } from './fixtures/closed-loop';
describe('Node replay tracer', () => {
// 验证 Node 宿主无需浏览器全局即可创建相互独立的现有存档状态
it('creates independent Node-safe CoreState instances', () => {
const first = createCoreState();
const second = createCoreState();
expect(first).not.toBe(second);
expect(first.saveSystem).not.toBe(second.saveSystem);
expect(first.saveSystem.constructor.name).toBe('SaveSystem');
expect(second.saveSystem.constructor.name).toBe('SaveSystem');
});
// 验证 replay 等待真实移动与事件完成后才结束并改变事件层矩阵
it('replays movement, awaits event mutation, and ends normally', async () => {
const fixture = createClosedLoopFixture();