aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/frontend/src/xtext/ModelGenerationService.ts
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/frontend/src/xtext/ModelGenerationService.ts')
-rw-r--r--subprojects/frontend/src/xtext/ModelGenerationService.ts26
1 files changed, 23 insertions, 3 deletions
diff --git a/subprojects/frontend/src/xtext/ModelGenerationService.ts b/subprojects/frontend/src/xtext/ModelGenerationService.ts
index 1e9f837a..29a70623 100644
--- a/subprojects/frontend/src/xtext/ModelGenerationService.ts
+++ b/subprojects/frontend/src/xtext/ModelGenerationService.ts
@@ -4,12 +4,18 @@
4 * SPDX-License-Identifier: EPL-2.0 4 * SPDX-License-Identifier: EPL-2.0
5 */ 5 */
6 6
7import type { Transaction } from '@codemirror/state';
8
7import type EditorStore from '../editor/EditorStore'; 9import type EditorStore from '../editor/EditorStore';
8 10
9import type UpdateService from './UpdateService'; 11import type UpdateService from './UpdateService';
10import { ModelGenerationResult } from './xtextServiceResults'; 12import { ModelGenerationResult } from './xtextServiceResults';
11 13
14const INITIAL_RANDOM_SEED = 1;
15
12export default class ModelGenerationService { 16export default class ModelGenerationService {
17 private nextRandomSeed = INITIAL_RANDOM_SEED;
18
13 constructor( 19 constructor(
14 private readonly store: EditorStore, 20 private readonly store: EditorStore,
15 private readonly updateService: UpdateService, 21 private readonly updateService: UpdateService,
@@ -26,14 +32,24 @@ export default class ModelGenerationService {
26 } 32 }
27 } 33 }
28 34
35 onTransaction(transaction: Transaction): void {
36 if (transaction.docChanged) {
37 this.resetRandomSeed();
38 }
39 }
40
29 onDisconnect(): void { 41 onDisconnect(): void {
30 this.store.modelGenerationCancelled(); 42 this.store.modelGenerationCancelled();
43 this.resetRandomSeed();
31 } 44 }
32 45
33 async start(): Promise<void> { 46 async start(randomSeed?: number): Promise<void> {
34 const result = await this.updateService.startModelGeneration(); 47 const randomSeedOrNext = randomSeed ?? this.nextRandomSeed;
48 this.nextRandomSeed = randomSeedOrNext + 1;
49 const result =
50 await this.updateService.startModelGeneration(randomSeedOrNext);
35 if (!result.cancelled) { 51 if (!result.cancelled) {
36 this.store.addGeneratedModel(result.data.uuid); 52 this.store.addGeneratedModel(result.data.uuid, randomSeedOrNext);
37 } 53 }
38 } 54 }
39 55
@@ -43,4 +59,8 @@ export default class ModelGenerationService {
43 this.store.modelGenerationCancelled(); 59 this.store.modelGenerationCancelled();
44 } 60 }
45 } 61 }
62
63 private resetRandomSeed() {
64 this.nextRandomSeed = INITIAL_RANDOM_SEED;
65 }
46} 66}