Be explicit about return types, fix a few visibilities

This commit is contained in:
Matthias Schiffer 2016-01-08 09:00:07 +01:00
parent 00970b9faa
commit a2ea4e5ef5
4 changed files with 17 additions and 18 deletions

View file

@ -13,13 +13,12 @@ import MapView from '../view/MapView';
export default class MapContext { export default class MapContext {
view: MapView; private view: MapView;
entities: EntityPosition[] = []; private entities: EntityPosition[] = [];
playerEntity: EntityPosition; private playerEntity: EntityPosition;
private collision: number[][];
collision: number[][];
constructor(private map: MapData, private inputHandler: InputHandler) { 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; 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)) if (this.inMap(p))
this.collision[p.x][p.y]++; this.collision[p.x][p.y]++;
} }
private decCollision(p: Position) { private decCollision(p: Position): void {
if (this.inMap(p)) if (this.inMap(p))
this.collision[p.x][p.y]--; 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); 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.entities.push(entity);
this.incCollision(entity.position); 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); entity.transition = new Transition(start, start+dur, entity.position, dest);
this.incCollision(dest); this.incCollision(dest);
} }
private finishTransition(entity: EntityPosition) { private finishTransition(entity: EntityPosition): void {
this.decCollision(entity.position); this.decCollision(entity.position);
entity.position = entity.transition.dest; entity.position = entity.transition.dest;

View file

@ -8,7 +8,7 @@ import Transition from './Transition';
export default class EntityPosition { export default class EntityPosition {
public transition: Transition = null; transition: Transition = null;
constructor(public entity: Entity, public position: Position, public direction: Direction) {} constructor(public entity: Entity, public position: Position, public direction: Direction) {}
} }

View file

@ -7,9 +7,9 @@ import Direction from '../model/Direction';
class InputHandler { class InputHandler {
keys: {[key: number]: boolean} = {}; keys: {[key: number]: boolean} = {};
listeners: (() => void)[] = []; private listeners: (() => void)[] = [];
private callListeners() { private callListeners(): void {
this.listeners.forEach(l => l()); this.listeners.forEach(l => l());
} }

View file

@ -100,7 +100,7 @@ export default class MapView {
}); });
} }
private setSize() { private setSize(): void {
var e = document.documentElement; var e = document.documentElement;
var w = window.innerWidth || e.clientWidth || body.clientWidth; var w = window.innerWidth || e.clientWidth || body.clientWidth;
var h = window.innerHeight || e.clientHeight || body.clientHeight; var h = window.innerHeight || e.clientHeight || body.clientHeight;
@ -114,7 +114,7 @@ export default class MapView {
this.redraw() this.redraw()
} }
private drawTile(x: number, y: number, tile: HTMLImageElement) { private drawTile(x: number, y: number, tile: HTMLImageElement): void {
if (!tile) if (!tile)
return; return;
@ -139,7 +139,7 @@ export default class MapView {
return !!e.transition; return !!e.transition;
} }
private setOrigin(time: number) { private setOrigin(time: number): Rect {
var origin = entityPosition(this.origin, time); var origin = entityPosition(this.origin, time);
var w = this.canvas.width; 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.updateState(time);
this.redrawPending = false; this.redrawPending = false;
@ -204,7 +204,7 @@ export default class MapView {
this.redraw(); this.redraw();
} }
redraw() { redraw(): void {
if (this.redrawPending) if (this.redrawPending)
return; return;