11import type { MatchModeConfig } from "@/ui/panels/configuring/MatchModeConfigPanel"
2- import { convertFeetToMeters } from "@/util/UnitConversions"
2+ import { API_URL } from "@/util/Consts.ts"
3+
4+ type ManifestMatchModeConfig = Omit < MatchModeConfig , "id" > & { id : string }
5+ interface MatchConfigManifest {
6+ private : Record < string , ManifestMatchModeConfig >
7+ public : Record < string , ManifestMatchModeConfig >
8+ }
39
410/** The purpose of this class is to store any defaults related to match mode configurations. */
511class DefaultMatchModeConfigs {
6- static frcReefscape2025 = ( ) : MatchModeConfig => {
7- return {
8- id : "FRC-Reefscape-2025" ,
9- name : "FRC Reefscape 2025" ,
10- isDefault : true ,
11- autonomousTime : 15 ,
12- teleopTime : 135 ,
13- endgameTime : 20 ,
14- ignoreRotation : true ,
15- maxHeight : Number . MAX_SAFE_INTEGER ,
16- heightLimitPenalty : 0 ,
17- sideMaxExtension : convertFeetToMeters ( 1.5 ) ,
18- sideExtensionPenalty : 0 ,
19- }
20- }
12+ private static readonly MANIFEST_LOCATION = `${ API_URL } /match_configs/manifest.json`
13+ private static _configs : MatchModeConfig [ ] = [ ]
2114
22- static frcCrescendo2024 = ( ) : MatchModeConfig => {
23- return {
24- id : "FRC-Crescendo-2024" ,
25- name : "FRC Crescendo 2024" ,
26- isDefault : true ,
27- autonomousTime : 15 ,
28- teleopTime : 135 ,
29- endgameTime : 20 ,
30- ignoreRotation : true ,
31- maxHeight : convertFeetToMeters ( 4 ) ,
32- heightLimitPenalty : 2 ,
33- sideMaxExtension : convertFeetToMeters ( 1 ) ,
34- sideExtensionPenalty : 2 ,
35- }
15+ static {
16+ setTimeout ( ( ) => this . reload ( ) )
3617 }
37-
38- static frcPowerUp2023 = ( ) : MatchModeConfig => {
39- return {
40- id : "FRC-Power-Up-2023" ,
41- name : "FRC Power Up 2023" ,
42- isDefault : true ,
43- autonomousTime : 15 ,
44- teleopTime : 135 ,
45- endgameTime : 30 ,
46- ignoreRotation : true ,
47- maxHeight : convertFeetToMeters ( 6.5 ) ,
48- heightLimitPenalty : 5 ,
49- sideMaxExtension : convertFeetToMeters ( 4 ) ,
50- sideExtensionPenalty : 5 ,
18+ static async reload ( ) {
19+ const manifest = await fetch ( this . MANIFEST_LOCATION )
20+ const json : MatchConfigManifest | undefined = await manifest . json ( ) . catch ( e => {
21+ console . error ( e )
22+ return undefined
23+ } )
24+ if ( json == null ) {
25+ console . error ( "Could not load match mode manifest" )
26+ return undefined
27+ }
28+ const keys : ( keyof MatchConfigManifest ) [ ] = import . meta. env . DEV
29+ ? ( [ "public" , "private" ] as const )
30+ : ( [ "public" ] as const )
31+ for ( const key of keys ) {
32+ const configs = json [ key as keyof MatchConfigManifest ]
33+ Object . entries ( configs ) . forEach ( ( [ key , value ] ) => {
34+ value . id = key
35+ this . _configs . push ( value )
36+ } )
5137 }
5238 }
5339
54- static matchTest = ( ) : MatchModeConfig => {
55- return {
56- id : "Match-Test" ,
57- name : "Match Test" ,
58- isDefault : true ,
59- autonomousTime : 5 ,
60- teleopTime : 15 ,
61- endgameTime : 5 ,
62- ignoreRotation : true ,
63- maxHeight : Number . MAX_SAFE_INTEGER ,
64- heightLimitPenalty : 0 ,
65- sideMaxExtension : Number . MAX_SAFE_INTEGER ,
66- sideExtensionPenalty : 0 ,
67- }
40+ public static get configs ( ) : MatchModeConfig [ ] {
41+ return this . _configs
6842 }
6943
7044 static fallbackValues = ( ) : MatchModeConfig => {
@@ -76,22 +50,12 @@ class DefaultMatchModeConfigs {
7650 teleopTime : 135 ,
7751 endgameTime : 20 ,
7852 ignoreRotation : true ,
79- maxHeight : Number . MAX_SAFE_INTEGER ,
53+ maxHeight : - 1 ,
8054 heightLimitPenalty : 2 ,
81- sideMaxExtension : Number . MAX_SAFE_INTEGER ,
55+ sideMaxExtension : - 1 ,
8256 sideExtensionPenalty : 2 ,
8357 }
8458 }
85-
86- /** @returns {MatchModeConfig[] } New copies of the default match mode configs without reference to any others. */
87- public static get defaultMatchModeConfigCopies ( ) : MatchModeConfig [ ] {
88- return [
89- DefaultMatchModeConfigs . frcReefscape2025 ( ) ,
90- DefaultMatchModeConfigs . frcCrescendo2024 ( ) ,
91- DefaultMatchModeConfigs . frcPowerUp2023 ( ) ,
92- DefaultMatchModeConfigs . matchTest ( ) ,
93- ]
94- }
9559}
9660
9761export default DefaultMatchModeConfigs
0 commit comments