Exemplo n.º 1
0
        public static SpawnItem Load(XmlElement elem, ILog log)
        {
            string type = elem.Name;

            if (!Pack.SpawnItemConfig.Types.Keys.Contains(type))
            {
                throw new CommonException("Unknown type: {0}", type);
            }

            var result = new SpawnItem(type, elem.GetFloatAttribute(DelayAttribName));

            foreach (XmlElement attachElem in elem.GetChildElements())
            {
                try
                {
                    result.Attachments.Add(SpawnItemAttachment.Load(attachElem));
                }
                catch (Exception ex)
                {
                    log.Write("Error while loading attachment: {0}. Skipped.", ex.Message);
                }
            }

            return(result);
        }
Exemplo n.º 2
0
 public void RemoveItem(SpawnItem item)
 {
     if (!_items.Remove(item))
     {
         throw new CommonException("Item is not contained within current line");
     }
 }
Exemplo n.º 3
0
        public SpawnItem InsertItem(string type, int index)
        {
            float delay = index == 0 ? 0 : DefaultDelay;
            var   item  = new SpawnItem(type, delay);

            return(InsertItem(item, index));
        }
Exemplo n.º 4
0
        public SpawnItem InsertItem(SpawnItem item, int index)
        {
            if (_items.Contains(item))
            {
                throw new ArgumentException("The item is already contained in the collection");
            }

            _items.Insert(index, item);
            return(item);
        }
Exemplo n.º 5
0
        public SpawnItem Clone()
        {
            var result = new SpawnItem(Type, Delay);

            foreach (var attach in Attachments)
            {
                result.Attachments.Add(attach.Clone());
            }

            return(result);
        }
Exemplo n.º 6
0
        public float GetAbsoluteTime(SpawnItem item)
        {
            float result = 0;
            foreach (var curItem in Items)
            {
                result += curItem.Delay;

                if (curItem == item)
                    return result;
            }

            throw new CommonException("Item is not contained within current line");
        }
Exemplo n.º 7
0
        public float GetAbsoluteTime(SpawnItem item)
        {
            float result = 0;

            foreach (var curItem in Items)
            {
                result += curItem.Delay;

                if (curItem == item)
                {
                    return(result);
                }
            }

            throw new CommonException("Item is not contained within current line");
        }
Exemplo n.º 8
0
        public SpawnItemButton(SpawnItem item, Func<string, Image> getTypeImageByFileName, Func<string, Image> getAttachImageByFileName)
            : base()
        {
            if (item == null)
                throw new ArgumentNullException("item");

            if (getTypeImageByFileName == null)
                throw new ArgumentNullException("getTypeImageByFileName");

            if (getAttachImageByFileName == null)
                throw new ArgumentNullException("getAttachImageByFileName");

            _getTypeImageByFileName = getTypeImageByFileName;
            _getAttachImageByFileName = getAttachImageByFileName;
            Item = item;
            FlatStyle = FlatStyle.Flat;
            Size = new Size(PackForm.PixelInSec, 75);
        }
Exemplo n.º 9
0
        private int GetNewItemIndex(SpawnItem prevItem = null)
        {
            int index = 0;

            if (prevItem != null)
            {
                index = _items.IndexOf(prevItem);
                if (index == -1)
                {
                    throw new CommonException("Item is not contained within current line");
                }
                else
                {
                    index += 1;
                }
            }

            return(index);
        }
Exemplo n.º 10
0
        public void Load(XmlElement elem, ILog log)
        {
            if (elem.Name != ElementName)
            {
                throw new LevelXmlException("Unexpected element name: \"{0}\". Expected: \"{1}\".", elem.Name, ElementName);
            }

            Clear();
            foreach (XmlElement itemElem in elem.GetChildElements())
            {
                try
                {
                    _items.Add(SpawnItem.Load(itemElem, log));
                }
                catch (Exception ex)
                {
                    log.Write("Error while loading spawn item: {0}. Item is skipped.", ex.Message);
                }
            }
        }
Exemplo n.º 11
0
        public static SpawnItem Load(XmlElement elem, ILog log)
        {
            string type = elem.Name;
            if (!Pack.SpawnItemConfig.Types.Keys.Contains(type))
                throw new CommonException("Unknown type: {0}", type);

            var result = new SpawnItem(type, elem.GetFloatAttribute(DelayAttribName));

            foreach (XmlElement attachElem in elem.GetChildElements())
            {
                try
                {
                    result.Attachments.Add(SpawnItemAttachment.Load(attachElem));
                }
                catch (Exception ex)
                {
                    log.Write("Error while loading attachment: {0}. Skipped.", ex.Message);
                }
            }

            return result;
        }
Exemplo n.º 12
0
        public SpawnItem InsertItem(string type, int index)
        {
            float delay = index == 0 ? 0 : DefaultDelay;
            var item = new SpawnItem(type, delay);

            return InsertItem(item, index);
        }
Exemplo n.º 13
0
        public SpawnItem InsertItem(SpawnItem item, int index)
        {
            if (_items.Contains(item))
                throw new ArgumentException("The item is already contained in the collection");

            _items.Insert(index, item);
            return item;
        }
Exemplo n.º 14
0
 public SpawnItem InsertItem(string type, SpawnItem prevItem = null)
 {
     return InsertItem(type, GetNewItemIndex(prevItem));
 }
Exemplo n.º 15
0
 public SpawnItem InsertItem(SpawnItem item, SpawnItem prevItem = null)
 {
     return InsertItem(item, GetNewItemIndex(prevItem));
 }
Exemplo n.º 16
0
 public SpawnItem InsertItem(string type, SpawnItem prevItem = null)
 {
     return(InsertItem(type, GetNewItemIndex(prevItem)));
 }
Exemplo n.º 17
0
        private int GetNewItemIndex(SpawnItem prevItem = null)
        {
            int index = 0;
            if (prevItem != null)
            {
                index = _items.IndexOf(prevItem);
                if (index == -1)
                    throw new CommonException("Item is not contained within current line");
                else
                    index += 1;
            }

            return index;
        }
Exemplo n.º 18
0
 public void RemoveItem(SpawnItem item)
 {
     if (!_items.Remove(item))
         throw new CommonException("Item is not contained within current line");
 }
Exemplo n.º 19
0
 public SpawnItem InsertItem(SpawnItem item, SpawnItem prevItem = null)
 {
     return(InsertItem(item, GetNewItemIndex(prevItem)));
 }
Exemplo n.º 20
0
        public SpawnItem Clone()
        {
            var result = new SpawnItem(Type, Delay);
            foreach (var attach in Attachments)
            {
                result.Attachments.Add(attach.Clone());
            }

            return result;
        }