Skip to content

Add static scriptName property to multiple script classes #7633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions examples/assets/scripts/misc/rotator.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Script } from 'playcanvas';

class Rotator extends Script {
static scriptName = 'rotator';

/**
* @attribute
*/
Expand Down
2 changes: 2 additions & 0 deletions scripts/esm/camera-controls.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const EPSILON = 0.0001;
const lerpRate = (damping, dt) => 1 - Math.pow(damping, dt * 1000);

class CameraControls extends Script {
static scriptName = 'cameraControls';

/**
* Fired to clamp the position (Vec3).
*
Expand Down
2 changes: 2 additions & 0 deletions scripts/esm/camera-frame.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ class Dof {
}

class CameraFrame extends Script {
static scriptName = 'cameraFrame';

/**
* @attribute
* @type {Rendering}
Expand Down
2 changes: 2 additions & 0 deletions scripts/esm/first-person-controller.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,8 @@ class GamePadInput {
}

class FirstPersonController extends Script {
static scriptName = 'firstPersonController';

/**
* @type {RigidBodyComponent}
* @private
Expand Down
2 changes: 2 additions & 0 deletions scripts/esm/grid.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ const fragmentCode = /* glsl */ `
`;

class Grid extends Script {
static scriptName = 'grid';

/**
* @type {number}
*/
Expand Down
2 changes: 2 additions & 0 deletions scripts/esm/shadow-catcher.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import {
* app.root.addChild(shadowCatcher);
*/
class ShadowCatcher extends Script {
static scriptName = 'shadowCatcher';

/**
* The scale of the shadow catcher.
* @type {Vec3}
Expand Down
2 changes: 2 additions & 0 deletions scripts/esm/xr-controllers.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Script } from 'playcanvas';

class XrControllers extends Script {
static scriptName = 'xrControllers';

/**
* The base URL for fetching the WebXR input profiles.
*
Expand Down
2 changes: 2 additions & 0 deletions scripts/esm/xr-navigation.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { Color, Script, Vec3 } from 'playcanvas';
* the controllers.
*/
class XrNavigation extends Script {
static scriptName = 'xrNavigation';

/** @type {Set<XrInputSource>} */
inputSources = new Set();

Expand Down
9 changes: 9 additions & 0 deletions src/framework/script/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import { SCRIPT_INITIALIZE, SCRIPT_POST_INITIALIZE } from './constants.js';
* @example
* ```javascript
* class EntityRotator extends Script {
* static scriptName = 'entityRotator';
*
* update(dt) {
* this.entity.rotateLocal(0, 1, 0);
* }
Expand All @@ -48,6 +50,7 @@ export class Script extends EventHandler {
* @event
* @example
* export class PlayerController extends Script {
* static scriptName = 'playerController';
* initialize() {
* this.on('enable', () => {
* // Script Instance is now enabled
Expand All @@ -63,6 +66,7 @@ export class Script extends EventHandler {
* @event
* @example
* export class PlayerController extends Script {
* static scriptName = 'playerController';
* initialize() {
* this.on('disable', () => {
* // Script Instance is now disabled
Expand All @@ -79,6 +83,7 @@ export class Script extends EventHandler {
* @event
* @example
* export class PlayerController extends Script {
* static scriptName = 'playerController';
* initialize() {
* this.on('state', (enabled) => {
* console.log(`Script Instance is now ${enabled ? 'enabled' : 'disabled'}`);
Expand All @@ -94,6 +99,7 @@ export class Script extends EventHandler {
* @event
* @example
* export class PlayerController extends Script {
* static scriptName = 'playerController';
* initialize() {
* this.on('destroy', () => {
* // no longer part of the entity
Expand All @@ -117,6 +123,7 @@ export class Script extends EventHandler {
* @event
* @example
* export class PlayerController extends Script {
* static scriptName = 'playerController';
* initialize() {
* this.on('attr', (name, newValue, oldValue) => {
* console.log(`Attribute '${name}' changed from '${oldValue}' to '${newValue}'`);
Expand All @@ -125,6 +132,7 @@ export class Script extends EventHandler {
* };
* @example
* export class PlayerController extends Script {
* static scriptName = 'playerController';
* initialize() {
* this.on('attr:speed', (newValue, oldValue) => {
* console.log(`Attribute 'speed' changed from '${oldValue}' to '${newValue}'`);
Expand All @@ -142,6 +150,7 @@ export class Script extends EventHandler {
* @event
* @example
* export class PlayerController extends Script {
* static scriptName = 'playerController';
* initialize() {
* this.on('error', (err, method) => {
* // caught an exception
Expand Down