Skip to content

Commit

Permalink
[ng] Tracks ui
Browse files Browse the repository at this point in the history
  • Loading branch information
DraTeots committed May 28, 2024
1 parent 28e3e24 commit 8498c57
Show file tree
Hide file tree
Showing 4 changed files with 259 additions and 114 deletions.
24 changes: 12 additions & 12 deletions firebird-ng/src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@
<li class="nav-item" id="lil-gui-place">

</li>
<li class="nav-item">
<a class="nav-link" href="https://github.com/eic/firebird" target="_blank">
<svg height="32" aria-hidden="true" viewBox="0 0 16 16" version="1.1" width="32" data-view-component="true" class="octicon octicon-mark-github v-align-middle">
<path d="M8 0c4.42 0 8 3.58 8 8a8.013 8.013 0 0 1-5.45 7.59c-.4.08-.55-.17-.55-.38 0-.27.01-1.13.01-2.2 0-.75-.25-1.23-.54-1.48 1.78-.2 3.65-.88 3.65-3.95 0-.88-.31-1.59-.82-2.15.08-.2.36-1.02-.08-2.12 0 0-.67-.22-2.2.82-.64-.18-1.32-.27-2-.27-.68 0-1.36.09-2 .27-1.53-1.03-2.2-.82-2.2-.82-.44 1.1-.16 1.92-.08 2.12-.51.56-.82 1.28-.82 2.15 0 3.06 1.86 3.75 3.64 3.95-.23.2-.44.55-.51 1.07-.46.21-1.61.55-2.33-.66-.15-.24-.6-.83-1.23-.82-.67.01-.27.38.01.53.34.19.73.9.82 1.13.16.45.68 1.31 2.69.94 0 .67.01 1.3.01 1.49 0 .21-.15.45-.55.38A7.995 7.995 0 0 1 0 8c0-4.42 3.58-8 8-8Z"></path>
</svg>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://github.com/eic/firebird#README" target="_blank">
<img src="assets/firebird/firebird-simplified-circle.png" width="32" height="32" alt="App Logo">
</a>
</li>
<!-- <li class="nav-item">-->
<!-- <a class="nav-link" href="https://github.com/eic/firebird" target="_blank">-->
<!-- <svg height="32" aria-hidden="true" viewBox="0 0 16 16" version="1.1" width="32" data-view-component="true" class="octicon octicon-mark-github v-align-middle">-->
<!-- <path d="M8 0c4.42 0 8 3.58 8 8a8.013 8.013 0 0 1-5.45 7.59c-.4.08-.55-.17-.55-.38 0-.27.01-1.13.01-2.2 0-.75-.25-1.23-.54-1.48 1.78-.2 3.65-.88 3.65-3.95 0-.88-.31-1.59-.82-2.15.08-.2.36-1.02-.08-2.12 0 0-.67-.22-2.2.82-.64-.18-1.32-.27-2-.27-.68 0-1.36.09-2 .27-1.53-1.03-2.2-.82-2.2-.82-.44 1.1-.16 1.92-.08 2.12-.51.56-.82 1.28-.82 2.15 0 3.06 1.86 3.75 3.64 3.95-.23.2-.44.55-.51 1.07-.46.21-1.61.55-2.33-.66-.15-.24-.6-.83-1.23-.82-.67.01-.27.38.01.53.34.19.73.9.82 1.13.16.45.68 1.31 2.69.94 0 .67.01 1.3.01 1.49 0 .21-.15.45-.55.38A7.995 7.995 0 0 1 0 8c0-4.42 3.58-8 8-8Z"></path>-->
<!-- </svg>-->
<!-- </a>-->
<!-- </li>-->
<!-- <li class="nav-item">-->
<!-- <a class="nav-link" href="https://github.com/eic/firebird#README" target="_blank">-->
<!-- <img src="assets/firebird/firebird-simplified-circle.png" width="32" height="32" alt="App Logo">-->
<!-- </a>-->
<!-- </li>-->
</ul>
</div>
</nav>
Expand Down
3 changes: 1 addition & 2 deletions firebird-ng/src/app/app.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import {FileBrowserComponent} from "./file-browser/file-browser.component";
import {InputConfigComponent} from "./input-config/input-config.component";

