annotate API/Exporters/WarFoundryXMLWithXSLExporter.cs @ 499:2fc99446f9c9 default tip

Add initial structure for categories of equipment
author IBBoard <dev@ibboard.co.uk>
date Sun, 16 Oct 2016 20:26:44 +0100
parents cd367acd7c48
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
497
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
1 // This file (WarFoundryXmlWithXslExporter.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2011 Dan Kulinski
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
2 //
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
3 // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
4
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
5 using System;
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
6 using System.Collections.Generic;
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
7 using System.IO;
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
8 using System.Text;
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
9 using System.Xml;
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
10 using System.Xml.Xsl;
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
11 using System.Xml.XPath;
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
12 using System.Xml.Schema;
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
13 using IBBoard.Lang;
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
14 using IBBoard.Xml;
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
15 using IBBoard.WarFoundry.API.Objects;
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
16 using IBBoard.WarFoundry.API.Util;
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
17 using System.Reflection;
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
18 using IBBoard.IO;
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
19
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
20 namespace IBBoard.WarFoundry.API.Exporters
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
21 {
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
22 /// <summary>
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
23 /// Custom exporter that exports an army as an XML file with an XSLT applied
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
24 /// </summary>
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
25 public class WarFoundryXmlWithXslExporter : IWarFoundryExporter
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
26 {
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
27 private static WarFoundryXmlWithXslExporter exporter;
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
28
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
29 // Return the default class associated with this exporter
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
30 public static WarFoundryXmlWithXslExporter GetDefault()
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
31 {
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
32 if (exporter == null)
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
33 {
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
34 exporter = new WarFoundryXmlWithXslExporter();
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
35 }
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
36
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
37 return exporter;
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
38 }
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
39
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
40 private WarFoundryXmlWithXslExporter()
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
41 {
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
42 // Hide constructor
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
43 }
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
44
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
45 public NamedStream[] GetXsltStreams() {
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
46 Assembly assm = GetType().Assembly;
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
47 NamedStream[] streams = new NamedStream[2];
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
48 streams[0] = new NamedStream("Default Roster", assm.GetManifestResourceStream("IBBoard.WarFoundry.API.xsl.default_html.xsl"));
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
49 streams[1] = new NamedStream("Unit Cards", assm.GetManifestResourceStream("IBBoard.WarFoundry.API.xsl.unitcard.xsl"));
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
50 return streams;
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
51 }
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
52
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
53 // Write to file
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
54 public void ExportArmy(Army army, string path)
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
55 {
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
56 XmlDocument xmlDoc = BuildXml(army);
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
57 // Simple XML output settings
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
58 XmlWriterSettings xmlSettings = new XmlWriterSettings();
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
59 xmlSettings.Indent = true;
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
60 xmlSettings.IndentChars = " ";
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
61
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
62 // Write XML to file
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
63 using (XmlWriter writer = XmlWriter.Create(path, xmlSettings))
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
64 {
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
65 xmlDoc.Save(writer);
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
66 writer.Flush();
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
67 writer.Close();
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
68 }
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
69 }
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
70
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
71 // Write to file with transform
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
72 public void ExportArmyWithTransform(Army army, string savePath, Stream xslStream)
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
73 {
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
74 XmlDocument xmlDoc = BuildXml(army);
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
75 XslCompiledTransform xslTransform = new XslCompiledTransform();
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
76
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
77 xslTransform.Load(new XmlTextReader(xslStream));
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
78 XmlWriter writer = XmlWriter.Create(savePath, xslTransform.OutputSettings);
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
79 xslTransform.Transform(xmlDoc, writer);
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
80 writer.Flush();
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
81 writer.Close();
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
82 }
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
83
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
84 // Build the XML document to save or transform
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
85 private XmlDocument BuildXml(Army army)
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
86 {
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
87 XmlDocument armyList = new XmlDocument();
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
88
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
89 // Everything will be a child of the army element
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
90 XmlElement root = armyList.CreateElement("army");
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
91
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
92 // Basic army information
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
93 XmlElement armyRace = armyList.CreateElement("race");
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
94 armyRace.InnerText = army.Race.Name;
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
95 root.AppendChild(armyRace);
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
96
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
97 XmlElement armyName = armyList.CreateElement("name");
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
98 armyName.InnerText = army.Name;
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
99 root.AppendChild(armyName);
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
100
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
101 XmlElement armyAvailablePoints = armyList.CreateElement("pointsAvailable");
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
102 armyAvailablePoints.InnerText = army.MaxPoints.ToString();
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
103 root.AppendChild(armyAvailablePoints);
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
104
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
105 XmlElement armyUsedPoints = armyList.CreateElement("pointsUsed");
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
106 armyUsedPoints.InnerText = army.Points.ToString();
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
107 root.AppendChild(armyUsedPoints);
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
108
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
109 // Get Categories and interate through each
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
110 foreach(ArmyCategory cat in army.Categories)
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
111 {
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
112 if (cat.GetUnits().Length == 0)
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
113 continue;
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
114 XmlElement armyCategory = armyList.CreateElement("category");
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
115 armyCategory.SetAttribute("type", cat.Name);
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
116
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
117
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
118 // Get units and iterate through each
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
119 foreach(Unit uni in cat.GetUnits())
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
120 {
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
121 XmlElement armyUnit = armyList.CreateElement("unit");
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
122 armyUnit.SetAttribute("name", uni.UnitType.Name);
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
123
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
124 foreach (Stat[] stat in uni.UnitStatsArraysWithName)
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
125 {
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
126 XmlElement armyStatLine = armyList.CreateElement("statLine");
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
127 foreach (Stat singleStat in stat)
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
128 {
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
129 XmlElement armyStat = armyList.CreateElement("stat");
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
130 armyStat.SetAttribute("name", singleStat.ParentSlotName);
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
131 armyStat.SetAttribute("value", singleStat.SlotValueString);
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
132 armyStatLine.AppendChild(armyStat);
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
133 }
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
134 armyUnit.AppendChild(armyStatLine);
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
135 }
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
136 armyUnit.SetAttribute("points", uni.Points.ToString());
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
137 armyUnit.SetAttribute("models", uni.Size.ToString());
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
138
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
139 foreach (UnitEquipmentItem equip in uni.GetEquipment())
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
140 {
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
141 XmlElement armyEquipmentItem = armyList.CreateElement("equipmentItem");
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
142 armyEquipmentItem.SetAttribute("name", equip.Name);
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
143
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
144 int armyEquipAmount = 0;
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
145 armyEquipAmount = (int)UnitEquipmentUtil.GetEquipmentAmount(uni, equip);
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
146
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
147 if (UnitEquipmentUtil.GetEquipmentAmountIsRatio(uni, equip))
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
148 {
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
149 float fraction = (float)(armyEquipAmount / 100.0);
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
150 armyEquipAmount = (int)(fraction * uni.Size);
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
151 }
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
152
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
153 armyEquipmentItem.SetAttribute("count", armyEquipAmount.ToString());
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
154
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
155 armyUnit.AppendChild(armyEquipmentItem);
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
156 }
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
157
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
158 foreach (Ability abil in uni.Abilities)
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
159 {
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
160 XmlElement armyAbilityItem = armyList.CreateElement("abilityItem");
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
161
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
162 armyAbilityItem.SetAttribute("name", abil.Name);
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
163 armyAbilityItem.SetAttribute("description", abil.Description);
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
164
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
165 armyUnit.AppendChild(armyAbilityItem);
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
166 }
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
167
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
168 armyCategory.AppendChild(armyUnit);
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
169 }
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
170 root.AppendChild(armyCategory);
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
171 }
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
172
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
173
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
174
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
175
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
176 // Append all Categories to the XML doc
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
177
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
178 // Append tree to document
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
179 armyList.AppendChild(root);
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
180
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
181 return armyList;
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
182 }
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
183 private string GetEquipmentAmountRatioTranslation(double amount, int number)
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
184 {
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
185 return Translation.GetTranslation("armyHtmlExportEquipAmountPercentage", "{0}% ({1})", amount, number);
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
186 }
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
187
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
188 private string GetEquipmentAmountNumberTranslation(int amount)
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
189 {
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
190 return Translation.GetTranslation("armyHtmlExportEquipAmountNumber", "{0}", amount);
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
191 }
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
192
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
193 private string GetEquipmentAmountAllTranslation(Unit unit)
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
194 {
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
195 return Translation.GetTranslation("armyHtmlExportEquipAmountAll", "all ({1})", 100, unit.Size);
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
196 }
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
197 }
cd367acd7c48 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 419
diff changeset
198 }