import { Component } from '@angular/core';
import { DataService } from 'src/services/data/data.service';

@Component({
  selector: 'app-movement',
  templateUrl: './movement.component.html',
  styleUrls: ['./movement.component.scss'],
})
export class MovementComponent {
  public constructor(public dataAccessor: DataService) {}

  public movement: number = 0;

  ngOnInit(): void {
    this.initAttributeSubscription();
  }

  private initAttributeSubscription(): void {
    this.dataAccessor.speed$.subscribe((newValue: any) => {
      this.movement = newValue.value;
    });
  }

  public updateValue(): void {
    this.dataAccessor.updateCharacterData({
      name: 'armorClass',
      value: this.movement,
    });
  }
}
