Created
August 17, 2016 02:56
-
-
Save holys/aa949785346d797c32966e8c727bbbce to your computer and use it in GitHub Desktop.
generate_json
This file contains hidden or 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
| package main | |
| import ( | |
| "encoding/json" | |
| "flag" | |
| "fmt" | |
| "log" | |
| "os" | |
| ) | |
| var ( | |
| name = flag.String("name", "", "name of json file") | |
| ) | |
| func main() { | |
| flag.Parse() | |
| if *name == "" { | |
| fmt.Println("please specify name") | |
| os.Exit(1) | |
| } | |
| fileName := *name + ".json" | |
| target, err := os.Create(fileName) | |
| if err != nil { | |
| log.Fatal(err.Error()) | |
| } | |
| defer target.Close() | |
| args := flag.Args() | |
| defaultScalePoint := make([]ScalePoint, 1) | |
| defaultScalePoint[0] = ScalePoint{} | |
| face := &Face{Version: "1.0"} | |
| face.Parts = make(map[string]Part) | |
| for i, arg := range args { | |
| face.Parts[arg] = Part{ | |
| ZPosition: i, | |
| RotateCenters: defaultScalePoint, | |
| ScalePointsA: defaultScalePoint, | |
| ScalePointsB: defaultScalePoint, | |
| PositionPoints: defaultScalePoint, | |
| } | |
| } | |
| encoder := json.NewEncoder(target) | |
| encoder.SetIndent("", "\t") | |
| if err := encoder.Encode(face); err != nil { | |
| log.Fatalf(err.Error()) | |
| } | |
| fmt.Printf("%s json file generated.\n", fileName) | |
| } | |
| type RotateCenter struct { | |
| X float64 `json:"x"` | |
| Y float64 `json:"y"` | |
| Index int `json:"index"` | |
| } | |
| type ScalePoint struct { | |
| X float64 `json:"x"` | |
| Y float64 `json:"y"` | |
| Index int `json:"index"` | |
| } | |
| type Part struct { | |
| ZPosition int `json:"zPosition"` | |
| Width int `json:"width"` | |
| Height int `json:"height"` | |
| Type int `json:"type"` | |
| FrameCount int `json:"frameCount"` | |
| TriggerAction int `json:"triggerAction"` | |
| TriggerLoop int `json:"triggerLoop"` | |
| TriggerDelay int `json:"triggerDelay"` | |
| TriggerStop bool `json:"triggerStop"` | |
| RotateCenters []ScalePoint `json:"rotateCenters"` | |
| ScalePointsA []ScalePoint `json:"scalePointsA"` | |
| ScalePointsB []ScalePoint `json:"scalePointsB"` | |
| PositionPoints []ScalePoint `json:"positionPoints"` | |
| } | |
| type Face struct { | |
| Version string `json:"version"` | |
| Parts map[string]Part `json:"parts"` | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment