From 5a93c846fa0d22b153c618af7f75f784ea138eda Mon Sep 17 00:00:00 2001 From: Steve Van Opstal Date: Mon, 12 Dec 2016 16:56:33 +0100 Subject: [PATCH] feat(items): add gold offset --- .../build/items/item-slot.component.spec.ts | 43 +------ src/client/build/items/item-slot.component.ts | 99 +++++---------- .../build/items/items.component.spec.ts | 17 +-- src/client/build/items/items.component.ts | 120 +++++++++++++++--- 4 files changed, 137 insertions(+), 142 deletions(-) diff --git a/src/client/build/items/item-slot.component.spec.ts b/src/client/build/items/item-slot.component.spec.ts index 0665565..d9e887c 100644 --- a/src/client/build/items/item-slot.component.spec.ts +++ b/src/client/build/items/item-slot.component.spec.ts @@ -1,6 +1,5 @@ -import {inject, TestBed} from '@angular/core/testing'; +import {TestBed} from '@angular/core/testing'; -import {settings} from '../../../../config/settings'; import {LolApiService} from '../../services/lolapi.service'; import {StatsService} from '../../services/stats.service'; import {TestModule} from '../../testing'; @@ -15,44 +14,4 @@ describe('ItemSlotComponent', () => { imports: [TestModule] }); }); - - let item1; - let item2; - - beforeEach(inject([ItemSlotComponent], (component) => { - item1 = {id: 3341, gold: {total: 0}}; - - item2 = {id: 2003, gold: {total: 50}}; - - component.samples = {gold: [0, 100, 200, 300]}; - component.items = [item1, item2, item2, item2]; - })); - - it('should add an item', inject([ItemSlotComponent], (component) => { - spyOn(component, 'addTime'); - spyOn(component, 'addBundle'); - expect(component.addTime).not.toHaveBeenCalled(); - expect(component.addBundle).not.toHaveBeenCalled(); - component.addItem(item1); - expect(component.addTime).toHaveBeenCalled(); - expect(component.addBundle).toHaveBeenCalled(); - expect(component.items[4]).toHaveEqualContent(item1); - })); - - it('should calculate time', inject([ItemSlotComponent], (component) => { - component.addTime(item1); - expect(item1.time).toBe(0); - component.addTime(item2); - expect(item2.time) - .toBe( - (settings.gameTime / settings.matchServer.sampleSize) / component.samples.gold[1] * - item2.gold.total); - })); - - it('should bundle', inject([ItemSlotComponent], (component) => { - component.addTime(item2); - component.addBundle(item2); - expect(component.items.length).toBe(2); - expect(component.items[1].bundle).toBe(3); - })); }); diff --git a/src/client/build/items/item-slot.component.ts b/src/client/build/items/item-slot.component.ts index b4a36d7..83d9569 100644 --- a/src/client/build/items/item-slot.component.ts +++ b/src/client/build/items/item-slot.component.ts @@ -1,9 +1,7 @@ import {Component, Input, OnInit} from '@angular/core'; -import {settings} from '../../../../config/settings'; import {LolApiService} from '../../services/lolapi.service'; import {Item} from '../item'; -import {Samples} from '../samples'; @Component({ selector: 'lb-item-slot', @@ -18,96 +16,59 @@ import {Samples} from '../samples'; export class ItemSlotComponent implements OnInit { @Input() id: number; - private samples: Samples; - private items: Array = new Array(); + items = Array(); + + private allItems; constructor(private lolApi: LolApiService) {} ngOnInit() { - this.lolApi.getCurrentMatchData().subscribe(samples => { - this.samples = samples; + this.lolApi.getItems().subscribe(res => { + this.allItems = res.data; }); } - addItem(item: Item) { - this.addTime(item); - this.addBundle(item); - this.items.push(item); - } - - removeItem(item: Item) { - this.items.splice(this.items.indexOf(item), 1); - } - - getItems(): Array { - return this.items; - } - compatible(item: Item) { if (!this.items.length) { return true; } - let from = this.items[this.items.length - 1].from; - if (!from) { - return true; - } - return from.indexOf(item.id.toString()) > -1; + let item2 = this.items[this.items.length - 1]; + return this.buildsFrom(item, item2); } // TODO: move to itemComponent when angular allows events on