Skip to content

Commit

Permalink
Add: Car select
Browse files Browse the repository at this point in the history
  • Loading branch information
Tamas Cseh committed Apr 11, 2021
1 parent 1444f5b commit 6804068
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
All notable changes to this project will be documented in this file.

## [Unreleased]
## Added
- Car select

## Fixed
- Opponent selector freezes the game

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ export class EventHandlerComponent implements OnInit, OnDestroy {

private tabHolder: HTMLDivElement;
private observer: MutationObserver;
private injector: any;

constructor(private raceButtonService: RaceButtonService) {
}

ngOnInit(): void {
this.injector = angular.element('ui-view').injector();
this.raceButtonService.addRaceButton();
waitForElement('nav em').then((e: Element) => {
const countDown: HTMLElement = document.createElement('rf-race-countdown-timer');
Expand All @@ -29,6 +31,12 @@ export class EventHandlerComponent implements OnInit, OnDestroy {
this.injectChat();
this.observeTabChange();
});

waitForElement('svg.track-map', 2000).then(() => {
this.tabHolder = document.querySelector('div[ng-if=\'eventCtrl.gameState.navigationState\']');
this.addCarSelect();
this.observeTabChange();
});
}

private observeTabChange(): void {
Expand All @@ -39,12 +47,39 @@ export class EventHandlerComponent implements OnInit, OnDestroy {
this.injectChat();
break;
}

if (m.attributeName === 'class' && this.tabHolder.classList.contains('tab-eventinfo')) {
this.addCarSelect();
break;
}
}
});

this.observer.observe(this.tabHolder, {attributes: true});
}

private async addCarSelect(): Promise<void> {
const holderDiv: HTMLDivElement = document.querySelector('.left-content-bottom div');

if (holderDiv.querySelector('button.carSelect')) {
// already added
return;
}

const carSelect: HTMLButtonElement = document.createElement('button');
carSelect.classList.add('secondary', 'carSelect');
carSelect.innerHTML = `<span>Car Select</span>`;

const appSwitchService: any = this.injector.get('appSwitchService');

carSelect.onclick = () => {
sessionStorage.setItem('betterUI.carSelect', 'true');
appSwitchService.openAppWithTab('race', 'car');
};

holderDiv.appendChild(carSelect);
}

private injectChat(): void {
const ngIncludeElement: HTMLElement = document.querySelector('.camera-wrapper').parentElement;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export class RaceHandlerComponent implements OnInit {
}

ngOnInit(): void {
this.carSelect();

window.addEventListener('hashchange', () => {
this.listItems = document.querySelectorAll('ol.tabnavigation:not(.bottom) li');
this.rememberPassword();
Expand Down Expand Up @@ -128,4 +130,22 @@ export class RaceHandlerComponent implements OnInit {
// There is no download
}
}

private carSelect(): void {
if (sessionStorage.getItem('betterUI.carSelect') === 'true') {
const carSelectCtrl = angular.element('ui-view').controller();
const origFun: () => void = carSelectCtrl.joinServer;

carSelectCtrl.joinServer = () => {
origFun();
carSelectCtrl.appSwitchService.openAppWithTab('event');
};

angular.element('nav.jumpmenu').scope().config.back = () => {
carSelectCtrl.appSwitchService.openAppWithTab('event');
};

sessionStorage.removeItem('betterUI.carSelect');
}
}
}

0 comments on commit 6804068

Please sign in to comment.