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

Support Inherited Attributes across files #21

Merged
merged 4 commits into from
Oct 24, 2024
Merged

Conversation

marklundin
Copy link
Member

@marklundin marklundin commented Oct 9, 2024

This PR adds support to extend ESM Scripts in relative modules and inherit their attributes.

This means you can declare a base class in one file, extend it in another and inherit it's attributes.

Fixes #20. Tests included.

// "./rotator.js"
import { Script } from 'playcanvas';

export class Rotator extends Script {
    /**
     * @attribute
     * You can now set the `speed`property dynamically in the editor
     */
    speed = 2;

    update(dt){
        this.entity.rotateLocal(0, this.speed * dt, 0)
    }
}

// "./double-fast-rotator.mjs"
import {Rotator} from './rotator.mjs'

export class DoubleFastRotator extends Rotator {
    update(dt){
        this.entity.rotateLocal(0, this.speed * dt * 2, 0)
    }
}

@marklundin marklundin added the bug Something isn't working label Oct 9, 2024
@marklundin marklundin requested a review from a team October 9, 2024 16:25
@marklundin marklundin self-assigned this Oct 9, 2024
Copy link
Collaborator

@mvaligursky mvaligursky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesomeness.

@marklundin marklundin merged commit 963a3e9 into main Oct 24, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extending Scripts with Attributes
3 participants