private void ReadSpellDescription(XmlNode spellNode) { // avoid null references from incomplete files (e.g. PFRPG SRD from PFRPG Essentials) var nameNode = spellNode.SelectSingleNode("name/text()"); var schoolNode = spellNode.SelectSingleNode("school/text()"); var levelNode = spellNode.SelectSingleNode("level/text()"); var componentsNode = spellNode.SelectSingleNode("components/text()"); var castingTimeNode = spellNode.SelectSingleNode("castingtime/text()"); var rangeNode = spellNode.SelectSingleNode("range/text()"); var effectNode = spellNode.SelectSingleNode("effect/text()"); var durationNode = spellNode.SelectSingleNode("duration/text()"); var saveNode = spellNode.SelectSingleNode("save/text()"); var srNode = spellNode.SelectSingleNode("sr/text()"); var shortDescNode = spellNode.SelectSingleNode("shortdescription/text()"); var longDescNode = spellNode.SelectSingleNode("description"); var spell = new SpellDescription { Name = nameNode?.Value, School = schoolNode?.Value, Level = levelNode?.Value, Components = componentsNode?.Value, CastingTime = castingTimeNode?.Value, Range = rangeNode?.Value, Effect = effectNode?.Value, Duration = durationNode?.Value, Save = saveNode?.Value, AllowSpellResistance = srNode?.Value == "Yes", ShortDescription = shortDescNode?.Value, LongDescription = longDescNode?.InnerXml }; _editor.AddSpellFromFile(spell); }
private void WriteSpellXml(XmlWriter w, string name, SpellDescription spell) { string shortName = Regex.Replace(name, "[^\\w]", "").ToLower(); w.WriteStartElement(shortName); w.WriteStartElement("name"); w.WriteAttributeString("type", "string"); w.WriteString(name); w.WriteEndElement(); // name w.WriteStartElement("school"); w.WriteAttributeString("type", "string"); w.WriteString(spell.School); w.WriteEndElement(); // school w.WriteStartElement("level"); w.WriteAttributeString("type", "string"); w.WriteString(spell.Level); w.WriteEndElement(); // level w.WriteStartElement("components"); w.WriteAttributeString("type", "string"); w.WriteString(spell.Components); w.WriteEndElement(); // components w.WriteStartElement("castingtime"); w.WriteAttributeString("type", "string"); w.WriteString(spell.CastingTime); w.WriteEndElement(); // castingtime w.WriteStartElement("range"); w.WriteAttributeString("type", "string"); w.WriteString(spell.Range); w.WriteEndElement(); // range w.WriteStartElement("effect"); w.WriteAttributeString("type", "string"); w.WriteString(spell.Effect); w.WriteEndElement(); // effect w.WriteStartElement("duration"); w.WriteAttributeString("type", "string"); w.WriteString(spell.Duration); w.WriteEndElement(); // duration w.WriteStartElement("save"); w.WriteAttributeString("type", "string"); w.WriteString(spell.Save); w.WriteEndElement(); // save w.WriteStartElement("sr"); w.WriteAttributeString("type", "string"); w.WriteString(spell.AllowSpellResistance ? "Yes" : "No"); w.WriteEndElement(); // sr w.WriteStartElement("description"); w.WriteAttributeString("type", "formattedtext"); var description = Regex.Replace(spell.LongDescription, @"[\r\n]+", ""); // replace HTML tags with their lowercase versions (formattedtext is case sensitive...) // we don't support very many; h1, p, b, i, u, table, tr, td description = Regex.Replace(description, @"<[^<>]+>", m => { return m.Value.ToLower(); }); w.WriteRaw(description); w.WriteEndElement(); // description w.WriteStartElement("shortdescription"); w.WriteAttributeString("type", "string"); w.WriteString(spell.ShortDescription); w.WriteEndElement(); // shortdescription w.WriteEndElement(); // <shortName> }
public SpellEditor(SpellbookEditor editor, string spellName) : this() { _spellbookEditor = editor; if (_spellbookEditor.Spells.ContainsKey(spellName)) { Spell = _spellbookEditor.Spells[spellName]; } else { Spell = new SpellDescription(); _spellbookEditor.Spells.Add(spellName, Spell); } bsSpell.DataSource = Spell; }
// load from file public void AddSpellFromFile(SpellDescription spell) { Spells.Add(spell.Name, spell); lvSpells.Items.Add(spell.Name); }