From a2ea4e5ef5233c7373ceeaaccc3d8df72dc6359e Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 8 Jan 2016 09:00:07 +0100 Subject: Be explicit about return types, fix a few visibilities --- src/control/MapContext.ts | 19 +++++++++---------- src/model/EntityPosition.ts | 2 +- src/view/InputHandler.ts | 4 ++-- src/view/MapView.ts | 10 +++++----- 4 files changed, 17 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/control/MapContext.ts b/src/control/MapContext.ts index 73b3c4d..1660ad4 100644 --- a/src/control/MapContext.ts +++ b/src/control/MapContext.ts @@ -13,13 +13,12 @@ import MapView from '../view/MapView'; export default class MapContext { - view: MapView; + private view: MapView; - entities: EntityPosition[] = []; - playerEntity: EntityPosition; + private entities: EntityPosition[] = []; + private playerEntity: EntityPosition; - - collision: number[][]; + private collision: number[][]; constructor(private map: MapData, private inputHandler: InputHandler) { @@ -63,12 +62,12 @@ export default class MapContext { return p.x >= 0 && p.x < this.map.width && p.y >= 0 && p.y < this.map.height; } - private incCollision(p: Position) { + private incCollision(p: Position): void { if (this.inMap(p)) this.collision[p.x][p.y]++; } - private decCollision(p: Position) { + private decCollision(p: Position): void { if (this.inMap(p)) this.collision[p.x][p.y]--; } @@ -77,19 +76,19 @@ export default class MapContext { return (!this.inMap(p)) || (this.collision[p.x][p.y] > 0); } - private addEntity(entity: EntityPosition) { + private addEntity(entity: EntityPosition): void { this.entities.push(entity); this.incCollision(entity.position); } - private addTransition(entity: EntityPosition, dest: Position, start: number, dur: number) { + private addTransition(entity: EntityPosition, dest: Position, start: number, dur: number): void { entity.transition = new Transition(start, start+dur, entity.position, dest); this.incCollision(dest); } - private finishTransition(entity: EntityPosition) { + private finishTransition(entity: EntityPosition): void { this.decCollision(entity.position); entity.position = entity.transition.dest; diff --git a/src/model/EntityPosition.ts b/src/model/EntityPosition.ts index 28b3837..19bcad5 100644 --- a/src/model/EntityPosition.ts +++ b/src/model/EntityPosition.ts @@ -8,7 +8,7 @@ import Transition from './Transition'; export default class EntityPosition { - public transition: Transition = null; + transition: Transition = null; constructor(public entity: Entity, public position: Position, public direction: Direction) {} } diff --git a/src/view/InputHandler.ts b/src/view/InputHandler.ts index dcfd85d..86d4ec6 100644 --- a/src/view/InputHandler.ts +++ b/src/view/InputHandler.ts @@ -7,9 +7,9 @@ import Direction from '../model/Direction'; class InputHandler { keys: {[key: number]: boolean} = {}; - listeners: (() => void)[] = []; + private listeners: (() => void)[] = []; - private callListeners() { + private callListeners(): void { this.listeners.forEach(l => l()); } diff --git a/src/view/MapView.ts b/src/view/MapView.ts index 230ecf3..daab7cb 100644 --- a/src/view/MapView.ts +++ b/src/view/MapView.ts @@ -100,7 +100,7 @@ export default class MapView { }); } - private setSize() { + private setSize(): void { var e = document.documentElement; var w = window.innerWidth || e.clientWidth || body.clientWidth; var h = window.innerHeight || e.clientHeight || body.clientHeight; @@ -114,7 +114,7 @@ export default class MapView { this.redraw() } - private drawTile(x: number, y: number, tile: HTMLImageElement) { + private drawTile(x: number, y: number, tile: HTMLImageElement): void { if (!tile) return; @@ -139,7 +139,7 @@ export default class MapView { return !!e.transition; } - private setOrigin(time: number) { + private setOrigin(time: number): Rect { var origin = entityPosition(this.origin, time); var w = this.canvas.width; @@ -156,7 +156,7 @@ export default class MapView { ); } - private draw(time: number) { + private draw(time: number): void { this.updateState(time); this.redrawPending = false; @@ -204,7 +204,7 @@ export default class MapView { this.redraw(); } - redraw() { + redraw(): void { if (this.redrawPending) return; -- cgit v1.2.3