diff options
author | Kristóf Marussy <kristof@marussy.com> | 2023-09-14 03:05:28 +0200 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2023-09-14 03:43:26 +0200 |
commit | 13b464db253566290be6a1063ad8e296288d3339 (patch) | |
tree | 29e0a9a346f66974d6c0be0482f511e9becab51c /subprojects/frontend/src/xtext/ModelGenerationService.ts | |
parent | fix(frontend): keep live while model generation (diff) | |
download | refinery-13b464db253566290be6a1063ad8e296288d3339.tar.gz refinery-13b464db253566290be6a1063ad8e296288d3339.tar.zst refinery-13b464db253566290be6a1063ad8e296288d3339.zip |
feat: specify random seed for generation
Diffstat (limited to 'subprojects/frontend/src/xtext/ModelGenerationService.ts')
-rw-r--r-- | subprojects/frontend/src/xtext/ModelGenerationService.ts | 26 |
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 | ||
7 | import type { Transaction } from '@codemirror/state'; | ||
8 | |||
7 | import type EditorStore from '../editor/EditorStore'; | 9 | import type EditorStore from '../editor/EditorStore'; |
8 | 10 | ||
9 | import type UpdateService from './UpdateService'; | 11 | import type UpdateService from './UpdateService'; |
10 | import { ModelGenerationResult } from './xtextServiceResults'; | 12 | import { ModelGenerationResult } from './xtextServiceResults'; |
11 | 13 | ||
14 | const INITIAL_RANDOM_SEED = 1; | ||
15 | |||
12 | export default class ModelGenerationService { | 16 | export 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 | } |