Example #1
0
        public static List <EntityTypes.ClassInfo> GetClassInfo(this EntityType entityType)
        {
            List <EntityTypes.ClassInfo> result = new List <EntityTypes.ClassInfo>();

            if (entityType == null)
            {
                return(result);
            }
            for (EntityTypes.ClassInfo classInfo = entityType.ClassInfo; classInfo != null; classInfo = classInfo.BaseClassInfo)
            {
                result.Add(classInfo);
            }
            return(result);
        }
Example #2
0
 /// <summary>
 /// Whether to check up there is a link to object.
 /// </summary>
 /// <remarks>
 /// This method it is necessary to redirect to all of you created
 /// <b>MapObject.MapObjectCreateObjectCollection</b> objects and
 /// for all custom not serializable <b>EntityType</b> fields.
 /// It is necessary for normal work of Resource Editor.
 /// </remarks>
 /// <param name="obj">The cheched object.</param>
 /// <returns><b>true</b> if a link to object is exists; otherwise, <b>false</b>.</returns>
 protected internal virtual bool OnIsExistsReferenceToObject(object obj)
 {
     for (EntityTypes.ClassInfo baseClassInfo = this.ClassInfo; baseClassInfo != null; baseClassInfo = baseClassInfo.BaseClassInfo)
     {
         foreach (EntityTypes.ClassInfo.EntityTypeSerializableFieldItem current in baseClassInfo.EntityTypeSerializableFields)
         {
             bool flag = current.Field.GetValue(this) == obj;
             if (flag)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Example #3
0
        internal bool loadEntityTypeFromTextBlock(TextBlock block)
        {
            string errorString = string.Format("File path: \"{0}\"", this.FilePath);

            for (EntityTypes.ClassInfo baseClassInfo = this.ClassInfo; baseClassInfo != null; baseClassInfo = baseClassInfo.BaseClassInfo)
            {
                foreach (EntityTypes.ClassInfo.EntityTypeSerializableFieldItem current in baseClassInfo.EntityTypeSerializableFields)
                {
                    bool failure = !EntityHelper.LoadFieldValue(false, this, current.Field, block, errorString);
                    if (failure)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Example #4
0
        /// <summary>
        /// Replaces the link of all objects to another.
        /// </summary>
        /// <remarks>
        /// This method it is necessary to redirect to all of you created
        /// <b>MapObject.MapObjectCreateObjectCollection</b> objects and
        /// for all custom not serializable <b>EntityType</b> fields.
        /// It is necessary for normal work of Resource Editor.
        /// </remarks>
        /// <param name="obj">The source link to object.</param>
        /// <param name="newValue">The new link to object.</param>
        protected internal virtual List <EntityTypes.ClassInfo.EntityTypeSerializableFieldItem> OnChangeReferencesToObject(object obj, object newValue)
        {
            List <EntityTypes.ClassInfo.EntityTypeSerializableFieldItem> result = new List <EntityTypes.ClassInfo.EntityTypeSerializableFieldItem>();

            for (EntityTypes.ClassInfo baseClassInfo = this.ClassInfo; baseClassInfo != null; baseClassInfo = baseClassInfo.BaseClassInfo)
            {
                foreach (EntityTypes.ClassInfo.EntityTypeSerializableFieldItem current in baseClassInfo.EntityTypeSerializableFields)
                {
                    bool flag = current.Field.GetValue(this) == obj;
                    if (flag)
                    {
                        current.Field.SetValue(this, newValue);
                        result.Add(current);
                    }
                }
            }
            return(result);
        }
Example #5
0
        public Entity _CreateInternal(EntityType type, Entity parent, uint uin, uint networkUIN)
        {
            if (type == null)
            {
                Log.Fatal("Entities: _CreateInternal: type == null.");
            }
            EntityTypes.ClassInfo classInfo = type.ClassInfo;
            if (classInfo == null)
            {
                Log.Fatal("Entities: _CreateInternal: classInfo == null.");
            }
            Type            entityClassType = classInfo.EntityClassType;
            ConstructorInfo constructor     = entityClassType.GetConstructor(new Type[0]);
            Entity          entity          = (Entity)constructor.Invoke(new object[] {});

            entity.parent     = parent;
            entity.createTime = this.TickTime;
            for (EntityTypes.ClassInfo classInfo2 = classInfo; classInfo2 != null; classInfo2 = classInfo2.baseClassInfo)
            {
                if (classInfo2.fieldInfo != null)
                {
                    classInfo2.fieldInfo.SetValue(entity, type);
                }
            }
            this.AddToSystem(entity, uin, networkUIN);
            entity.OnPreCreate();
            if (CreateEntity != null)
            {
                CreateEntity(entity);
            }
            if (EntitySystemWorld.Instance.IsServer() && entity.Type.NetworkType == EntityNetworkTypes.Synchronized)
            {
                //SynchronizeEntityCreation(entity, null);
            }
            return(entity);
        }
Example #6
0
        protected virtual bool OnLoad(TextBlock block)
        {
            if (block.IsAttributeExist("logicClass"))
            {
                this.logicClass = (Entities.Instance.GetLoadingEntityBySerializedUIN(uint.Parse(block.GetAttribute("logicClass"))) as LogicClass);
            }
            if (this.logicObject == null && this.logicClass != null)
            {
                this.CreateLogicObject();
                TextBlock textBlock = block.FindChild("logicObject");
                if (textBlock != null && !this.logicObject.A(textBlock))
                {
                    return(false);
                }
            }
            string text = this.Type.Name;

            if (this.name != "")
            {
                text += string.Format(" ({0})", this.name);
            }
            text = string.Format("Entity: \"{0}\"", text);
            for (EntityTypes.ClassInfo classInfo = this.Type.ClassInfo; classInfo != null; classInfo = classInfo.BaseClassInfo)
            {
                foreach (EntityTypes.ClassInfo.EntitySerializableFieldItem current in classInfo.EntitySerializableFields)
                {
                    if (/*EntitySystemWorld.Instance.isEntitySerializable(current.SupportedSerializationTypes) &&*/ !EntityHelper.LoadFieldValue(true, this, current.Field, block, text))
                    {
                        return(false);
                    }
                }
            }
            string text2 = null;

            if (block.IsAttributeExist("subscriptionsToDeletionEvent"))
            {
                text2 = block.GetAttribute("subscriptionsToDeletionEvent");
            }
            else if (block.IsAttributeExist("relationships"))
            {
                text2 = block.GetAttribute("relationships");
            }
            else if (block.IsAttributeExist("relations"))
            {
                text2 = block.GetAttribute("relations");
            }
            if (text2 != null)
            {
                string[] array = text2.Split(new char[]
                {
                    ' '
                }, StringSplitOptions.RemoveEmptyEntries);
                this.subscriptionsToDeletionEvent = new List <Entity>(Math.Max(array.Length, 4));
                string[] array2 = array;
                for (int i = 0; i < array2.Length; i++)
                {
                    string s = array2[i];
                    Entity loadingEntityBySerializedUIN = Entities.Instance.GetLoadingEntityBySerializedUIN(uint.Parse(s));
                    if (loadingEntityBySerializedUIN != null)
                    {
                        this.subscriptionsToDeletionEvent.Add(loadingEntityBySerializedUIN);
                    }
                }
            }
            TextBlock textBlock2 = block.FindChild("extendedProperties");

            if (textBlock2 != null)
            {
                string typeClass = textBlock2.GetAttribute("class");
                Type   type      = EntitySystemWorld.Instance.FindEntityClassType(typeClass);
                if (type == null)
                {
                    Log.Error("Extended properties class \"{0}\" not exists.", typeClass);
                    return(false);
                }
                this.CreateExtendedProperties(type);
                if (!this.extendedProperties.OnLoad(textBlock2))
                {
                    return(false);
                }
            }
            if (block.IsAttributeExist("textUserData"))
            {
                string attribute2 = block.GetAttribute("textUserData");
                if (!string.IsNullOrEmpty(attribute2))
                {
                    this.SetTag("TextUserData", attribute2);
                }
            }
            return(true);
        }
Example #7
0
        protected virtual void OnSave(TextBlock block)
        {
            block.SetAttribute("type", Type.Name);
            block.SetAttribute("uin", uin.ToString());

            if (!(this is LogicComponent))
            {
                block.SetAttribute("classPrompt", Type.ClassInfo.entityClassType.Name);
            }

            if (subscriptionsToDeletionEvent != null && subscriptionsToDeletionEvent.Count != 0)
            {
                string _subscriptionsToDeletionEvent = string.Join(" ", subscriptionsToDeletionEvent.Select(_x => _x.UIN));
                block.SetAttribute("subscriptionsToDeletionEvent", _subscriptionsToDeletionEvent);
            }

            string text = Type.Name;

            if (this.name != "")
            {
                text += string.Format(" ({0})", this.name);
            }

            text = string.Format("Entity: \"{0}\"", text);

            for (EntityTypes.ClassInfo classInfo = Type.ClassInfo; classInfo != null; classInfo = classInfo.BaseClassInfo)
            {
                foreach (EntityTypes.ClassInfo.EntitySerializableFieldItem current2 in classInfo.EntitySerializableFields)
                {
                    //if (EntitySystemWorld.Instance.IsEntityFieldSerializable(current2.SupportedSerializationTypes))
                    {
                        if (!EntityHelper.SaveFieldValue(true, this, current2.Field, block, text))
                        {
                            return;
                        }
                    }
                }
            }
            if (logicClass != null)
            {
                block.SetAttribute("logicClass", logicClass.UIN.ToString());
            }

            if (extendedProperties != null)
            {
                TextBlock textBlock = block.AddChild("extendedProperties");
                textBlock.SetAttribute("class", this.extendedProperties.GetType().Name);
                extendedProperties.OnSave(textBlock);
            }

            if (logicObject != null)
            {
                TextBlock logicObjectBlock = block.FindChild("logicObject");
                if (logicObjectBlock == null)
                {
                    logicObjectBlock = block.AddChild("logicObject");
                }

                logicObject.OnSave(logicObjectBlock);
                return;
            }
        }