-
Notifications
You must be signed in to change notification settings - Fork 423
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
114 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package printer | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/davyxu/pbmeta" | ||
pbprotos "github.com/davyxu/pbmeta/proto" | ||
"github.com/davyxu/tabtoy/data" | ||
) | ||
|
||
func getDefaultValueCount(msg *data.DynamicMessage) int { | ||
|
||
var valueCount int | ||
|
||
for i := 0; i < msg.Desc.FieldCount(); i++ { | ||
fd := msg.Desc.Field(i) | ||
if fd.DefaultValue() != "" { | ||
valueCount++ | ||
} | ||
} | ||
|
||
return valueCount | ||
} | ||
|
||
func valueWrapper(fd *pbmeta.FieldDescriptor, value string) string { | ||
switch fd.Type() { | ||
case pbprotos.FieldDescriptorProto_TYPE_STRING: | ||
return strEscape(value) | ||
} | ||
|
||
return value | ||
} | ||
|
||
func strEscape(s string) string { | ||
|
||
b := make([]byte, 0) | ||
|
||
var index int | ||
|
||
// 表中直接使用换行会干扰最终合并文件格式, 所以转成\n,由pbt文本解析层转回去 | ||
for index < len(s) { | ||
c := s[index] | ||
|
||
switch c { | ||
case '"': | ||
b = append(b, '\\') | ||
b = append(b, '"') | ||
case '\x0A': | ||
b = append(b, '\\') | ||
b = append(b, 'n') | ||
case '\x0D': | ||
b = append(b, '\\') | ||
b = append(b, 'r') | ||
default: | ||
b = append(b, c) | ||
} | ||
|
||
index++ | ||
|
||
} | ||
|
||
return fmt.Sprintf("\"%s\"", string(b)) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
{ | ||
|
||
"Actor" : [ | ||
{"ID": 100, "Name": "黑猫警长", "Struct" : {"HP": 100, "AttackRate": 0.6}, "BuffID" : [0, 0], "SkillID" : [4, 6, 7]}, | ||
{"ID": 101, "Name": "葫芦\n娃", "Struct" : {"HP": 10, "AttackRate": 0.8}, "BuffID" : [3, 1], "Type": 21, "SkillID" : [1]}, | ||
{"ID": 102, "Name": "舒\"克\"", "Struct" : {"HP": 10, "AttackRate": 0.7}, "BuffID" : [0, 0], "SkillID" : [0], "StrStruct" : {"HP": 2, "AttackRate": 0.5}}, | ||
{"ID": 103, "Name": "贝\n塔", "Struct" : {"HP": 205}, "BuffID" : [0, 0], "SkillID" : [0]}, | ||
{"ID": 104, "Name": "邋遢大王", "Struct" : {"HP": 10, "AttackRate": 1}, "BuffID" : [0, 0], "SkillID" : [0]} | ||
{"ID": 100, "Name": "黑猫警长", "Struct" : {"HP": 100, "AttackRate": 0.6}, "BuffID" : [0, 0], "SkillID" : [4, 6, 7], "StrStruct" : []}, | ||
{"ID": 101, "Name": "葫芦\n娃", "Struct" : {"HP": 10, "AttackRate": 0.8}, "BuffID" : [3, 1], "Type": 21, "SkillID" : [1], "StrStruct" : []}, | ||
{"ID": 102, "Name": "舒\"克\"", "Struct" : {"HP": 10, "AttackRate": 0.7}, "BuffID" : [0, 0], "SkillID" : [0], "StrStruct" : [{"HP": 2}, {"AttackRate": 0.5}, {"HP": 3, "AttackRate": 1}]}, | ||
{"ID": 103, "Name": "贝\n塔", "Struct" : {"HP": 205}, "BuffID" : [0, 0], "SkillID" : [0], "StrStruct" : []}, | ||
{"ID": 104, "Name": "邋遢大王", "Struct" : {"HP": 10, "AttackRate": 1}, "BuffID" : [0, 0], "SkillID" : [0], "StrStruct" : []} | ||
] | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# Generated by github.com/davyxu/tabtoy | ||
Actor {ID: 100 Name: "黑猫警长" Struct {HP: 100 AttackRate: 0.6} BuffID: 0 BuffID: 0 SkillID: 4 SkillID: 6 SkillID: 7} | ||
Actor {ID: 101 Name: "葫芦\n娃" Struct {HP: 10 AttackRate: 0.8} BuffID: 3 BuffID: 1 Type: Power SkillID: 1} | ||
Actor {ID: 102 Name: "舒\"克\"" Struct {HP: 10 AttackRate: 0.7} BuffID: 0 BuffID: 0 SkillID: 0 StrStruct {HP: 2 AttackRate: 0.5}} | ||
Actor {ID: 103 Name: "贝\n塔" Struct {HP: 205} BuffID: 0 BuffID: 0 SkillID: 0} | ||
Actor {ID: 104 Name: "邋遢大王" Struct {HP: 10 AttackRate: 1} BuffID: 0 BuffID: 0 SkillID: 0} | ||
Actor {ID: 100 Name: "黑猫警长" Struct {HP: 100 AttackRate: 0.6} BuffID: 0 BuffID: 0 SkillID: 4 SkillID: 6 SkillID: 7 } | ||
Actor {ID: 101 Name: "葫芦\n娃" Struct {HP: 10 AttackRate: 0.8} BuffID: 3 BuffID: 1 Type: Power SkillID: 1 } | ||
Actor {ID: 102 Name: "舒\"克\"" Struct {HP: 10 AttackRate: 0.7} BuffID: 0 BuffID: 0 SkillID: 0 StrStruct {HP: 2} StrStruct {AttackRate: 0.5} StrStruct {HP: 3 AttackRate: 1}} | ||
Actor {ID: 103 Name: "贝\n塔" Struct {HP: 205} BuffID: 0 BuffID: 0 SkillID: 0 } | ||
Actor {ID: 104 Name: "邋遢大王" Struct {HP: 10 AttackRate: 1} BuffID: 0 BuffID: 0 SkillID: 0 } |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.