示例#1
0
        void SaveLine(JArray linesArray, CastleLine line, CastleSheet sheet)
        {
            JObject lineObject = new JObject();

            linesArray.Add(lineObject);

            for (int i = 0; i < sheet.Columns.Count; ++i)
            {
                switch (sheet.Columns[i].TypeID)
                {
                case CastleType.List:
                    JArray      subList  = new JArray();
                    CastleSheet subSheet = line.Values[i] as CastleSheet;
                    if (subSheet != null)
                    {
                        SaveSheetLines(subList, subSheet);
                    }
                    lineObject.Add(new JProperty(sheet.Columns[i].Name, subList));
                    break;

                case CastleType.Custom:
                    CastleCustomInst ci        = line.Values[i] as CastleCustomInst;
                    JArray           ctorArray = new JArray();
                    if (ci == null)
                    {
                    }
                    lineObject.Add(new JProperty(sheet.Columns[i].Name, ctorArray));
                    break;

                default:
                    lineObject.Add(new JProperty(sheet.Columns[i].Name, CastleTypeConverter.ConvertType(sheet.Columns[i].TypeID, line.Values[i])));
                    break;
                }
            }
        }
示例#2
0
 void FillSheetData(CastleSheet targetSheet, JArray linesArray)
 {
     foreach (JObject line in linesArray)
     {
         CastleLine newLine = new CastleLine();
         foreach (JProperty property in line.Properties())
         {
             string       propName = property.Name;
             CastleColumn col      = targetSheet.Columns.FirstOrDefault(c => c.Name.Equals(propName));
             if (col == null)
             {
                 continue;
             }
             if (col.TypeID == CastleType.List)
             {
                 string      newSheetName = string.Format("{0}@{1}", targetSheet.Name, col.Name);
                 CastleSheet newTarget    = Sheets.FirstOrDefault(s => s.Name.Equals(newSheetName)).Clone();
                 if (newTarget != null)
                 {
                     FillSheetData(newTarget, property.Value as JArray);
                 }
                 newLine.Values.Add(newTarget);
             }
             else if (col.TypeID == CastleType.Custom)
             {
                 CastleCustom customType = CustomTypes.FirstOrDefault(c => c.Name.Equals(col.Key));
                 if (customType != null)
                 {
                     JArray           valArray = property.Value as JArray;
                     CastleCustomInst inst     = new CastleCustomInst();
                     for (int i = 0; i < valArray.Count; ++i)
                     {
                         JToken token     = valArray[i];
                         string tokenText = token.ToString();
                         if (i == 0)
                         {
                             inst.ConstructorIndex = int.Parse(tokenText);
                         }
                         else
                         {
                             inst.Parameters.Add(tokenText);
                         }
                     }
                 }
                 else
                 {
                     throw new Exception("Unable to find custom type: " + col.Key);
                 }
             }
             else if (col.TypeID == CastleType.Image)
             {
                 string strValue = property.Value.ToString();
                 if (strValue.Contains(":"))
                 {
                     string[] words = strValue.Split(':');
                     newLine.Values.Add(new CastleImage {
                         MD5 = words[0], Path = words[1]
                     });
                 }
                 else
                 {
                     newLine.Values.Add(new CastleImage {
                         MD5 = strValue, Path = ""
                     });
                 }
             }
             else if (col.TypeID == CastleType.TilePos)
             {
                 JObject tileObj = property.Value as JObject;
                 if (tileObj != null)
                 {
                     newLine.Values.Add(new CastleTilePos {
                         File   = tileObj.Property("file").Value.ToString(),
                         Size   = int.Parse(tileObj.Property("size").Value.ToString()),
                         X      = int.Parse(tileObj.Property("x").Value.ToString()),
                         Y      = int.Parse(tileObj.Property("y").Value.ToString()),
                         Width  = tileObj.Property("width") != null ? int.Parse(tileObj.Property("width").Value.ToString()) : 0,
                         Height = tileObj.Property("height") != null ? int.Parse(tileObj.Property("height").Value.ToString()) : 0
                     });
                 }
             }
             else if (col.TypeID == CastleType.Layer)
             {
             }
             else if (col.TypeID == CastleType.TileLayer)
             {
             }
             else if (col.TypeID == CastleType.Dynamic)
             {
                 // Just straight add the JToken to it
                 newLine.Values.Add(property.Value);
             }
             else if (col.TypeID == CastleType.Ref)
             {
                 newLine.Values.Add(property.Value.ToString());
             }
             else
             {
                 newLine.Values.Add(property.Value.ToString());
             }
         }
     }
 }