forked from WiiLink24/NewsChannel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheadlines.go
More file actions
44 lines (33 loc) · 1.07 KB
/
headlines.go
File metadata and controls
44 lines (33 loc) · 1.07 KB
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
package main
import "unicode/utf16"
// Headlines are the news articles that will appear on the News Channel banner in the Wii Menu.
type Headlines struct {
HeadlineSize uint32
HeadlineOffset uint32
}
func (n *News) MakeWiiMenuHeadlines() {
n.Header.HeadlinesTableOffset = n.GetCurrentSize()
numberOfHeadlines := 11
if len(n.articles) < 11 {
numberOfHeadlines = len(n.articles)
}
n.Headlines = make([]Headlines, numberOfHeadlines)
for i := 0; i < numberOfHeadlines; i++ {
article := n.articles[i]
// Encode to UTF-16
encoded := utf16.Encode([]rune(article.Title))
n.Headlines[i] = Headlines{
HeadlineSize: uint32(len(encoded)) * 2,
HeadlineOffset: n.GetCurrentSize(),
}
n.HeadlineText = append(n.HeadlineText, encoded...)
// Padding time.
if (n.GetCurrentSize()+2)%4 == 0 {
n.HeadlineText = append(n.HeadlineText, uint16(0))
} else if (n.GetCurrentSize()+4)%4 == 0 {
n.HeadlineText = append(n.HeadlineText, uint16(0))
n.HeadlineText = append(n.HeadlineText, uint16(0))
}
}
n.Header.NumberOfHeadlines = uint32(numberOfHeadlines)
}