| 126 | } |
| 127 | |
| 128 | override async revert(): Promise<void> { |
| 129 | let history = this.engine.history('background') as string[]; |
| 130 | |
| 131 | history.pop(); |
| 132 | |
| 133 | if (history.length === 0) { |
| 134 | history = this.engine.history('scene') as string[]; |
| 135 | history.pop(); |
| 136 | this.engine.global('_scene_history_cleared_by_background', true); |
| 137 | } |
| 138 | |
| 139 | if (history.length > 0) { |
| 140 | const background = this.engine.element().find('[data-ui="background"]'); |
| 141 | const last = history[history.length - 1].replace('show scene', 'show background'); |
| 142 | const action = this.engine.prepareAction(last, { cycle: 'Application' }) as (ActionInstance & { property?: string; value?: string; classes?: string[] }) | null; |
| 143 | |
| 144 | background.style('background-image', 'initial'); |
| 145 | background.style('background-color', 'initial'); |
| 146 | if (action !== null && action.property && action.value) { |
| 147 | background.style(action.property, action.value); |
| 148 | } |
| 149 | |
| 150 | // Use the previous background's classes, not the current one being reverted |
| 151 | const classesToApply = action?.classes ?? []; |
| 152 | for (const newClass of classesToApply) { |
| 153 | background.addClass(newClass); |
| 154 | } |
| 155 | |
| 156 | this.engine.state({ |
| 157 | background: last |
| 158 | }); |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | override async didRevert(): Promise<ActionRevertResult> { |
| 163 | return { advance: true, step: true }; |