This repository was archived by the owner on Sep 29, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontextService.go
More file actions
59 lines (45 loc) · 1.39 KB
/
contextService.go
File metadata and controls
59 lines (45 loc) · 1.39 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"fmt"
"github.com/NotGhoull/void-mod-manager/pluginapi"
)
type ContextService struct {
activePluginContext pluginapi.Plugin
reg RegistryService
}
func (c *ContextService) GetActiveContext() string {
return "NO_CONTEXT"
}
func (c *ContextService) checkForValidContext() error {
if c.activePluginContext == nil {
return fmt.Errorf("called function without context")
}
return nil
}
func (c *ContextService) UpdateContextToGame(game string) string {
c.activePluginContext = c.reg.GetPluginForGame(game)[0]
return c.activePluginContext.GetMetaData().HumanName
}
func (c *ContextService) GetMods() ([]pluginapi.ModInfo, error) {
if c.activePluginContext == nil {
return nil, fmt.Errorf("getMods() called without a context")
}
plugin := c.activePluginContext
return plugin.GetMods(), nil
}
func (c *ContextService) GetScreenshots(mod int) ([]string, error) {
if c.activePluginContext == nil {
return nil, fmt.Errorf("getScreenshots() called without context")
}
images, err := c.activePluginContext.GetModScreenshots(mod)
if err != nil {
return nil, fmt.Errorf("Failed to get screenshots: %w", err)
}
return images, nil
}
func (c *ContextService) InstallMod(mod int) (bool, error) {
if c.activePluginContext == nil {
return false, fmt.Errorf("installMod() called without context")
}
return c.activePluginContext.InstallMod(mod, "PROFILE:DEFAULT")
}