예제 #1
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);
        }
예제 #2
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;
            }
        }