Skip to content

Commit

Permalink
Update typings
Browse files Browse the repository at this point in the history
  • Loading branch information
twastvedt committed Oct 10, 2018
1 parent 1123d79 commit 3072b7a
Show file tree
Hide file tree
Showing 13 changed files with 172 additions and 150 deletions.
21 changes: 21 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Monitor TS Errors",
"command": ".\\node_modules\\.bin\\tsc",
"type": "shell",
"args": ["--watch", "--project", "--no-emit", "."],
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
},
"isBackground": true,
"problemMatcher": "$tsc-watch"
}
]
}
21 changes: 15 additions & 6 deletions docs/javascript/bundle-hemisphere.js

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
"scripts": {
"build:ts": "browserify src/scenes/%npm_package_config_curScene%.scene.ts -p [ tsify --noImplicitAny ] -t glslify -o docs/javascript/bundle-%npm_package_config_curScene%.js",
"build:ts-dev": "npm run build:ts -- --debug",
"build-dev": "npm run copy:html && npm run build:ts-dev",
"build": "npm run copy:html && npm run build:ts",
"watch:ts": "rm -f docs/javascript/bundle-%npm_package_config_curScene%.js && watchify src/scenes/%npm_package_config_curScene%.scene.ts -v -p [ tsify --noImplicitAny ] -t glslify -o docs/javascript/bundle-%npm_package_config_curScene%.js --debug --ignore-watch=\"docs/**/**\"",
"serve": "live-server --wait=300 --no-browser docs",
"dev": "parallelshell \"npm run watch:ts\" \"npm run serve\""
Expand Down
14 changes: 8 additions & 6 deletions src/components/ConstantScale.component.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import { Camera } from "../../node_modules/@types/three/index";

AFRAME = require('aframe');

let tempScale = {x: 1, y: 1, z: 1};
let location = new AFRAME.THREE.Vector3();
let cameraLocation = new AFRAME.THREE.Vector3();
let distance = 0;

interface thisOb {
data?: { x: number, y: number, z: number };
interface ConstantScale extends AFrame.Component {
data: { x: number, y: number, z: number };
cameraLocation: THREE.Vector3;
}

export const ConstantScaleComp: AFrame.ComponentDefinition<thisOb> = {
export const ConstantScaleComp: AFrame.ComponentDefinition<ConstantScale> = {
schema: { type: 'vec3' },

init: function() {
this.cameraLocation = this.el.sceneEl.querySelector('#camera').object3D.position;
init: function(this: ConstantScale) {
this.cameraLocation = this.el.sceneEl.querySelector<AFrame.Entity>('#camera').object3D.position;
},

tick: function() {
tick: function(this: ConstantScale) {
location = this.el.object3D.getWorldPosition();
distance = location.distanceTo(this.cameraLocation);

Expand Down
8 changes: 4 additions & 4 deletions src/components/CopyPosition.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ AFRAME = require('aframe');
let parentPos = new AFRAME.THREE.Vector3();
let tempPos = {x: 0, y: 0, z: 0};

interface thisOb {
data?: {
interface CopyPosition extends AFrame.Component {
data: {
parent: AFrame.Entity;
offset: { x: number, y: number, z: number };
}
}

export const CopyPositionComp: AFrame.ComponentDefinition<thisOb> = {
export const CopyPositionComp: AFrame.ComponentDefinition<CopyPosition> = {
schema: {
parent: { type: 'selector' },
offset: { type: 'vec3' }
},

tick: function() {
tick: function(this: CopyPosition) {
parentPos = this.data.parent.object3D.getWorldPosition();

tempPos.x = parentPos.x + this.data.offset.x;
Expand Down
4 changes: 2 additions & 2 deletions src/components/CopyRotation.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ AFRAME = require('aframe');
let parentRot = {x: 0, y: 0, z: 0};
let tempRot = {x: 0, y: 0, z: 0};

interface thisOb extends AFrame.Component {
interface CopyRotation extends AFrame.Component {
data: {
parent: AFrame.Entity;

Expand All @@ -19,7 +19,7 @@ interface thisOb extends AFrame.Component {
}
}

export const CopyRotationComp: AFrame.ComponentDefinition<thisOb> = {
export const CopyRotationComp: AFrame.ComponentDefinition<CopyRotation> = {
schema: {
parent: { type: 'selector' },
offset: { type: 'vec3' },
Expand Down
22 changes: 11 additions & 11 deletions src/components/HDD.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ AFRAME = require('aframe');

let dateFormat: DateFormatStatic = require("dateformat");

import { sunSystemOb, SunSystem } from '../systems/Sun.system';
import { Sun, SunSystem } from '../systems/Sun.system';

interface thisOb {
sunSystem: sunSystemOb;
interface HDD extends AFrame.Component {
sunSystem: Sun;
children: AFrame.Entity[];
dateTime: AFrame.Entity;

setChildrenOpacity: (this: AFrame.Component<thisOb>, opacity: number ) => void;
setChildrenOpacity: (this: this, opacity: number ) => void;
}

let pointerFuse: AFrame.Entity;
Expand All @@ -28,14 +28,14 @@ let fuseScale = AFRAME.anime({
}
});

export const HDDComp: AFrame.ComponentDefinition<thisOb> = {
export const HDDComp: AFrame.ComponentDefinition<HDD> = {
schema: { },

/**
* Creates a new THREE.ShaderMaterial using the two shaders imported above.
*/
init: function() {
this.sunSystem = <any>document.querySelector('a-scene').systems['sun-system'] as sunSystemOb;
this.sunSystem = <any>document.querySelector('a-scene').systems['sun-system'] as Sun;

this.children = [].slice.call(this.el.children);

Expand All @@ -62,7 +62,7 @@ export const HDDComp: AFrame.ComponentDefinition<thisOb> = {

document.querySelector('#pointer-hdd').object3D.visible = true;

that.el.querySelector('#hdd-follow').components['copy-rotation'].pause();
that.el.querySelector<AFrame.Entity>('#hdd-follow').components['copy-rotation'].pause();
}

} else if (evt.target.getAttribute('rotation').x < -55 ) {
Expand All @@ -86,7 +86,7 @@ export const HDDComp: AFrame.ComponentDefinition<thisOb> = {

document.querySelector('#pointer-hdd').object3D.visible = false;

that.el.querySelector('#hdd-follow').components['copy-rotation'].play();
that.el.querySelector<AFrame.Entity>('#hdd-follow').components['copy-rotation'].play();
}
}
});
Expand All @@ -101,14 +101,14 @@ export const HDDComp: AFrame.ComponentDefinition<thisOb> = {
});

// Control speed by clicking on the gauge target mesh.
this.el.querySelector('#hdd-speedTarget').addEventListener('click', (e) => {
this.el.querySelector('#hdd-speedTarget').addEventListener('click', () => {
const rotation = document.querySelector('#camera').components['rotation'].data.y;

const relRot = that.el.querySelector('#hdd-follow').components['rotation'].data.y;
const relRot = that.el.querySelector<AFrame.Entity>('#hdd-follow').components['rotation'].data.y;

const speedFraction = Math.min( Math.max( 0, (-(rotation - relRot) + 90) / 180), 1 );

that.el.querySelector('#hdd-speedMarker').setAttribute( 'rotation', 'z', -(speedFraction * 174.6 + 2.7 - 90) );
that.el.querySelector<AFrame.Entity>('#hdd-speedMarker').setAttribute( 'rotation', 'z', -(speedFraction * 174.6 + 2.7 - 90) );

that.sunSystem.data.speed = Math.max(1, speedFraction * 1000);
});
Expand Down
10 changes: 6 additions & 4 deletions src/components/HemStepsMat.component.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
AFRAME = require('aframe');

import { HemStepsMatSysOb } from '../systems/HemStepsMat.system';
import { HemStepsMatSys } from '../systems/HemStepsMat.system';

interface thisOb {
interface HemStepsMat extends AFrame.Component {
data: {
sun: boolean;
};
applyToMesh: (this: AFrame.Component<thisOb, AFrame.System<HemStepsMatSysOb>>) => void;
system: HemStepsMatSys;

applyToMesh: (this: HemStepsMat) => void;
}

export const HemStepsMatComp: AFrame.ComponentDefinition<thisOb, AFrame.System<HemStepsMatSysOb>> = {
export const HemStepsMatComp: AFrame.ComponentDefinition<HemStepsMat> = {
schema: {
sun: { default: true }
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/MovingPointer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const MovingPointerComp: AFrame.ComponentDefinition = {
targetPos.setFromMatrixPosition( curNear.matrixWorld );

const dist = 0.7 * camPos.distanceTo( targetPos );
this.el.querySelector('#pointer-cursor').object3D.position.setZ( -dist );
this.el.querySelector<AFrame.Entity>('#pointer-cursor').object3D.position.setZ( -dist );

} else if (e.srcElement.id === 'pointer-raycaster-fuse' && (!curFuse || e.detail.els[0].object3D.uuid !== curFuse.uuid)) {
// Moving onto a checkpoint
Expand Down
10 changes: 5 additions & 5 deletions src/components/SunRotation.component.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
AFRAME = require('aframe');

import { sunSystemOb } from '../systems/Sun.system';
import { Sun } from '../systems/Sun.system';

interface thisOb extends AFrame.Component {
sunSystem: sunSystemOb;
interface SunRotation extends AFrame.Component {
sunSystem: Sun;
}

export const SunRotationComp: AFrame.ComponentDefinition<thisOb> = {
export const SunRotationComp: AFrame.ComponentDefinition<SunRotation> = {
schema: { },

/**
* Creates a new THREE.ShaderMaterial using the two shaders imported above.
*/
init: function() {
this.sunSystem = <any>document.querySelector('a-scene').systems['sun-system'] as sunSystemOb;
this.sunSystem = <any>document.querySelector('a-scene').systems['sun-system'] as Sun;

document.querySelector('a-scene').addEventListener('sunTick', (e) => {
this.el.setAttribute( 'rotation', { x: this.sunSystem.sunPos.altitude / Math.PI * 180, y: this.sunSystem.sunPos.azimuth / Math.PI * 180, z: 0 } );
Expand Down
12 changes: 6 additions & 6 deletions src/systems/HemStepsMat.system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ AFRAME = require('aframe');

const glsl = require('glslify');

import { sunSystemOb } from './Sun.system';
import { Sun } from './Sun.system';

const hemStepsVert = glsl.file('../shaders/hemisphere-steps.vert.glsl');
const hemStepsFrag = glsl.file('../shaders/hemisphere-steps.frag.glsl');
Expand All @@ -13,27 +13,27 @@ const vertexColorsFrag = glsl.file('../shaders/vertexColors.frag.glsl');
const lightMapVert = glsl.file('../shaders/lightMap.vert.glsl');
const lightMapFrag = glsl.file('../shaders/lightMap.frag.glsl');

export interface HemStepsMatSysOb {
sunSystem: sunSystemOb;
export interface HemStepsMatSys extends AFrame.System {
sunSystem: Sun;
material: THREE.ShaderMaterial;
sunMaterial: THREE.ShaderMaterial;
lightMapMaterial: THREE.ShaderMaterial;
}

let updateMaterial: ((this: HemStepsMatSysOb) => void) = function() {
let updateMaterial: ((this: HemStepsMatSys) => void) = function() {
// this.material.uniforms.skyLum.value = this.sunSystem.skyLum;
this.sunMaterial.uniforms.skyLum.value = this.sunSystem.skyLum;
this.lightMapMaterial.uniforms.skyLum.value = this.sunSystem.skyLum;

this.sunMaterial.uniforms.sunLux.value = this.sunSystem.sunLux;
}

export const HemStepsMatSys: AFrame.SystemDefinition<HemStepsMatSysOb> = {
export const HemStepsMatSys: AFrame.SystemDefinition<HemStepsMatSys> = {
schema: { },

init: function () {

this.sunSystem = <any>document.querySelector('a-scene').systems['sun-system'] as sunSystemOb;
this.sunSystem = <any>document.querySelector('a-scene').systems['sun-system'] as Sun;

const loader = new AFRAME.THREE.TextureLoader();
const concreteTexture = loader.load( './assets/hemisphere/concrete-19-2048.png' );
Expand Down
22 changes: 11 additions & 11 deletions src/systems/Sun.system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ const SunCalc = require('suncalc');

let tempColor = [0, 0, 0];

export interface sunSystemOb {
export interface Sun extends AFrame.System {
data: {
dateTime: Date;
longitude: Number;
latitude: Number;
speed: Number;
accuracy: Number;
longitude: number;
latitude: number;
speed: number;
accuracy: number;
};
paused: boolean;
scene: AFrame.ANode;
Expand All @@ -22,12 +22,12 @@ export interface sunSystemOb {
skyLum: number;
skyColor: [number, number, number];
sunSky: AFrame.Entity;
throttledTick: (t: number, dt: number) => void;
interpolate: (value: number, list: number[]) => number;
interpolateList: (value: number, list: number[][], dest: number[]) => number[];
throttledTick: (this: this, t: number, dt: number) => void;
interpolate: (this: this, value: number, list: number[]) => number;
interpolateList: (this: this, value: number, list: number[][], dest: number[]) => number[];
}

export const SunSystem: AFrame.SystemDefinition<sunSystemOb> = {
export const SunSystem: AFrame.SystemDefinition<Sun> = {
schema: {
dateTime: {
default: new Date( Date.UTC( 2017, 6, 22, 0, 0, 0, 0 ) ),
Expand All @@ -43,7 +43,7 @@ export const SunSystem: AFrame.SystemDefinition<sunSystemOb> = {
accuracy: { default: 1 }
},

init: function (this: sunSystemOb & AFrame.System) {
init: function () {
this.scene = document.querySelector('a-scene');

this.sunSky = this.scene.querySelector('a-sun-sky');
Expand All @@ -67,7 +67,7 @@ export const SunSystem: AFrame.SystemDefinition<sunSystemOb> = {
/**
* Tick function that will be wrapped to be throttled.
*/
throttledTick: function(this: sunSystemOb & AFrame.System, t: number, dt: number) {
throttledTick: function(t: number, dt: number) {
if (this.paused) {
this.paused = false;
} else {
Expand Down
Loading

0 comments on commit 3072b7a

Please sign in to comment.