| 40 | * @category Objects > Light |
| 41 | */ |
| 42 | export class LightRuntimeObject extends gdjs.RuntimeObject { |
| 43 | _radius: number; |
| 44 | |
| 45 | /** color in format [r, g, b], where each component is in the range [0, 255] */ |
| 46 | _color: integer[]; |
| 47 | _debugMode: boolean; |
| 48 | _texture: string; |
| 49 | _obstaclesManager: gdjs.LightObstaclesManager; |
| 50 | _renderer: gdjs.LightRuntimeObjectRenderer; |
| 51 | _instanceContainer: gdjs.RuntimeScene; |
| 52 | |
| 53 | constructor( |
| 54 | runtimeScene: gdjs.RuntimeScene, |
| 55 | lightObjectData: LightObjectData, |
| 56 | instanceData?: InstanceData |
| 57 | ) { |
| 58 | super(runtimeScene, lightObjectData, instanceData); |
| 59 | this._radius = |
| 60 | lightObjectData.content.radius > 0 ? lightObjectData.content.radius : 1; |
| 61 | this._color = gdjs.rgbOrHexToRGBColor(lightObjectData.content.color); |
| 62 | this._debugMode = lightObjectData.content.debugMode; |
| 63 | this._texture = lightObjectData.content.texture; |
| 64 | this._obstaclesManager = |
| 65 | gdjs.LightObstaclesManager.getManager(runtimeScene); |
| 66 | this._renderer = new gdjs.LightRuntimeObjectRenderer(this, runtimeScene); |
| 67 | this._instanceContainer = runtimeScene; |
| 68 | |
| 69 | // *ALWAYS* call `this.onCreated()` at the very end of your object constructor. |
| 70 | this.onCreated(); |
| 71 | } |
| 72 | |
| 73 | static hexToRGBColor(hex) { |
| 74 | const hexNumber = parseInt(hex.replace('#', ''), 16); |
| 75 | return [(hexNumber >> 16) & 255, (hexNumber >> 8) & 255, hexNumber & 255]; |
| 76 | } |
| 77 | |
| 78 | override getRendererObject() { |
| 79 | return this._renderer.getRendererObject(); |
| 80 | } |
| 81 | |
| 82 | override updateFromObjectData( |
| 83 | oldObjectData: LightObjectData, |
| 84 | newObjectData: LightObjectData |
| 85 | ): boolean { |
| 86 | if (oldObjectData.content.radius !== newObjectData.content.radius) { |
| 87 | this.setRadius(newObjectData.content.radius); |
| 88 | } |
| 89 | if (oldObjectData.content.color !== newObjectData.content.color) { |
| 90 | this._color = gdjs.rgbOrHexToRGBColor(newObjectData.content.color); |
| 91 | this._renderer.updateColor(); |
| 92 | } |
| 93 | if (oldObjectData.content.texture !== newObjectData.content.texture) { |
| 94 | this._texture = newObjectData.content.texture; |
| 95 | this._renderer.updateMesh(); |
| 96 | } |
| 97 | if (oldObjectData.content.debugMode !== newObjectData.content.debugMode) { |
| 98 | this._debugMode = newObjectData.content.debugMode; |
| 99 | this._renderer.updateDebugMode(); |
nothing calls this directly
no outgoing calls
no test coverage detected