56 lines
1.8 KiB
TypeScript
56 lines
1.8 KiB
TypeScript
import { Injectable } from '@angular/core';
|
|
import { map } from 'rxjs/operators';
|
|
import { StorageService } from './storage.service';
|
|
import { AlertService } from './alert.service';
|
|
|
|
interface ValuesCard {
|
|
title: string;
|
|
}
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class GameService {
|
|
|
|
cardset: Array<ValuesCard> = [];
|
|
|
|
constructor(private storage: StorageService, private alert: AlertService) {}
|
|
|
|
// main functions for all the games
|
|
public async checkGameStorage(game: string){
|
|
|
|
if(await this.storage.get(`${game.toUpperCase()}GAME_TOKEN`)){
|
|
// continue or restart
|
|
return await this.alert.presentAlertConfirm("Game found", "Do u want to continue or restart?", "restart", "continue");
|
|
}
|
|
// standard create new
|
|
return "create";
|
|
}
|
|
|
|
public async removeGameStorage(game: string){
|
|
await this.storage.remove(`${game.toUpperCase()}GAME_TOKEN`);
|
|
}
|
|
|
|
// finish when backend is completed
|
|
public async createGameStorage(game: string){
|
|
// return await this.http.post(`${config.endpoint}/...`, data).pipe(
|
|
|
|
// map((data) => {
|
|
|
|
// if (data["Status"] == "Success") {
|
|
// console.log(data["Data"]);
|
|
await this.storage.set(`${game.toUpperCase()}GAME_TOKEN`, { status: "sorting", cards:[{"title":"Temp_card_1"}, {"title":"Temp_card_2"}, {"title":"Temp_card_3"}, {"title":"Temp_card_4"}, {"title":"Temp_card_5"}, {"title":"Temp_card_6"}, {"title":"Temp_card_7"}, {"title":"Temp_card_8"}]});
|
|
// }
|
|
// return data;
|
|
// }),
|
|
|
|
// ).toPromise();
|
|
}
|
|
|
|
public async initValuesGame(){
|
|
console.log("[GameService] Initializing Value game...");
|
|
this.cardset = await this.storage.get("VALUESGAME_TOKEN");
|
|
console.log(this.cardset["cards"]);
|
|
this.cardset = this.cardset["cards"];
|
|
}
|
|
} |