Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using Firebase;
- using Firebase.Extensions;
- using Firebase.Firestore;
- using UnityEngine;
- public class FirestoneManager : MonoBehaviour
- {
- [SerializeField] private int YugtoLevelCount = 10;
- public static FirestoneManager Instance;
- FirebaseFirestore db;
- private const string COLLECTION = "Students";
- private const string INFO = "Informations";
- private const string GAME_INFO = "Game Information";
- private const string PERSONAL_INFO = "Personal Information";
- private const string SCHOOL_INFO = "School Information";
- void Awake()
- {
- Instance = this;
- }
- void Start()
- {
- db = FirebaseFirestore.DefaultInstance;
- }
- public int GetYugtoLevelCount() => YugtoLevelCount;
- // Method to verify login and return the document name (ID)
- public Task<StudentData> VerifyLogin(string inputUsername, string inputPassword)
- {
- if(db == null) db = FirebaseFirestore.DefaultInstance;
- CollectionReference studentsRef = db.Collection(COLLECTION);
- TaskCompletionSource<StudentData> taskCompletionSource =
- new TaskCompletionSource<StudentData>();
- studentsRef.GetSnapshotAsync().ContinueWithOnMainThread(async task =>
- {
- if (!task.IsCompleted || task.Result == null) {
- Debug.Log("No users found.");
- taskCompletionSource.SetResult(null);
- return;
- }
- if(task.IsFaulted) MessagePopup.Instance.ShowMessage("WALANG INTERNET O HINDI MAKA-KONEK SA MGA GURO");
- foreach (DocumentSnapshot studentDoc in task.Result.Documents)
- {
- string storedUsername = studentDoc.GetValue<string>("username");
- string storedPassword = studentDoc.GetValue<string>("password");
- string storedEmail = studentDoc.GetValue<string>("email");
- if (storedUsername != inputUsername
- || storedPassword != inputPassword) continue;
- string documentId = studentDoc.Id;
- // START SCHOOL INFO
- string teacher = "";
- string section = "";
- int year = 0;
- try {
- Debug.Log("START SCHOOL INFO");
- DocumentReference infoRef = studentDoc.Reference
- .Collection(INFO).Document(SCHOOL_INFO);
- DocumentSnapshot schoolInfoSnapshot = await infoRef.GetSnapshotAsync();
- if (!schoolInfoSnapshot.Exists)
- {
- Debug.LogError("MISSING SCHOOL INFO");
- taskCompletionSource.SetResult(null);
- return;
- }
- section = schoolInfoSnapshot.GetValue<string>("Section");
- year = schoolInfoSnapshot.GetValue<int>("Grade");
- teacher = schoolInfoSnapshot.GetValue<string>("Teacher");
- } catch(Exception ex) {
- Debug.LogError("SCHOOL " + ex.Message);
- taskCompletionSource.SetResult(null);
- }
- // END SCHOOL INFO
- // START GAME INFO
- int coins = 0, level = 0, forestDay = 0, forestNight = 0, city = 0, farm = 0;
- bool isFirstTime = false;
- List<StudentData.StudentHighscore.LevelHS> levelHS = new List<StudentData.StudentHighscore.LevelHS>();
- string setting = "", upgrade = "", customization = "";
- try {
- Debug.Log("START GAME INFO");
- DocumentReference gameInfoRef = studentDoc.Reference
- .Collection(INFO).Document(GAME_INFO);
- DocumentSnapshot gameInfoSnapshot = await gameInfoRef.GetSnapshotAsync();
- if (!gameInfoSnapshot.Exists)
- {
- Debug.Log("Creating default game info...");
- Dictionary<string, object> defaultYugtoHighscore = new Dictionary<string, object>()
- {
- { "Score", 0 },
- { "Time", "00:00:00" }
- };
- await gameInfoRef.SetAsync(new Dictionary<string, object>()
- {
- { "Coins", 0 },
- { "Level", 0 },
- { "Customization", "0###-1###0###0###-1###-1###0###0###0###0###0###-1###-1###-1###-1###-1###0" },
- { "Settings", "1::0::0.5::0.5::0.5::1::0" },
- { "Upgrades", "1::0::0::0::0" },
- { "First Time", true}
- });
- // Create the Highscore collection
- CollectionReference highscoreCollection = gameInfoRef.Collection("Highscore");
- // For each level, create a document with default values
- for (int i = 1; i <= YugtoLevelCount; i++)
- {
- await highscoreCollection.Document($"Level{i}").SetAsync(defaultYugtoHighscore);
- }
- // Optionally, you can create the Activity document
- await highscoreCollection.Document("Activity").SetAsync(new Dictionary<string, object>()
- {
- { "City", 0 },
- { "Farm", 0 },
- { "ForestDay", 0 },
- { "ForestNight", 0 }
- });
- }
- gameInfoSnapshot = await gameInfoRef.GetSnapshotAsync();
- coins = gameInfoSnapshot.GetValue<int>("Coins");
- level = gameInfoSnapshot.GetValue<int>("Level");
- setting = gameInfoSnapshot.GetValue<string>("Settings");
- upgrade = gameInfoSnapshot.GetValue<string>("Upgrades");
- customization = gameInfoSnapshot.GetValue<string>("Customization");
- isFirstTime = gameInfoSnapshot.GetValue<bool>("First Time");
- CollectionReference highscoreRef = gameInfoRef.Collection("Highscore");
- DocumentSnapshot highscoreSnap = await gameInfoRef.GetSnapshotAsync();
- DocumentReference highscoreActivityRef = highscoreRef.Document("Activity");
- DocumentSnapshot highscoreActivitySnap = await highscoreActivityRef.GetSnapshotAsync();
- DocumentReference highscoreYugtoRef = highscoreRef.Document("Level");
- DocumentSnapshot highscoreYugtoSnap = await highscoreYugtoRef.GetSnapshotAsync();
- forestDay = highscoreActivitySnap.GetValue<int>("ForestDay");
- forestNight = highscoreActivitySnap.GetValue<int>("ForestNight");
- city = highscoreActivitySnap.GetValue<int>("City");
- farm = highscoreActivitySnap.GetValue<int>("Farm");
- for (int i = 1; i <= YugtoLevelCount; i++)
- {
- highscoreYugtoRef = highscoreRef.Document("Level"+i);
- highscoreYugtoSnap = await highscoreYugtoRef.GetSnapshotAsync();
- levelHS.Add(new StudentData.StudentHighscore.LevelHS(
- highscoreYugtoSnap.GetValue<int>("Score"),
- highscoreYugtoSnap.GetValue<string>("Time")
- ));
- }
- } catch(Exception ex) {
- Debug.LogError("GAME " + ex.Message);
- taskCompletionSource.SetResult(null);
- }
- // END OF GAME INFO
- // START PERSONAL INFO
- string fullName = "";
- try {
- Debug.Log("START PERSONAL INFO");
- DocumentReference personalInfoRef = studentDoc.Reference
- .Collection(INFO).Document(PERSONAL_INFO);
- DocumentSnapshot personalInfoSnapshot = await personalInfoRef.GetSnapshotAsync();
- if (!personalInfoSnapshot.Exists)
- {
- Debug.LogError($"MISSING PERSONAL INFO: {studentDoc.Id}");
- taskCompletionSource.SetResult(null);
- return;
- }
- fullName = personalInfoSnapshot.GetValue<string>("Full Name");
- } catch(Exception ex) {
- Debug.LogError("PERSONAL " + ex.Message);
- taskCompletionSource.SetResult(null);
- }
- // END OF PERSONAL INFO
- // START LEADERBOARD
- CollectionReference lbRef = db.Collection("Leaderboard");
- DocumentReference lbLvlRef = lbRef.Document("Level");
- DocumentSnapshot lbLvlSnap = await lbLvlRef.GetSnapshotAsync();
- List<StudentData.DataLeaderboard.Level> levelLB = new List<StudentData.DataLeaderboard.Level>();
- // START LEVEL
- for(int i = 1; i <= YugtoLevelCount; i++) {
- lbLvlRef = lbRef.Document($"Level{i} Score");
- lbLvlSnap = await lbLvlRef.GetSnapshotAsync();
- Dictionary<string, object> scoreDict = new Dictionary<string, object>();
- Dictionary<string, object> timeDict = new Dictionary<string, object>();
- foreach (var field in lbLvlSnap.ToDictionary()) {
- scoreDict.Add(field.Key, Convert.ToInt32(field.Value));
- }
- lbLvlRef = lbRef.Document($"Level{i} Time");
- lbLvlSnap = await lbLvlRef.GetSnapshotAsync();
- foreach (var field in lbLvlSnap.ToDictionary()) {
- timeDict.Add(field.Key, field.Value.ToString());
- }
- levelLB.Add(new StudentData.DataLeaderboard.Level(
- scoreDict, timeDict
- ));
- }
- // END OF LEVEL
- // END OF LEADERBOARD
- // Create the StudentData object with all the fetched data
- StudentData studentData = new StudentData(
- documentId, storedUsername, storedPassword,
- storedEmail, section, year, fullName, level,
- new StudentData.StudentSetting(setting),
- new StudentData.StudentUpgrade(upgrade),
- coins, customization,
- new StudentData.StudentHighscore(levelHS, forestDay, forestNight, farm, city),
- new StudentData.DataLeaderboard(levelLB,
- await GetActivityLB("City"), await GetActivityLB("Farm"),
- await GetActivityLB("ForestDay"), await GetActivityLB("ForestNight")),
- teacher, isFirstTime
- );
- taskCompletionSource.SetResult(studentData);
- Debug.Log("Login successful for user: " + storedUsername);
- return;
- }
- taskCompletionSource.SetResult(null);
- });
- return taskCompletionSource.Task;
- }
- private async Task<StudentData.DataLeaderboard.Activity> GetActivityLB(string stage) {
- Dictionary<string, object> scoreDict = new Dictionary<string, object>();
- Dictionary<string, object> foodDict = new Dictionary<string, object>();
- Dictionary<string, object> answerDict = new Dictionary<string, object>();
- try {
- DocumentReference lbActRef = db.Collection("Leaderboard").Document($"{stage} Score");
- DocumentSnapshot lbActSnap = await lbActRef.GetSnapshotAsync();
- foreach(var field in lbActSnap.ToDictionary())
- scoreDict.Add(field.Key, Convert.ToInt32(field.Value));
- lbActRef = db.Collection("Leaderboard").Document($"{stage} Food");
- lbActSnap = await lbActRef.GetSnapshotAsync();
- foreach(var field in lbActSnap.ToDictionary())
- foodDict.Add(field.Key, Convert.ToInt32(field.Value));
- lbActRef = db.Collection("Leaderboard").Document($"{stage} Correct Answer");
- lbActSnap = await lbActRef.GetSnapshotAsync();
- foreach(var field in lbActSnap.ToDictionary())
- answerDict.Add(field.Key, Convert.ToInt32(field.Value));
- } catch(Exception ex) {
- Debug.LogError(ex.Message);
- }
- return new StudentData.DataLeaderboard.Activity(
- scoreDict, foodDict, answerDict
- );
- }
- private Task UpdateData(DocumentReference docRef, Dictionary<string, object> data) {
- string id = DatabaseData.Instance.student.GetID();
- return docRef.UpdateAsync(data).ContinueWithOnMainThread(task =>
- {
- if(task.IsFaulted) MessagePopup.Instance.ShowMessage("WALANG INTERNET O HINDI MAKA-KONEK SA MGA GURO");
- if (task.IsCompleted)
- Debug.Log($"Game Highscore yugto updated for student ID: {id}");
- else
- Debug.LogError($"Failed to update yugto highscore for student ID: {id}: {task.Exception}");
- });
- }
- #region GAME FIREBASE
- public Task UpdateGameInfo(Dictionary<string, object> data) {
- string id = DatabaseData.Instance.student.GetID();
- DocumentReference gameRef = db.Collection(COLLECTION)
- .Document(id)
- .Collection(INFO)
- .Document(GAME_INFO);
- return UpdateData(gameRef, data);
- }
- public Task UpdateUpgrade(float scoreMult, float speed, int maxFood, int dmg, int time) {
- Dictionary<string, object> newData = new Dictionary<string, object>() {
- { "Upgrades", StudentData.StudentUpgrade.CombineAllUpgrade(
- scoreMult, speed, maxFood, dmg, time
- )}
- };
- return UpdateGameInfo(newData);
- }
- public Task UpdateSetting(int platform, int mobileControl,
- float music, float sfx, float dialogue,
- int graphic, int vfx) {
- Dictionary<string, object> newData = new Dictionary<string, object>() {
- {"Settings", StudentData.StudentSetting
- .CombineAllSetting(platform, mobileControl, music,
- sfx, dialogue, graphic, vfx)}
- };
- return UpdateGameInfo(newData);
- }
- public Task UpdateCoins(int coins) {
- return UpdateGameInfo(new Dictionary<string, object>() {
- { "Coins", coins}
- });
- }
- public Task UpdateTutorial() {
- return UpdateGameInfo(new Dictionary<string, object>() {
- { "First Time", false}
- });
- }
- public Task IncreaseLevel() {
- return UpdateGameInfo(new Dictionary<string, object>() {
- { "Level", DatabaseData.Instance.student.GetLevel()+1}
- });
- }
- public Task UpdateCharacterCuztomization(string outfit) {
- return UpdateGameInfo(new Dictionary<string, object>() {
- { "Customization", outfit}
- });
- }
- public Task UpdateYugtoHighscore(int level, int score = 0, string time = "") {
- string id = DatabaseData.Instance.student.GetID();
- DocumentReference gameRef = db.Collection(COLLECTION)
- .Document(id)
- .Collection(INFO)
- .Document(GAME_INFO)
- .Collection("Highscore")
- .Document("Level"+level);
- Dictionary<string, object> data = new Dictionary<string, object>();
- if(score != 0) data.Add("Score", score);
- if(!string.IsNullOrEmpty(time) || time != "") data.Add("Time", time);
- return UpdateData(gameRef, data);
- }
- #endregion
- #region LEADERBOARD
- public Task UpdateActivityHighscore(string stage, int score) {
- string id = DatabaseData.Instance.student.GetID();
- DocumentReference gameRef = db.Collection(COLLECTION)
- .Document(id)
- .Collection(INFO)
- .Document(GAME_INFO)
- .Collection("Highscore")
- .Document("Activity");
- Dictionary<string, object> data = new Dictionary<string, object>() {
- { stage, score }
- };
- return UpdateData(gameRef, data);
- }
- public async void CheckLeaderboardExist() {
- try
- {
- CollectionReference lbRef = db.Collection("Leaderboard");
- DocumentReference yugtoRef = lbRef.Document("Level");
- DocumentSnapshot yugtoSnapshot = await yugtoRef.GetSnapshotAsync();
- for(int i = 1; i <= YugtoLevelCount; i++) {
- // YUGTO SCORE
- yugtoRef = lbRef.Document($"Level{i} Score");
- yugtoSnapshot = await yugtoRef.GetSnapshotAsync();
- if(!yugtoSnapshot.Exists) {
- await yugtoRef.SetAsync(new Dictionary<string, object>()
- {
- {"WALA1", 0},
- {"WALA2", 0},
- {"WALA3", 0},
- {"WALA4", 0},
- {"WALA5", 0}
- });
- }
- // YUGTO TIME
- yugtoRef = lbRef.Document($"Level{i} Time");
- yugtoSnapshot = await yugtoRef.GetSnapshotAsync();
- if(!yugtoSnapshot.Exists) {
- await yugtoRef.SetAsync(new Dictionary<string, object>()
- {
- {"WALA1", "00:00:00"},
- {"WALA2", "00:00:00"},
- {"WALA3", "00:00:00"},
- {"WALA4", "00:00:00"},
- {"WALA5", "00:00:00"}
- });
- }
- }
- await CheckActivityLeaderboard("City");
- await CheckActivityLeaderboard("Farm");
- await CheckActivityLeaderboard("ForestDay");
- await CheckActivityLeaderboard("ForestNight");
- } catch(Exception ex) { Debug.LogError(ex.Message); }
- }
- public async Task UpdateLeaderboardAct(string stage,
- Dictionary<string, int> score = null,
- Dictionary<string, int> food = null,
- Dictionary<string, int> answer = null) {
- CollectionReference lbRef = db.Collection("Leaderboard");
- // SCORE
- DocumentReference actRef = lbRef.Document($"{stage} Score");
- DocumentSnapshot actSnapshot = await actRef.GetSnapshotAsync();
- if(score != null) {
- await actRef.SetAsync(score, SetOptions.Overwrite).ContinueWithOnMainThread(
- task => {
- if (task.IsFaulted) {
- MessagePopup.Instance.ShowMessage("WALANG INTERNET O HINDI MAKA-KONEK SA MGA GURO");
- Debug.LogError("Error replacing field: " + task.Exception);
- }
- else Debug.Log("Field replaced successfully.");
- }
- );
- }
- // FOOD
- actRef = lbRef.Document($"{stage} Food");
- actSnapshot = await actRef.GetSnapshotAsync();
- if(food != null) {
- await actRef.SetAsync(food, SetOptions.Overwrite).ContinueWithOnMainThread(
- task => {
- if (task.IsFaulted) {
- MessagePopup.Instance.ShowMessage("WALANG INTERNET O HINDI MAKA-KONEK SA MGA GURO");
- Debug.LogError("Error replacing field: " + task.Exception);
- }
- else Debug.Log("Field replaced successfully.");
- }
- );
- }
- // CORRECT ANSWER
- actRef = lbRef.Document($"{stage} Correct Answer");
- actSnapshot = await actRef.GetSnapshotAsync();
- if(answer != null) {
- await actRef.SetAsync(answer, SetOptions.Overwrite).ContinueWithOnMainThread(
- task => {
- if (task.IsFaulted) {
- MessagePopup.Instance.ShowMessage("WALANG INTERNET O HINDI MAKA-KONEK SA MGA GURO");
- Debug.LogError("Error replacing field: " + task.Exception);
- }
- else Debug.Log("Field replaced successfully.");
- }
- );
- }
- }
- public async Task UpdateLeaderboardLevel(int level,
- Dictionary<string, object> score = null,
- Dictionary<string, object> time = null) {
- CollectionReference lbRef = db.Collection("Leaderboard");
- DocumentReference actRef = lbRef.Document($"Level{level} Score");
- DocumentSnapshot actSnapshot = await actRef.GetSnapshotAsync();
- if(score != null) {
- await actRef.SetAsync(score, SetOptions.Overwrite).ContinueWithOnMainThread(
- task => {
- if (task.IsFaulted) {
- MessagePopup.Instance.ShowMessage("WALANG INTERNET O HINDI MAKA-KONEK SA MGA GURO");
- Debug.LogError("Error replacing field: " + task.Exception);
- }
- else Debug.Log("Field replaced successfully.");
- }
- );
- }
- if(time == null) return;
- actRef = lbRef.Document($"Level{level} Time");
- actSnapshot = await actRef.GetSnapshotAsync();
- await actRef.SetAsync(time, SetOptions.Overwrite).ContinueWithOnMainThread(
- task => {
- if (task.IsFaulted) {
- MessagePopup.Instance.ShowMessage("WALANG INTERNET O HINDI MAKA-KONEK SA MGA GURO");
- Debug.LogError("Error replacing field: " + task.Exception);
- }
- else Debug.Log("Field replaced successfully.");
- }
- );
- }
- private async Task CheckActivityLeaderboard(string stage) {
- CollectionReference lbRef = db.Collection("Leaderboard");
- DocumentReference actRef = lbRef.Document($"{stage} Score");
- DocumentSnapshot actSnapshot = await actRef.GetSnapshotAsync();
- if(!actSnapshot.Exists) {
- await actRef.SetAsync(new Dictionary<string, object>()
- {
- {"WALA1", 0},
- {"WALA2", 0},
- {"WALA3", 0},
- {"WALA4", 0},
- {"WALA5", 0}
- });
- }
- actRef = lbRef.Document($"{stage} Correct Answer");
- actSnapshot = await actRef.GetSnapshotAsync();
- if(!actSnapshot.Exists) {
- await actRef.SetAsync(new Dictionary<string, object>()
- {
- {"WALA1", 0},
- {"WALA2", 0},
- {"WALA3", 0},
- {"WALA4", 0},
- {"WALA5", 0}
- });
- }
- actRef = lbRef.Document($"{stage} Food");
- actSnapshot = await actRef.GetSnapshotAsync();
- if(!actSnapshot.Exists) {
- await actRef.SetAsync(new Dictionary<string, object>()
- {
- {"WALA1", 0},
- {"WALA2", 0},
- {"WALA3", 0},
- {"WALA4", 0},
- {"WALA5", 0}
- });
- }
- }
- #endregion
- #region Activities/TODO
- public async Task<TodoData> GetTodo(string teacherName, string section, string studentName)
- {
- if (db == null) db = FirebaseFirestore.DefaultInstance;
- CollectionReference todoRef = db.Collection("Activities").Document(teacherName).Collection(section);
- TaskCompletionSource<TodoData> taskCompletionSource = new TaskCompletionSource<TodoData>();
- // Fetch the list of todos for the section
- QuerySnapshot todoSnapshot = await todoRef.GetSnapshotAsync();
- if (todoSnapshot == null || todoSnapshot.Documents.Count() == 0)
- {
- Debug.Log("No sections found.");
- return null;
- }
- List<TodoData.Todo> todos = new List<TodoData.Todo>();
- int done = 0;
- int notDone = 0;
- int all = 0;
- foreach (DocumentSnapshot todoDoc in todoSnapshot.Documents)
- {
- if (todoDoc.GetValue<bool>("isClosed")) continue;
- if (DateChecker.IsPastDue(todoDoc.GetValue<string>("Due"))) continue;
- if (!DateChecker.HasStarted(todoDoc.GetValue<string>("Start"))) continue;
- // Get Base Values
- int maxAttempts = todoDoc.GetValue<int>("MaxAttemps");
- string start = todoDoc.GetValue<string>("Start");
- string due = todoDoc.GetValue<string>("Due");
- string title = todoDoc.GetValue<string>("Title");
- string type = todoDoc.GetValue<string>("Type");
- int attempted = 0;
- int DefaultPoint = 0;
- DefaultPoint = todoDoc.GetValue<int>("Default Point");
- // Fetch the submission data for the student
- CollectionReference submissionRef = todoDoc.Reference.Collection("Submissions");
- DocumentSnapshot submissionSnap = await submissionRef.Document(studentName).GetSnapshotAsync();
- all++;
- if (submissionSnap.Exists)
- {
- attempted = submissionSnap.GetValue<int>("Attemps");
- if(attempted > 0) done++;
- else notDone++;
- if (attempted >= maxAttempts) continue;
- }
- // Fetch the questions
- CollectionReference questionRef = todoDoc.Reference.Collection("Questions");
- QuerySnapshot questionSnapshot = await questionRef.GetSnapshotAsync();
- if (questionSnapshot == null || questionSnapshot.Documents.Count() == 0)
- {
- Debug.Log("No questions found.");
- continue;
- }
- List<TodoData.Todo.Questions> questionList = new List<TodoData.Todo.Questions>();
- foreach (DocumentSnapshot questionDoc in questionSnapshot.Documents)
- {
- int CustomPoint = questionDoc.GetValue<int>("Custom Point");
- questionList.Add(new TodoData.Todo.Questions(
- questionDoc.GetValue<string>("Question"),
- questionDoc.GetValue<string>("Answer"),
- new List<string> {
- questionDoc.GetValue<string>("Wrong 1"),
- questionDoc.GetValue<string>("Wrong 2"),
- questionDoc.GetValue<string>("Wrong 3")
- },
- questionDoc.Id, CustomPoint == -1 ? DefaultPoint : CustomPoint
- ));
- }
- // Add the todo to the list
- todos.Add(new TodoData.Todo(questionList, maxAttempts, attempted, start,
- due, title, type, todoDoc.Id, DefaultPoint));
- }
- TodoData todoData = new TodoData(todos, done, notDone, all);
- return todoData;
- }
- public async Task SetSubmissions(string todoID, TodoData.Todo todo) {
- if (db == null) db = FirebaseFirestore.DefaultInstance;
- try {
- DatabaseData.StudentData studDB = DatabaseData.Instance.student;
- List<TodoData.Todo.Questions> questions = todo.Data;
- DocumentReference todoRef = db.Collection("Activities")
- .Document(studDB.GetTeacher())
- .Collection(studDB.GetSection())
- .Document(todoID)
- .Collection("Submissions")
- .Document(studDB.GetFullName());
- int TotalCorrect = 0;
- int TotalWrong = 0;
- int TotalScore = 0;
- for(int i = 0; i < questions.Count; i++) {
- TodoData.Todo.Questions question = questions[i];
- if(question?.isCorrect == true) {
- TotalCorrect++;
- TotalScore += question.CustomPoint;
- }
- else TotalWrong++;
- await todoRef.Collection("Questions").Document(question.QuestioID).SetAsync(new Dictionary<string, object>() {
- { "Question", question.Question},
- { "Answer", question.Answer},
- { "Wrong 1", question.Wrong[0]},
- { "Wrong 2", question.Wrong[1]},
- { "Wrong 3", question.Wrong[2]},
- { "Selected Answer", question.SelectedAnswer},
- { "IsCorrect", question.isCorrect}
- });
- }
- await todoRef.SetAsync(new Dictionary<string, object>()
- {
- { "Attemps", todo.Attempted+1 },
- { "Total Correct", TotalCorrect },
- { "Total Wrong", TotalWrong },
- { "Total Score", TotalScore }
- });
- } catch(Exception ex) { Debug.LogError(ex.Message); }
- }
- #endregion
- }
Advertisement
Add Comment
Please, Sign In to add comment