| 125 | * Default runtime mode service implementation |
| 126 | */ |
| 127 | export class RuntimeModeService implements IRuntimeMode { |
| 128 | private _isEditor: boolean; |
| 129 | private _isPlaying: boolean; |
| 130 | private _isPreview: boolean; |
| 131 | private _callbacks: Set<ModeChangeCallback> = new Set(); |
| 132 | |
| 133 | /** |
| 134 | * 创建运行时模式服务 |
| 135 | * Create runtime mode service |
| 136 | * |
| 137 | * @param config 初始配置 |
| 138 | */ |
| 139 | constructor(config: RuntimeModeConfig = {}) { |
| 140 | this._isEditor = config.isEditor ?? false; |
| 141 | this._isPlaying = config.isPlaying ?? false; |
| 142 | this._isPreview = config.isPreview ?? false; |
| 143 | } |
| 144 | |
| 145 | // ========== IRuntimeMode 实现 ========== |
| 146 | |
| 147 | get isEditor(): boolean { |
| 148 | return this._isEditor; |
| 149 | } |
| 150 | |
| 151 | get isPlaying(): boolean { |
| 152 | return this._isPlaying; |
| 153 | } |
| 154 | |
| 155 | get isPreview(): boolean { |
| 156 | return this._isPreview; |
| 157 | } |
| 158 | |
| 159 | get isStandalone(): boolean { |
| 160 | return !this._isEditor; |
| 161 | } |
| 162 | |
| 163 | onModeChanged(callback: ModeChangeCallback): () => void { |
| 164 | this._callbacks.add(callback); |
| 165 | return () => { |
| 166 | this._callbacks.delete(callback); |
| 167 | }; |
| 168 | } |
| 169 | |
| 170 | // ========== 设置方法(供运行时内部使用)========== |
| 171 | |
| 172 | /** |
| 173 | * 设置编辑器模式 |
| 174 | * Set editor mode |
| 175 | * |
| 176 | * @internal |
| 177 | */ |
| 178 | setEditorMode(isEditor: boolean): void { |
| 179 | if (this._isEditor !== isEditor) { |
| 180 | this._isEditor = isEditor; |
| 181 | this._notifyChange(); |
| 182 | } |
| 183 | } |
| 184 |
nothing calls this directly
no test coverage detected