-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpane.go
186 lines (159 loc) · 4.1 KB
/
pane.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
package brlyt
import (
"bytes"
"encoding/binary"
"io"
"strings"
)
func (r *Root) ParsePAN(data []byte) (*XMLPane, error) {
var pane Pane
err := binary.Read(bytes.NewReader(data), binary.BigEndian, &pane)
if err != nil {
return nil, err
}
// Strip the null bytes from the strings
name := strings.Replace(string(pane.PaneName[:]), "\x00", "", -1)
userData := strings.Replace(string(pane.UserData[:]), "\x00", "", -1)
xmlData := XMLPane{
Name: name,
UserData: userData,
Flag: pane.Flag,
Origin: Coord2D{X: float32(pane.Origin % 3), Y: float32(pane.Origin / 3)},
Alpha: pane.Alpha,
Padding: 0,
Translate: Coord3D{X: pane.XTranslation, Y: pane.YTranslation, Z: pane.ZTranslation},
Rotate: Coord3D{X: pane.XRotate, Y: pane.YRotate, Z: pane.ZRotate},
Scale: Coord2D{X: pane.XScale, Y: pane.YScale},
Width: pane.Width,
Height: pane.Height,
}
if name == "RootPane" {
r.RootPane = xmlData
r.count--
_, err = r.reader.Seek(8, io.SeekCurrent)
if err != nil {
return nil, err
}
r.RootPane.Children, err = r.ParseChildren()
if err != nil {
return nil, err
}
} else {
// Only the Root Pane is guaranteed to have children, peek to see if this pane does.
if r.HasChildren() {
xmlData.Children, err = r.ParseChildren()
if err != nil {
return nil, err
}
}
}
return &xmlData, nil
}
func (r *Root) ParseBND(data []byte) (*XMLPane, error) {
var pane Pane
err := binary.Read(bytes.NewReader(data), binary.BigEndian, &pane)
if err != nil {
return nil, err
}
// Strip the null bytes from the strings
name := strings.Replace(string(pane.PaneName[:]), "\x00", "", -1)
userData := strings.Replace(string(pane.UserData[:]), "\x00", "", -1)
xmlData := XMLPane{
Name: name,
UserData: userData,
Flag: pane.Flag,
Origin: Coord2D{X: float32(pane.Origin % 3), Y: float32(pane.Origin / 3)},
Alpha: pane.Alpha,
Padding: 0,
Translate: Coord3D{X: pane.XTranslation, Y: pane.YTranslation, Z: pane.ZTranslation},
Rotate: Coord3D{X: pane.XRotate, Y: pane.YRotate, Z: pane.ZRotate},
Scale: Coord2D{X: pane.XScale, Y: pane.YScale},
Width: pane.Width,
Height: pane.Height,
}
if r.HasChildren() {
xmlData.Children, err = r.ParseChildren()
if err != nil {
return nil, err
}
}
return &xmlData, nil
}
func (b *BRLYTWriter) WritePane(pan XMLPane) error {
header := SectionHeader{
Type: SectionTypePAN,
Size: 76,
}
var name [16]byte
copy(name[:], pan.Name)
var userData [8]byte
copy(userData[:], pan.UserData)
pane := Pane{
Flag: pan.Flag,
Origin: uint8(pan.Origin.X + (pan.Origin.Y * 3)),
Alpha: pan.Alpha,
PaneName: name,
UserData: userData,
XTranslation: pan.Translate.X,
YTranslation: pan.Translate.Y,
ZTranslation: pan.Translate.Z,
XRotate: pan.Rotate.X,
YRotate: pan.Rotate.Y,
ZRotate: pan.Rotate.Z,
XScale: pan.Scale.X,
YScale: pan.Scale.Y,
Width: pan.Width,
Height: pan.Height,
}
err := write(b, header)
if err != nil {
return err
}
return write(b, pane)
}
func (b *BRLYTWriter) WriteBND(pan XMLPane) error {
header := SectionHeader{
Type: SectionTypeBND,
Size: 76,
}
var name [16]byte
copy(name[:], pan.Name)
var userData [8]byte
copy(userData[:], pan.UserData)
pane := Pane{
Flag: pan.Flag,
Origin: uint8(pan.Origin.X + (pan.Origin.Y * 3)),
Alpha: pan.Alpha,
PaneName: name,
UserData: userData,
XTranslation: pan.Translate.X,
YTranslation: pan.Translate.Y,
ZTranslation: pan.Translate.Z,
XRotate: pan.Rotate.X,
YRotate: pan.Rotate.Y,
ZRotate: pan.Rotate.Z,
XScale: pan.Scale.X,
YScale: pan.Scale.Y,
Width: pan.Width,
Height: pan.Height,
}
err := write(b, header)
if err != nil {
return err
}
return write(b, pane)
}
func (b *BRLYTWriter) WritePAS() error {
header := SectionHeader{
Type: SectionTypePAS,
Size: 8,
}
return write(b, header)
}
func (b *BRLYTWriter) WritePAE() error {
header := SectionHeader{
Type: SectionTypePAE,
Size: 8,
}
return write(b, header)
}