|
@@ -4,9 +4,30 @@ using System.Collections.Generic;
|
|
|
using LitJson;
|
|
|
using UnityEngine;
|
|
|
|
|
|
+public class ThanksGiftJson
|
|
|
+{
|
|
|
+ public static string PackID = "packid";
|
|
|
+ public static string StartTime = "starttime";
|
|
|
+ public static string EndTime = "endtime";
|
|
|
+
|
|
|
+ public static int UnvalidValue = 0;
|
|
|
+ public static string UnvalidValues = "0";
|
|
|
+
|
|
|
+ public static Dictionary<Gift.GiftType, string> TypeDictionary = new Dictionary<Gift.GiftType, string>
|
|
|
+ {
|
|
|
+ {Gift.GiftType.金币,"g"},
|
|
|
+ {Gift.GiftType.钻石,"d"},
|
|
|
+ {Gift.GiftType.礼包,"p"},
|
|
|
+ {Gift.GiftType.花朵,"f"},
|
|
|
+ {Gift.GiftType.服装,"c"},
|
|
|
+ {Gift.GiftType.开垦土地,"s"},
|
|
|
+ {Gift.GiftType.精灵,"a"},
|
|
|
+ };
|
|
|
+}
|
|
|
+
|
|
|
public class Gift
|
|
|
{
|
|
|
- private enum GiftType
|
|
|
+ public enum GiftType
|
|
|
{
|
|
|
金币 = 0,
|
|
|
钻石 = 1,
|
|
@@ -17,24 +38,8 @@ public class Gift
|
|
|
精灵 = 6,
|
|
|
}
|
|
|
|
|
|
- private static Dictionary<GiftType, string> TypeLabelDictionary = new Dictionary<GiftType, string>
|
|
|
- {
|
|
|
- {GiftType.金币,"g"},
|
|
|
- {GiftType.钻石,"d"},
|
|
|
- {GiftType.礼包,"p"},
|
|
|
- {GiftType.花朵,"f"},
|
|
|
- {GiftType.服装,"c"},
|
|
|
- {GiftType.开垦土地,"s"},
|
|
|
- {GiftType.精灵,"a"},
|
|
|
- };
|
|
|
-
|
|
|
#region Config
|
|
|
|
|
|
- private static int UnvalidValue = 0;
|
|
|
- private static string UnvalidValues = "0";
|
|
|
- private static string StartTimeLabel = "starttime";
|
|
|
- private static string EndTimeLabel = "endtime";
|
|
|
-
|
|
|
private List<List<int>> Values = new List<List<int>>();
|
|
|
private List<GiftType> Types = new List<GiftType>();
|
|
|
private DateTime StartDate;
|
|
@@ -45,50 +50,57 @@ public class Gift
|
|
|
public Gift(JsonData jsonData)
|
|
|
{
|
|
|
//Debug.Log(jsonData.ToJson());
|
|
|
- int value = (int) jsonData[TypeLabelDictionary[GiftType.金币]];
|
|
|
- if (value != UnvalidValue)
|
|
|
+ string label = ThanksGiftJson.TypeDictionary[GiftType.金币];
|
|
|
+ int value = (int) jsonData[label];
|
|
|
+ if (value != ThanksGiftJson.UnvalidValue)
|
|
|
{
|
|
|
Types.Add(GiftType.金币);
|
|
|
Values.Add(new List<int> {value});
|
|
|
}
|
|
|
- value = (int)jsonData[TypeLabelDictionary[GiftType.钻石]];
|
|
|
- if (value != UnvalidValue)
|
|
|
+ label = ThanksGiftJson.TypeDictionary[GiftType.钻石];
|
|
|
+ value = (int)jsonData[label];
|
|
|
+ if (value != ThanksGiftJson.UnvalidValue)
|
|
|
{
|
|
|
Types.Add(GiftType.钻石);
|
|
|
Values.Add(new List<int> { value });
|
|
|
}
|
|
|
- string values = (string)jsonData[TypeLabelDictionary[GiftType.礼包]];
|
|
|
- if (values != UnvalidValues)
|
|
|
+ label = ThanksGiftJson.TypeDictionary[GiftType.礼包];
|
|
|
+ string values = (string)jsonData[label];
|
|
|
+ if (values != ThanksGiftJson.UnvalidValues)
|
|
|
{
|
|
|
Types.Add(GiftType.礼包);
|
|
|
Values.Add(Auxiliary.StringToInts(' ', values, new List<int>()));
|
|
|
}
|
|
|
- values = (string)jsonData[TypeLabelDictionary[GiftType.花朵]];
|
|
|
- if (values != UnvalidValues)
|
|
|
+ label = ThanksGiftJson.TypeDictionary[GiftType.花朵];
|
|
|
+ values = (string)jsonData[label];
|
|
|
+ if (values != ThanksGiftJson.UnvalidValues)
|
|
|
{
|
|
|
Types.Add(GiftType.花朵);
|
|
|
Values.Add(Auxiliary.StringToInts(' ', values, new List<int>()));
|
|
|
}
|
|
|
- values = (string)jsonData[TypeLabelDictionary[GiftType.服装]];
|
|
|
- if (values != UnvalidValues)
|
|
|
+ label = ThanksGiftJson.TypeDictionary[GiftType.服装];
|
|
|
+ values = (string)jsonData[label];
|
|
|
+ if (values != ThanksGiftJson.UnvalidValues)
|
|
|
{
|
|
|
Types.Add(GiftType.服装);
|
|
|
Values.Add(Auxiliary.StringToInts(' ', values, new List<int>()));
|
|
|
}
|
|
|
- value = (int)jsonData[TypeLabelDictionary[GiftType.开垦土地]];
|
|
|
- if (value != UnvalidValue)
|
|
|
+ label = ThanksGiftJson.TypeDictionary[GiftType.开垦土地];
|
|
|
+ value = (int)jsonData[label];
|
|
|
+ if (value != ThanksGiftJson.UnvalidValue)
|
|
|
{
|
|
|
Types.Add(GiftType.开垦土地);
|
|
|
Values.Add(new List<int> { value });
|
|
|
}
|
|
|
- values = (string)jsonData[TypeLabelDictionary[GiftType.精灵]];
|
|
|
- if (values != UnvalidValues)
|
|
|
+ label = ThanksGiftJson.TypeDictionary[GiftType.精灵];
|
|
|
+ values = (string)jsonData[label];
|
|
|
+ if (values != ThanksGiftJson.UnvalidValues)
|
|
|
{
|
|
|
Types.Add(GiftType.精灵);
|
|
|
Values.Add(Auxiliary.StringToInts(' ', values, new List<int>()));
|
|
|
}
|
|
|
- StartDate = DateTime.Parse(jsonData[StartTimeLabel].ToString());
|
|
|
- EndDate = DateTime.Parse(jsonData[EndTimeLabel].ToString());
|
|
|
+ StartDate = DateTime.Parse(jsonData[ThanksGiftJson.StartTime].ToString());
|
|
|
+ EndDate = DateTime.Parse(jsonData[ThanksGiftJson.EndTime].ToString());
|
|
|
//for (int i = 0; i < Types.Count; i++)
|
|
|
//{
|
|
|
// Debug.LogWarning(Types[i]);
|
|
@@ -212,7 +224,7 @@ public class ThanksGift
|
|
|
|
|
|
private static bool Inited;
|
|
|
private static Dictionary<int, Gift> GiftDictionary = new Dictionary<int, Gift>();
|
|
|
-
|
|
|
+
|
|
|
#endregion
|
|
|
|
|
|
public static void Init(JsonData jsonData)
|
|
@@ -221,7 +233,7 @@ public class ThanksGift
|
|
|
Inited = true;
|
|
|
for (int i = 0; i < jsonData.Count; i++)
|
|
|
{
|
|
|
- int packID = (int) jsonData[i]["packid"];
|
|
|
+ int packID = (int) jsonData[i][ThanksGiftJson.PackID];
|
|
|
Gift gift = new Gift(jsonData[i]);
|
|
|
GiftDictionary.Add(packID, gift);
|
|
|
}
|