コード例 #1
0
        private void ProcessResults(WaitableTask actionResult, TaskResult <string> serverResult, EncounterMetadata metadata)
        {
            if (serverResult.IsError())
            {
                actionResult.SetError(serverResult.Exception);
                return;
            }

            Debug.Log("Returned text from PHP: \n" + serverResult.Value);
            if (string.IsNullOrWhiteSpace(serverResult.Value))
            {
                actionResult.SetError(new Exception("No text returned from the server."));
            }
            else if (!int.TryParse(serverResult.Value, out int recordNumber))
            {
                actionResult.SetError(new Exception(serverResult.Value));
            }
            else if (recordNumber != metadata.RecordNumber)
            {
                actionResult.SetError(new Exception("Did not get the correct metadata from the server."));
            }
            else
            {
                actionResult.SetCompleted();
            }
        }
コード例 #2
0
        protected virtual void ProcessResults(WaitableTask result, TaskResult <string> serverOutput)
        {
            if (serverOutput == null || serverOutput.IsError())
            {
                result.SetError(serverOutput.Exception);
                return;
            }

            var output = serverOutput.Value.Trim();

            if (output.StartsWith("1"))
            {
                result.SetCompleted();
                return;
            }

            string errorStart = "-1|";

            if (output.StartsWith(errorStart, StringComparison.InvariantCultureIgnoreCase))
            {
                var encounterLock = parser.Deserialize(output.Substring(errorStart.Length));
                result.SetError(new EncounterAlreadyLockedException(encounterLock));
                return;
            }

            result.SetError(new Exception("Could not unlock the encounter."));
        }
コード例 #3
0
        private void ProcessResults(WaitableTask <User> result, TaskResult <string> serverResult)
        {
            if (serverResult.IsError() || string.IsNullOrWhiteSpace(serverResult.Value))
            {
                result.SetError(serverResult.Exception);
                return;
            }

            var user = UserDeserializer.Deserialize(serverResult.Value);

            if (user == null)
            {
                result.SetError(new Exception($"Could not parse user: {serverResult.Value}"));
            }
            else
            {
                result.SetResult(user);
            }
        }
コード例 #4
0
 private void CopyValue(TaskResult source, WaitableTask destination)
 {
     if (source.IsError())
     {
         destination.SetError(source.Exception);
     }
     else
     {
         destination.SetCompleted();
     }
 }
コード例 #5
0
 protected virtual void SetFileResult(TaskResult <string> serverResult, WaitableTask <string> fileText)
 {
     if (serverResult.IsError())
     {
         fileText.SetError(serverResult.Exception);
     }
     else
     {
         fileText.SetResult(serverResult.Value);
     }
 }
コード例 #6
0
 protected void ProcessWebrequest(UnityWebRequest webRequest, WaitableTask <string> result)
 {
     try {
         var serverResult = GetResults(webRequest);
         webRequest.Dispose();
         result.SetResult(serverResult);
     } catch (WebException webException) {
         webRequest.Dispose();
         result.SetError(webException);
     }
 }
コード例 #7
0
        private void ProcessResults(WaitableTask <List <EncounterMetadata> > result, TaskResult <string> serverOutput)
        {
            if (serverOutput == null || serverOutput.IsError())
            {
                result.SetError(serverOutput.Exception);
                return;
            }

            var metadatas = parser.Deserialize(serverOutput.Value);

            result.SetResult(metadatas);
        }
コード例 #8
0
        protected void SetEncounters(TaskResult <string> serverResult)
        {
            if (demoEncounters == null || demoEncounters.IsCompleted() || serverResult.IsError())
            {
                demoEncounters.SetError(new Exception("Could not get demo encounters from file."));
                return;
            }

            var splitChars = new char[] { '\n', '\r' };
            var encounters = serverResult.Value.Split(splitChars, StringSplitOptions.RemoveEmptyEntries);

            demoEncounters.SetResult(encounters);
        }
コード例 #9
0
        protected virtual void SetUserEncounter(WaitableTask <UserEncounter> result, User user, TaskResult <IMenuEncountersInfo> encounters, int recordNumber)
        {
            if (encounters.IsError())
            {
                result.SetError(encounters.Exception);
                return;
            }

            foreach (var encounter in encounters.Value.GetEncounters())
            {
                var typedMetadata = encounter.GetLatestTypedMetada();
                if (typedMetadata.Value.RecordNumber != recordNumber)
                {
                    continue;
                }

                ImageHolder.HoldImage(typedMetadata.Value.Sprite);
                var userEncounter = EncounterReader.GetUserEncounter(user, typedMetadata.Value, encounter.Status, typedMetadata.Key);
                userEncounter.CopyValueWhenCompleted(result);
                return;
            }

            result.SetError(new Exception("Could not find an encounter with the given record number."));
        }
