-
Notifications
You must be signed in to change notification settings - Fork 18
/
e-shape-action-value-gesture.ts
100 lines (90 loc) · 3.6 KB
/
e-shape-action-value-gesture.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
* 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 { EShapeActionRuntime } from "./e-shape-action-runtime";
import { EShapeActionRuntimeGestureLayer } from "./e-shape-action-runtime-gesture-layer";
import { EShapeActionRuntimeGestureShape } from "./e-shape-action-runtime-gesture-shape";
import { EShapeActionValueGestureOperationType } from "./e-shape-action-value-gesture-operation-type";
import { EShapeActionValueGestureType } from "./e-shape-action-value-gesture-type";
import { EShapeActionValueMiscType } from "./e-shape-action-value-misc-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 EShapeActionValueGestureSerializedLegacy = [
typeof EShapeActionValueType.MISC,
number,
typeof EShapeActionValueMiscType.GESTURE | typeof EShapeActionValueMiscType.GESTURE_LAYER,
EShapeActionValueGestureOperationType,
number, // Minimum scale
number // Maximum scale
];
export type EShapeActionValueGestureSerializedNew = [
typeof EShapeActionValueType.GESTURE,
number,
EShapeActionValueGestureType,
EShapeActionValueGestureOperationType,
number, // Minimum scale
number // Maximum scale
];
export type EShapeActionValueGestureSerialized =
| EShapeActionValueGestureSerializedLegacy
| EShapeActionValueGestureSerializedNew;
export class EShapeActionValueGesture extends EShapeActionValueSubtyped<EShapeActionValueGestureType> {
readonly operationType: EShapeActionValueGestureOperationType;
readonly scaleMin: number;
readonly scaleMax: number;
constructor(
condition: string = "",
subtype: EShapeActionValueGestureType,
operationType: EShapeActionValueGestureOperationType,
scaleMin: number = 0.05,
scaleMax: number = 20
) {
super(EShapeActionValueType.GESTURE, condition, subtype);
this.operationType = operationType;
this.scaleMin = scaleMin;
this.scaleMax = scaleMax;
}
toRuntime(): EShapeActionRuntime {
switch (this.subtype) {
case EShapeActionValueGestureType.SHAPE:
return new EShapeActionRuntimeGestureShape(this);
case EShapeActionValueGestureType.LAYER:
return new EShapeActionRuntimeGestureLayer(this);
}
}
serialize(manager: EShapeResourceManagerSerialization): number {
const conditionId = manager.addResource(this.condition);
return manager.addResource(
`[${this.type},${conditionId},${this.subtype},${this.operationType},${this.scaleMin},${this.scaleMax}]`
);
}
static deserialize(
serialized: EShapeActionValueGestureSerialized,
manager: EShapeResourceManagerDeserialization
): EShapeActionValueGesture {
const condition = EShapeActionValues.toResource(1, serialized, manager.resources);
const subtype = this.toSubType(serialized);
const operationType = serialized[3];
const scaleMin = serialized[4];
const scaleMax = serialized[5];
return new EShapeActionValueGesture(condition, subtype, operationType, scaleMin, scaleMax);
}
protected static toSubType(
serialized: EShapeActionValueGestureSerialized
): EShapeActionValueGestureType {
if (serialized[0] === EShapeActionValueType.MISC) {
switch (serialized[2]) {
case EShapeActionValueMiscType.GESTURE:
return EShapeActionValueGestureType.SHAPE;
case EShapeActionValueMiscType.GESTURE_LAYER:
return EShapeActionValueGestureType.LAYER;
}
} else {
return serialized[2];
}
}
}