This commit is contained in:
Sewmina Dilshan 2023-07-02 16:39:53 +05:30
parent f337e72476
commit 9bba037c66
3 changed files with 44 additions and 26 deletions

View File

@ -17,6 +17,18 @@ class DataManager{
static dynamic UserJson;
static dynamic cryptoRates;
static double currentEarnings =0;
static Map<String, int> GamesEarnings = {};
static Map<String, int> CryptoEarnings = {};
static void Reset(){
UserJson = LinkedGamesJson = NonLinkedGamesJson = Challenges = [];
currentEarnings = 0;
GamesEarnings = CryptoEarnings = {};
}
static Future<bool> Init() async{
bool isSettingsDone = await GetSettings();
bool isGamesDone = await GetGames();
@ -43,31 +55,35 @@ class DataManager{
}
static void FilterLinkedGames(){
LinkedGamesJson = [];
NonLinkedGamesJson = [];
if(UserJson['linkedGames'].toString().length < 3){
NonLinkedGamesJson = AllGames;
return;
}
List<Map<String, dynamic>> linkedGames = jsonDecode(
UserJson['linkedGames']).cast<Map<String, dynamic>>();
Debug.Log("err044 : $UserJson");
LinkedGamesJson = [];
NonLinkedGamesJson = [];
if (UserJson['linkedGames']
.toString()
.length < 3) {
NonLinkedGamesJson = AllGames;
return;
}
List<Map<String, dynamic>> linkedGames = jsonDecode(
UserJson['linkedGames']).cast<Map<String, dynamic>>();
AllGames.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;
AllGames.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);
}
});
if (!foundLink) {
NonLinkedGamesJson.add(element);
}
});
}
static Future<bool> GetSettings() async{
@ -143,10 +159,7 @@ class DataManager{
Challenges = _Challenges;
return true;
}
static dynamic cryptoRates;
static double currentEarnings =0;
static Map<String, int> GamesEarnings = {};
static Map<String, int> CryptoEarnings = {};
static void CalculateEarnings() async{
@ -215,4 +228,6 @@ class DataManager{
Debug.LogError(e);
}
}
}

View File

@ -525,6 +525,7 @@ class _HomeState extends State<Home> {
Navigator.of(context).pushAndRemoveUntil(MaterialPageRoute(builder: (context) =>
MyHomePage()), (Route<dynamic> route) => false);
DataManager.Reset();
},
child: GlassCard(child: Padding(
padding: const EdgeInsets.all(15.0),

View File

@ -200,7 +200,9 @@ class _MyHomePageState extends State<MyHomePage> {
int regResult = await LoginManager.Register(usernameController.text, passwordController.text);
if(regResult == 0){
await LoginManager.AutoLogin();
await DataManager.GetGamesProgress();
loadHome();
}else if(regResult == 5){
Dialogs.showAlertDialog(context, "Register Failed", "Username Already exists, Please try again with a different username");