Skip to content
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

Add Script alias #6237

Merged
merged 13 commits into from
Apr 15, 2024
3 changes: 3 additions & 0 deletions src/deprecated/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ import { RigidBodyComponentSystem } from '../framework/components/rigid-body/sys
import { basisInitialize } from '../framework/handlers/basis.js';
import { LitShader } from '../scene/shader-lib/programs/lit-shader.js';

// ScriptType alias
export { Script as ScriptType } from '../framework/script/script.js';

// CORE
export const LINEBATCH_WORLD = 0;
export const LINEBATCH_OVERLAY = 1;
Expand Down
20 changes: 15 additions & 5 deletions src/framework/script/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,20 @@ import { ScriptAttributes } from './script-attributes.js';
const funcNameRegex = new RegExp('^\\s*function(?:\\s|\\s*\\/\\*.*\\*\\/\\s*)+([^\\(\\s\\/]*)\\s*');

/**
* Represents the type of a script. It is returned by {@link createScript}. Also referred to as
* Script Type.
* The Script class is a base class that you must extend to receive
* {@link https://developer.playcanvas.com/user-manual/scripting/anatomy/}[various lifecycle updates]
* from the engine.
*
* The type is to be extended using its JavaScript prototype. There is a list of methods that will
* be executed by the engine on instances of this type, such as:
* You can create a Script using either {@link createScript} or by extending the class directly.
*
* ```javascript
* class Rotator extends Script {
* update() {
* this.entity.rotate(0, 0.1, 0);
marklundin marked this conversation as resolved.
Show resolved Hide resolved
* }
* }
* ```
* The following methods are called if they exist on the Script instance:
*
* - `initialize`
* - `postInitialize`
Expand All @@ -30,6 +39,7 @@ const funcNameRegex = new RegExp('^\\s*function(?:\\s|\\s*\\/\\*.*\\*\\/\\s*)+([
* new Script has a `swap` method in its prototype, then it will be executed to perform hot-
* reload at runtime.
*
* @see {@link https://developer.playcanvas.com/user-manual/scripting/anatomy/} for more information.
* @category Script
*/
class Script extends EventHandler {
Expand Down Expand Up @@ -390,4 +400,4 @@ class Script extends EventHandler {
*/
}

export { Script, Script as ScriptType };
export { Script };
Loading