From 69a8e2a3be2db11c8a714259a8710d52e3d4b94b Mon Sep 17 00:00:00 2001 From: tanghai Date: Thu, 16 Oct 2014 16:10:07 +0800 Subject: [PATCH] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E7=B1=BB=E8=B0=83=E8=AF=95OK,=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=BD=BF=E7=94=A8mongodb=E7=9A=84json?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F,=E6=97=A2=E5=8F=AF=E4=BD=9C=E4=B8=BA?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=AD=98=E6=94=BE=E4=B9=9F=E5=8F=AF=E6=94=BE?= =?UTF-8?q?=E5=88=B0mongodb=E6=95=B0=E6=8D=AE=E5=BA=93=E4=B8=AD,=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E4=B8=80=E8=87=B4,=E9=9D=9E=E5=B8=B8=E6=96=B9?= =?UTF-8?q?=E4=BE=BF=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CSharp/CSharp.sln | 15 ----- CSharp/Config/BuffConfig/1.json | 6 ++ CSharp/Config/GlobalConfig/1.json | 3 +- CSharp/Game/BehaviorTree/BehaviorTree.csproj | 5 +- .../Game/BehaviorTree/BehaviorTreeFactory.cs | 1 + CSharp/Game/BehaviorTree/Node.cs | 1 + CSharp/Game/BehaviorTree/Not.cs | 4 +- CSharp/Game/BehaviorTree/Selector.cs | 4 +- CSharp/Game/BehaviorTree/Sequence.cs | 4 +- CSharp/Game/Model/Buff.cs | 15 ++++- CSharp/Game/Model/BuffComponent.cs | 44 ++++++------- CSharp/Game/Model/BuffConfig.cs | 24 +++++++ CSharp/Game/Model/GameObjectManager.cs | 16 ++--- .../{World/Config => Model}/GlobalConfig.cs | 6 +- CSharp/Game/Model/Model.csproj | 4 ++ .../{BehaviorTree => Model}/NodeConfig.cs | 6 +- CSharp/Game/{World => Model}/World.cs | 5 +- CSharp/Game/MongoDBTest/MongoDBTest.cs | 4 +- CSharp/Game/World/Properties/AssemblyInfo.cs | 39 ------------ CSharp/Game/World/World.csproj | 63 ------------------- CSharp/Platform/Common/Base/Component.cs | 5 +- CSharp/Platform/Common/Base/Entity.cs | 20 +++++- CSharp/Platform/Common/Base/Object.cs | 8 +-- CSharp/Platform/Common/Common.csproj | 2 +- CSharp/Platform/Common/Config/ACategory.cs | 22 +++---- CSharp/Platform/Common/Config/AConfig.cs | 19 ++++++ .../Platform/Common/Config/ConfigManager.cs | 55 +++++++++++----- CSharp/Platform/Common/Config/ICategory.cs | 5 +- CSharp/Platform/Common/Config/IConfig.cs | 7 --- CSharp/Platform/ENetTest/ENetTest.csproj | 4 +- .../ENetTest/Properties/AssemblyInfo.cs | 39 ------------ 31 files changed, 204 insertions(+), 251 deletions(-) create mode 100644 CSharp/Config/BuffConfig/1.json create mode 100644 CSharp/Game/Model/BuffConfig.cs rename CSharp/Game/{World/Config => Model}/GlobalConfig.cs (52%) rename CSharp/Game/{BehaviorTree => Model}/NodeConfig.cs (74%) rename CSharp/Game/{World => Model}/World.cs (83%) delete mode 100644 CSharp/Game/World/Properties/AssemblyInfo.cs delete mode 100644 CSharp/Game/World/World.csproj create mode 100644 CSharp/Platform/Common/Config/AConfig.cs delete mode 100644 CSharp/Platform/Common/Config/IConfig.cs delete mode 100644 CSharp/Platform/ENetTest/Properties/AssemblyInfo.cs diff --git a/CSharp/CSharp.sln b/CSharp/CSharp.sln index 8ee0f35f..fb75f87d 100644 --- a/CSharp/CSharp.sln +++ b/CSharp/CSharp.sln @@ -32,8 +32,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Game", "Game", "{D0CC1FF4-2 EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BehaviorTree", "Game\BehaviorTree\BehaviorTree.csproj", "{C4E7A34A-095C-4983-AB63-FC2D20CD6824}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "World", "Game\World\World.csproj", "{CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ENetExe", "Platform\ENetExe\ENetExe.csproj", "{CBA52DC8-1C80-4A79-9AC5-73514EBBD749}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2814EB55-E1C2-4751-AC14-94116DA9D22B}" @@ -140,18 +138,6 @@ Global {C4E7A34A-095C-4983-AB63-FC2D20CD6824}.Release|Mixed Platforms.Build.0 = Release|Any CPU {C4E7A34A-095C-4983-AB63-FC2D20CD6824}.Release|Win32.ActiveCfg = Release|Any CPU {C4E7A34A-095C-4983-AB63-FC2D20CD6824}.Release|x86.ActiveCfg = Release|Any CPU - {CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0}.Debug|Any CPU.Build.0 = Debug|Any CPU - {CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0}.Debug|Win32.ActiveCfg = Debug|Any CPU - {CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0}.Debug|x86.ActiveCfg = Debug|Any CPU - {CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0}.Release|Any CPU.ActiveCfg = Release|Any CPU - {CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0}.Release|Any CPU.Build.0 = Release|Any CPU - {CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0}.Release|Win32.ActiveCfg = Release|Any CPU - {CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0}.Release|x86.ActiveCfg = Release|Any CPU {CBA52DC8-1C80-4A79-9AC5-73514EBBD749}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {CBA52DC8-1C80-4A79-9AC5-73514EBBD749}.Debug|Any CPU.Build.0 = Debug|Any CPU {CBA52DC8-1C80-4A79-9AC5-73514EBBD749}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU @@ -260,7 +246,6 @@ Global {D0B4CFAC-A368-4742-9863-68776CFA9938} = {ADBF5F67-B480-4A93-9D50-C81856FC61A9} {901A8E5C-C4C6-4C3C-8E18-068D75119F5D} = {ADBF5F67-B480-4A93-9D50-C81856FC61A9} {C4E7A34A-095C-4983-AB63-FC2D20CD6824} = {D0CC1FF4-2747-4278-A51F-BE9AA959175B} - {CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0} = {D0CC1FF4-2747-4278-A51F-BE9AA959175B} {CBA52DC8-1C80-4A79-9AC5-73514EBBD749} = {ADBF5F67-B480-4A93-9D50-C81856FC61A9} {B42D431A-3A54-4649-942A-C5356D7F9FBC} = {ADBF5F67-B480-4A93-9D50-C81856FC61A9} {F176D1FA-63E5-4B89-9A03-D44CCCCC069A} = {ADBF5F67-B480-4A93-9D50-C81856FC61A9} diff --git a/CSharp/Config/BuffConfig/1.json b/CSharp/Config/BuffConfig/1.json new file mode 100644 index 00000000..79fe3b2b --- /dev/null +++ b/CSharp/Config/BuffConfig/1.json @@ -0,0 +1,6 @@ +{ + "_id" : 1, + "Type" : 0, + "Name" : "yun", + "Duration" : 1500, +} \ No newline at end of file diff --git a/CSharp/Config/GlobalConfig/1.json b/CSharp/Config/GlobalConfig/1.json index 4a1809f7..51d648b2 100644 --- a/CSharp/Config/GlobalConfig/1.json +++ b/CSharp/Config/GlobalConfig/1.json @@ -1,3 +1,4 @@ -{ +{ + "_id": 1 "Type" : 1 } \ No newline at end of file diff --git a/CSharp/Game/BehaviorTree/BehaviorTree.csproj b/CSharp/Game/BehaviorTree/BehaviorTree.csproj index 22b01a23..8c587e6d 100644 --- a/CSharp/Game/BehaviorTree/BehaviorTree.csproj +++ b/CSharp/Game/BehaviorTree/BehaviorTree.csproj @@ -46,7 +46,6 @@ - @@ -60,6 +59,10 @@ {19f8f043-1f99-4550-99df-dea5c7d77e55} Common + + {0FA529D1-D0A9-4A8E-90F5-117CE80F2EDE} + Model + diff --git a/CSharp/Game/BehaviorTree/BehaviorTreeFactory.cs b/CSharp/Game/BehaviorTree/BehaviorTreeFactory.cs index 6c45113d..766bad43 100644 --- a/CSharp/Game/BehaviorTree/BehaviorTreeFactory.cs +++ b/CSharp/Game/BehaviorTree/BehaviorTreeFactory.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Reflection; +using Model; namespace BehaviorTree { diff --git a/CSharp/Game/BehaviorTree/Node.cs b/CSharp/Game/BehaviorTree/Node.cs index f138ed02..adc6f5cd 100644 --- a/CSharp/Game/BehaviorTree/Node.cs +++ b/CSharp/Game/BehaviorTree/Node.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using Model; namespace BehaviorTree { diff --git a/CSharp/Game/BehaviorTree/Not.cs b/CSharp/Game/BehaviorTree/Not.cs index e5e9d643..1f867e53 100644 --- a/CSharp/Game/BehaviorTree/Not.cs +++ b/CSharp/Game/BehaviorTree/Not.cs @@ -1,4 +1,6 @@ -namespace BehaviorTree +using Model; + +namespace BehaviorTree { [Node(NodeType.Not)] public class Not: Node diff --git a/CSharp/Game/BehaviorTree/Selector.cs b/CSharp/Game/BehaviorTree/Selector.cs index 0ff2ecb8..37a87421 100644 --- a/CSharp/Game/BehaviorTree/Selector.cs +++ b/CSharp/Game/BehaviorTree/Selector.cs @@ -1,4 +1,6 @@ -namespace BehaviorTree +using Model; + +namespace BehaviorTree { [Node(NodeType.Selector)] public class Selector: Node diff --git a/CSharp/Game/BehaviorTree/Sequence.cs b/CSharp/Game/BehaviorTree/Sequence.cs index d8de93ba..d482abba 100644 --- a/CSharp/Game/BehaviorTree/Sequence.cs +++ b/CSharp/Game/BehaviorTree/Sequence.cs @@ -1,4 +1,6 @@ -namespace BehaviorTree +using Model; + +namespace BehaviorTree { [Node(NodeType.Sequence)] internal class Sequence: Node diff --git a/CSharp/Game/Model/Buff.cs b/CSharp/Game/Model/Buff.cs index 5d4c197e..552b75f4 100644 --- a/CSharp/Game/Model/Buff.cs +++ b/CSharp/Game/Model/Buff.cs @@ -4,6 +4,19 @@ namespace Model { public class Buff: Object { - public BuffType Type { get; set; } + private int ConfigId { get; set; } + + public Buff(int configId) + { + this.ConfigId = configId; + } + + public BuffConfig Config + { + get + { + return World.Instance.ConfigManager.Get(this.ConfigId); + } + } } } \ No newline at end of file diff --git a/CSharp/Game/Model/BuffComponent.cs b/CSharp/Game/Model/BuffComponent.cs index ffcaf203..1d0cd6e2 100644 --- a/CSharp/Game/Model/BuffComponent.cs +++ b/CSharp/Game/Model/BuffComponent.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Common.Base; using MongoDB.Bson; using MongoDB.Bson.Serialization.Attributes; @@ -11,14 +12,14 @@ namespace Model [BsonElement] private HashSet Buffs { get; set; } - private Dictionary buffGuidDict { get; set; } + private Dictionary buffIdDict { get; set; } private MultiMap buffTypeMMap { get; set; } public BuffComponent() { this.Buffs = new HashSet(); - this.buffGuidDict = new Dictionary(); + this.buffIdDict = new Dictionary(); this.buffTypeMMap = new MultiMap(); } @@ -26,43 +27,36 @@ namespace Model { foreach (var buff in this.Buffs) { - this.buffGuidDict.Add(buff.Guid, buff); - this.buffTypeMMap.Add(buff.Type, buff); + this.buffIdDict.Add(buff.Id, buff); + this.buffTypeMMap.Add(buff.Config.Type, buff); } } - public bool Add(Buff buff) + public void Add(Buff buff) { if (this.Buffs.Contains(buff)) { - return false; - } - - if (this.buffGuidDict.ContainsKey(buff.Guid)) - { - return false; + throw new ArgumentException(string.Format("already exist same buff, Id: {0} ConfigId: {1}", buff.Id, buff.Config.Id)); } - if (this.buffTypeMMap.GetOne(buff.Type) != null) + if (this.buffIdDict.ContainsKey(buff.Id)) { - return false; + throw new ArgumentException(string.Format("already exist same buff, Id: {0} ConfigId: {1}", buff.Id, buff.Config.Id)); } this.Buffs.Add(buff); - this.buffGuidDict.Add(buff.Guid, buff); - this.buffTypeMMap.Add(buff.Type, buff); - - return true; + this.buffIdDict.Add(buff.Id, buff); + this.buffTypeMMap.Add(buff.Config.Type, buff); } - public Buff GetByGuid(ObjectId guid) + public Buff GetById(ObjectId id) { - if (!this.buffGuidDict.ContainsKey(guid)) + if (!this.buffIdDict.ContainsKey(id)) { return null; } - return this.buffGuidDict[guid]; + return this.buffIdDict[id]; } public Buff GetOneByType(BuffType type) @@ -83,15 +77,15 @@ namespace Model } this.Buffs.Remove(buff); - this.buffGuidDict.Remove(buff.Guid); - this.buffTypeMMap.Remove(buff.Type, buff); + this.buffIdDict.Remove(buff.Id); + this.buffTypeMMap.Remove(buff.Config.Type, buff); return true; } - public bool RemoveByGuid(ObjectId guid) + public bool RemoveById(ObjectId id) { - Buff buff = this.GetByGuid(guid); + Buff buff = this.GetById(id); return this.Remove(buff); } diff --git a/CSharp/Game/Model/BuffConfig.cs b/CSharp/Game/Model/BuffConfig.cs new file mode 100644 index 00000000..9e0ce52f --- /dev/null +++ b/CSharp/Game/Model/BuffConfig.cs @@ -0,0 +1,24 @@ +using System.Collections.Generic; +using Common.Config; + +namespace Model +{ + public class BuffConfig: AConfig + { + public BuffType Type { get; set; } + public string Name { get; set; } + public long Duration { get; set; } + public int MaxStack { get; set; } + public List Effects { get; set; } + + public BuffConfig() + { + this.Effects = new List(); + } + } + + [Config] + public class BuffCategory : ACategory + { + } +} diff --git a/CSharp/Game/Model/GameObjectManager.cs b/CSharp/Game/Model/GameObjectManager.cs index 89722a72..b076b512 100644 --- a/CSharp/Game/Model/GameObjectManager.cs +++ b/CSharp/Game/Model/GameObjectManager.cs @@ -15,18 +15,18 @@ namespace Model public void Add(GameObject gameObject) { - this.gameObjects.Add(gameObject.Guid, gameObject); + this.gameObjects.Add(gameObject.Id, gameObject); if (!this.typeGameObjects.ContainsKey(gameObject.Type)) { this.typeGameObjects.Add(gameObject.Type, new Dictionary()); } - this.typeGameObjects[gameObject.Type].Add(gameObject.Guid, gameObject); + this.typeGameObjects[gameObject.Type].Add(gameObject.Id, gameObject); } - public GameObject Get(ObjectId guid) + public GameObject Get(ObjectId id) { GameObject gameObject = null; - this.gameObjects.TryGetValue(guid, out gameObject); + this.gameObjects.TryGetValue(id, out gameObject); return gameObject; } @@ -46,20 +46,20 @@ namespace Model { throw new ArgumentNullException("gameObject"); } - if (!this.gameObjects.Remove(gameObject.Guid)) + if (!this.gameObjects.Remove(gameObject.Id)) { return false; } - if (!this.typeGameObjects[gameObject.Type].Remove(gameObject.Guid)) + if (!this.typeGameObjects[gameObject.Type].Remove(gameObject.Id)) { return false; } return true; } - public bool Remove(ObjectId guid) + public bool Remove(ObjectId id) { - GameObject gameObject = this.Get(guid); + GameObject gameObject = this.Get(id); if (gameObject == null) { return false; diff --git a/CSharp/Game/World/Config/GlobalConfig.cs b/CSharp/Game/Model/GlobalConfig.cs similarity index 52% rename from CSharp/Game/World/Config/GlobalConfig.cs rename to CSharp/Game/Model/GlobalConfig.cs index d696cae4..5d0715db 100644 --- a/CSharp/Game/World/Config/GlobalConfig.cs +++ b/CSharp/Game/Model/GlobalConfig.cs @@ -1,10 +1,10 @@ using Common.Config; -namespace World.Config +namespace Model { - public class GlobalConfig: IConfig + public class GlobalConfig: AConfig { - public int Id { get; set; } + public int Type { get; set; } } [Config] diff --git a/CSharp/Game/Model/Model.csproj b/CSharp/Game/Model/Model.csproj index e0137ead..cebde35d 100644 --- a/CSharp/Game/Model/Model.csproj +++ b/CSharp/Game/Model/Model.csproj @@ -47,9 +47,13 @@ + + + + diff --git a/CSharp/Game/BehaviorTree/NodeConfig.cs b/CSharp/Game/Model/NodeConfig.cs similarity index 74% rename from CSharp/Game/BehaviorTree/NodeConfig.cs rename to CSharp/Game/Model/NodeConfig.cs index 1114eb2b..9ea310ea 100644 --- a/CSharp/Game/BehaviorTree/NodeConfig.cs +++ b/CSharp/Game/Model/NodeConfig.cs @@ -2,12 +2,10 @@ using Common.Config; using MongoDB.Bson.Serialization.Attributes; -namespace BehaviorTree +namespace Model { - public class NodeConfig: IConfig + public class NodeConfig: AConfig { - public int Id { get; set; } - [BsonIgnoreIfNull] public List Args { get; set; } diff --git a/CSharp/Game/World/World.cs b/CSharp/Game/Model/World.cs similarity index 83% rename from CSharp/Game/World/World.cs rename to CSharp/Game/Model/World.cs index b402eefa..53cff982 100644 --- a/CSharp/Game/World/World.cs +++ b/CSharp/Game/Model/World.cs @@ -1,13 +1,12 @@ using Common.Config; -using Model; -namespace World +namespace Model { public class World { private static readonly World instance = new World(); - private readonly ConfigManager configManager = new ConfigManager(); + private readonly ConfigManager configManager = ConfigManager.Instance; private readonly GameObjectManager gameObjectManager = new GameObjectManager(); diff --git a/CSharp/Game/MongoDBTest/MongoDBTest.cs b/CSharp/Game/MongoDBTest/MongoDBTest.cs index 03e6d788..4213c79b 100644 --- a/CSharp/Game/MongoDBTest/MongoDBTest.cs +++ b/CSharp/Game/MongoDBTest/MongoDBTest.cs @@ -21,12 +21,12 @@ namespace MongoDBTest var collection = database.GetCollection("GameObjects"); GameObject player1 = GameObjectFactory.CreatePlayer(); - player1.GetComponent().Add(new Buff()); + player1.GetComponent().Add(new Buff(1)); player1["hp"] = 10; collection.Insert(player1); - var query = Query.EQ(e => e.Guid, player1.Guid); + var query = Query.EQ(e => e.Id, player1.Id); GameObject player2 = collection.FindOne(query); Console.WriteLine(MongoHelper.ToJson(player2)); diff --git a/CSharp/Game/World/Properties/AssemblyInfo.cs b/CSharp/Game/World/Properties/AssemblyInfo.cs deleted file mode 100644 index d475e981..00000000 --- a/CSharp/Game/World/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -// 有关程序集的常规信息通过以下 -// 特性集控制。更改这些特性值可修改 -// 与程序集关联的信息。 - -[assembly: AssemblyTitle("Component")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Component")] -[assembly: AssemblyCopyright("Copyright © 2013")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// 将 ComVisible 设置为 false 使此程序集中的类型 -// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型, -// 则将该类型上的 ComVisible 特性设置为 true。 - -[assembly: ComVisible(false)] - -// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID - -[assembly: Guid("55cc5b17-d8c8-4c34-922c-47afac13d174")] - -// 程序集的版本信息由下面四个值组成: -// -// 主版本 -// 次版本 -// 生成号 -// 修订号 -// -// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, -// 方法是按如下所示使用“*”: -// [assembly: AssemblyVersion("1.0.*")] - -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/CSharp/Game/World/World.csproj b/CSharp/Game/World/World.csproj deleted file mode 100644 index ddcb1598..00000000 --- a/CSharp/Game/World/World.csproj +++ /dev/null @@ -1,63 +0,0 @@ - - - - - Debug - AnyCPU - {CBEDBE33-A883-4BFA-AE0A-8B3573F09BD0} - Library - Properties - World - World - v4.5.1 - 512 - ..\..\ - true - - - - true - full - false - ..\..\Bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - ..\..\Bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - {19f8f043-1f99-4550-99df-dea5c7d77e55} - Common - - - {0fa529d1-d0a9-4a8e-90f5-117ce80f2ede} - Model - - - - - - \ No newline at end of file diff --git a/CSharp/Platform/Common/Base/Component.cs b/CSharp/Platform/Common/Base/Component.cs index afa3e074..72498c31 100644 --- a/CSharp/Platform/Common/Base/Component.cs +++ b/CSharp/Platform/Common/Base/Component.cs @@ -3,6 +3,9 @@ using MongoDB.Bson.Serialization.Attributes; namespace Common.Base { + /// + /// Component的Id与Owner Entity Id一样 + /// public abstract class Component : Object, ISupportInitialize { private Entity owner; @@ -17,7 +20,7 @@ namespace Common.Base set { this.owner = value; - this.Guid = this.owner.Guid; + this.Id = this.owner.Id; } } diff --git a/CSharp/Platform/Common/Base/Entity.cs b/CSharp/Platform/Common/Base/Entity.cs index 4783f99f..efbd65bd 100644 --- a/CSharp/Platform/Common/Base/Entity.cs +++ b/CSharp/Platform/Common/Base/Entity.cs @@ -21,6 +21,12 @@ namespace Common.Base public void AddComponent() where T : Component, new() { + if (this.ComponentDict.ContainsKey(typeof (T))) + { + throw new Exception( + string.Format("AddComponent, component already exist, id: {0}, component: {1}", + this.Id, typeof(T).Name)); + } T t = new T { Owner = this }; this.Components.Add(t); this.ComponentDict.Add(typeof (T), t); @@ -29,7 +35,13 @@ namespace Common.Base public void RemoveComponent() where T : Component { Component t; - this.ComponentDict.TryGetValue(typeof(T), out t); + if (!this.ComponentDict.TryGetValue(typeof (T), out t)) + { + throw new Exception( + string.Format("RemoveComponent, component not exist, id: {0}, component: {1}", + this.Id, typeof(T).Name)); + } + this.Components.Remove(t); this.ComponentDict.Remove(typeof(T)); } @@ -39,7 +51,9 @@ namespace Common.Base Component t; if (!this.ComponentDict.TryGetValue(typeof (T), out t)) { - return null; + throw new Exception( + string.Format("GetComponent, component not exist, id: {0}, component: {1}", + this.Id, typeof(T).Name)); } return (T) t; } @@ -57,8 +71,8 @@ namespace Common.Base { foreach (Component component in this.Components) { - this.ComponentDict.Add(component.GetType(), component); component.Owner = this; + this.ComponentDict.Add(component.GetType(), component); } } } diff --git a/CSharp/Platform/Common/Base/Object.cs b/CSharp/Platform/Common/Base/Object.cs index 92c2760c..b08114be 100644 --- a/CSharp/Platform/Common/Base/Object.cs +++ b/CSharp/Platform/Common/Base/Object.cs @@ -7,7 +7,7 @@ namespace Common.Base public abstract class Object { [BsonId] - public ObjectId Guid { get; protected set; } + public ObjectId Id { get; protected set; } [BsonElement] [BsonIgnoreIfNull] @@ -15,12 +15,12 @@ namespace Common.Base protected Object() { - this.Guid = ObjectId.GenerateNewId(); + this.Id = ObjectId.GenerateNewId(); } - protected Object(ObjectId guid) + protected Object(ObjectId id) { - this.Guid = guid; + this.Id = id; } public object this[string key] diff --git a/CSharp/Platform/Common/Common.csproj b/CSharp/Platform/Common/Common.csproj index caf0f400..0529f8b9 100644 --- a/CSharp/Platform/Common/Common.csproj +++ b/CSharp/Platform/Common/Common.csproj @@ -70,7 +70,7 @@ - + diff --git a/CSharp/Platform/Common/Config/ACategory.cs b/CSharp/Platform/Common/Config/ACategory.cs index 1178d65a..8051ebfa 100644 --- a/CSharp/Platform/Common/Config/ACategory.cs +++ b/CSharp/Platform/Common/Config/ACategory.cs @@ -6,13 +6,13 @@ using Common.Helper; namespace Common.Config { - public abstract class ACategory: ICategory where T : IConfig + public abstract class ACategory: ICategory where T : AConfig { protected readonly Dictionary dict = new Dictionary(); - public void BeginInit() + public virtual void BeginInit() { - string path = Path.Combine(@"./Config/", this.Name); + string path = Path.Combine(@"../../Config/", typeof(T).Name); if (!Directory.Exists(path)) { @@ -26,23 +26,23 @@ namespace Common.Config } } - public void EndInit() - { - } - - public T this[int type] + public Type ConfigType { get { - return this.dict[type]; + return typeof (T); } } - public string Name + public virtual void EndInit() + { + } + + public T this[int type] { get { - return typeof (T).Name; + return this.dict[type]; } } diff --git a/CSharp/Platform/Common/Config/AConfig.cs b/CSharp/Platform/Common/Config/AConfig.cs new file mode 100644 index 00000000..cd169c5f --- /dev/null +++ b/CSharp/Platform/Common/Config/AConfig.cs @@ -0,0 +1,19 @@ +using System.ComponentModel; +using MongoDB.Bson.Serialization.Attributes; + +namespace Common.Config +{ + public abstract class AConfig: ISupportInitialize + { + [BsonId] + public int Id { get; set; } + + public virtual void BeginInit() + { + } + + public virtual void EndInit() + { + } + } +} \ No newline at end of file diff --git a/CSharp/Platform/Common/Config/ConfigManager.cs b/CSharp/Platform/Common/Config/ConfigManager.cs index 9d712b67..6a5de6ac 100644 --- a/CSharp/Platform/Common/Config/ConfigManager.cs +++ b/CSharp/Platform/Common/Config/ConfigManager.cs @@ -1,20 +1,36 @@ using System; using System.Collections.Generic; using System.Reflection; +using Common.Logger; namespace Common.Config { public class ConfigManager { - public Dictionary allConfig; + private static ConfigManager instance = new ConfigManager(); + + public static ConfigManager Instance + { + get + { + return instance; + } + } + + public Dictionary allConfig; + + private ConfigManager() + { + } public void Load(Assembly assembly) { - var localAllConfig = new Dictionary(); + var localAllConfig = new Dictionary(); Type[] types = assembly.GetTypes(); - foreach (var type in types) + foreach (Type type in types) { object[] attrs = type.GetCustomAttributes(typeof (ConfigAttribute), false); + Log.Debug(type.Name); if (attrs.Length == 0) { continue; @@ -25,34 +41,45 @@ namespace Common.Config ICategory iCategory = obj as ICategory; if (iCategory == null) { - throw new Exception(string.Format("class: {0} not inherit from ACategory", - type.Name)); + throw new Exception( + string.Format("class: {0} not inherit from ACategory", type.Name)); } iCategory.BeginInit(); iCategory.EndInit(); - localAllConfig[type.Name] = obj; + localAllConfig[iCategory.ConfigType] = iCategory; } this.allConfig = localAllConfig; } - public T Get(int type) where T : IConfig + public T Get(int id) where T : AConfig { - var configCategory = (ACategory) this.allConfig[typeof (T).Name]; - return configCategory[type]; + Type type = typeof (T); + ICategory configCategory; + if (!this.allConfig.TryGetValue(type, out configCategory)) + { + throw new KeyNotFoundException(string.Format("ConfigManager not found key: {0}", type.FullName)); + } + return ((ACategory) configCategory)[id]; } - public T[] GetAll() where T : IConfig + public T[] GetAll() where T : AConfig { - var configCategory = (ACategory) this.allConfig[typeof (T).Name]; - return configCategory.GetAll(); + Type type = typeof(T); + ICategory configCategory; + if (!this.allConfig.TryGetValue(type, out configCategory)) + { + throw new KeyNotFoundException(string.Format("ConfigManager not found key: {0}", type.FullName)); + } + return ((ACategory)configCategory).GetAll(); } public T GetCategory() where T : class, ICategory, new() { T t = new T(); - object category; - bool ret = this.allConfig.TryGetValue(t.Name, out category); + Type type = t.ConfigType; + ICategory category; + bool ret = this.allConfig.TryGetValue(type, out category); return ret? (T) category : null; } } diff --git a/CSharp/Platform/Common/Config/ICategory.cs b/CSharp/Platform/Common/Config/ICategory.cs index c91f9282..021dcca6 100644 --- a/CSharp/Platform/Common/Config/ICategory.cs +++ b/CSharp/Platform/Common/Config/ICategory.cs @@ -1,9 +1,10 @@ -using System.ComponentModel; +using System; +using System.ComponentModel; namespace Common.Config { public interface ICategory: ISupportInitialize { - string Name { get; } + Type ConfigType { get; } } } \ No newline at end of file diff --git a/CSharp/Platform/Common/Config/IConfig.cs b/CSharp/Platform/Common/Config/IConfig.cs deleted file mode 100644 index 7e1be02f..00000000 --- a/CSharp/Platform/Common/Config/IConfig.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Common.Config -{ - public interface IConfig - { - int Id { get; } - } -} \ No newline at end of file diff --git a/CSharp/Platform/ENetTest/ENetTest.csproj b/CSharp/Platform/ENetTest/ENetTest.csproj index 21e67575..c5c1491a 100644 --- a/CSharp/Platform/ENetTest/ENetTest.csproj +++ b/CSharp/Platform/ENetTest/ENetTest.csproj @@ -55,7 +55,6 @@ - @@ -67,6 +66,9 @@ ENet + + + diff --git a/CSharp/Platform/ENetTest/Properties/AssemblyInfo.cs b/CSharp/Platform/ENetTest/Properties/AssemblyInfo.cs deleted file mode 100644 index 71e4b0c2..00000000 --- a/CSharp/Platform/ENetTest/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -// 有关程序集的常规信息通过以下特性集 -// 控制。更改这些特性值可修改 -// 与程序集关联的信息。 - -[assembly: AssemblyTitle("ENetCSTest")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Microsoft")] -[assembly: AssemblyProduct("ENetCSTest")] -[assembly: AssemblyCopyright("Copyright © Microsoft 2012")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// 将 ComVisible 设置为 false 会使此程序集中的类型 -// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型, -// 请将该类型上的 ComVisible 特性设置为 true。 - -[assembly: ComVisible(false)] - -// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID - -[assembly: Guid("b52f4804-3f6e-4268-810a-08fe8ca12bd0")] - -// 程序集的版本信息由以下四个值组成: -// -// 主版本 -// 次版本 -// 生成号 -// 修订号 -// -// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, -// 方法是按如下所示使用“*”: -// [assembly: AssemblyVersion("1.0.*")] - -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file -- GitLab