-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
89 lines (80 loc) · 2.16 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main
import (
"bufio"
"fmt"
"os"
"github.com/tidwall/gjson"
)
func main() {
args := os.Args
fmt.Print(`
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Atlased to Phaser Parser
Version: 0.0
Build Date: 2024-01-24
Author: Gabriel A. Zorrilla - @GabrielZorrilla - zorrilla.me
Site: https://github.com/GAZ082/atlased_phaserjs_parser
FREE TO USE FOR ANY ENDEVOUR BUT PLEASE ASK FOR AUTHORIZATION AND MENTION THE
ORIGINAL AUTHOR IN YOUR PROJECT.
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
`)
fmt.Println("")
if len(args) != 3 {
fmt.Print(`ERROR: Must provide two files, the input (Atlased JSON) and the output destination JSON.`)
os.Exit(1)
}
input := readAtlasedJson(args[1])
output, _ := os.Create(args[2])
write_buffer := bufio.NewWriter(output)
parseAtlasedJson(input, write_buffer)
write_buffer.Flush()
println(`DONE!`)
}
func readAtlasedJson(inputFile string) string {
b, err := os.ReadFile(inputFile)
if err != nil {
print(err.Error())
return "Something wrong with the input file."
}
return string(b)
}
func parseAtlasedJson(json string, wbuffer *bufio.Writer) {
wbuffer.WriteString(`{ "frames": {`)
results := gjson.Get(json, "regions").Array()
lastItem := len(results)
for counter, i := range results {
value := fmt.Sprintf(`
"%v": {
"frame": {
"x":%v,
"y":%v,
"w":%v,
"h":%v
},
"pivot": {
"x":%.2f,
"y":%.2f
}
},`,
i.Get("name").String(),
i.Get("rect.0").Int(),
i.Get("rect.1").Int(),
i.Get("rect.2").Int(),
i.Get("rect.3").Int(),
i.Get("origin.0").Float()/i.Get("rect.2").Float(),
i.Get("origin.1").Float()/i.Get("rect.3").Float(),
)
if counter == lastItem-1 {
value = value[:len(value)-1]
}
wbuffer.WriteString(value)
counter++
}
wbuffer.WriteString(`
}
}`)
}