From 0a2e2a7cbad304950adeaf99b0468546ffc4431a Mon Sep 17 00:00:00 2001 From: Rintim Date: Sun, 17 Mar 2024 20:24:32 +0800 Subject: [PATCH] feat: `lib.announce` type hints. --- noname/library/announce/index.d.ts | 8 ++-- noname/library/announce/interface.d.ts | 54 ++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 noname/library/announce/interface.d.ts diff --git a/noname/library/announce/index.d.ts b/noname/library/announce/index.d.ts index 7c41545d0..8e4af684b 100644 --- a/noname/library/announce/index.d.ts +++ b/noname/library/announce/index.d.ts @@ -1,3 +1,5 @@ +import { NonameAnnounceType } from "./interface.d.ts" + export interface IAnnounceSubscriber { subscribe(name: string): void; unsubscribe(name: string): void; @@ -21,7 +23,7 @@ export class Announce { * @param name - 要推送事件的名称 * @param values - 要推送的数据 */ - publish(name: string, values: T): T + publish(name: Name, values: Parameters[0]): Parameters[0] /** * 订阅给定名字的事件,并返回给定的函数 @@ -33,7 +35,7 @@ export class Announce { * @param name - 要订阅事件的名称 * @param method - 事件触发时执行的函数 */ - subscribe(name: string, method: (values: T) => void): (values: T) => void + subscribe(name: Name, method: Type[Name]): Type[Name] /** * 取消指定事件某一个函数的订阅,并返回该函数 @@ -43,7 +45,7 @@ export class Announce { * @param name - 要取消订阅事件的名称 * @param method - 订阅指定事件的函数 */ - unsubscribe(name: string, method: (values: T) => void): (values: T) => void + unsubscribe(name: Name, method: Type[Name]): Type[Name] } export class AnnounceSubscriber implements IAnnounceSubscriber { diff --git a/noname/library/announce/interface.d.ts b/noname/library/announce/interface.d.ts new file mode 100644 index 000000000..329a6be84 --- /dev/null +++ b/noname/library/announce/interface.d.ts @@ -0,0 +1,54 @@ + +export interface NonameAnnounceType { + // Apperaence 外观区域 + // 用于关于无名杀外观方面的通知 + + // Apperaence.Theme 无名杀主题区域 + /** + * 主题正在被切换时通知 + * + * @param values - 主题名称 + */ + "Noname.Apperaence.Theme.onChanging": AnnounceFunction + + /** + * 主题被切换时通知 + * + * @param values - 主题名称 + */ + "Noname.Apperaence.Theme.onChanged": AnnounceFunction + + /** + * 主题被切换时,已经显示完毕后通知 + * + * @param values - 主题名称 + */ + "Noname.Apperaence.Theme.onChangeFinished": AnnounceFunction + + // Game 游戏区域 + // 包含游戏对局下的通知 + + // Game.Event 事件区域 + /** + * 当游戏对局开始时进行通知 + * + * @param values - 空对象 + */ + "Noname.Game.Event.GameStart": AnnounceFunction<{}> + + + // Init 初始化区域 + // 用于关于初始化方面的通知 + + // Init.Extension 扩展初始化区域 + /** + * 当扩展初始化完成时通知 + * + * @param values - 扩展名称 + */ + "Noname.Init.Extension.onLoad": AnnounceFunction + + +} + +export type AnnounceFunction = (values: T) => void