Games list wip

This commit is contained in:
2023-02-08 18:03:27 +05:30
parent b20b8ac538
commit e0ce08fa69
3 changed files with 82 additions and 17 deletions

View File

@@ -7,20 +7,47 @@ import 'package:http/http.dart' as http;
class Hoarder{
static List<dynamic> GamesJson = [];
static Map<String,String> Settings = {};
static List<dynamic> FeaturedGames = [];
static void GrabInitData() async{
var response = null;
static Future<void> GrabInitData() async{
try {
response = (await http.post(Uri.parse('${Brain.API_ENDPOINT}get_games.php')));
var response = (await http.post(Uri.parse('${Brain.API_ENDPOINT}get_settings.php')));
Debug.LogError(response.body.toString());
GamesJson=[];
List<String> games = response.body.toString().split("<td>");
games.forEach((game) {
GamesJson.add(jsonDecode(game));
Debug.LogResponse(response.body.toString());
// Settings= jsonDecode(response.body.toString());
List jsonList = jsonDecode(response.body.toString());
jsonList.forEach((jsonItem) {
Settings[jsonItem['id']] = jsonItem['value'];
});
} catch (e) {
Debug.LogError("Error while loading settings : $e");
}
try {
var response = (await http.post(Uri.parse('${Brain.API_ENDPOINT}get_games.php')));
Debug.LogResponse(response.body.toString());
GamesJson=[];
FeaturedGames = [];
List<String> games = response.body.toString().split("<td>");
List<String> featuredGames = Settings["featured_games"].toString().split(',');
games.forEach((game) {
dynamic Json = jsonDecode(game);
String id = Json['id'];
GamesJson.add(Json);
if(featuredGames.contains(id)){
FeaturedGames.add(Json);
}
});
Debug.Log("Total games ${GamesJson.length} and ${FeaturedGames.length} featured");
} catch (e) {
Debug.LogError("Error while loading games : $e");
}
}
}