mirror of
https://github.com/motajs/template.git
synced 2026-10-27 11:00:17 +08:00
fix: 注释与实现错位问题
This commit is contained in:
parent
29c91c10d5
commit
c5b0a255ba
@ -201,7 +201,7 @@ export class ClientCore extends CoreState implements IClientCore {
|
||||
}
|
||||
const dataDeps = this.getDataDependencies(plugin);
|
||||
const clientDeps = this.getClientDependencies(plugin);
|
||||
await plugin.initialize(this, dataDeps, clientDeps);
|
||||
await plugin.afterLoad(this, dataDeps, clientDeps);
|
||||
holder.status = PluginStatus.Loaded;
|
||||
}
|
||||
}
|
||||
|
||||
@ -877,7 +877,7 @@ export interface IPassCheckHandler extends IDataCommonExtended {
|
||||
|
||||
export interface IPassPredicate {
|
||||
/**
|
||||
* 检查在指定楼层中,能否从某一个移动入某一格,若会产生撞击,则此项应返回 `false`
|
||||
* 检查在指定楼层中,能否从某一个移动入某一格,若会产生撞击,则此项应返回 `true`,且 `shouldHit` 也返回 `true`
|
||||
* @param handler 通行性检查信息对象
|
||||
*/
|
||||
canPass(handler: IPassCheckHandler): boolean;
|
||||
|
||||
@ -216,7 +216,7 @@ export interface IObjectMoverHooks<T extends IObjectMovable> extends IHookBase {
|
||||
onSetPos?(x: number, y: number, tile: T, mover: IObjectMover<T>): void;
|
||||
|
||||
/**
|
||||
* 当设置移动对象的朝向时触发,仅 `setFaceDir` 可以触发
|
||||
* 当设置移动对象的朝向方向时触发,仅 `setFaceDir` 可以触发
|
||||
* @param dir 面朝朝向
|
||||
* @param tile 移动器绑定的图块
|
||||
* @param mover 当前移动器
|
||||
@ -224,7 +224,7 @@ export interface IObjectMoverHooks<T extends IObjectMovable> extends IHookBase {
|
||||
onSetFaceDir?(dir: FaceDirection, tile: T, mover: IObjectMover<T>): void;
|
||||
|
||||
/**
|
||||
* 当设置移动对象的朝向时触发,仅 `setMoveDir` 可以触发
|
||||
* 当设置移动对象的移动方向时触发,仅 `setMoveDir` 可以触发
|
||||
* @param dir 移动朝向
|
||||
* @param tile 移动器绑定的图块
|
||||
* @param mover 当前移动器
|
||||
@ -301,7 +301,7 @@ export interface IObjectMover<T extends IObjectMovable> extends IHookable<
|
||||
stepFace(move: FaceDirection, face: FaceDirection, count?: number): this;
|
||||
|
||||
/**
|
||||
* 追加若干个前进步,沿当前移动方向移动
|
||||
* 追加若干个前进步,沿当前朝向方向移动
|
||||
* @param count 追加次数,默认 1
|
||||
*/
|
||||
forward(count?: number): this;
|
||||
|
||||
@ -7,23 +7,38 @@ export class PrefixedJSONCProcessor<T> implements ILoadTaskProcessor<
|
||||
> {
|
||||
constructor(readonly prefixSplit: string) {}
|
||||
|
||||
process(
|
||||
response: string,
|
||||
/**
|
||||
* 反序列化并输出
|
||||
* @param str JSON 字符串内容
|
||||
* @param task 加载任务对象
|
||||
*/
|
||||
private output(
|
||||
str: string,
|
||||
task: ILoadTask<LoadDataType.Text, T>
|
||||
): Promise<T> {
|
||||
const splitted = response.split(this.prefixSplit);
|
||||
if (splitted.length !== 2) {
|
||||
logger.error(66, task.url, this.prefixSplit);
|
||||
return Promise.resolve({} as T);
|
||||
}
|
||||
|
||||
const raw = splitted[1];
|
||||
try {
|
||||
const obj = JSON.parse(raw);
|
||||
const obj = JSON.parse(str);
|
||||
return Promise.resolve(obj as T);
|
||||
} catch (e) {
|
||||
logger.error(67, task.url, String(e));
|
||||
return Promise.resolve({} as T);
|
||||
}
|
||||
}
|
||||
|
||||
process(
|
||||
response: string,
|
||||
task: ILoadTask<LoadDataType.Text, T>
|
||||
): Promise<T> {
|
||||
const splitted = response.split(this.prefixSplit);
|
||||
if (splitted.length === 1) {
|
||||
return this.output(response, task);
|
||||
}
|
||||
|
||||
if (splitted.length !== 2) {
|
||||
logger.error(66, task.url, this.prefixSplit);
|
||||
return Promise.resolve({} as T);
|
||||
}
|
||||
|
||||
return this.output(splitted[1], task);
|
||||
}
|
||||
}
|
||||
|
||||
@ -83,6 +83,7 @@ export class MotaDataLoader
|
||||
|
||||
async *start(): AsyncIterable<number> {
|
||||
if (this.loading || this.dataLoaded) return;
|
||||
this.loading = true;
|
||||
|
||||
// 首先加载核心配置
|
||||
const processor = new PrefixedJSONCProcessor<ICoreStateCoreConfig>(
|
||||
@ -100,14 +101,21 @@ export class MotaDataLoader
|
||||
coreTask.setProcessor(processor);
|
||||
coreTask.setStarter(this.starter);
|
||||
this.manager.addTask(coreTask);
|
||||
coreTask.loaded().then(obj => {
|
||||
if (this.configMap.has(id)) {
|
||||
logger.error(68, id);
|
||||
return;
|
||||
}
|
||||
this.configMap.set(id, obj);
|
||||
});
|
||||
}
|
||||
yield* this.manager.load();
|
||||
|
||||
// 然后加载其他配置文件
|
||||
await Promise.all(
|
||||
this.forEachHook(hook => hook.onCoreConfigLoaded?.(this))
|
||||
);
|
||||
|
||||
// 然后加载其他配置文件
|
||||
for (const [id, url] of this.extraConfigs) {
|
||||
const task = new LoadTask({
|
||||
identifier: id,
|
||||
@ -138,6 +146,7 @@ export class MotaDataLoader
|
||||
|
||||
yield* this.manager.load();
|
||||
|
||||
this.dataLoaded = true;
|
||||
this.loadResolve();
|
||||
}
|
||||
|
||||
|
||||
@ -32,7 +32,7 @@ export interface IMotaDataLoader extends IHookable<IMotaDataLoaderHooks> {
|
||||
|
||||
/**
|
||||
* 添加核心配置文件,仅允许在加载前调用,之后调用无效。
|
||||
* 文件必须放在 `src/content` 下,并填写相对于 `src/content` 文件夹的路径,文件包含如下要求:
|
||||
* 文件必须放在 `src` 下,并填写相对于 `src` 文件夹的路径,文件包含如下要求:
|
||||
*
|
||||
* - 文件必须为 `jsonc` 格式
|
||||
* - 文件的注释必须全部集中在开头
|
||||
@ -45,7 +45,7 @@ export interface IMotaDataLoader extends IHookable<IMotaDataLoaderHooks> {
|
||||
|
||||
/**
|
||||
* 添加额外配置文件,仅允许在 `onCoreConfigLoaded` 中调用或在加载前调用,加载中及加载后后调用无效。
|
||||
* 文件必须放在 `src/content` 下,并填写相对于 `src/content` 文件夹的路径,文件包含如下要求:
|
||||
* 文件必须放在 `src` 下,并填写相对于 `src` 文件夹的路径,文件包含如下要求:
|
||||
*
|
||||
* - 文件必须为 `jsonc` 格式
|
||||
* - 文件的注释必须全部集中在开头
|
||||
|
||||
@ -36,7 +36,7 @@ export interface IBlockEventEnv extends IDataBaseExtended {
|
||||
readonly heroLocator: Readonly<ITileLocator>;
|
||||
/** 事件系统对象 */
|
||||
readonly system: IGameEventSystem;
|
||||
/** 触发事件时玩家的位置 */
|
||||
/** 触发事件时玩家所在的楼层 */
|
||||
readonly heroFloor: string | undefined;
|
||||
/** 触发事件时触发者的位置,有可能不存在 */
|
||||
readonly triggerLocator: Readonly<ITileLocator> | null;
|
||||
|
||||
@ -51,7 +51,7 @@ export class LoadManager
|
||||
async *load(): AsyncIterable<number> {
|
||||
for (const task of this.addedTasks) {
|
||||
if (!task.contentLoaded) {
|
||||
task.start();
|
||||
Array.fromAsync(task.start());
|
||||
}
|
||||
}
|
||||
while (true) {
|
||||
@ -90,7 +90,7 @@ export class LoadManager
|
||||
}
|
||||
|
||||
getTotalByte(): number {
|
||||
return this.loaded;
|
||||
return this.total;
|
||||
}
|
||||
|
||||
getLoadedTasks(): number {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user