/
ScalableBehavior.ts
116 lines (96 loc) · 2.7 KB
/
ScalableBehavior.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
* GDevelop JS Platform
* Copyright 2013-2023 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
*/
namespace gdjs {
export interface Scalable {
/**
* Change the scale on X and Y axis of the object.
*
* @param newScale The new scale (must be greater than 0).
*/
setScale(newScale: float): void;
/**
* Change the scale on X axis of the object (changing its width).
*
* @param newScale The new scale (must be greater than 0).
*/
setScaleX(newScale: float): void;
/**
* Change the scale on Y axis of the object (changing its height).
*
* @param newScale The new scale (must be greater than 0).
*/
setScaleY(newScale: float): void;
/**
* Get the scale of the object (or the geometric mean of the X and Y scale
* in case they are different).
*
* @return the scale of the object (or the geometric mean of the X and
* Y scale in case they are different).
*/
getScale(): float;
/**
* Get the scale of the object on Y axis.
*
* @return the scale of the object on Y axis
*/
getScaleY(): float;
/**
* Get the scale of the object on X axis.
*
* @return the scale of the object on X axis
*/
getScaleX(): float;
}
/**
* A behavior that forwards the Scalable interface to its object.
*/
export class ScalableBehavior
extends gdjs.RuntimeBehavior
implements Scalable {
private object: gdjs.RuntimeObject & Scalable;
constructor(
instanceContainer: gdjs.RuntimeInstanceContainer,
behaviorData,
owner: gdjs.RuntimeObject & Scalable
) {
super(instanceContainer, behaviorData, owner);
this.object = owner;
}
usesLifecycleFunction(): boolean {
return false;
}
updateFromBehaviorData(oldBehaviorData, newBehaviorData): boolean {
// Nothing to update.
return true;
}
onDeActivate() {}
onDestroy() {}
doStepPreEvents(instanceContainer: gdjs.RuntimeInstanceContainer) {}
doStepPostEvents(instanceContainer: gdjs.RuntimeInstanceContainer) {}
setScale(newScale: float): void {
this.object.setScale(newScale);
}
setScaleX(newScale: float): void {
this.object.setScaleX(newScale);
}
setScaleY(newScale: float): void {
this.object.setScaleY(newScale);
}
getScale(): float {
return this.object.getScale();
}
getScaleY(): float {
return this.object.getScaleY();
}
getScaleX(): float {
return this.object.getScaleX();
}
}
gdjs.registerBehavior(
'ScalableCapability::ScalableBehavior',
gdjs.ScalableBehavior
);
}