mirror of
https://github.com/kevinveenbirkenbach/roulette-wheel.git
synced 2025-09-10 12:17:16 +02:00
add wheel & colors change & delete items fix & add item animation
This commit is contained in:
@@ -1,39 +0,0 @@
|
||||
export class Counter {
|
||||
static value: number;
|
||||
min: number;
|
||||
max: number;
|
||||
|
||||
constructor(min: number, max: number){
|
||||
Counter.value = min;
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
increment(){
|
||||
if(!this.isMax()){
|
||||
Counter.value++;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
decrement(){
|
||||
if(!this.isMin()){
|
||||
Counter.value--;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
clear(){
|
||||
Counter.value = 0;
|
||||
}
|
||||
|
||||
private isMax(){
|
||||
return this.max === Counter.value;
|
||||
}
|
||||
|
||||
private isMin(){
|
||||
return this.min === Counter.value;
|
||||
}
|
||||
}
|
32
src/model/item-list.ts
Normal file
32
src/model/item-list.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { Item } from "./item";
|
||||
import { List } from "./list";
|
||||
|
||||
export class ItemList implements List<Item> {
|
||||
items: Item[];
|
||||
maximumSize: number;
|
||||
|
||||
constructor(maxSize: number){
|
||||
this.items = [];
|
||||
this.maximumSize = maxSize;
|
||||
}
|
||||
|
||||
add(item: Item){
|
||||
if(this.items.length < this.maximumSize)
|
||||
this.items.push(item);
|
||||
}
|
||||
|
||||
removeById(id: number){
|
||||
const toRemove = this.items.find(e => e.id === id);
|
||||
if(toRemove){
|
||||
this.remove(toRemove);
|
||||
}
|
||||
}
|
||||
|
||||
remove(item: Item){
|
||||
this.items.splice(this.items.indexOf(item), 1);
|
||||
}
|
||||
|
||||
clear(){
|
||||
this.items = [];
|
||||
}
|
||||
}
|
@@ -1,11 +1,11 @@
|
||||
export class Item {
|
||||
id: number;
|
||||
name: string;
|
||||
color: string;
|
||||
id: number;
|
||||
name: string;
|
||||
color: string;
|
||||
|
||||
constructor(id: number, name: string, color: string){
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.color = color;
|
||||
}
|
||||
}
|
||||
constructor(id: number, name: string, color: string) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.color = color;
|
||||
}
|
||||
}
|
||||
|
5
src/model/list.ts
Normal file
5
src/model/list.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export interface List<T> {
|
||||
items: T[];
|
||||
|
||||
add(item: T): void;
|
||||
}
|
Reference in New Issue
Block a user