Exemple #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;
        }
Exemple #2
0
        private CodeGenerator CreateCodeGenerator(XmlElement domainEl)
        {
            string[] dlls = domainEl.GetMandatoryAttribute("dlls").Split(',');
            CodeGenerator gen = new CodeGenerator();
            XmlElement[] entryEls = domainEl.GetChildElements("entry");

            _namedEntries.Clear();

            foreach (XmlElement entryEl in entryEls)
            {
                string typeName = entryEl.GetMandatoryAttribute("handle-interface");
                string entryName = entryEl.GetMandatoryAttribute("entry-name");

                Type handleInterfaceType = null;

                for (int i = 0; i < dlls.Length; i++)
                {
                    string fullDllPath = Path.Combine(Directory.GetCurrentDirectory(), dlls[i]);
                    Assembly asm = Assembly.LoadFile(fullDllPath);
                    handleInterfaceType = asm.GetType(typeName);
                    if (handleInterfaceType != null)
                    {
                        break;
                    }
                }

                if (handleInterfaceType == null)
                {
                    throw new ApplicationException(); // todo2[ak]
                }

                CodeGeneratorEntry entry = new CodeGeneratorEntry(handleInterfaceType);
                gen.AddEntry(entry);

                _namedEntries[entryName] = entry;
            }

            return gen;
        }
Exemple #3
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);
                }
            }
        }