예제 #1
0
        public static string WriteToLua(WDBSheet sheet, TargetPlatformType platformType)
        {
            if (sheet.FieldCount == 0 || sheet.RowCount == 0)
            {
                return(string.Empty);
            }

            WDBFieldPlatform platform = platformType == TargetPlatformType.Client ? WDBFieldPlatform.Client : WDBFieldPlatform.Server;

            StringBuilder builder = new StringBuilder();
            int           indent  = 0;

            builder.AppendLine($"local {sheet.Name} = {{");
            for (int r = 0; r < sheet.RowCount; r++)
            {
                WDBRow row = sheet.GetRowAtIndex(r);

                WDBField keyField = sheet.GetFieldAtIndex(0);
                WDBCell  keyCell  = row.GetCellByIndex(0);
                indent++;
                string keyStr = keyCell.GetContent(keyField);
                builder.AppendLine($"{GetIndent(indent)}[{keyStr}] = {{");

                for (int f = 0; f < sheet.FieldCount; f++)
                {
                    WDBField field = sheet.GetFieldAtIndex(f);
                    if (string.IsNullOrEmpty(field.Name))
                    {
                        continue;
                    }

                    if (field.FieldPlatform != WDBFieldPlatform.All && field.FieldPlatform != platform)
                    {
                        continue;
                    }
                    indent++;
                    WDBCell cell = row.GetCellByIndex(f);
                    AppendValueLine(builder, indent, field, cell);
                    indent--;
                }

                builder.AppendLine($"{GetIndent(indent)}}},");
                indent--;
            }
            builder.AppendLine("}");
            builder.AppendLine($"return {sheet.Name}");

            return(builder.ToString());
        }
예제 #2
0
        public static string WriteToJson(WDBSheet sheet, TargetPlatformType platformType)
        {
            if (sheet.FieldCount == 0 || sheet.RowCount == 0)
            {
                return(string.Empty);
            }

            WDBFieldPlatform platform = platformType == TargetPlatformType.Client ? WDBFieldPlatform.Client : WDBFieldPlatform.Server;

            JObject sheetObject = new JObject();

            for (int r = 0; r < sheet.RowCount; r++)
            {
                WDBRow row = sheet.GetRowAtIndex(r);

                JObject rowObject = new JObject();

                for (int f = 0; f < sheet.FieldCount; f++)
                {
                    WDBField field = sheet.GetFieldAtIndex(f);
                    if (string.IsNullOrEmpty(field.Name))
                    {
                        continue;
                    }

                    if (field.FieldPlatform != WDBFieldPlatform.All && field.FieldPlatform != platform)
                    {
                        continue;
                    }

                    object value = GetValue(field, row.GetCellByIndex(f));
                    rowObject.Add(field.Name, JToken.FromObject(value));

                    if (f == 0)
                    {
                        sheetObject.Add(value.ToString(), rowObject);
                    }
                }
            }

            return(sheetObject.ToString(Formatting.Indented));
        }