Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
VersionConverter23To24.cs
浏览该文件的文档.
1using System.Xml.Linq;
2using Engine;
3using XmlUtilities;
4
5namespace Game {
7 public override string SourceVersion => "2.3";
8
9 public override string TargetVersion => "2.4";
10
11 public override void ConvertProjectXml(XElement projectNode) {
12 XmlUtils.SetAttributeValue(projectNode, "Version", TargetVersion);
13 foreach (XElement item in from e in projectNode.Element("Subsystems").Elements()
14 where XmlUtils.GetAttributeValue(e, "Name", string.Empty) == "GameInfo"
15 select e) {
16 XElement xElement = XmlUtils.AddElement(item, "Value");
17 xElement.SetAttributeValue("Name", "AreSeasonsChanging");
18 xElement.SetAttributeValue("Type", "bool");
19 xElement.SetAttributeValue("Value", "false");
20 XElement xElement2 = XmlUtils.AddElement(item, "Value");
21 xElement2.SetAttributeValue("Name", "TimeOfYear");
22 xElement2.SetAttributeValue("Type", "float");
23 xElement2.SetAttributeValue("Value", IntervalUtils.Midpoint(SubsystemSeasons.SummerStart, SubsystemSeasons.AutumnStart));
24 }
25 }
26
27 public override void ConvertWorld(string directoryName) {
28 string path = Storage.CombinePaths(directoryName, "Project.xml");
29 XElement xElement;
30 using (Stream stream = Storage.OpenFile(path, OpenFileMode.Read)) {
31 xElement = XmlUtils.LoadXmlFromStream(stream, null, true);
32 }
33 ConvertProjectXml(xElement);
34 using Stream stream2 = Storage.OpenFile(path, OpenFileMode.Create);
35 XmlUtils.SaveXmlToStream(xElement, stream2, null, true);
36 }
37 }
38}
static Stream OpenFile(string path, OpenFileMode openFileMode)
static string CombinePaths(params string[] paths)
static float Midpoint(float t1, float t2, float factor=0.5f)
override void ConvertWorld(string directoryName)
override void ConvertProjectXml(XElement projectNode)
static void SetAttributeValue(XElement node, string attributeName, object value)
static object GetAttributeValue(XElement node, string attributeName, Type type)
static XElement LoadXmlFromStream(Stream stream, Encoding encoding, bool throwOnError)
static XElement AddElement(XElement parentNode, string name)
static void SaveXmlToStream(XElement node, Stream stream, Encoding encoding, bool throwOnError)