aboutsummaryrefslogtreecommitdiff
path: root/internal/game/sys_science.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/game/sys_science.go')
-rw-r--r--internal/game/sys_science.go53
1 files changed, 53 insertions, 0 deletions
diff --git a/internal/game/sys_science.go b/internal/game/sys_science.go
index 23aeef4..e35105a 100644
--- a/internal/game/sys_science.go
+++ b/internal/game/sys_science.go
@@ -81,6 +81,59 @@ func FindMod(input string) *ModDef {
return nil
}
+func findAllModMatches(input string) []*ModDef {
+ inputWords := strings.Fields(strings.ToLower(input))
+ if len(inputWords) == 0 {
+ return nil
+ }
+ var matches []*ModDef
+ for _, m := range AllMods {
+ lowerName := strings.ToLower(m.Name)
+ lowerID := strings.ToLower(m.ID)
+ allMatch := true
+ for _, word := range inputWords {
+ if !strings.Contains(lowerName, word) && !strings.Contains(lowerID, word) {
+ allMatch = false
+ break
+ }
+ }
+ if allMatch {
+ matches = append(matches, m)
+ }
+ }
+ return matches
+}
+
+func FindModForPlayer(input string, sciLevel int) *ModDef {
+ if m, ok := modByID[input]; ok {
+ return m
+ }
+ lower := strings.ToLower(strings.ReplaceAll(input, " ", "_"))
+ for _, m := range AllMods {
+ if strings.HasPrefix(m.ID, lower) {
+ return m
+ }
+ }
+
+ matches := findAllModMatches(input)
+ if len(matches) == 0 {
+ return nil
+ }
+ if len(matches) == 1 {
+ return matches[0]
+ }
+
+ sort.Slice(matches, func(i, j int) bool {
+ return matches[i].Level > matches[j].Level
+ })
+ for _, m := range matches {
+ if m.Level <= sciLevel {
+ return m
+ }
+ }
+ return matches[len(matches)-1]
+}
+
type chipEntry struct {
Input string
Output string