public async Task GetOtherWheatStatesAsync(bool forceStatesFromOffline) { // Tries to download wheat-states from firebase: // - doesn't work -> gets states from disk // - when getting from firebase finishes -> commits the data only when disk-data haven't already been used // NOTE: No need to be worried about `DataStorage.OtherWheatStatesOnline` race conditions -> this method // will always be called on UI thread -> two calls can't interleave. if (!forceStatesFromOffline) { var onlineStates = await FireBaseConnector.GetStatesFromFirebaseAsync(); Debug.Log($"Downloaded {onlineStates?.Count} states."); if (DataStorage.OtherWheatStatesOnline == null && onlineStates != null) { DataStorage.OtherWheatStatesOnline = onlineStates; StatesFromOnline = true; return; } } var offlineStates = await FireBaseConnector.GetStatesFromDiskAsync("OfflineFields/klas-struggle-3d476-export"); Debug.Log($"Read from disk {offlineStates?.Count} states."); if (offlineStates == null) { offlineStates = new List <WheatState>(); Debug.LogWarning("Couldn't get other wheat states from online/disk."); } DataStorage.OtherWheatStatesOnline = offlineStates; StatesFromOnline = true; return; }
public GameController() { FireBaseConnector = new FireBaseConnector(); DataStorage = new DataStorage(); }