public void Write(SceneBindingInfo info, XmlWriter writer)
 {
     writer.WriteStartElement("Binding");
     writer.WriteAttributeString("source", info.Source);
     writer.WriteAttributeString("target", info.Target);
     writer.WriteEndElement();
 }
 public SceneBindingInfo Load(XElement node)
 {
     var info = new SceneBindingInfo();
     info.Source = node.RequireAttribute("source").Value;
     info.Target = node.RequireAttribute("target").Value;
     return info;
 }
示例#3
0
        public static Binding Create(SceneBindingInfo info, object target)
        {
            var sourceParts = info.Source.Split('.');
            if (sourceParts.Length == 0)
            {
                throw new GameRunException(String.Format("Binding source '{0}' is invalid.", info.Source));
            }

            var targetProperty = target.GetType().GetProperty(info.Target);

            if (targetProperty == null)
            {
                throw new GameRunException(String.Format("Binding target '{0}' is invalid.", info.Target));
            }

            switch (sourceParts[0].ToUpper())
            {
                case "INVENTORY":
                    return new InventoryBinding(target, targetProperty, sourceParts);

                case "WEAPON":
                    if (sourceParts.Length != 2)
                    {
                        throw new GameRunException("Weapon bindings must be given of the format 'Weapon.{NAME}', for example, 'Weapon.MBuster'.");
                    }

                    return new WeaponBinding(target, targetProperty, sourceParts[1]);

                case "HEALTH":
                    if (sourceParts.Length != 2)
                    {
                        throw new GameRunException("Health bindings must be given of the format 'Health.{ENTITYNAME}', for example, 'Health.Player'.");
                    }

                    return new HealthBinding(target, targetProperty, sourceParts[1]);

                default:
                    throw new GameRunException(String.Format("Binding type '{0}' is invalid.", info.Source));
            }
        }