Mod archive model

This commit is contained in:
MrKBear 2022-04-13 18:27:44 +08:00
parent 14037ecc93
commit fca467a427
4 changed files with 26 additions and 9 deletions

View File

@ -1,6 +1,6 @@
import { Component, ReactNode } from "react";
import { Icon } from '@fluentui/react/lib/Icon';
import { useStatus, IMixinStatusProps } from "@Context/Status";
import { useStatusWithEvent, IMixinStatusProps } from "@Context/Status";
import { useSetting, IMixinSettingProps } from "@Context/Setting";
import { Theme, BackgroundLevel, FontLevel } from "@Component/Theme/Theme";
import { LocalizationTooltipHost } from "@Component/Localization/LocalizationTooltipHost";
@ -20,7 +20,7 @@ interface HeaderBarState {
*
*/
@useSetting
@useStatus
@useStatusWithEvent("fileChange")
class HeaderBar extends Component<
IHeaderBarProps & IMixinStatusProps & IMixinSettingProps,
HeaderBarState
@ -63,7 +63,6 @@ class HeaderBar extends Component<
setting.on("language", this.changeListener);
}
if (status) {
status.archive.on("save", this.changeListener);
status.on("physicsLoop", this.physicsFpsCalc);
status.on("renderLoop", this.renderFpsCalc);
}
@ -75,7 +74,6 @@ class HeaderBar extends Component<
setting.off("language", this.changeListener);
}
if (status) {
status.archive.off("save", this.changeListener);
status.off("physicsLoop", this.physicsFpsCalc);
status.off("renderLoop", this.renderFpsCalc);
}

View File

@ -30,6 +30,7 @@ function randomColor(unNormal: boolean = false) {
}
interface IStatusEvent {
fileChange: void;
renderLoop: number;
physicsLoop: number;
mouseModChange: void;
@ -148,6 +149,9 @@ class Status extends Emitter<IStatusEvent> {
this.on("groupLabelChange", updateBehaviorParameter);
this.on("rangeLabelChange", updateBehaviorParameter);
this.on("behaviorAttrChange", updateBehaviorParameter);
// 映射文件状态改变事件
this.archive.on("fileChange", () => this.emit("fileChange"));
}
public bindRenderer(renderer: AbstractRenderer) {

View File

@ -1,8 +1,8 @@
import { Emitter, EventType } from "@Model/Emitter";
import { Model } from "./Model";
interface IArchiveEvent {
save: Archive;
load: Archive;
fileChange: Archive;
}
class Archive<
@ -34,13 +34,28 @@ class Archive<
*
*
*/
public save() {};
public save(model: Model): string {
let fileData: Record<string, any> = {};
// 保存 Next ID
fileData.idIndex = model.idIndex;
// 保存对象
fileData.objects = [];
// 记录
model.objectPool.map((object) => {
})
return JSON.stringify(model);
}
/**
*
* return Model
*/
public load() {};
public load(model: Model, data: string) {};
}
export { Archive };

View File

@ -33,7 +33,7 @@ class Model extends Emitter<ModelEvent> {
/**
* ID
*/
private idIndex: number = 1;
public idIndex: number = 1;
public nextId(label: string = "U"): string {
return `${label}-${this.idIndex ++}`;
}