提交 366e59bc 编写于 作者: T tanghai

Config相关功能放到Config模块中

上级 a8efa551
using System;
using System.Collections.Generic;
using System.Linq;
namespace Model
{
/// <summary>
/// 管理该所有的配置
/// </summary>
/// <typeparam name="T"></typeparam>
public abstract class ACategory<T>: ICategory where T : AConfig
{
protected Dictionary<long, T> dict;
public virtual void BeginInit()
{
this.dict = new Dictionary<long, T>();
string configStr = ConfigHelper.GetText(typeof (T).Name);
foreach (string str in configStr.Split(new[] { "\n" }, StringSplitOptions.None))
{
try
{
string str2 = str.Trim();
if (str2 == "")
{
continue;
}
T t = MongoHelper.FromJson<T>(str2);
this.dict.Add(t.Id, t);
}
catch (Exception e)
{
throw new Exception($"parser json fail: {str}", e);
}
}
}
public Type ConfigType
{
get
{
return typeof (T);
}
}
public virtual void EndInit()
{
}
public T this[long type]
{
get
{
if (!this.dict.TryGetValue(type, out T t))
{
throw new KeyNotFoundException($"{typeof(T)} 没有找到配置, key: {type}");
}
return t;
}
}
public T TryGet(int type)
{
if (!this.dict.TryGetValue(type, out T t))
{
return null;
}
return t;
}
public T[] GetAll()
{
return this.dict.Values.ToArray();
}
public T GetOne()
{
return this.dict.Values.First();
}
}
}
\ No newline at end of file
......@@ -59,7 +59,6 @@
<Compile Include="..\..\Unity\Assets\Scripts\Base\QueueDictionary.cs" Link="Base\QueueDictionary.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Base\TryLocker.cs" Link="Base\TryLocker.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Base\UnOrderMultiMap.cs" Link="Base\UnOrderMultiMap.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Component\ConfigComponent.cs" Link="Component\ConfigComponent.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Component\Config\ClientConfig.cs" Link="Component\Config\ClientConfig.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Component\Config\DBConfig.cs" Link="Module\DB\DBConfig.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Component\Config\HttpConfig.cs" Link="Module\Http\HttpConfig.cs" />
......@@ -70,6 +69,11 @@
<Compile Include="..\..\Unity\Assets\Scripts\Helper\SessionHelper.cs" Link="Base\Helper\SessionHelper.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Message\OuterMessage.cs" Link="Message\OuterMessage.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Message\OuterOpcode.cs" Link="Message\OuterOpcode.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Module\Config\ACategory.cs" Link="Module\Config\ACategory.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Module\Config\AConfig.cs" Link="Module\Config\AConfig.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Module\Config\ConfigAttribute.cs" Link="Module\Config\ConfigAttribute.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Module\Config\ConfigComponent.cs" Link="Module\Config\ConfigComponent.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Module\Config\ICategory.cs" Link="Module\Config\ICategory.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Module\Message\AMHandler.cs" Link="Module\Message\AMHandler.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Module\Message\ErrorCode.cs" Link="Module\Message\ErrorCode.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Module\Message\IActorMessage.cs" Link="Module\Message\IActorMessage.cs" />
......
fileFormatVersion: 2
guid: d574f09c5596d2440b51164c43606464
folderAsset: yes
timeCreated: 1498118203
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
namespace Model
{
/// <summary>
/// 每个Config的基类
/// </summary>
public abstract class AConfig: Entity
{
protected AConfig()
{
}
protected AConfig(long id): base(id)
{
}
}
}
\ No newline at end of file
using System;
namespace Model
{
[AttributeUsage(AttributeTargets.Class)]
public class ConfigAttribute: Attribute
{
public AppType Type { get; }
public ConfigAttribute(AppType type)
{
this.Type = type;
}
}
}
\ No newline at end of file
using System;
using System.ComponentModel;
namespace Model
{
public interface ICategory: ISupportInitialize
{
Type ConfigType { get; }
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 79cf86d179ba4eda88b3bd3708dab066
timeCreated: 1519369141
\ No newline at end of file
......@@ -12,12 +12,15 @@
<ProjectTypeGuids>{E097FAD1-6243-4DAD-9C02-E9B9EFC3FFC1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<TargetFrameworkIdentifier>.NETFramework</TargetFrameworkIdentifier>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<TargetFrameworkProfile></TargetFrameworkProfile>
<CompilerResponseFile></CompilerResponseFile>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<CompilerResponseFile>
</CompilerResponseFile>
<UnityProjectType>Game:1</UnityProjectType>
<UnityBuildTarget>StandaloneWindows64:19</UnityBuildTarget>
<UnityVersion>2017.1.1p4</UnityVersion>
<RootNamespace></RootNamespace>
<RootNamespace>
</RootNamespace>
<LangVersion>6</LangVersion>
</PropertyGroup>
<PropertyGroup>
......@@ -114,12 +117,6 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Compile Include="Assets\Scripts\Base\Config\ACategory.cs" />
<Compile Include="Assets\Scripts\Base\Config\AConfig.cs" />
<Compile Include="Assets\Scripts\Base\Config\AConfigComponent.cs" />
<Compile Include="Assets\Scripts\Base\Config\ConfigAttribute.cs" />
<Compile Include="Assets\Scripts\Base\Config\ConfigHelper.cs" />
<Compile Include="Assets\Scripts\Base\Config\ICategory.cs" />
<Compile Include="Assets\Scripts\Base\DoubleMap.cs" />
<Compile Include="Assets\Scripts\Base\Event\AEventAttribute.cs" />
<Compile Include="Assets\Scripts\Base\Event\CrossEventAttribute.cs" />
......@@ -202,7 +199,7 @@
<Compile Include="Assets\Scripts\Component\Config\RunServerConfig.cs" />
<Compile Include="Assets\Scripts\Component\Config\StartConfig.cs" />
<Compile Include="Assets\Scripts\Component\Config\VersionConfig.cs" />
<Compile Include="Assets\Scripts\Component\ConfigComponent.cs" />
<Compile Include="Assets\Scripts\Module\Config\ConfigComponent.cs" />
<Compile Include="Assets\Scripts\Component\GlobalConfigComponent.cs" />
<Compile Include="Assets\Scripts\Component\MoveComponent.cs" />
<Compile Include="Assets\Scripts\Component\PlayerComponent.cs" />
......@@ -291,6 +288,12 @@
<Compile Include="Assets\Scripts\Module\BehaviorTree\NodePropAttribute.cs" />
<Compile Include="Assets\Scripts\Module\BehaviorTree\NodeProto.cs" />
<Compile Include="Assets\Scripts\Module\BehaviorTree\TypeHelper.cs" />
<Compile Include="Assets\Scripts\Module\Config\ACategory.cs" />
<Compile Include="Assets\Scripts\Module\Config\AConfig.cs" />
<Compile Include="Assets\Scripts\Module\Config\AConfigComponent.cs" />
<Compile Include="Assets\Scripts\Module\Config\ConfigAttribute.cs" />
<Compile Include="Assets\Scripts\Module\Config\ConfigHelper.cs" />
<Compile Include="Assets\Scripts\Module\Config\ICategory.cs" />
<Compile Include="Assets\Scripts\Module\Message\AMHandler.cs" />
<Compile Include="Assets\Scripts\Module\Message\ClientDispatcher.cs" />
<Compile Include="Assets\Scripts\Module\Message\ErrorCode.cs" />
......@@ -775,4 +778,4 @@
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="GenerateTargetFrameworkMonikerAttribute" />
</Project>
</Project>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册