コード例 #10
0
        protected virtual void ProcessResults(WaitableTask actionResult, TaskResult <string> serverResult, EncounterMetadata metadata)
        {
            if (serverResult.IsError())
            {
                actionResult.SetError(serverResult.Exception);
                return;
            }

            Debug.Log("Returned text from PHP: \n" + serverResult.Value);
            if (string.IsNullOrWhiteSpace(serverResult.Value))
            {
                actionResult.SetError(new Exception("No text returned from the server."));
                return;
            }

            var splitStr = serverResult.Value.Split('|');

            if (int.TryParse(splitStr[0], out var recordNumber))
            {
                metadata.RecordNumber = recordNumber;
            }

            actionResult.SetCompleted();
        }
コード例 #11
0
        protected virtual void ProcessResults(User user, WaitableTask <IMenuEncountersInfo> result, TaskResult <List <MenuEncounter> > menuEncounters)
        {
            if (menuEncounters.Value == null)
            {
                result.SetError(null);
                return;
            }

            var menuEncountersInfo = new MenuEncountersInfo(user);

            foreach (var menuEncounter in menuEncounters.Value)
            {
                menuEncountersInfo.AddEncounter(menuEncounter);
            }

            result.SetResult(menuEncountersInfo);
        }
コード例 #12
0
        private void ProcessResults(WaitableTask <List <EncounterMetadata> > result, TaskResult <string[]> fileTexts)
        {
            if (fileTexts == null)
            {
                result.SetError(null);
                return;
            }

            var metadatas = new List <EncounterMetadata>();

            foreach (var fileText in fileTexts.Value)
            {
                var metadata = parser.Deserialize(fileText);
                if (metadata != null)
                {
                    metadatas.Add(metadata);
                }
            }

            result.SetResult(metadatas);
        }
コード例 #13
0
        protected virtual void CompleteMenuEncountersInfoTask(WaitableTask <IMenuEncountersInfo> task,
                                                              TaskResult <IMenuEncountersInfo> result, UserEncounter userEncounter)
        {
            if (userEncounter?.Status != null)
            {
                userEncounter.Status.BasicStatus.Completed = userEncounter.Status.ContentStatus.Read;
            }

            if (result.IsError())
            {
                task.SetError(result.Exception);
                return;
            }

            if (result.Value == null)
            {
                task.SetResult(null);
                return;
            }

            foreach (var encounter in result.Value.GetEncounters())
            {
                if (encounter.GetLatestMetadata().RecordNumber != userEncounter.Data.Metadata.RecordNumber)
                {
                    continue;
                }

                if (userEncounter.Status != null)
                {
                    encounter.Status = userEncounter.Status.BasicStatus;
                }
                else
                {
                    encounter.Status = new EncounterBasicStatus();
                }
                break;
            }

            task.SetResult(result.Value);
        }
コード例 #14
0
        protected virtual void ProcessResults(
            WaitableTask <Dictionary <int, EncounterEditLock> > result,
            TaskResult <string> serverOutput)
        {
            if (serverOutput == null || serverOutput.IsError())
            {
                result.SetError(serverOutput.Exception);
                return;
            }

            var locks          = parser.Deserialize(serverOutput.Value);
            var lockDictionary = new Dictionary <int, EncounterEditLock>();

            foreach (var encounterLock in locks)
            {
                if (!lockDictionary.ContainsKey(encounterLock.RecordNumber))
                {
                    lockDictionary.Add(encounterLock.RecordNumber, encounterLock);
                }
            }
            result.SetResult(lockDictionary);
        }
コード例 #15
0
        protected virtual void ProcessResults(WaitableTask <List <MenuEncounter> > result,
                                              WaitableTask <Dictionary <int, Dictionary <SaveType, EncounterMetadata> > > metadataGroups,
                                              WaitableTask <Dictionary <int, EncounterEditLock> > locks,
                                              WaitableTask <Dictionary <int, EncounterBasicStatus> > statuses)
        {
            if (result.IsCompleted() || !metadataGroups.IsCompleted() || !statuses.IsCompleted() || !locks.IsCompleted())
            {
                return;
            }

            if (metadataGroups.Result.Value == null)
            {
                result.SetError(null);
                return;
            }

            var menuEncounters = new List <MenuEncounter>();

            foreach (var metadataGroup in metadataGroups.Result.Value)
            {
                menuEncounters.Add(GetMenuEncounter(metadataGroup, locks, statuses));
            }
            result.SetResult(menuEncounters);
        }