Ejemplo n.º 1
0
 public static InitializerInfoBase GetInfo(GlobalItem item)
 {
     if (item is IInitializableObject)
     {
         IInitializableObject initializable = (IInitializableObject)item;
         if ((initializable.Initializer == null) || String.IsNullOrWhiteSpace(initializable.Initializer.Source))
         {
             return(null);
         }
         return(new InitializerInfo(initializable));
     }
     if (item is Pool)
     {
         Pool pool = (Pool)item;
         List <InitializerInfoBase> values = new List <InitializerInfoBase>();
         foreach (PoolValue value in pool.Values)
         {
             if ((value.Initializer != null) && !String.IsNullOrWhiteSpace(value.Initializer.Source))
             {
                 values.Add(new InitializerInfo(value));
             }
         }
         if (values.Count == 0)
         {
             return(null);
         }
         values.Sort();
         InitializerInfoContainer info = new InitializerInfoContainer(pool.Name, "enum");
         info.SortOrder = Math.Truncate(values[0].SortOrder);
         info.Items.AddRange(values);
         info.ResortChildItems();
         return(info);
     }
     throw new ArgumentException(String.Format("Unknown object: {0}", item));
 }
Ejemplo n.º 2
0
        public async Task UnregisterAsync(IInitializableObject initializable)
        {
            if (_initializablesHolder.Contains(initializable) == false)
            {
                FLog.Warning(CLASS_TYPE.Name, $"{initializable.Name} has not registered but wants to unregister itself.");

                return;
            }

            await initializable.UninitializeAsync();

            _registeredObjects.Remove(initializable);

            _initializablesHolder.Remove(initializable);

            if (initializable is ITickableObject tickable)
            {
                if (_ticksHolder.Contains(tickable))
                {
                    UnregisterTick(tickable);
                }

                if (_lateTicksHolder.Contains(tickable))
                {
                    UnregisterLateTick(tickable);
                }

                if (_fixedTicksHolder.Contains(tickable))
                {
                    UnregisterFixedTick(tickable);
                }
            }
        }
Ejemplo n.º 3
0
            public InitializerInfo(IInitializableObject owner)
                : base(InitializerInfo.GetHeading(owner), InitializerInfo.GetImageKey(owner))
            {
                if (owner == null)
                {
                    throw new ArgumentNullException();
                }
                if ((owner.Initializer == null) || String.IsNullOrWhiteSpace(owner.Initializer.Source))
                {
                    throw new ArgumentException();
                }

                this.Owner       = owner;
                this.Initializer = owner.Initializer;
                this.SortOrder   = this.Initializer.SortKey;
            }
Ejemplo n.º 4
0
 protected static string GetHeading(IInitializableObject owner)
 {
     if (owner is Class)
     {
         return(((Class)owner).Name);
     }
     if (owner is Global)
     {
         return(((Global)owner).Name);
     }
     if (owner is PoolValue)
     {
         return(((PoolValue)owner).Name);
     }
     throw new ArgumentException(String.Format("Unknown object: {0}", owner));
 }
Ejemplo n.º 5
0
 protected static string GetImageKey(IInitializableObject owner)
 {
     if (owner is Class)
     {
         return("class");
     }
     if (owner is Global)
     {
         return("structure");
     }
     if (owner is PoolValue)
     {
         return("field");
     }
     throw new ArgumentException(String.Format("Unknown object: {0}", owner));
 }
Ejemplo n.º 6
0
        public void Register(IInitializableObject initializable)
        {
            try
            {
                if (_initializablesHolder.Contains(initializable))
                {
                    FLog.Warning(CLASS_TYPE.Name, $"{initializable.Name} has already registered");

                    return;
                }

                if (HasInitialized == false)
                {
                    if (initializable is IService && (initializable is IGameService) == false)
                    {
                        _registeredObjects.Add(initializable);
                    }
                    else
                    {
                        _pendingRegiserationRequests.Add(initializable);
                    }
                }
                else
                {
                    if (initializable is IService && (initializable is IGameService) == false)
                    {
                        FLog.Error(CLASS_TYPE.Name, $"{initializable.Name} is a service and should not be registered during game play, use GameStartup to register them. Registration aborted.");

                        return;
                    }

                    _pendingRegiserationRequests.Add(initializable);
                }

                _initializablesHolder.Add(initializable);
            }
            catch (Exception exception)
            {
                FLog.Error(nameof(MDreamwork), exception.Message);
            }
        }
Ejemplo n.º 7
0
        private async Task BeginPlayAsync(IReadOnlyList <IInitializableObject> list)
        {
            for (int i = 0; i < list.Count; i++)
            {
                try
                {
                    IInitializableObject initializable = list[i];

                    if (initializable.HasBeganPlay)
                    {
                        continue;
                    }

                    await initializable.BeginPlayAsync();
                }
                catch (Exception exception)
                {
                    FLog.Error(CLASS_TYPE.Name, exception);
                }
            }
        }
Ejemplo n.º 8
0
 int IInitializableObject.CompareTo(IInitializableObject other)
 {
     return this.Initializer.SortKey.CompareTo(other.Initializer.SortKey);
 }
Ejemplo n.º 9
0
 int IInitializableObject.CompareTo(IInitializableObject other)
 {
     return(this.Initializer.SortKey.CompareTo(other.Initializer.SortKey));
 }