@@ -5,14 +5,8 @@ export const AVATAR_FILE_PATH = "./assets/img/avatars";
55// File extension
66export const LOCAL_EXT = "avif" ;
77
8+ import { type AssetMap } from "@App/network" ;
89// mappings will be loaded into Javascript bundle by using resolveJSON from Typescript
9- import defaultMapping from "@Mapping/english.json" ;
10-
11- // mapping that is different from the wiki definition
12- // so we don't need to modify the original files
13- // content is sorted by values
14- import specialMapping from "@Mapping/specials.json" ;
15- import { AssetMap } from "./network" ;
1610
1711/**
1812 * Types for mapping vehicle name to file name
@@ -32,23 +26,25 @@ export enum VehicleType {
3226 Ship = "ships" ,
3327}
3428
35- let assetMap : AssetMap = defaultMapping ;
36-
37- /**
38- * Selects the correct localized asset name mapping
39- * @param mapping localized mapping
40- */
41- export function setAssetMap ( mapping : AssetMap ) {
42- console . log ( "Overriding mapping" , mapping ) ;
43- assetMap = mapping ;
29+ // mapping that is different from the wiki definition
30+ // so we don't need to modify the original files
31+ // content is sorted by
32+ interface SpecialLocation {
33+ type : VehicleType ,
34+ file : string
4435}
4536
37+ export type SpecialMap = Record < string , SpecialLocation >
38+ import specialMapping from "@Mapping/specials.json" ;
39+
40+
41+
4642/**
4743 * Get file path or null
4844 * @param vehicle localized battle log vehicle name
4945 * @returns file name with extension and path or null if not existing
5046 */
51- export function findVehicleFile ( vehicle : LocalizedVehicle ) : string | null {
47+ export function findVehicleFile ( assetMap : AssetMap , vehicle : LocalizedVehicle ) : string | null {
5248 // vehicles are translated to local languages
5349 // some vehicles (i.e. russian) use cyrillic characters.
5450 // however they should not be cleaned, because then we would have duplicates see for example T-34-85
@@ -61,7 +57,7 @@ export function findVehicleFile(vehicle: LocalizedVehicle): string | null {
6157 // clean up crlf that somehow got into game files and are therefore used
6258 . replace ( "\r" , "" ) ;
6359
64- const fileName = findLocalMapping ( cleanVehicleName ) ;
60+ const fileName = findLocalMapping ( assetMap , cleanVehicleName ) ;
6561 if ( fileName ) {
6662 // add path data if existing
6763 return `${ VEHICLE_FILE_PATH } /${ fileName } ` ;
@@ -75,8 +71,8 @@ export function findVehicleFile(vehicle: LocalizedVehicle): string | null {
7571 * @param vehicle localized vehicle name
7672 * @returns folder name and file name if existing
7773 */
78- function findLocalMapping ( vehicle : LocalizedVehicle ) : string | null {
79- const mapping = findMapping ( vehicle ) ;
74+ function findLocalMapping ( assetMap : AssetMap , vehicle : LocalizedVehicle ) : string | null {
75+ const mapping = findMapping ( assetMap , vehicle ) ;
8076 if ( mapping ) {
8177 const [ typeFolder , normalizedFileName ] = mapping ;
8278
@@ -97,8 +93,8 @@ const REMOTE_EXT = "png";
9793 * @returns full path to vehicle file
9894 */
9995// eslint-disable-next-line @typescript-eslint/no-unused-vars
100- function findRemoteMapping ( vehicle : LocalizedVehicle ) : string | null {
101- const mapping = findMapping ( vehicle ) ;
96+ function findRemoteMapping ( assetMap : AssetMap , vehicle : LocalizedVehicle ) : string | null {
97+ const mapping = findMapping ( assetMap , vehicle ) ;
10298 if ( mapping ) {
10399 // images are organized here in a flatten folder structure
104100 const [ , normalizedFileName ] = mapping ;
@@ -110,26 +106,35 @@ function findRemoteMapping(vehicle: LocalizedVehicle): string | null {
110106
111107/**
112108 * Find type and normalized vehicle identifier for a given localized vehicle name
113- * @param vehicle localized vehicle name
109+ * @param searchVehicle localized vehicle name
114110 * @returns vehicle type and vehicle identifier in an array
115111 */
116- function findMapping ( vehicle : LocalizedVehicle ) {
112+ function findMapping ( assetMap : AssetMap , searchVehicle : LocalizedVehicle ) {
117113 // search ground vehicles first, because it is mostly played
118114 const vehicleTypes : [ string , Mapping ] [ ] = [
119- [ VehicleType . Ground , assetMap . ground ] ,
120- [ VehicleType . Air , assetMap . air ] ,
121- [ VehicleType . Ship , assetMap . ships ] ,
122- [ "" , specialMapping ] ,
115+ [ VehicleType . Ground , assetMap . vehicles . ground ] ,
116+ [ VehicleType . Air , assetMap . vehicles . air ] ,
117+ [ VehicleType . Ship , assetMap . vehicles . ships ] ,
123118 ] ;
124119
125120 for ( const vehicleType of vehicleTypes ) {
126- const [ path , map ] = vehicleType ;
121+ const [ pathType , map ] = vehicleType ;
127122
128- const name = map [ vehicle ] ;
123+ const name = map [ searchVehicle ] ;
129124 if ( name ) {
130125 // UNIX file systems are case-sensitive
131- const normalizedFile = name . toLowerCase ( ) ;
132- return [ path , normalizedFile ] ;
126+ const normalizedFileName = name . toLowerCase ( ) ;
127+ return [ pathType , normalizedFileName ] ;
128+ }
129+ }
130+
131+ const specialMap = specialMapping as SpecialMap ;
132+ for ( const specialVehicleName in specialMap ) {
133+ if ( specialVehicleName === searchVehicle ) {
134+ const vehicleType = specialMap [ specialVehicleName ] . type ;
135+ const vehicleFileName = specialMap [ specialVehicleName ] . file . toLowerCase ( ) ;
136+
137+ return [ vehicleType , vehicleFileName ] ;
133138 }
134139 }
135140
0 commit comments