import 'package:faucethub/Backend/DebugHelper.dart'; import 'package:faucethub/Backend/hoarder.dart'; import 'dart:convert'; class Brain{ static const String API_ENDPOINT = "http://vps.playpoolstudios.com/faucet/api/"; static dynamic UserJson; static List LinkedGamesJson = []; static List NonLinkedGamesJson = []; static String get DisplayName{ String name = UserJson['name']; if(name.contains('#0')){ return name.substring(0,name.indexOf('@')); } return UserJson['name']; } static String get Username{ String name = UserJson['name']; if(name.contains('#0')){ return name.replaceAll("#0",""); } return UserJson['name']; } static void InitUserData(){ LinkedGamesJson = []; NonLinkedGamesJson = []; Debug.Log("Going to filter linked games from ${Hoarder.GamesJson.length} games\nmy linked game ids : ${UserJson['linkedGames']}"); try { List> linkedGames = jsonDecode( UserJson['linkedGames']).cast>(); Hoarder.GamesJson.forEach((element) { bool foundLink = false; for (var linkedGame in linkedGames) { int gid = linkedGame["game_id"]; int id = int.parse(element['id']); if (gid == id) { LinkedGamesJson.add(element); foundLink = true; break; } } if (!foundLink) { NonLinkedGamesJson.add(element); } }); Debug.Log("Linked games count : ${linkedGames.length}"); }catch(e){ NonLinkedGamesJson = Hoarder.GamesJson; } Hoarder.FetchChallenges(); } }