@@ -20,6 +20,16 @@ const floatNames = [{
20
20
name : 'SFUI_InvTooltip_Wear_Amount_4'
21
21
} ] ;
22
22
23
+
24
+ const LanguageHandler = {
25
+ get : function ( obj , prop ) {
26
+ return obj [ prop . toLowerCase ( ) ] ;
27
+ } ,
28
+ has : function ( obj , prop ) {
29
+ return prop . toLowerCase ( ) in obj ;
30
+ }
31
+ } ;
32
+
23
33
class GameData {
24
34
constructor ( update_interval , enable_update ) {
25
35
this . items_game_url = 'https://raw.githubusercontent.com/SteamDatabase/GameTracking-CSGO/master/csgo/scripts/items/items_game.txt' ;
@@ -60,7 +70,9 @@ class GameData {
60
70
}
61
71
62
72
if ( fs . existsSync ( 'game_files/csgo_english.txt' ) ) {
63
- this . csgo_english = vdf . parse ( fs . readFileSync ( 'game_files/csgo_english.txt' , 'utf8' ) ) [ 'lang' ] [ 'Tokens' ] ;
73
+ const f = fs . readFileSync ( 'game_files/csgo_english.txt' , 'utf8' ) ;
74
+ this . csgo_english = this . objectKeysToLowerCase ( vdf . parse ( f ) [ 'lang' ] [ 'Tokens' ] ) ;
75
+ this . csgo_english = new Proxy ( this . csgo_english , LanguageHandler ) ;
64
76
}
65
77
66
78
if ( fs . existsSync ( 'game_files/items_game_cdn.txt' ) ) {
@@ -93,6 +105,21 @@ class GameData {
93
105
return result ;
94
106
}
95
107
108
+ /*
109
+ Calls toLowerCase on all object shallow keys, modifies in-place, not pure
110
+ */
111
+ objectKeysToLowerCase ( obj ) {
112
+ const keys = Object . keys ( obj ) ;
113
+ let n = keys . length ;
114
+ while ( n -- ) {
115
+ const key = keys [ n ] ;
116
+ obj [ key . toLowerCase ( ) ] = obj [ key ] ;
117
+ delete obj [ key ] ;
118
+ }
119
+
120
+ return obj
121
+ }
122
+
96
123
/*
97
124
Updates and saves the most recent versions of csgo_english, items_game, and items_game_cdn from the SteamDB Github
98
125
*/
@@ -111,7 +138,9 @@ class GameData {
111
138
utils . downloadFile ( this . csgo_english_url , ( data ) => {
112
139
if ( data ) {
113
140
winston . debug ( 'Fetched csgo_english.txt' ) ;
114
- this . csgo_english = vdf . parse ( data ) [ 'lang' ] [ 'Tokens' ] ;
141
+ this . csgo_english = this . objectKeysToLowerCase ( vdf . parse ( data ) [ 'lang' ] [ 'Tokens' ] ) ;
142
+ this . csgo_english = new Proxy ( this . csgo_english , LanguageHandler ) ;
143
+
115
144
fs . writeFileSync ( 'game_files/csgo_english.txt' , data , 'utf8' ) ;
116
145
}
117
146
else winston . error ( 'Failed to fetch csgo_english.txt' ) ;
0 commit comments