forked from 4ian/GDevelop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRenderedInstance.js
130 lines (110 loc) · 3.05 KB
/
RenderedInstance.js
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// @flow
import * as PIXI from 'pixi.js-legacy';
import PixiResourcesLoader from '../../ObjectsRendering/PixiResourcesLoader';
/**
* RenderedInstance is the base class used for creating 2D renderers of instances,
* which display on the scene editor, using Pixi.js, the instance of an object (see InstancesEditor).
*/
export default class RenderedInstance {
_project: gdProject;
_layout: gdLayout;
_instance: gdInitialInstance;
_associatedObjectConfiguration: gdObjectConfiguration;
_pixiContainer: PIXI.Container;
_pixiResourcesLoader: Class<PixiResourcesLoader>;
_pixiObject: PIXI.DisplayObject;
wasUsed: boolean;
constructor(
project: gdProject,
layout: gdLayout,
instance: gdInitialInstance,
associatedObjectConfiguration: gdObjectConfiguration,
pixiContainer: PIXI.Container,
pixiResourcesLoader: Class<PixiResourcesLoader>
) {
this._pixiObject = null;
this._instance = instance;
this._associatedObjectConfiguration = associatedObjectConfiguration;
this._pixiContainer = pixiContainer;
this._project = project;
this._layout = layout;
this._pixiResourcesLoader = pixiResourcesLoader;
this.wasUsed = true; //Used by InstancesRenderer to track rendered instance that are not used anymore.
}
isRenderedIn3D(): boolean {
return false;
}
/**
* Convert an angle from degrees to radians.
*/
static toRad(angleInDegrees: number) {
return (angleInDegrees / 180) * Math.PI;
}
/**
* Called when the scene editor is rendered.
*/
update() {
//Nothing to do.
}
getPixiObject(): PIXI.DisplayObject | null {
return this._pixiObject;
}
getInstance(): gdInitialInstance {
return this._instance;
}
/**
* Called to notify the instance renderer that its associated instance was removed from
* the scene. The PIXI object should probably be removed from the container: This is what
* the default implementation of the method does.
*/
onRemovedFromScene(): void {
if (this._pixiObject !== null)
this._pixiContainer.removeChild(this._pixiObject);
}
getOriginX(): number {
return 0;
}
getOriginY(): number {
return 0;
}
getCenterX(): number {
return this.getWidth() / 2;
}
getCenterY(): number {
return this.getHeight() / 2;
}
getCustomWidth(): number {
return this._instance.getCustomWidth();
}
getCustomHeight(): number {
return this._instance.getCustomHeight();
}
getWidth(): number {
return this._instance.hasCustomSize()
? this.getCustomWidth()
: this.getDefaultWidth();
}
getHeight(): number {
return this._instance.hasCustomSize()
? this.getCustomHeight()
: this.getDefaultHeight();
}
getDepth(): number {
return 0;
}
/**
* Return the width of the instance when the instance doesn't have a custom size.
*/
getDefaultWidth(): number {
return 32;
}
/**
* Return the height of the instance when the instance doesn't have a custom size.
*/
getDefaultHeight(): number {
return 32;
}
getDefaultDepth(): number {
return 0;
}
}