Exemplo n.º 1
0
        public override AFIObject CreateObject(AFIDENTID self, int nContainerID, int nGroupID, string strClassName, string strConfigIndex, AFIDataList arg)
        {
            if (!mhtObject.ContainsKey(self))
            {
                AFIObject xNewObject = new AFCObject(self, nContainerID, nGroupID, strClassName, strConfigIndex);
                mhtObject.Add(self, xNewObject);

                AFCDataList varConfigID = new AFCDataList();
                varConfigID.AddString(strConfigIndex);
                xNewObject.GetPropertyManager().AddProperty("ConfigID", varConfigID);

                AFCDataList varConfigClass = new AFCDataList();
                varConfigClass.AddString(strClassName);
                xNewObject.GetPropertyManager().AddProperty("ClassName", varConfigClass);

                if (arg.Count() % 2 == 0)
                {
                    for (int i = 0; i < arg.Count() - 1; i += 2)
                    {
                        string strPropertyName         = arg.StringVal(i);
                        AFIDataList.VARIANT_TYPE eType = arg.GetType(i + 1);
                        switch (eType)
                        {
                        case AFIDataList.VARIANT_TYPE.VTYPE_INT:
                        {
                            AFIDataList xDataList = new AFCDataList();
                            xDataList.AddInt64(arg.Int64Val(i + 1));
                            xNewObject.GetPropertyManager().AddProperty(strPropertyName, xDataList);
                        }
                        break;

                        case AFIDataList.VARIANT_TYPE.VTYPE_FLOAT:
                        {
                            AFIDataList xDataList = new AFCDataList();
                            xDataList.AddFloat(arg.FloatVal(i + 1));
                            xNewObject.GetPropertyManager().AddProperty(strPropertyName, xDataList);
                        }
                        break;

                        case AFIDataList.VARIANT_TYPE.VTYPE_DOUBLE:
                        {
                            AFIDataList xDataList = new AFCDataList();
                            xDataList.AddDouble(arg.DoubleVal(i + 1));
                            xNewObject.GetPropertyManager().AddProperty(strPropertyName, xDataList);
                        }
                        break;

                        case AFIDataList.VARIANT_TYPE.VTYPE_STRING:
                        {
                            AFIDataList xDataList = new AFCDataList();
                            xDataList.AddString(arg.StringVal(i + 1));
                            xNewObject.GetPropertyManager().AddProperty(strPropertyName, xDataList);
                        }
                        break;

                        case AFIDataList.VARIANT_TYPE.VTYPE_OBJECT:
                        {
                            AFIDataList xDataList = new AFCDataList();
                            xDataList.AddObject(arg.ObjectVal(i + 1));
                            xNewObject.GetPropertyManager().AddProperty(strPropertyName, xDataList);
                        }
                        break;

                        default:
                            break;
                        }
                    }
                }

                InitProperty(self, strClassName);
                InitRecord(self, strClassName);

                if (mhtClassHandleDel.ContainsKey(strClassName))
                {
                    ClassHandleDel xHandleDel = (ClassHandleDel)mhtClassHandleDel[strClassName];
                    if (null != xHandleDel && null != xHandleDel.GetHandler())
                    {
                        AFIObject.ClassEventHandler xHandlerList = xHandleDel.GetHandler();
                        xHandlerList(self, nContainerID, nGroupID, AFIObject.CLASS_EVENT_TYPE.OBJECT_CREATE, strClassName, strConfigIndex);
                        xHandlerList(self, nContainerID, nGroupID, AFIObject.CLASS_EVENT_TYPE.OBJECT_LOADDATA, strClassName, strConfigIndex);
                        xHandlerList(self, nContainerID, nGroupID, AFIObject.CLASS_EVENT_TYPE.OBJECT_CREATE_FINISH, strClassName, strConfigIndex);
                    }
                }

                //AFCLog.Instance.Log(AFCLog.LOG_LEVEL.DEBUG, "Create object: " + self.ToString() + " ClassName: " + strClassName + " SceneID: " + nContainerID + " GroupID: " + nGroupID);
                return(xNewObject);
            }

            return(null);
        }
Exemplo n.º 2
0
        private void LoadInstanceElement(AFILogicClass xLogicClass)
        {
            string strLogicPath = mstrRootPath;

            strLogicPath += xLogicClass.GetInstance();

            XmlDocument xmldoc = new XmlDocument();

            xmldoc.Load(strLogicPath);
            /////////////////////////////////////////////////////////////////

            XmlNode xRoot = xmldoc.SelectSingleNode("XML");

            XmlNodeList xNodeList = xRoot.SelectNodes("Entry");

            for (int i = 0; i < xNodeList.Count; ++i)
            {
                //AFCLog.Instance.Log("Class:" + xLogicClass.GetName());

                XmlNode      xNodeClass = xNodeList.Item(i);
                XmlAttribute strID      = xNodeClass.Attributes["Id"];

                //AFCLog.Instance.Log("ClassID:" + strID.Value);

                AFIElement xElement = GetElement(strID.Value);
                if (null == xElement)
                {
                    xElement = new AFCElement();
                    AddElement(strID.Value, xElement);
                    xLogicClass.AddConfigName(strID.Value);

                    XmlAttributeCollection xCollection = xNodeClass.Attributes;
                    for (int j = 0; j < xCollection.Count; ++j)
                    {
                        XmlAttribute xAttribute = xCollection[j];
                        AFIProperty  xProperty  = xLogicClass.GetPropertyManager().GetProperty(xAttribute.Name);
                        if (null != xProperty)
                        {
                            AFIDataList.VARIANT_TYPE eType = xProperty.GetDataType();
                            switch (eType)
                            {
                            case AFIDataList.VARIANT_TYPE.VTYPE_INT:
                            {
                                AFIDataList xValue = new AFCDataList();
                                xValue.AddInt64(int.Parse(xAttribute.Value));
                                xElement.GetPropertyManager().AddProperty(xAttribute.Name, xValue);
                            }
                            break;

                            case AFIDataList.VARIANT_TYPE.VTYPE_FLOAT:
                            {
                                AFIDataList xValue = new AFCDataList();
                                xValue.AddFloat(float.Parse(xAttribute.Value));
                                xElement.GetPropertyManager().AddProperty(xAttribute.Name, xValue);
                            }
                            break;

                            case AFIDataList.VARIANT_TYPE.VTYPE_DOUBLE:
                            {
                                AFIDataList xValue = new AFCDataList();
                                xValue.AddDouble(double.Parse(xAttribute.Value));
                                xElement.GetPropertyManager().AddProperty(xAttribute.Name, xValue);
                            }
                            break;

                            case AFIDataList.VARIANT_TYPE.VTYPE_STRING:
                            {
                                AFIDataList xValue = new AFCDataList();
                                xValue.AddString(xAttribute.Value);
                                AFIProperty xTestProperty = xElement.GetPropertyManager().AddProperty(xAttribute.Name, xValue);
                            }
                            break;

                            case AFIDataList.VARIANT_TYPE.VTYPE_OBJECT:
                            {
                                AFIDataList xValue = new AFCDataList();
                                xValue.AddObject(new AFIDENTID(0, int.Parse(xAttribute.Value)));
                                xElement.GetPropertyManager().AddProperty(xAttribute.Name, xValue);
                            }
                            break;

                            default:
                                break;
                            }
                        }
                    }
                }
            }
        }