Skip to content

Commit 20da0f7

Browse files
authored
Add static scriptName property to multiple script classes (#7633)
* Add static scriptName property to multiple script classes * Refactor scriptName properties in multiple script classes to camelCase format
1 parent 133a99e commit 20da0f7

File tree

9 files changed

+25
-0
lines changed

9 files changed

+25
-0
lines changed

examples/assets/scripts/misc/rotator.mjs

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { Script } from 'playcanvas';
22

33
class Rotator extends Script {
4+
static scriptName = 'rotator';
5+
46
/**
57
* @attribute
68
*/

scripts/esm/camera-controls.mjs

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ const EPSILON = 0.0001;
3333
const lerpRate = (damping, dt) => 1 - Math.pow(damping, dt * 1000);
3434

3535
class CameraControls extends Script {
36+
static scriptName = 'cameraControls';
37+
3638
/**
3739
* Fired to clamp the position (Vec3).
3840
*

scripts/esm/camera-frame.mjs

+2
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,8 @@ class Dof {
333333
}
334334

335335
class CameraFrame extends Script {
336+
static scriptName = 'cameraFrame';
337+
336338
/**
337339
* @attribute
338340
* @type {Rendering}

scripts/esm/first-person-controller.mjs

+2
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,8 @@ class GamePadInput {
663663
}
664664

665665
class FirstPersonController extends Script {
666+
static scriptName = 'firstPersonController';
667+
666668
/**
667669
* @type {RigidBodyComponent}
668670
* @private

scripts/esm/grid.mjs

+2
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ const fragmentCode = /* glsl */ `
122122
`;
123123

124124
class Grid extends Script {
125+
static scriptName = 'grid';
126+
125127
/**
126128
* @type {number}
127129
*/

scripts/esm/shadow-catcher.mjs

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import {
3030
* app.root.addChild(shadowCatcher);
3131
*/
3232
class ShadowCatcher extends Script {
33+
static scriptName = 'shadowCatcher';
34+
3335
/**
3436
* The scale of the shadow catcher.
3537
* @type {Vec3}

scripts/esm/xr-controllers.mjs

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { Script } from 'playcanvas';
22

33
class XrControllers extends Script {
4+
static scriptName = 'xrControllers';
5+
46
/**
57
* The base URL for fetching the WebXR input profiles.
68
*

scripts/esm/xr-navigation.mjs

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import { Color, Script, Vec3 } from 'playcanvas';
1313
* the controllers.
1414
*/
1515
class XrNavigation extends Script {
16+
static scriptName = 'xrNavigation';
17+
1618
/** @type {Set<XrInputSource>} */
1719
inputSources = new Set();
1820

src/framework/script/script.js

+9
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import { SCRIPT_INITIALIZE, SCRIPT_POST_INITIALIZE } from './constants.js';
2828
* @example
2929
* ```javascript
3030
* class EntityRotator extends Script {
31+
* static scriptName = 'entityRotator';
32+
*
3133
* update(dt) {
3234
* this.entity.rotateLocal(0, 1, 0);
3335
* }
@@ -48,6 +50,7 @@ export class Script extends EventHandler {
4850
* @event
4951
* @example
5052
* export class PlayerController extends Script {
53+
* static scriptName = 'playerController';
5154
* initialize() {
5255
* this.on('enable', () => {
5356
* // Script Instance is now enabled
@@ -63,6 +66,7 @@ export class Script extends EventHandler {
6366
* @event
6467
* @example
6568
* export class PlayerController extends Script {
69+
* static scriptName = 'playerController';
6670
* initialize() {
6771
* this.on('disable', () => {
6872
* // Script Instance is now disabled
@@ -79,6 +83,7 @@ export class Script extends EventHandler {
7983
* @event
8084
* @example
8185
* export class PlayerController extends Script {
86+
* static scriptName = 'playerController';
8287
* initialize() {
8388
* this.on('state', (enabled) => {
8489
* console.log(`Script Instance is now ${enabled ? 'enabled' : 'disabled'}`);
@@ -94,6 +99,7 @@ export class Script extends EventHandler {
9499
* @event
95100
* @example
96101
* export class PlayerController extends Script {
102+
* static scriptName = 'playerController';
97103
* initialize() {
98104
* this.on('destroy', () => {
99105
* // no longer part of the entity
@@ -117,6 +123,7 @@ export class Script extends EventHandler {
117123
* @event
118124
* @example
119125
* export class PlayerController extends Script {
126+
* static scriptName = 'playerController';
120127
* initialize() {
121128
* this.on('attr', (name, newValue, oldValue) => {
122129
* console.log(`Attribute '${name}' changed from '${oldValue}' to '${newValue}'`);
@@ -125,6 +132,7 @@ export class Script extends EventHandler {
125132
* };
126133
* @example
127134
* export class PlayerController extends Script {
135+
* static scriptName = 'playerController';
128136
* initialize() {
129137
* this.on('attr:speed', (newValue, oldValue) => {
130138
* console.log(`Attribute 'speed' changed from '${oldValue}' to '${newValue}'`);
@@ -142,6 +150,7 @@ export class Script extends EventHandler {
142150
* @event
143151
* @example
144152
* export class PlayerController extends Script {
153+
* static scriptName = 'playerController';
145154
* initialize() {
146155
* this.on('error', (err, method) => {
147156
* // caught an exception

0 commit comments

Comments
 (0)