1- import { DropdownItem , GameComponentProps , GameGridComponentProps , GameListComponentProps } from 'flashpoint-launcher-renderer' ;
1+ import { DropdownItem , GameComponentProps , GameGridComponentProps , GameListComponentProps , SearchableSelectItem , SearchComponentProps } from 'flashpoint-launcher-renderer' ;
22import { IconType } from 'react-icons' ;
33import { FaBug , FaChalkboardTeacher , FaCog , FaCrown , FaDesktop , FaDollarSign , FaFilm , FaMicrophone , FaMusic , FaPaintBrush , FaPenAlt , FaPencilAlt , FaSun , FaTruck , FaVolumeUp } from 'react-icons/fa' ;
44
@@ -50,17 +50,97 @@ type ExtData = {
5050
5151const numFormat = new Intl . NumberFormat ( ) ;
5252
53- export function mapNgRatingString ( rs : string ) {
54- switch ( rs ) {
55- case '' :
56- return 'None' ;
53+ export function mapNgRatingString ( s : string ) {
54+ switch ( s ) {
5755 case 'e' :
58- return 'Standalone' ;
56+ return 'Everyone' ;
57+ case 't' :
58+ return 'Teen' ;
59+ case 'm' :
60+ return 'Mature' ;
61+ case 'a' :
62+ return 'Adult' ;
5963 default :
60- return 'Broken Value' ;
64+ return s ;
6165 }
6266}
6367
68+ const genSelectItem = ( missing : string ) : SearchableSelectItem => {
69+ return {
70+ value : missing ,
71+ orderVal : `zzzzzzz${ missing } ` ,
72+ } ;
73+ } ;
74+
75+ export function NgRatingSearchableSelect ( props : SearchComponentProps ) {
76+ const { SearchableSelect } = window . ext . components ;
77+ const { onBlacklistFactory, onWhitelistFactory, onClearFactory, onSetAndToggleFactory } = window . ext . utils . search ;
78+ const { advancedFilter, setAdvancedFilter } = props ;
79+ const extFilter = advancedFilter . ext . toggles [ 'nga' ] ;
80+ const extAndToggles = advancedFilter . andToggles . ext [ 'nga' ] ;
81+
82+ const labelRenderer = ( item : SearchableSelectItem ) => {
83+ const label = mapNgRatingString ( item . value ) ;
84+ return (
85+ < div className = 'platform-label-row' >
86+ < div
87+ className = { `dropdown-icon dropdown-icon-image ng-image-rating_${ item . value } ` } >
88+ </ div >
89+ < div className = "searchable-select-dropdown-item-title" >
90+ { label }
91+ </ div >
92+ </ div >
93+ ) ;
94+ } ;
95+
96+ const ratingItems : SearchableSelectItem [ ] = [
97+ {
98+ value : 'e' ,
99+ orderVal : '1'
100+ } , {
101+ value : 't' ,
102+ orderVal : '2'
103+ } , {
104+ value : 'm' ,
105+ orderVal : '3'
106+ } , {
107+ value : 'a' ,
108+ orderVal : '4'
109+ }
110+ ] ;
111+
112+ const onWhitelist = onWhitelistFactory ( 'nga' , 'rating' , advancedFilter , setAdvancedFilter ) ;
113+ const onBlacklist = onBlacklistFactory ( 'nga' , 'rating' , advancedFilter , setAdvancedFilter ) ;
114+ const onClear = onClearFactory ( 'nga' , 'rating' , advancedFilter , setAdvancedFilter ) ;
115+ const onSetAndToggle = onSetAndToggleFactory ( 'nga' , 'rating' , advancedFilter , setAdvancedFilter ) ;
116+
117+ const andToggle = ! ! ( extAndToggles ?. rating ) ;
118+ const selected = extFilter ?. rating || { } ;
119+
120+ return (
121+ < SearchableSelect
122+ title = { 'NG Rating' }
123+ items = { ratingItems }
124+ andToggle = { andToggle }
125+ selected = { selected }
126+ labelRenderer = { labelRenderer }
127+ generateItem = { genSelectItem }
128+ onWhitelist = { onWhitelist }
129+ onBlacklist = { onBlacklist }
130+ onClear = { onClear }
131+ onSetAndToggle = { onSetAndToggle }
132+ mapName = { ( item ) => {
133+ switch ( item ) {
134+ case 'e' : return 'Everyone' ;
135+ case 't' : return 'Teen' ;
136+ case 'm' : return 'Mature' ;
137+ case 'a' : return 'Adult' ;
138+ default : return '' ;
139+ }
140+ } } />
141+ ) ;
142+ }
143+
64144export function NgRatingListIcon ( props : GameListComponentProps ) {
65145 if ( props . game ) {
66146 const extData : ExtData | undefined = props . game . extData ?. nga ;
@@ -174,9 +254,9 @@ export function NgScore(props: GameComponentProps) {
174254 const extData : ExtData | undefined = props . game . extData ?. nga ;
175255 const { GameComponentInputField } = window . ext . components ;
176256 const score = Number ( extData ?. score ) || 0 ;
177- const { updateGameExtData } = props ;
257+ const { updateGameExtData, editable } = props ;
178258
179- return (
259+ return editable ? (
180260 < GameComponentInputField
181261 header = 'NG Score'
182262 text = { score . toString ( ) }
@@ -190,6 +270,20 @@ export function NgScore(props: GameComponentProps) {
190270 }
191271 } }
192272 { ...props } />
273+ ) : (
274+ < div className = 'browse-right-sidebar__row browse-right-sidebar__row--one-line' >
275+ < p > NG Score: </ p >
276+ { ! score ? (
277+ < p > None</ p >
278+ ) : (
279+ < div className = { 'ng-score-sidebar' } >
280+ < div className = 'ng-score-value' > { score } </ div >
281+ < div className = 'ng-score-stars' >
282+ < div className = 'ng-score-stars-filled' style = { { clipPath : `inset(0 ${ ( 1 - ( score / 5 ) ) * 100 } % 0 0)` } } > </ div >
283+ </ div >
284+ </ div >
285+ ) }
286+ </ div >
193287 ) ;
194288}
195289
0 commit comments