-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
style: apply prettier on exfils-targets.ts
- Loading branch information
Trap
committed
Dec 22, 2024
1 parent
9fcd3da
commit bc3d4fd
Showing
1 changed file
with
135 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,135 +1,135 @@ | ||
import type { Config, MapName } from './config'; | ||
import { resolveMapNameFromLocation } from './map-name-resolver'; | ||
import { ensureArray } from './utils'; | ||
|
||
// Warning: This type should be the same than the corresponding client type | ||
export type ExfilTarget = { | ||
isTransit: boolean; | ||
transitMapId: string; // transit only | ||
transitSpawnPointId: string; // transit only | ||
offraidPosition: string; // empty on transit | ||
}; | ||
|
||
// Warning: This type should be the same than the corresponding client type | ||
export type ExfilsTargets = { | ||
[exitName: string]: ExfilTarget[]; | ||
}; | ||
|
||
// Warning: This type should be the same than the corresponding client type | ||
export type ExfilsTargetsResponse = { | ||
data: ExfilsTargets; | ||
}; | ||
|
||
// Warning: This type should be the same than the corresponding client type | ||
export type ExfilsTargetsRequest = { | ||
locationId: string; | ||
}; | ||
|
||
export const getExfilsTargets = (config: Config, mapName: MapName): ExfilsTargetsResponse => { | ||
const response: ExfilsTargetsResponse = { | ||
data: {}, | ||
}; | ||
|
||
const exfilsConfig = config.exfiltrations[mapName]; | ||
if (!exfilsConfig) { | ||
return response; | ||
} | ||
|
||
void Object.keys(exfilsConfig).forEach(exfilName => { | ||
const targets = ensureArray(exfilsConfig[exfilName]).map<ExfilTarget>(targetValue => { | ||
const parsed = parseExilTargetFromPTTConfig(targetValue); | ||
|
||
return { | ||
isTransit: Boolean(!parsed.targetOffraidPosition), | ||
offraidPosition: parsed.targetOffraidPosition ?? '', | ||
transitMapId: parsed.transitTargetLocationId ?? '', | ||
transitSpawnPointId: parsed.transitTargetSpawnPointId ?? '', | ||
}; | ||
}); | ||
|
||
response.data[exfilName] = targets; | ||
}); | ||
|
||
return response; | ||
}; | ||
|
||
type ParsedExfilTarget = { | ||
targetOffraidPosition: string | null; // is null on transit | ||
transitTargetLocationId: string | null; | ||
transitTargetSpawnPointId: string | null; | ||
}; | ||
|
||
/** | ||
* @param compoundExfilName e.g. "Gate 3.MY_OFFRAID_POSITION" for extract and "Gate 3.bigmap.MY_SPAWN_POINT" for transit | ||
*/ | ||
export const parseExfilTargetFromExitName = ( | ||
compoundExfilName: string, | ||
): ParsedExfilTarget & { exitName: string | null } => { | ||
const splitted = compoundExfilName.split('.'); | ||
|
||
if (splitted.length === 0) { | ||
return { | ||
exitName: null, | ||
targetOffraidPosition: null, | ||
transitTargetLocationId: null, | ||
transitTargetSpawnPointId: null, | ||
}; | ||
} | ||
|
||
const exitName = splitted[0]; | ||
|
||
if (splitted.length === 1) { | ||
return { | ||
exitName, | ||
targetOffraidPosition: null, | ||
transitTargetLocationId: null, | ||
transitTargetSpawnPointId: null, | ||
}; | ||
} | ||
|
||
if (splitted.length === 2) { | ||
const offraidPosition = splitted[1]; | ||
return { | ||
exitName, | ||
targetOffraidPosition: offraidPosition, | ||
transitTargetLocationId: null, | ||
transitTargetSpawnPointId: null, | ||
}; | ||
} | ||
|
||
const locationId = resolveMapNameFromLocation(splitted[1]); | ||
const spawnPointId = splitted[2]; | ||
|
||
return { | ||
exitName, | ||
targetOffraidPosition: null, | ||
transitTargetLocationId: locationId, | ||
transitTargetSpawnPointId: spawnPointId, | ||
}; | ||
}; | ||
|
||
export const parseExilTargetFromPTTConfig = (exfilTargetFromConfig: string): ParsedExfilTarget => { | ||
const splitted = exfilTargetFromConfig.split('.'); | ||
|
||
if (splitted.length === 0) { | ||
return { | ||
targetOffraidPosition: null, | ||
transitTargetLocationId: null, | ||
transitTargetSpawnPointId: null, | ||
}; | ||
} | ||
|
||
if (splitted.length === 1) { | ||
return { | ||
targetOffraidPosition: splitted[0], | ||
transitTargetLocationId: null, | ||
transitTargetSpawnPointId: null, | ||
}; | ||
} | ||
|
||
return { | ||
targetOffraidPosition: null, | ||
transitTargetLocationId: splitted[0], | ||
transitTargetSpawnPointId: splitted[1], | ||
}; | ||
}; | ||
import type { Config, MapName } from './config'; | ||
import { resolveMapNameFromLocation } from './map-name-resolver'; | ||
import { ensureArray } from './utils'; | ||
|
||
// Warning: This type should be the same than the corresponding client type | ||
export type ExfilTarget = { | ||
isTransit: boolean; | ||
transitMapId: string; // transit only | ||
transitSpawnPointId: string; // transit only | ||
offraidPosition: string; // empty on transit | ||
}; | ||
|
||
// Warning: This type should be the same than the corresponding client type | ||
export type ExfilsTargets = { | ||
[exitName: string]: ExfilTarget[]; | ||
}; | ||
|
||
// Warning: This type should be the same than the corresponding client type | ||
export type ExfilsTargetsResponse = { | ||
data: ExfilsTargets; | ||
}; | ||
|
||
// Warning: This type should be the same than the corresponding client type | ||
export type ExfilsTargetsRequest = { | ||
locationId: string; | ||
}; | ||
|
||
export const getExfilsTargets = (config: Config, mapName: MapName): ExfilsTargetsResponse => { | ||
const response: ExfilsTargetsResponse = { | ||
data: {}, | ||
}; | ||
|
||
const exfilsConfig = config.exfiltrations[mapName]; | ||
if (!exfilsConfig) { | ||
return response; | ||
} | ||
|
||
void Object.keys(exfilsConfig).forEach(exfilName => { | ||
const targets = ensureArray(exfilsConfig[exfilName]).map<ExfilTarget>(targetValue => { | ||
const parsed = parseExilTargetFromPTTConfig(targetValue); | ||
|
||
return { | ||
isTransit: Boolean(!parsed.targetOffraidPosition), | ||
offraidPosition: parsed.targetOffraidPosition ?? '', | ||
transitMapId: parsed.transitTargetLocationId ?? '', | ||
transitSpawnPointId: parsed.transitTargetSpawnPointId ?? '', | ||
}; | ||
}); | ||
|
||
response.data[exfilName] = targets; | ||
}); | ||
|
||
return response; | ||
}; | ||
|
||
type ParsedExfilTarget = { | ||
targetOffraidPosition: string | null; // is null on transit | ||
transitTargetLocationId: string | null; | ||
transitTargetSpawnPointId: string | null; | ||
}; | ||
|
||
/** | ||
* @param compoundExfilName e.g. "Gate 3.MY_OFFRAID_POSITION" for extract and "Gate 3.bigmap.MY_SPAWN_POINT" for transit | ||
*/ | ||
export const parseExfilTargetFromExitName = ( | ||
compoundExfilName: string, | ||
): ParsedExfilTarget & { exitName: string | null } => { | ||
const splitted = compoundExfilName.split('.'); | ||
|
||
if (splitted.length === 0) { | ||
return { | ||
exitName: null, | ||
targetOffraidPosition: null, | ||
transitTargetLocationId: null, | ||
transitTargetSpawnPointId: null, | ||
}; | ||
} | ||
|
||
const exitName = splitted[0]; | ||
|
||
if (splitted.length === 1) { | ||
return { | ||
exitName, | ||
targetOffraidPosition: null, | ||
transitTargetLocationId: null, | ||
transitTargetSpawnPointId: null, | ||
}; | ||
} | ||
|
||
if (splitted.length === 2) { | ||
const offraidPosition = splitted[1]; | ||
return { | ||
exitName, | ||
targetOffraidPosition: offraidPosition, | ||
transitTargetLocationId: null, | ||
transitTargetSpawnPointId: null, | ||
}; | ||
} | ||
|
||
const locationId = resolveMapNameFromLocation(splitted[1]); | ||
const spawnPointId = splitted[2]; | ||
|
||
return { | ||
exitName, | ||
targetOffraidPosition: null, | ||
transitTargetLocationId: locationId, | ||
transitTargetSpawnPointId: spawnPointId, | ||
}; | ||
}; | ||
|
||
export const parseExilTargetFromPTTConfig = (exfilTargetFromConfig: string): ParsedExfilTarget => { | ||
const splitted = exfilTargetFromConfig.split('.'); | ||
|
||
if (splitted.length === 0) { | ||
return { | ||
targetOffraidPosition: null, | ||
transitTargetLocationId: null, | ||
transitTargetSpawnPointId: null, | ||
}; | ||
} | ||
|
||
if (splitted.length === 1) { | ||
return { | ||
targetOffraidPosition: splitted[0], | ||
transitTargetLocationId: null, | ||
transitTargetSpawnPointId: null, | ||
}; | ||
} | ||
|
||
return { | ||
targetOffraidPosition: null, | ||
transitTargetLocationId: splitted[0], | ||
transitTargetSpawnPointId: splitted[1], | ||
}; | ||
}; |