|
@@ -8,6 +8,7 @@ using UnityEngine;
|
|
|
using GFGGame;
|
|
|
using System.Text.RegularExpressions;
|
|
|
using static Google.Protobuf.Reflection.GeneratedCodeInfo.Types;
|
|
|
+using OfficeOpenXml;
|
|
|
|
|
|
namespace GFGEditor
|
|
|
{
|
|
@@ -25,8 +26,9 @@ namespace GFGEditor
|
|
|
private static Dictionary<string, string> _idDic = new Dictionary<string, string>();
|
|
|
private static Dictionary<string, string> _itemTypeDicByName = new Dictionary<string, string>();
|
|
|
|
|
|
- public static void GenerateCode(DataRowCollection rowCollection, string configName, string configArrayName)
|
|
|
+ public static void GenerateCode(ExcelWorksheet worksheet, string configName, string configArrayName)
|
|
|
{
|
|
|
+ ET.Log.Debug($"configName {configName}");
|
|
|
_declarationBuilder.Clear();
|
|
|
_assignmentBuilder.Clear();
|
|
|
_parseBuilder.Clear();
|
|
@@ -41,19 +43,20 @@ namespace GFGEditor
|
|
|
List<string> groupTypes = new List<string>();
|
|
|
bool needAll = false;
|
|
|
bool groupOnly = false;
|
|
|
- int len = rowCollection[1].ItemArray.Length;
|
|
|
+ int len = worksheet.Dimension.End.Column;
|
|
|
if (len <= 0)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
- for (int i = 0; i < len; ++i)
|
|
|
+ for (int i = 1; i <= len; ++i)
|
|
|
{
|
|
|
- string annotation = rowCollection[0][i].ToString();
|
|
|
- string type = rowCollection[1][i].ToString();
|
|
|
- string nameWhole = rowCollection[2][i].ToString();
|
|
|
+ ET.Log.Debug($"GenerateCode for i {i}");
|
|
|
+ string annotation = worksheet.Cells[1, i].Text.Trim();
|
|
|
+ string type = worksheet.Cells[2, i].Text.Trim();
|
|
|
+ string nameWhole = worksheet.Cells[3, i].Text.Trim();
|
|
|
string[] nameInfos = nameWhole.Split('#');
|
|
|
string name = nameInfos[0];
|
|
|
- if (i == 0 || nameWhole.Contains("#k"))
|
|
|
+ if (i == 1 || nameWhole.Contains("#k"))
|
|
|
{
|
|
|
keyNames.Add(name);
|
|
|
keyTypes.Add(type);
|
|
@@ -79,7 +82,7 @@ namespace GFGEditor
|
|
|
}
|
|
|
//创建sqlite表
|
|
|
SQLiteHelper.Instance.CreateTable(configArrayName, _names.ToArray(), _types.ToArray());
|
|
|
- AddDataToSql(rowCollection, configName, configArrayName);
|
|
|
+ AddDataToSql(worksheet, configName, configArrayName);
|
|
|
|
|
|
//生成管理类代码
|
|
|
string configArrayStr = CodeTemplateFactory.ConfigArrayTemplate;
|
|
@@ -241,19 +244,18 @@ namespace GFGEditor
|
|
|
}
|
|
|
|
|
|
|
|
|
- private static void AddDataToSql(DataRowCollection rowCollection, string configName, string configArrayName)
|
|
|
+ private static void AddDataToSql(ExcelWorksheet worksheet, string configName, string configArrayName)
|
|
|
{
|
|
|
- int rowNum = rowCollection.Count;
|
|
|
- for (int i = 4; i < rowNum; i++)
|
|
|
+ int rowNum = worksheet.Dimension.End.Row;
|
|
|
+ for (int i = 5; i <= rowNum; i++)
|
|
|
{
|
|
|
- DataRow dataRow = rowCollection[i];
|
|
|
- string key = dataRow[0].ToString();
|
|
|
+ string key = worksheet.Cells[i, 1].Text.Trim();
|
|
|
if (key.Length == 0)
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
//解析每行的数据
|
|
|
- WriteRowDataToSqlite(dataRow, configArrayName);
|
|
|
+ WriteRowDataToSqlite(worksheet.Cells, configArrayName, i);
|
|
|
if (_idDic.ContainsKey(key))
|
|
|
{
|
|
|
_hasSameIds = true;
|
|
@@ -265,14 +267,14 @@ namespace GFGEditor
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private static void WriteRowDataToSqlite(DataRow row, string configArrayName)
|
|
|
+ private static void WriteRowDataToSqlite(ExcelRange excelRange, string configArrayName, int row)
|
|
|
{
|
|
|
List<string> values = new List<string>();
|
|
|
- var keyValue = row[0].ToString();
|
|
|
+ var keyValue = excelRange[row, 1].Text.Trim();
|
|
|
foreach (var i in _indexs)
|
|
|
{
|
|
|
- var fieldName = _names[i];
|
|
|
- var value = row[i].ToString();
|
|
|
+ var fieldName = _names[i-1];
|
|
|
+ var value = excelRange[row, i].Text.Trim();
|
|
|
if (configArrayName == nameof(ItemTypeCfgArray))
|
|
|
{
|
|
|
CacheItemTypeByName(keyValue, fieldName, value);
|
|
@@ -299,6 +301,7 @@ namespace GFGEditor
|
|
|
private static void HandleItemCfgField(string idStr, string fieldName, ref string value)
|
|
|
{
|
|
|
fieldName = fieldName.Substring(1);
|
|
|
+ ET.Log.Debug($"idStr {idStr} fieldName {fieldName} value {value}");
|
|
|
int id = int.Parse(idStr);
|
|
|
int itemType = (int)Mathf.Floor(id / GameConst.MAX_COUNT_EVERY_TYPE_ITEM);
|
|
|
if (fieldName == "itemType")
|