调整 convert.py 转换逻辑 + 规划后续开发
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using Definition.DataStruct;
|
||||
using Definition.Enum;
|
||||
using GameFramework;
|
||||
using CustomUtility;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using UnityEngine;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
@@ -74,6 +74,11 @@ namespace DataTable
|
||||
/// </summary>
|
||||
public Dictionary<string, string> Pramas { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取武器额外参数 Json。
|
||||
/// </summary>
|
||||
public string ParamsJson { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取武器额外属性。
|
||||
/// </summary>
|
||||
@@ -97,7 +102,8 @@ namespace DataTable
|
||||
Cooldown = float.Parse(columnStrings[index++]);
|
||||
AttackRange = float.Parse(columnStrings[index++]);
|
||||
AttackSoundId = int.Parse(columnStrings[index++]);
|
||||
Pramas = DeserializeParams(columnStrings[index++]);
|
||||
ParamsJson = columnStrings[index++];
|
||||
Pramas = DeserializeParams(ParamsJson);
|
||||
Modifiers = Utility.Json.ToObject<StatModifier[]>(columnStrings[index++]);
|
||||
|
||||
GeneratePropertyArray();
|
||||
@@ -114,30 +120,38 @@ namespace DataTable
|
||||
/// </summary>
|
||||
/// <param name="rawParams"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
private Dictionary<string, string> DeserializeParams(string rawParams)
|
||||
{
|
||||
if (!rawParams.StartsWith('[') || !rawParams.EndsWith(']'))
|
||||
{
|
||||
throw new ArgumentException("Input must be enclosed in square brackets.");
|
||||
}
|
||||
|
||||
var dict = new Dictionary<string, string>();
|
||||
|
||||
if (string.IsNullOrEmpty(rawParams)) return dict;
|
||||
|
||||
string[] items = rawParams.Substring(1, rawParams.Length - 2).Split(";");
|
||||
foreach (var item in items)
|
||||
if (string.IsNullOrWhiteSpace(rawParams))
|
||||
{
|
||||
string entry = item.Trim();
|
||||
if (string.IsNullOrEmpty(entry)) continue;
|
||||
return dict;
|
||||
}
|
||||
|
||||
string[] pair = entry.Split(':' , StringSplitOptions.RemoveEmptyEntries);
|
||||
if (pair.Length != 2) continue;
|
||||
dict.Add(pair[0].ToLower(), pair[1]);
|
||||
try
|
||||
{
|
||||
JObject paramObject = Utility.Json.ToObject<JObject>(rawParams);
|
||||
if (paramObject == null)
|
||||
{
|
||||
return dict;
|
||||
}
|
||||
|
||||
foreach (var pair in paramObject)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(pair.Key) || pair.Value == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
dict[pair.Key.ToLower()] = pair.Value.ToString();
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Warning("Failed to parse weapon params json '{0}'. Error: {1}", rawParams, exception.Message);
|
||||
}
|
||||
|
||||
return dict;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user