using System;
using System.Collections.Generic;
using TEngine;
namespace GameProto
{
///
/// 指定Key委托。
///
/// 键。
/// 值。
public delegate TKey ConvertDictionaryKey(TValue val);
///
/// 配置表辅助工具。
///
public static class ConfigUtility
{
///
/// 生成64long的主键。
///
/// 键1。
/// 键2。
/// 64long的主键。
public static UInt64 Make64Key(uint key1, uint key2)
{
return ((UInt64)key1 << 32) | key2;
}
///
/// 拷贝配置表字典。
///
/// 拷贝地址。
/// 拷贝源。
/// 指定主键。
/// 键。
/// 值。
/// 是否拷贝成功。
public static bool CopyConfigDict(ref Dictionary dict,List source, ConvertDictionaryKey convKey)
{
if (source == null)
{
return false;
}
dict.Clear();
bool failed = false;
for (int i = 0; i < source.Count; i++)
{
var data = source[i];
TKey key = convKey(data);
if (dict.ContainsKey(key))
{
Log.Fatal("Copy Config Failed: {0} IndexOf {1} Had Repeated Key: {2} ", typeof(TValue).Name, i + 1, key);
failed = true;
break;
}
dict.Add(key, data);
}
return !failed;
}
}
}