Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ProjectData.cs
浏览该文件的文档.
1using System;
2using System.Xml.Linq;
4using XmlUtilities;
5
6namespace GameEntitySystem {
7 public class ProjectData {
9
11
12 public int NextEntityID = 1;
13 public ProjectData() { }
14
15 // ReSharper disable UnusedParameter.Local
16 public ProjectData(GameDatabase gameDatabase, DatabaseObject projectTemplate, ValuesDictionary overrides)
17 // ReSharper restore UnusedParameter.Local
18 {
20 ValuesDictionary.PopulateFromDatabaseObject(projectTemplate);
21 if (overrides != null) {
22 ValuesDictionary.ApplyOverrides(overrides);
23 }
24 }
25
26 public ProjectData(GameDatabase gameDatabase, XElement projectNode, ValuesDictionary overrides, bool ignoreInvalidEntities) {
27 Guid attributeValue = XmlUtils.GetAttributeValue(projectNode, "Guid", Guid.Empty);
28 string attributeValue2 = XmlUtils.GetAttributeValue(projectNode, "Name", string.Empty);
29 DatabaseObject databaseObject;
30 if (attributeValue != Guid.Empty) {
31 databaseObject = gameDatabase.Database.FindDatabaseObject(attributeValue, gameDatabase.ProjectTemplateType, true);
32 }
33 else {
34 if (string.IsNullOrEmpty(attributeValue2)) {
35 throw new InvalidOperationException("Project template guid or name must be specified.");
36 }
37 databaseObject = gameDatabase.Database.FindDatabaseObject(attributeValue2, gameDatabase.ProjectTemplateType, true);
38 }
40 ValuesDictionary.PopulateFromDatabaseObject(databaseObject);
41 XElement xElement = XmlUtils.FindChildElement(projectNode, "Subsystems", false);
42 if (xElement != null) {
43 ValuesDictionary.ApplyOverrides(xElement);
44 }
45 if (overrides != null) {
46 ValuesDictionary.ApplyOverrides(overrides);
47 }
48 XElement xElement2 = XmlUtils.FindChildElement(projectNode, "Entities", false);
49 if (xElement2 != null) {
50 NextEntityID = XmlUtils.GetAttributeValue(xElement2, "NextID", 1000001);
51 //Log.Information("Load NextEntityID: " + NextEntityID);
52 EntityDataList = new EntityDataList(gameDatabase, xElement2, ignoreInvalidEntities);
53 }
54 }
55
56 public void Save(XElement projectNode) {
57 XmlUtils.SetAttributeValue(projectNode, "Guid", ValuesDictionary.DatabaseObject.Guid);
58 XmlUtils.SetAttributeValue(projectNode, "Name", ValuesDictionary.DatabaseObject.Name);
59 XElement node = XmlUtils.AddElement(projectNode, "Subsystems");
60 ValuesDictionary.Save(node);
61 if (EntityDataList != null) {
62 XElement entitiesNode = XmlUtils.AddElement(projectNode, "Entities");
63 EntityDataList.Save(entitiesNode, NextEntityID);
64 }
65 }
66 }
67}
DatabaseObjectType ProjectTemplateType
ProjectData(GameDatabase gameDatabase, XElement projectNode, ValuesDictionary overrides, bool ignoreInvalidEntities)
ProjectData(GameDatabase gameDatabase, DatabaseObject projectTemplate, ValuesDictionary overrides)
void Save(XElement projectNode)
DatabaseObject FindDatabaseObject(Guid guid, DatabaseObjectType type, bool throwIfNotFound)
static void SetAttributeValue(XElement node, string attributeName, object value)
static object GetAttributeValue(XElement node, string attributeName, Type type)
static XElement AddElement(XElement parentNode, string name)
static XElement FindChildElement(XElement node, string elementName, bool throwIfNotFound)