Exemplo n.º 1
0
        public void deserializeFromXml(string filename)
        {
            m_document.Load(filename);

            XmlNode objectBuilderNode = Helper.XmlHelper.getNodeByName(m_document.ChildNodes, "ObjectBuilder");
            if (objectBuilderNode == null)
                return;

            Parameters.Clear();
            m_scriptObjects.Clear();

            foreach (XmlAttribute attrib in objectBuilderNode.Attributes)
            {
                if (attrib.Name == "name")
                    this.m_name = attrib.Value;
                else if (attrib.Name == "offset_x")
                {
                    double x;
                    if (double.TryParse(attrib.Value, out x))
                        m_offset.X = x;
                }
                else if (attrib.Name == "offset_y")
                {
                    double y;
                    if (double.TryParse(attrib.Value, out y))
                        m_offset.Y = y;
                }
                else if (attrib.Name == "is_macro")
                {
                    bool.TryParse(attrib.Value, out this.m_isMacro);
                }
            }

            // Parameters
            XmlNode parameterNode = Helper.XmlHelper.getNodeByName(objectBuilderNode.ChildNodes, "Parameters");
            if (parameterNode != null)
            {
                foreach (XmlNode parameter in parameterNode.ChildNodes)
                {
                    if (parameter is XmlElement && parameter.Name == "Parameter")
                    {
                        XmlElement param = parameter as XmlElement;
                        Parameter p = new Parameter();
                        p.deserializeFromXml(param);
                        AddParameter(p);
                    }
                }
            }

            // Objects
            XmlNode objectsNode = Helper.XmlHelper.getNodeByName(objectBuilderNode.ChildNodes, "Objects");
            if (objectsNode != null)
            {
                foreach (XmlNode object_ in objectsNode.ChildNodes)
                {
                    if (object_ is XmlElement)
                    {
                        IScriptObject so = null;
                        XmlElement obj = object_ as XmlElement;
                        if (obj.Name == "GameObject")
                        {
                            so = new GameObject(this);
                            so.deserializeFromXml(obj);
                        }
                        else if (obj.Name == "MacroCall")
                        {
                            so = new MacroCall();
                            so.deserializeFromXml(obj);
                        }
                        else if (obj.Name == "MacroRegistration")
                        {
                            so = new MacroRegistration();
                            so.deserializeFromXml(obj);
                        }
                        else if (obj.Name == "FunctionCall")
                        {
                            so = new FunctionCall();
                            so.deserializeFromXml(obj);
                        }
                        else if (obj.Name == "Function")
                        {
                            so = new Function();
                            so.deserializeFromXml(obj);
                        }
                        if (so != null)
                            m_scriptObjects.Add(so);
                    }
                }
            }
        }
Exemplo n.º 2
0
 public void registerMacroInScript(ObjectBuilder macro)
 {
     if (macro.IsRegistered)
     {
         System.Windows.MessageBox.Show("Macro is already registered!", "Error");
     }
     else if (macro == ObjectBuilder)
     {
         System.Windows.MessageBox.Show("Cannot register macro within itself!", "Error");
     }
     else
     {
         MacroRegistration macroReg = new MacroRegistration();
         StringQueryItem qry = new StringQueryItem("Enter new macro name", "New Macro", "Macro");
         StringQuery q = new StringQuery();
         q.DataContext = qry;
         bool? result = q.ShowDialog();
         if (result.Value)
         {
             macro.IsRegistered = true;
             macro.RegisteredName = qry.Text;
             macroReg.Name = qry.Text;
             macroReg.Script = macro;
             ObjectBuilder.ScriptObjects.Add(macroReg);
         }
     }
 }
Exemplo n.º 3
0
        public void deserialize(System.IO.BinaryReader br)
        {
            Parameters.Clear();
            m_scriptObjects.Clear();

            Name = br.ReadString();
            Point p = new Point();
            p.X = br.ReadDouble();
            p.Y = br.ReadDouble();
            m_isMacro = br.ReadBoolean();
            int parameterCount = br.ReadInt32();
            for (int i = 0; i < parameterCount; ++i)
            {
                Parameter param = new Parameter();
                param.deserialize(br);
                AddParameter(param);
            }
            m_offset = p;
            int goCount = br.ReadInt32();
            for (int i = 0; i < goCount; ++i)
            {
                String type = br.ReadString();
                IScriptObject so = null;
                if (type == "GameObject")
                {
                    so = new GameObject(this);
                }
                else if (type == "MacroCall")
                {
                    so = new MacroCall();
                }
                else if (type == "MacroRegistration")
                {
                    so = new MacroRegistration();
                }
                else if (type == "FunctionCall")
                {
                    so = new FunctionCall();
                }
                else if (type == "Function")
                {
                    so = new Function();
                }
                if (so != null)
                {
                    so.deserialize(br);
                    so.ParentObjectBuilder = this;
                    m_scriptObjects.Add(so);
                }
            }
        }