MCPcopy Create free account
hub / github.com/SolarLune/masterplan / loadThemes

Function loadThemes

gui.go:98–154  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

96}
97
98func loadThemes() {
99
100 newGUIColors := map[string]map[string]Color{}
101 availableThemes = []string{}
102
103 filepath.Walk(LocalRelativePath("assets/themes"), func(fp string, info os.FileInfo, err error) error {
104
105 if !info.IsDir() {
106
107 themeFile, err := os.Open(fp)
108
109 if err == nil {
110
111 defer themeFile.Close()
112
113 _, themeName := filepath.Split(fp)
114 themeName = strings.Split(themeName, ".json")[0]
115
116 availableThemes = append(availableThemes, themeName)
117
118 // themeData := []byte{}
119 themeData := ""
120 var jsonData map[string][]uint8
121
122 scanner := bufio.NewScanner(themeFile)
123 for scanner.Scan() {
124 // themeData = append(themeData, scanner.Bytes()...)
125 themeData += scanner.Text()
126 }
127 json.Unmarshal([]byte(themeData), &jsonData)
128
129 // A length of 0 means JSON couldn't properly unmarshal the data, so it was mangled somehow.
130 if len(jsonData) > 0 {
131
132 newGUIColors[themeName] = map[string]Color{}
133
134 for key, value := range jsonData {
135 if !strings.Contains(key, "//") { // Strings that begin with "//" are ignored
136 newGUIColors[themeName][key] = Color{value[0], value[1], value[2], value[3]}
137 }
138 }
139
140 } else {
141 newGUIColors[themeName] = guiColors[themeName]
142 }
143
144 }
145 }
146 if err != nil {
147 return err
148 }
149 return nil
150 })
151
152 guiColors = newGUIColors
153
154}
155

Callers 2

mainFunction · 0.85
ConstructMenusFunction · 0.85

Calls 4

LocalRelativePathFunction · 0.85
CloseMethod · 0.80
OpenMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected