Adrià Vilanova MartÃnez | ab4c80e | 2024-05-04 19:53:33 +0200 | [diff] [blame] | 1 | import Script from './Script'; |
2 | |||||
3 | export default class ScriptRunner { | ||||
4 | private scripts: Script[] = []; | ||||
5 | |||||
6 | add(...scripts: Script[]) { | ||||
7 | this.scripts.push(...scripts); | ||||
8 | } | ||||
9 | |||||
10 | run() { | ||||
11 | this.scripts.sort((a, b) => { | ||||
12 | if (a.priority < b.priority) return -1; | ||||
13 | if (a.priority > b.priority) return 1; | ||||
14 | return 0; | ||||
15 | }); | ||||
16 | for (const script of this.scripts) { | ||||
17 | script.execute(); | ||||
18 | } | ||||
19 | } | ||||
20 | } |