DefinitelyTyped/types/aframe/aframe-tests.ts
Trygve Wastvedt 229e28706e A-Frame additions (#25006)
* Add new PropertyTypes

* A-Frame: Expand registerComponent test.

* Add generics to properties, components, and systems.

* Add missing ShaderDefinition interface.

* Add missing event data.

* Add missing throttle and throttleTick functions.

* Update Typescript version

* Use classes for component, system, and geometry

* Add tests for class inheritance.

* Improve defaults, rename ComponentBase -> ComponentDefault

* Saw the sign - many simplifications, return to interfaces
Can't extend a class definition that doesn't exist at runtime, so we need to use interfaces?

* Remove unnecessary generics

* Simplified some references, added a couple tests.

* Moving undefined system from generic to property.

* Revert "Update Typescript version"

This reverts commit 43ef72cef75b0bcee2d04eddcaa0f594290ec46f.
2018-05-08 10:12:01 -07:00

120 lines
2.3 KiB
TypeScript

// Global
const threeCamera = new AFRAME.THREE.Camera();
AFRAME.TWEEN.Easing;
// Entity
const entity = document.createElement('a-entity');
entity.emit('rotate');
entity.emit('collide', { target: entity });
entity.emit('sink', null, false);
const position = entity.getAttribute('position');
position.x;
position.y;
position.z;
entity.setAttribute('material', 'color', 'red');
entity.components['geometry'].data;
type MyEntity = AFrame.Entity<{
camera: THREE.Camera;
material: THREE.Material;
sound: { pause(): void };
}>;
const camera = (document.querySelector('a-entity[camera]') as MyEntity).components.camera;
const material = (document.querySelector('a-entity[material]') as MyEntity).components.material;
(document.querySelector('a-entity[sound]') as MyEntity).components.sound.pause();
entity.getDOMAttribute('geometry').primitive;
entity.setAttribute('light', {
type: 'spot',
distance: 30,
intensity: 2.0
});
entity.addEventListener('child-detached', (event) => {
event.detail;
});
// Components
interface TestComponent extends AFrame.Component {
multiply: (f: number) => number;
data: {
myProperty: any[],
string: string,
num: number
};
system: TestSystem;
}
const Component = AFRAME.registerComponent<TestComponent>('test-component', {
schema: {
myProperty: {
default: [],
parse() { return [true]; },
},
string: { type: 'string' },
num: 0
},
init() {
this.data.num = 0;
},
update() {},
tick() {},
remove() {},
pause() {},
play() {},
multiply(this: TestComponent, f: number) {
// Reference to system because both were registered with the same name.
return f * this.data.num * this.system.data.counter;
}
});
// Scene
const scene = document.querySelector('a-scene');
scene.hasLoaded;
// System
interface TestSystem extends AFrame.System {
data: {
counter: number;
};
}
const testSystem: AFrame.SystemDefinition<TestSystem> = {
schema: {
counter: 0
},
init() {
this.data.counter = 1;
}
};
AFRAME.registerSystem('test-component', testSystem);
// Register Custom Geometry
interface TestGeometry extends AFrame.Geometry {
schema: AFrame.MultiPropertySchema<{
groupIndex: number;
}>;
}
AFRAME.registerGeometry<TestGeometry>('a-test-geometry', {
schema: {
groupIndex: { default: 0 }
},
init(data) {
this.geometry = new THREE.Geometry();
const temp = data.groupIndex;
temp;
}
});