public IEnumerator Load(IAssetRequest <Texture2D> assetRequest)
        {
            if (!GameDatabase.Instance.IsReady())
            {
                FARLogger.Warning("Trying to load textures before GameDatabase has been loaded");
                assetRequest.State = Progress.Error;
                assetRequest.OnError();
                yield break;
            }

            assetRequest.State = Progress.InProgress;
            try
            {
                FARLogger.DebugFormat("Getting texture {0} from GameDatabase", assetRequest.Url);
                Texture2D texture = GameDatabase.Instance.GetTexture(assetRequest.Url, false);
                assetRequest.State = Progress.Completed;
                assetRequest.OnLoad(texture);
            }
            catch (Exception e)
            {
                FARLogger.Exception(e, $"While loading texture {assetRequest.Url} from game database:");
                assetRequest.State = Progress.Error;
                assetRequest.OnError();
            }
        }
Пример #2
0
        private IEnumerator DoLoad(Action callback)
        {
            // offload to another thread and wait for it to complete
            Task task = Task.Factory.StartNew(InitTask);

            yield return(new WaitUntil(() => task.IsCompleted));

            if (task.Exception != null)
            {
                FARLogger.Exception(task.Exception, "Exception while loading FAR addons:");
                yield break;
            }

            // do instantiation in the main thread in case any of the types are Unity objects
            FARLogger.Debug("Instantiating FAR addons");
            foreach (Pair <FARAddonAttribute, Type> pair in AddonTypes)
            {
                yield return(SetupType(pair.Second, pair.First.Persistant, AddonObjects));

                yield return(null);
            }

            FARLogger.Debug("Instantiating Reloadable types");
            foreach (Type type in ReloadableTypes)
            {
                yield return(SetupType(type, true, ReloadableObjects));

                yield return(null);
            }

            callback?.Invoke();
        }
 public static bool TryParseEnum(string str, Type type, out Enum value)
 {
     value = default;
     try
     {
         value = Enum.Parse(type, str, true) as Enum;
         return(true);
     }
     catch (Exception e)
     {
         FARLogger.Exception(e, "While parsing enum");
         return(false);
     }
 }
 public static bool TryParseGuid(string str, out Guid g)
 {
     try
     {
         g = new Guid(str);
         return(true);
     }
     catch (Exception e)
     {
         FARLogger.Exception(e, "While trying to parse Guid");
         g = Guid.Empty;
         return(false);
     }
 }
        private static IEnumerator DoSetup()
        {
            using LoadGuard guard = Guard(Operation.None);

            Task task = Task.Factory.StartNew(() => ConfigReflection.Instance.Initialize());

            while (!task.IsCompleted)
            {
                yield return(null);
            }

            if (task.Exception != null)
            {
                FARLogger.Exception(task.Exception, "Exception while setting up config");
            }
        }
        public static bool IsAbsolute(string path, bool retry = true)
        {
            try
            {
                return(Path.IsPathRooted(path));
            }
            catch (ArgumentException e)
            {
                if (retry)
                {
                    FARLogger.Warning($"Invalid path: {path}, retrying");
                    return(IsAbsolute(path.Replace("\\", "/"), false));
                }

                FARLogger.Exception(e, $"Exception in path: {path}");
                throw;
            }
        }
        private IEnumerator DoLoadConfig()
        {
            if (loading)
            {
                yield break;
            }

            while (saving)
            {
                yield return(null);
            }

            using LoadGuard guard = Guard(Operation.Loading);
            Task task = Task.Factory.StartNew(LoadConfigs);

            yield return(new WaitWhile(() => !task.IsCompleted));

            if (task.Exception != null)
            {
                FARLogger.Exception(task.Exception, "Exception while loading config");
            }
        }
        public static IEnumerator SaveAll()
        {
            if (Instance.saving)
            {
                yield break;
            }

            while (Instance.loading)
            {
                yield return(null);
            }

            using LoadGuard guard = Guard(Operation.Saving);

            Task task = Task.Factory.StartNew(Save);

            yield return(new WaitUntil(() => task.IsCompleted));

            if (task.Exception != null)
            {
                FARLogger.Exception(task.Exception, "Exception while saving up configs");
            }
        }