lyt.go 825 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package main
  2. import (
  3. "bytes"
  4. "encoding/binary"
  5. "encoding/xml"
  6. )
  7. // LYT defines the main layout of the BRLYT
  8. type LYT struct {
  9. Centered [1]byte
  10. Padding [3]byte
  11. Width float32
  12. Height float32
  13. }
  14. func (r *Root) ParseLYT(data []byte) {
  15. // Parse LYT section
  16. readable := bytes.NewReader(data)
  17. var lyt LYT
  18. err := binary.Read(readable, binary.BigEndian, &lyt)
  19. if err != nil {
  20. panic(err)
  21. }
  22. r.LYT = LYTNode{
  23. XMLName: xml.Name{},
  24. Centered: uint16(lyt.Centered[0]),
  25. Width: lyt.Width,
  26. Height: lyt.Height,
  27. }
  28. }
  29. func (b *BRLYTWriter) WriteLYT(data Root) {
  30. header := SectionHeader{
  31. Type: SectionTypeLYT,
  32. Size: 20,
  33. }
  34. lyt := LYT{
  35. Centered: [1]byte{byte(data.LYT.Centered)},
  36. Padding: [3]byte{},
  37. Width: data.LYT.Width,
  38. Height: data.LYT.Height,
  39. }
  40. write(b, header)
  41. write(b, lyt)
  42. }