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

bugfix/ATC-4 #14

Merged
merged 1 commit into from
Oct 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions src/assets/scripts/airport/AirportController.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ import { STORAGE_KEY } from '../constants/storageKeys';
// Temporary const declaration here to attach to the window AND use as internal property
const airport = {};

/**
* @property DEFAULT_AIRPORT_ICAO
* @type {string}
* @final
*/
const DEFAULT_AIRPORT_ICAO = 'ksfo';

/**
* @class AirportController
*/
Expand All @@ -22,6 +29,8 @@ export default class AirportController {
}

/**
* Lifecycle method. Should run only once on App initialiazation
*
* @for AirportController
* @method init_pre
*/
Expand All @@ -32,6 +41,8 @@ export default class AirportController {
}

/**
* Lifecycle method. Should run only once on App initialiazation
*
* Load each airport in the `airportLoadList`
*
* @for AirportController
Expand All @@ -44,16 +55,18 @@ export default class AirportController {
}

/**
* Lifecycle method. Should run only once on App initialiazation
*
* @for AirportController
* @method ready
*/
ready() {
let airportName = 'ksfo';
let airportName = DEFAULT_AIRPORT_ICAO;

if (!_has(localStorage, STORAGE_KEY.ATC_LAST_AIRPORT) ||
!_has(prop.airport.airports, STORAGE_KEY.ATC_LAST_AIRPORT)
if (_has(localStorage, STORAGE_KEY.ATC_LAST_AIRPORT) ||
_has(prop.airport.airports, localStorage[STORAGE_KEY.ATC_LAST_AIRPORT].toLowerCase())
) {
airportName = 'ksfo';
airportName = localStorage[STORAGE_KEY.ATC_LAST_AIRPORT].toLowerCase();
}

this.airport_set(airportName);
Expand All @@ -64,16 +77,13 @@ export default class AirportController {
* @method airport_set
*/
airport_set(icao) {
// TODO: simplify these ifs by combining them
if (!icao) {
if (_has(localStorage, STORAGE_KEY.ATC_LAST_AIRPORT)) {
icao = localStorage[STORAGE_KEY.ATC_LAST_AIRPORT];
}
if (!icao && _has(localStorage, STORAGE_KEY.ATC_LAST_AIRPORT)) {
icao = localStorage[STORAGE_KEY.ATC_LAST_AIRPORT];
}

icao = icao.toLowerCase();

if (!icao in prop.airport.airports) {
if (!prop.airport.airports[icao]) {
console.log(`${icao}: no such airport`);

return;
Expand Down
15 changes: 8 additions & 7 deletions src/assets/scripts/airport/AirportModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { angle_offset } from '../math/circle';
import { getOffset } from '../math/flightMath';
import { vlen, vsub, vadd, vscale, raysIntersect } from '../math/vector';
import { LOG } from '../constants/logLevel';
import { SELECTORS } from '../constants/selectors';
import { STORAGE_KEY } from '../constants/storageKeys';

// TODO: This function should really live in a different file and have tests.
Expand Down Expand Up @@ -369,17 +370,17 @@ export default class AirportModel {
localStorage[STORAGE_KEY.ATC_LAST_AIRPORT] = this.icao;
prop.airport.current = this;

$('#airport')
$(SELECTORS.DOM_SELECTORS.AIRPORT)
.text(this.icao.toUpperCase())
.attr('title', this.name);

prop.canvas.draw_labels = true;
$('.toggle-labels').toggle(!_isEmpty(this.maps));
$('.toggle-restricted-areas').toggle((this.restricted_areas || []).length > 0);
$('.toggle-sids').toggle(!_isEmpty(this.sids));
$(SELECTORS.DOM_SELECTORS.TOGGLE_LABELS).toggle(!_isEmpty(this.maps));
$(SELECTORS.DOM_SELECTORS.TOGGLE_RESTRICTED_AREAS).toggle((this.restricted_areas || []).length > 0);
$(SELECTORS.DOM_SELECTORS.TOGGLE_SIDS).toggle(!_isEmpty(this.sids));

prop.canvas.dirty = true;
$('.toggle-terrain').toggle(!_isEmpty(this.terrain));
$(SELECTORS.DOM_SELECTORS.TOGGLE_TERRAIN).toggle(!_isEmpty(this.terrain));

window.gameController.game_reset_score();
this.start = window.gameController.game_time();
Expand Down Expand Up @@ -446,8 +447,8 @@ export default class AirportModel {
apt.terrain = {};

for (const i in data.features) {
const f = data.features[i],
ele = round(f.properties.elevation / 0.3048, 1000); // m => ft, rounded to 1K (but not divided)
const f = data.features[i];
const ele = round(f.properties.elevation / 0.3048, 1000); // m => ft, rounded to 1K (but not divided)

if (!apt.terrain[ele]) {
apt.terrain[ele] = [];
Expand Down