export const routes: Routes = [
{ path: '', redirectTo: '/config', pathMatch: 'full' },
{ path: '', redirectTo: '/display', pathMatch: 'full' },
{ path: 'config', component: InputConfigComponent },

{
path: 'files',
loadComponent: () => import('./file-browser/file-browser.component').then(m => m.FileBrowserComponent)
Expand Down
114 changes: 113 additions & 1 deletion firebird-ng/src/app/game-controller.service.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,121 @@
import { Injectable } from '@angular/core';
import * as THREE from "three";
import {BehaviorSubject, Observable, Subject} from "rxjs";


export enum ControllerButtonIndexes {
ButtonA = 0,
ButtonB = 1,
ButtonX = 2,
ButtonY = 3,
ButtonLB = 4,
ButtonRB = 5,
ButtonLT = 6,
ButtonRT = 7,
Select = 8,
Start = 9,
}


@Injectable({
providedIn: 'root'
})
export class GameControllerService {

constructor() { }
private xAxisSubject = new BehaviorSubject<number>(0);
public xAxisChanged = this.xAxisSubject.asObservable();
public xAxis = 0;

private yAxisSubject = new BehaviorSubject<number>(0);
private yAxisChanged = this.yAxisSubject.asObservable();
public yAxis: number = 0;
public buttons: GamepadButton[] = [];
public prevButtons: GamepadButton[] = [];

private buttonASubject = new Subject<boolean>();
public buttonAPressed = this.buttonASubject.asObservable();
public buttonA: GamepadButton = {pressed: false, touched: false, value: 0};
private buttonBSubject = new Subject<boolean>();
public buttonBPressed = this.buttonBSubject.asObservable();
public buttonB: GamepadButton = {pressed: false, touched: false, value: 0};
private buttonXSubject = new Subject<boolean>();
public buttonXPressed = this.buttonXSubject.asObservable();
public buttonX: GamepadButton = {pressed: false, touched: false, value: 0};
private buttonYSubject = new Subject<boolean>();
public buttonYPressed = this.buttonYSubject.asObservable();
public buttonY: GamepadButton = {pressed: false, touched: false, value: 0};
private buttonLBSubject = new Subject<boolean>();
public buttonLBPressed = this.buttonLBSubject.asObservable();
public buttonLB: GamepadButton = {pressed: false, touched: false, value: 0};
private buttonRBSubject = new Subject<boolean>();
public buttonRBPressed = this.buttonRBSubject.asObservable();
public buttonRB: GamepadButton = {pressed: false, touched: false, value: 0};
private buttonLTSubject = new Subject<boolean>();
public buttonLTPressed = this.buttonLTSubject.asObservable();
public buttonLT: GamepadButton = {pressed: false, touched: false, value: 0};
private buttonRTSubject = new Subject<boolean>();
public buttonRTPressed = this.buttonRTSubject.asObservable();
public buttonRT: GamepadButton = {pressed: false, touched: false, value: 0};
private buttonSelectSubject = new Subject<boolean>();
public buttonSelectPressed = this.buttonSelectSubject.asObservable();
public buttonSelect: GamepadButton = {pressed: false, touched: false, value: 0};
private buttonStartSubject = new Subject<boolean>();
public buttonStartPressed = this.buttonStartSubject.asObservable();
public buttonStart: GamepadButton = {pressed: false, touched: false, value: 0};

public activeGamepad: Gamepad|null = null;

animationLoopHandler () {

const epsilon = 0.01;
const gamepads = navigator.getGamepads();
for (const gamepad of gamepads) {
if (gamepad) {

this.activeGamepad = gamepad;
// Example: Using left joystick to control OrbitControls
// Axis 0: Left joystick horizontal (left/right)
// Axis 1: Left joystick vertical (up/down)
this.xAxis = gamepad.axes[0];
this.yAxis = gamepad.axes[1];

if(Math.abs(this.xAxis - this.xAxisSubject.value) > epsilon) {
this.xAxisSubject.next(this.xAxis);
}

if(Math.abs(this.yAxis - this.yAxisSubject.value) > epsilon) {
this.yAxisSubject.next(this.yAxis);
}

this.buttonA = gamepad.buttons[ControllerButtonIndexes.ButtonA];
this.buttonB = gamepad.buttons[ControllerButtonIndexes.ButtonB];
this.buttonX = gamepad.buttons[ControllerButtonIndexes.ButtonX];
this.buttonY = gamepad.buttons[ControllerButtonIndexes.ButtonY];
this.buttonLB = gamepad.buttons[ControllerButtonIndexes.ButtonLB];
this.buttonRB = gamepad.buttons[ControllerButtonIndexes.ButtonRB];
this.buttonLT = gamepad.buttons[ControllerButtonIndexes.ButtonLT];
this.buttonRT = gamepad.buttons[ControllerButtonIndexes.ButtonRT];
this.buttonSelect = gamepad.buttons[ControllerButtonIndexes.Select];
this.buttonStart = gamepad.buttons[ControllerButtonIndexes.Start];

if (this.buttonA.pressed !== this.buttonASubject.observed) this.buttonASubject.next(this.buttonA.pressed);
if (this.buttonB.pressed !== this.buttonBSubject.observed) this.buttonASubject.next(this.buttonB.pressed);
if (this.buttonX.pressed !== this.buttonXSubject.observed) this.buttonASubject.next(this.buttonX.pressed);
if (this.buttonY.pressed !== this.buttonYSubject.observed) this.buttonASubject.next(this.buttonY.pressed);
if (this.buttonLB.pressed !== this.buttonLBSubject.observed) this.buttonASubject.next(this.buttonLB.pressed);
if (this.buttonRB.pressed !== this.buttonRBSubject.observed) this.buttonASubject.next(this.buttonRB.pressed);
if (this.buttonLT.pressed !== this.buttonLTSubject.observed) this.buttonASubject.next(this.buttonLT.pressed);
if (this.buttonRT.pressed !== this.buttonRTSubject.observed) this.buttonASubject.next(this.buttonRT.pressed);
if (this.buttonSelect.pressed !== this.buttonSelectSubject.observed) this.buttonASubject.next(this.buttonSelect.pressed);
if (this.buttonStart.pressed !== this.buttonStartSubject.observed) this.buttonASubject.next(this.buttonStart.pressed);

break; // Only use the first connected gamepad
}
}
};

constructor() {
// Run it on contruction so if we have an active controller we set up values
this.animationLoopHandler();
}
}
Loading

0 comments on commit 8498c57

Please sign in to comment.