Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

feat: support multiple output handlers in OutputService

esenginec7984de2f5cb
diff --git a/editor/src/services/OutputService.ts b/editor/src/services/OutputService.ts
index 372f789f2..07ab0fd50 100644
--- a/editor/src/services/OutputService.ts
+++ b/editor/src/services/OutputService.ts
@@ -5,19 +5,21 @@ export type OutputHandler = (text: string, type: OutputType) => void;
export class OutputService {
private mainWindowBridge_: MainWindowBridge | null = null;
- private outputHandler_: OutputHandler | null = null;
+ private handlers_ = new Set<OutputHandler>();
setMainWindowBridge(bridge: MainWindowBridge | null): void {
this.mainWindowBridge_ = bridge;
}
registerOutputHandler(handler: OutputHandler): () => void {
- this.outputHandler_ = handler;
- return () => { this.outputHandler_ = null; };
+ this.handlers_.add(handler);
+ return () => { this.handlers_.delete(handler); };
}
appendOutput(text: string, type: OutputType): void {
- this.outputHandler_?.(text, type);
+ for (const handler of this.handlers_) {
+ handler(text, type);
+ }
this.mainWindowBridge_?.broadcastOutput(text, type);
}