-
Notifications
You must be signed in to change notification settings - Fork 18
/
e-shape-action-value-change-text.ts
62 lines (54 loc) · 2.43 KB
/
e-shape-action-value-change-text.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
* Copyright (C) 2019 Toshiba Corporation
* SPDX-License-Identifier: Apache-2.0
*/
import { EShapeResourceManagerDeserialization } from "../e-shape-resource-manager-deserialization";
import { EShapeResourceManagerSerialization } from "../e-shape-resource-manager-serialization";
import { EShapeActionRuntimeChangeTextNumber } from "./e-shape-action-runtime-change-text-number";
import { EShapeActionRuntimeChangeTextText } from "./e-shape-action-runtime-change-text-text";
import { EShapeActionValue } from "./e-shape-action-value";
import { EShapeActionValueChangeTextType } from "./e-shape-action-value-change-text-type";
import { EShapeActionValueSubtyped } from "./e-shape-action-value-subtyped";
import { EShapeActionValueType } from "./e-shape-action-value-type";
import { EShapeActionValues } from "./e-shape-action-values";
export type EShapeActionValueChangeTextSerialized = [
typeof EShapeActionValueType.CHANGE_TEXT,
number,
EShapeActionValueChangeTextType,
number
];
export class EShapeActionValueChangeText extends EShapeActionValueSubtyped<EShapeActionValueChangeTextType> {
readonly value: string;
constructor(subtype: EShapeActionValueChangeTextType, condition: string, value: string) {
super(EShapeActionValueType.CHANGE_TEXT, condition, subtype);
this.value = value;
}
isEquals(value: EShapeActionValue): boolean {
return (
super.isEquals(value) &&
value instanceof EShapeActionValueChangeText &&
this.value === value.value
);
}
toRuntime(): EShapeActionRuntimeChangeTextText | EShapeActionRuntimeChangeTextNumber {
switch (this.subtype) {
case EShapeActionValueChangeTextType.TEXT:
return new EShapeActionRuntimeChangeTextText(this);
case EShapeActionValueChangeTextType.NUMBER:
return new EShapeActionRuntimeChangeTextNumber(this);
}
}
serialize(manager: EShapeResourceManagerSerialization): number {
const conditionId = manager.addResource(this.condition);
const valueId = manager.addResource(this.value);
return manager.addResource(`[${this.type},${conditionId},${this.subtype},${valueId}]`);
}
static deserialize(
serialized: EShapeActionValueChangeTextSerialized,
manager: EShapeResourceManagerDeserialization
): EShapeActionValueChangeText {
const condition = EShapeActionValues.toResource(1, serialized, manager.resources);
const value = EShapeActionValues.toResource(3, serialized, manager.resources);
return new EShapeActionValueChangeText(serialized[2], condition, value);
}
}