feat: eslint 적용 및 관련 코드 일괄 수정
This commit is contained in:
@@ -23,8 +23,7 @@ const DEFAULT_CREW_TYPE_ID = 1100;
|
||||
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
||||
value !== null && typeof value === 'object' && !Array.isArray(value);
|
||||
|
||||
const asRecord = (value: unknown): Record<string, unknown> =>
|
||||
isRecord(value) ? value : {};
|
||||
const asRecord = (value: unknown): Record<string, unknown> => (isRecord(value) ? value : {});
|
||||
|
||||
const normalizeCode = (value: string | null | undefined): string | null => {
|
||||
if (!value || value === 'None') {
|
||||
@@ -33,11 +32,7 @@ const normalizeCode = (value: string | null | undefined): string | null => {
|
||||
return value;
|
||||
};
|
||||
|
||||
const resolveNumber = (
|
||||
source: Record<string, unknown>,
|
||||
keys: string[],
|
||||
fallback: number
|
||||
): number => {
|
||||
const resolveNumber = (source: Record<string, unknown>, keys: string[], fallback: number): number => {
|
||||
for (const key of keys) {
|
||||
const value = source[key];
|
||||
if (typeof value === 'number' && Number.isFinite(value)) {
|
||||
@@ -47,10 +42,7 @@ const resolveNumber = (
|
||||
return fallback;
|
||||
};
|
||||
|
||||
const resolveOptionalString = (
|
||||
source: Record<string, unknown>,
|
||||
keys: string[]
|
||||
): string | null => {
|
||||
const resolveOptionalString = (source: Record<string, unknown>, keys: string[]): string | null => {
|
||||
for (const key of keys) {
|
||||
const value = source[key];
|
||||
if (typeof value === 'string') {
|
||||
@@ -60,82 +52,36 @@ const resolveOptionalString = (
|
||||
return null;
|
||||
};
|
||||
|
||||
export const buildCommandEnv = (
|
||||
config: ScenarioConfig,
|
||||
unitSet?: UnitSetDefinition
|
||||
): TurnCommandEnv => {
|
||||
export const buildCommandEnv = (config: ScenarioConfig, unitSet?: UnitSetDefinition): TurnCommandEnv => {
|
||||
const constValues = asRecord(config.const);
|
||||
|
||||
return {
|
||||
develCost: resolveNumber(
|
||||
constValues,
|
||||
['develCost', 'develcost', 'develrate'],
|
||||
0
|
||||
),
|
||||
develCost: resolveNumber(constValues, ['develCost', 'develcost', 'develrate'], 0),
|
||||
trainDelta: resolveNumber(constValues, ['trainDelta'], 0),
|
||||
atmosDelta: resolveNumber(constValues, ['atmosDelta'], 0),
|
||||
maxTrainByCommand: resolveNumber(constValues, ['maxTrainByCommand'], 0),
|
||||
maxAtmosByCommand: resolveNumber(
|
||||
constValues,
|
||||
['maxAtmosByCommand'],
|
||||
0
|
||||
),
|
||||
sabotageDefaultProb: resolveNumber(
|
||||
constValues,
|
||||
['sabotageDefaultProb'],
|
||||
0
|
||||
),
|
||||
sabotageProbCoefByStat: resolveNumber(
|
||||
constValues,
|
||||
['sabotageProbCoefByStat'],
|
||||
0
|
||||
),
|
||||
sabotageDefenceCoefByGeneralCount: resolveNumber(
|
||||
constValues,
|
||||
['sabotageDefenceCoefByGeneralCount'],
|
||||
0
|
||||
),
|
||||
maxAtmosByCommand: resolveNumber(constValues, ['maxAtmosByCommand'], 0),
|
||||
sabotageDefaultProb: resolveNumber(constValues, ['sabotageDefaultProb'], 0),
|
||||
sabotageProbCoefByStat: resolveNumber(constValues, ['sabotageProbCoefByStat'], 0),
|
||||
sabotageDefenceCoefByGeneralCount: resolveNumber(constValues, ['sabotageDefenceCoefByGeneralCount'], 0),
|
||||
sabotageDamageMin: resolveNumber(constValues, ['sabotageDamageMin'], 0),
|
||||
sabotageDamageMax: resolveNumber(constValues, ['sabotageDamageMax'], 0),
|
||||
openingPartYear: resolveNumber(constValues, ['openingPartYear'], 0),
|
||||
maxGeneral: resolveNumber(
|
||||
constValues,
|
||||
['defaultMaxGeneral', 'maxGeneral'],
|
||||
0
|
||||
),
|
||||
defaultNpcGold: resolveNumber(
|
||||
constValues,
|
||||
['defaultNpcGold', 'defaultGold'],
|
||||
DEFAULT_GENERAL_GOLD
|
||||
),
|
||||
defaultNpcRice: resolveNumber(
|
||||
constValues,
|
||||
['defaultNpcRice', 'defaultRice'],
|
||||
DEFAULT_GENERAL_RICE
|
||||
),
|
||||
maxGeneral: resolveNumber(constValues, ['defaultMaxGeneral', 'maxGeneral'], 0),
|
||||
defaultNpcGold: resolveNumber(constValues, ['defaultNpcGold', 'defaultGold'], DEFAULT_GENERAL_GOLD),
|
||||
defaultNpcRice: resolveNumber(constValues, ['defaultNpcRice', 'defaultRice'], DEFAULT_GENERAL_RICE),
|
||||
defaultCrewTypeId: resolveNumber(
|
||||
constValues,
|
||||
['defaultCrewTypeId'],
|
||||
unitSet?.defaultCrewTypeId ?? DEFAULT_CREW_TYPE_ID
|
||||
),
|
||||
defaultSpecialDomestic: resolveOptionalString(
|
||||
constValues,
|
||||
['defaultSpecialDomestic']
|
||||
),
|
||||
defaultSpecialDomestic: resolveOptionalString(constValues, ['defaultSpecialDomestic']),
|
||||
defaultSpecialWar: resolveOptionalString(constValues, ['defaultSpecialWar']),
|
||||
initialNationGenLimit: resolveNumber(
|
||||
constValues,
|
||||
['initialNationGenLimit'],
|
||||
0
|
||||
),
|
||||
initialNationGenLimit: resolveNumber(constValues, ['initialNationGenLimit'], 0),
|
||||
maxTechLevel: resolveNumber(constValues, ['maxTechLevel'], 0),
|
||||
baseGold: resolveNumber(constValues, ['baseGold', 'basegold'], 0),
|
||||
baseRice: resolveNumber(constValues, ['baseRice', 'baserice'], 0),
|
||||
maxResourceActionAmount: resolveNumber(
|
||||
constValues,
|
||||
['maxResourceActionAmount'],
|
||||
0
|
||||
),
|
||||
maxResourceActionAmount: resolveNumber(constValues, ['maxResourceActionAmount'], 0),
|
||||
};
|
||||
};
|
||||
|
||||
@@ -165,34 +111,18 @@ export const buildReservedTurnDefinitions = async (options: {
|
||||
const itemModules = await loadItemModules([...ITEM_KEYS]);
|
||||
const itemRegistry = createItemModuleRegistry(itemModules);
|
||||
const itemActionModules = createItemActionModules(itemRegistry);
|
||||
options.env.generalActionModules = [
|
||||
...(options.env.generalActionModules ?? []),
|
||||
...itemActionModules.general,
|
||||
];
|
||||
options.env.warActionModules = [
|
||||
...(options.env.warActionModules ?? []),
|
||||
...itemActionModules.war,
|
||||
];
|
||||
options.env.generalActionModules = [...(options.env.generalActionModules ?? []), ...itemActionModules.general];
|
||||
options.env.warActionModules = [...(options.env.warActionModules ?? []), ...itemActionModules.war];
|
||||
|
||||
const generalSpecs = await loadGeneralTurnCommandSpecs(
|
||||
options.commandProfile.general
|
||||
);
|
||||
const nationSpecs = await loadNationTurnCommandSpecs(
|
||||
options.commandProfile.nation
|
||||
);
|
||||
const generalSpecs = await loadGeneralTurnCommandSpecs(options.commandProfile.general);
|
||||
const nationSpecs = await loadNationTurnCommandSpecs(options.commandProfile.nation);
|
||||
|
||||
const general = new Map(
|
||||
generalSpecs.map((spec) => [spec.key, spec.createDefinition(options.env)])
|
||||
);
|
||||
const nation = new Map(
|
||||
nationSpecs.map((spec) => [spec.key, spec.createDefinition(options.env)])
|
||||
);
|
||||
const general = new Map(generalSpecs.map((spec) => [spec.key, spec.createDefinition(options.env)]));
|
||||
const nation = new Map(nationSpecs.map((spec) => [spec.key, spec.createDefinition(options.env)]));
|
||||
|
||||
await ensureGeneralFallback(general, options.defaultActionKey, options.env);
|
||||
if (!nation.has(options.defaultActionKey)) {
|
||||
const [spec] = await loadNationTurnCommandSpecs([
|
||||
options.defaultActionKey,
|
||||
]);
|
||||
const [spec] = await loadNationTurnCommandSpecs([options.defaultActionKey]);
|
||||
if (spec) {
|
||||
nation.set(spec.key, spec.createDefinition(options.env));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user