Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
EntityData.cs
浏览该文件的文档.
1using System;
2using System.Xml.Linq;
4using XmlUtilities;
5
6namespace GameEntitySystem {
7 public class EntityData {
8 public int Id;
9
11
12 public EntityData() { }
13
14 public EntityData(GameDatabase gameDatabase, XElement entityNode) {
15 Id = XmlUtils.GetAttributeValue<int>(entityNode, "Id");
16 Guid attributeValue = XmlUtils.GetAttributeValue(entityNode, "Guid", Guid.Empty);
17 string attributeValue2 = XmlUtils.GetAttributeValue(entityNode, "Name", string.Empty);
18 DatabaseObject databaseObject;
19 if (attributeValue != Guid.Empty) {
20 databaseObject = gameDatabase.Database.FindDatabaseObject(attributeValue, gameDatabase.EntityTemplateType, true);
21 }
22 else {
23 if (string.IsNullOrEmpty(attributeValue2)) {
24 throw new InvalidOperationException("Entity template guid or name must be specified.");
25 }
26 databaseObject = gameDatabase.Database.FindDatabaseObject(attributeValue2, gameDatabase.EntityTemplateType, true);
27 }
29 ValuesDictionary.PopulateFromDatabaseObject(databaseObject);
30 ValuesDictionary.ApplyOverrides(entityNode);
31 }
32
33 public void Save(XElement entityNode) {
34 XmlUtils.SetAttributeValue(entityNode, "Id", Id);
35 XmlUtils.SetAttributeValue(entityNode, "Guid", ValuesDictionary.DatabaseObject.Guid);
36 XmlUtils.SetAttributeValue(entityNode, "Name", ValuesDictionary.DatabaseObject.Name);
37 ValuesDictionary.Save(entityNode);
38 }
39 }
40}
EntityData(GameDatabase gameDatabase, XElement entityNode)
ValuesDictionary ValuesDictionary
void Save(XElement entityNode)
DatabaseObjectType EntityTemplateType
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)