@@ -5,13 +5,16 @@ import (
55 "io"
66 "log"
77 "os"
8+ "reflect"
9+ "strings"
810
911 "github.com/dblk/tinshop/config"
1012 "github.com/dblk/tinshop/repository"
1113 "github.com/dblk/tinshop/utils"
1214)
1315
1416var library map [string ]map [string ]interface {}
17+ var mergedLibrary map [string ]interface {}
1518var games repository.GameType
1619
1720// Load ensure that necessary data is loaded
@@ -58,28 +61,56 @@ func loadTitlesLibrary() {
5861func initGamesCollection () {
5962 // Build games object
6063 games .Success = "Welcome to your own shop!"
61- games .Titledb = make (map [string ]map [ string ] interface {})
64+ games .Titledb = make (map [string ]interface {})
6265 games .Files = make ([]interface {}, 0 )
66+ games .ThemeBlackList = nil
6367}
6468
65- // Reset the collection of files
66- func Reset ( src repository.Sources ) {
69+ // OnConfigUpdate the collection of files
70+ func OnConfigUpdate ( cfg repository.Config ) {
6771 initGamesCollection ()
72+
73+ // Create merged library
74+ mergedLibrary = make (map [string ]interface {})
75+
76+ // Copy library
77+ for key , entry := range library {
78+ gameID := strings .ToUpper (key )
79+
80+ mergedLibrary [gameID ] = entry
81+ }
82+
83+ // Copy CustomDB
84+ for key , entry := range config .GetConfig ().CustomDB () {
85+ gameID := strings .ToUpper (key )
86+ if mergedLibrary [gameID ] != nil {
87+ log .Println ("Duplicate customDB entry from official titledb (consider removing from configuration)" , gameID )
88+ } else {
89+ mergedLibrary [gameID ] = entry
90+ }
91+ }
92+
93+ // Check if blacklist entries
94+ if len (config .GetConfig ().BannedTheme ()) != 0 {
95+ games .ThemeBlackList = config .GetConfig ().BannedTheme ()
96+ } else {
97+ games .ThemeBlackList = nil
98+ }
6899}
69100
70101// Library returns the titledb library
71- func Library () map [string ]map [ string ] interface {} {
72- return library
102+ func Library () map [string ]interface {} {
103+ return mergedLibrary
73104}
74105
75106// HasGameIDInLibrary tells if we have gameID information in library
76107func HasGameIDInLibrary (gameID string ) bool {
77- return library [gameID ] != nil
108+ return Library () [gameID ] != nil
78109}
79110
80111// IsBaseGame tells if the gameID is a base game or not
81112func IsBaseGame (gameID string ) bool {
82- return library [gameID ]["iconUrl" ] != nil
113+ return Library () [gameID ].( map [ string ] interface {}) ["iconUrl" ] != nil
83114}
84115
85116// Games returns the games inside the library
@@ -91,8 +122,14 @@ func Games() repository.GameType {
91122func CountGames () int {
92123 var uniqueGames int
93124 for _ , entry := range games .Titledb {
94- if entry ["iconUrl" ] != nil {
95- uniqueGames ++
125+ if reflect .TypeOf (entry ).String () == "repository.CustomDBEntry" {
126+ if entry .(repository.CustomDBEntry ).IconURL != "" {
127+ uniqueGames ++
128+ }
129+ } else {
130+ if entry .(map [string ]interface {})["iconUrl" ] != nil {
131+ uniqueGames ++
132+ }
96133 }
97134 }
98135 return uniqueGames
@@ -114,7 +151,7 @@ func AddNewGames(newGames []repository.FileDesc) {
114151 if games .Titledb [file .GameID ] != nil && IsBaseGame (file .GameID ) {
115152 log .Println ("Already added id!" , file .GameID , file .Path )
116153 } else {
117- games .Titledb [file .GameID ] = library [file .GameID ]
154+ games .Titledb [file .GameID ] = Library () [file .GameID ]
118155 }
119156 } else {
120157 log .Println ("Game not found in database!" , file .GameInfo , file .Path )
0 commit comments