feat: eslint 적용 및 관련 코드 일괄 수정

This commit is contained in:
2026-01-05 15:46:47 +00:00
parent cb312f02b3
commit c965b1120f
387 changed files with 39808 additions and 38800 deletions
+13 -43
View File
@@ -13,9 +13,7 @@ import {
} from './helpers.js';
import type { Constraint, RequirementKey } from './types.js';
export const occupiedCity = (
options: { allowNeutral?: boolean } = {}
): Constraint => ({
export const occupiedCity = (options: { allowNeutral?: boolean } = {}): Constraint => ({
name: 'OccupiedCity',
requires: (ctx) => {
const reqs: RequirementKey[] = [{ kind: 'general', id: ctx.actorId }];
@@ -93,8 +91,7 @@ export const occupiedDestCity = (): Constraint => ({
export const suppliedCity = (): Constraint => ({
name: 'SuppliedCity',
requires: (ctx) =>
ctx.cityId !== undefined ? [{ kind: 'city', id: ctx.cityId }] : [],
requires: (ctx) => (ctx.cityId !== undefined ? [{ kind: 'city', id: ctx.cityId }] : []),
test: (ctx, view) => {
const city = readCity(view, ctx.cityId);
if (!city) {
@@ -142,13 +139,9 @@ export const suppliedDestCity = (): Constraint => ({
},
});
export const remainCityCapacity = (
key: keyof City,
label: string
): Constraint => ({
export const remainCityCapacity = (key: keyof City, label: string): Constraint => ({
name: 'RemainCityCapacity',
requires: (ctx) =>
ctx.cityId !== undefined ? [{ kind: 'city', id: ctx.cityId }] : [],
requires: (ctx) => (ctx.cityId !== undefined ? [{ kind: 'city', id: ctx.cityId }] : []),
test: (ctx, view) => {
const city = readCity(view, ctx.cityId);
if (!city) {
@@ -171,14 +164,9 @@ export const remainCityCapacity = (
},
});
export const remainCityCapacityByMax = (
key: keyof City,
maxKey: keyof City,
label: string
): Constraint => ({
export const remainCityCapacityByMax = (key: keyof City, maxKey: keyof City, label: string): Constraint => ({
name: 'RemainCityCapacityByMax',
requires: (ctx) =>
ctx.cityId !== undefined ? [{ kind: 'city', id: ctx.cityId }] : [],
requires: (ctx) => (ctx.cityId !== undefined ? [{ kind: 'city', id: ctx.cityId }] : []),
test: (ctx, view) => {
const city = readCity(view, ctx.cityId);
if (!city) {
@@ -200,14 +188,9 @@ export const remainCityCapacityByMax = (
},
});
export const reqCityCapacity = (
key: keyof City,
label: string,
required: number | string
): Constraint => ({
export const reqCityCapacity = (key: keyof City, label: string, required: number | string): Constraint => ({
name: 'ReqCityCapacity',
requires: (ctx) =>
ctx.cityId !== undefined ? [{ kind: 'city', id: ctx.cityId }] : [],
requires: (ctx) => (ctx.cityId !== undefined ? [{ kind: 'city', id: ctx.cityId }] : []),
test: (ctx, view) => {
const city = readCity(view, ctx.cityId);
if (!city) {
@@ -240,8 +223,7 @@ export const reqCityCapacity = (
export const reqCityTrust = (minTrust: number): Constraint => ({
name: 'ReqCityTrust',
requires: (ctx) =>
ctx.cityId !== undefined ? [{ kind: 'city', id: ctx.cityId }] : [],
requires: (ctx) => (ctx.cityId !== undefined ? [{ kind: 'city', id: ctx.cityId }] : []),
test: (ctx, view) => {
const city = readCity(view, ctx.cityId);
if (!city) {
@@ -251,11 +233,7 @@ export const reqCityTrust = (minTrust: number): Constraint => ({
const req: RequirementKey = { kind: 'city', id: ctx.cityId };
return unknownOrDeny(ctx, [req], '도시 정보가 없습니다.');
}
const trust =
readMetaNumberFromUnknown(
city.meta,
'trust'
) ?? null;
const trust = readMetaNumberFromUnknown(city.meta, 'trust') ?? null;
if (trust === null) {
return unknownOrDeny(ctx, [], '민심 정보가 없습니다.');
}
@@ -440,9 +418,7 @@ const hasRouteToDest = (
export const hasRouteWithEnemy = (): Constraint => ({
name: 'HasRouteWithEnemy',
requires: (ctx) => {
const reqs: RequirementKey[] = [
{ kind: 'general', id: ctx.actorId },
];
const reqs: RequirementKey[] = [{ kind: 'general', id: ctx.actorId }];
const destCityId = resolveDestCityId(ctx);
if (destCityId !== undefined) {
reqs.push({ kind: 'destCity', id: destCityId });
@@ -469,9 +445,7 @@ export const hasRouteWithEnemy = (): Constraint => ({
}
const map = view.get({ kind: 'env', key: 'map' }) as MapDefinition | null;
const cities = view.get({ kind: 'env', key: 'cities' }) as City[] | null;
const nations = view.get({ kind: 'env', key: 'nations' }) as
| Array<{ id: number }>
| null;
const nations = view.get({ kind: 'env', key: 'nations' }) as Array<{ id: number }> | null;
if (!map || !cities || !nations) {
return unknownOrDeny(ctx, [], '경로 정보가 없습니다.');
}
@@ -480,11 +454,7 @@ export const hasRouteWithEnemy = (): Constraint => ({
allowedNationIds.add(general.nationId);
allowedNationIds.add(0);
for (const nation of nations) {
const state = readDiplomacyState(
view,
general.nationId,
nation.id
);
const state = readDiplomacyState(view, general.nationId, nation.id);
if (state === 0) {
allowedNationIds.add(nation.id);
}
+9 -24
View File
@@ -32,17 +32,15 @@ const readDiplomacyEntry = (
typeof record.state === 'number'
? record.state
: typeof record.stateCode === 'number'
? record.stateCode
: null;
? record.stateCode
: null;
const term = typeof record.term === 'number' ? record.term : null;
return { state, term };
}
return null;
};
export const disallowDiplomacyBetweenStatus = (
disallowList: Record<number, string>
): Constraint => ({
export const disallowDiplomacyBetweenStatus = (disallowList: Record<number, string>): Constraint => ({
name: 'DisallowDiplomacyBetweenStatus',
requires: (ctx) => {
const reqs: RequirementKey[] = [];
@@ -73,8 +71,7 @@ export const disallowDiplomacyBetweenStatus = (
return unknownOrDeny(ctx, [], '국가 정보가 없습니다.');
}
const destCity = readDestCity(ctx, view);
const destNationId =
resolveDestNationId(ctx) ?? destCity?.nationId;
const destNationId = resolveDestNationId(ctx) ?? destCity?.nationId;
if (destNationId === undefined) {
return unknownOrDeny(ctx, [], '상대 국가 정보가 없습니다.');
}
@@ -95,10 +92,7 @@ export const disallowDiplomacyBetweenStatus = (
},
});
export const allowDiplomacyBetweenStatus = (
allowList: number[],
reason: string
): Constraint => ({
export const allowDiplomacyBetweenStatus = (allowList: number[], reason: string): Constraint => ({
name: 'AllowDiplomacyBetweenStatus',
requires: (ctx) => {
const reqs: RequirementKey[] = [];
@@ -129,8 +123,7 @@ export const allowDiplomacyBetweenStatus = (
return unknownOrDeny(ctx, [], '국가 정보가 없습니다.');
}
const destCity = readDestCity(ctx, view);
const destNationId =
resolveDestNationId(ctx) ?? destCity?.nationId;
const destNationId = resolveDestNationId(ctx) ?? destCity?.nationId;
if (destNationId === undefined) {
return unknownOrDeny(ctx, [], '상대 국가 정보가 없습니다.');
}
@@ -150,11 +143,7 @@ export const allowDiplomacyBetweenStatus = (
},
});
export const allowDiplomacyWithTerm = (
requiredState: number,
minTerm: number,
reason: string
): Constraint => ({
export const allowDiplomacyWithTerm = (requiredState: number, minTerm: number, reason: string): Constraint => ({
name: 'AllowDiplomacyWithTerm',
requires: (ctx) => {
const reqs: RequirementKey[] = [];
@@ -185,8 +174,7 @@ export const allowDiplomacyWithTerm = (
return unknownOrDeny(ctx, [], '국가 정보가 없습니다.');
}
const destCity = readDestCity(ctx, view);
const destNationId =
resolveDestNationId(ctx) ?? destCity?.nationId;
const destNationId = resolveDestNationId(ctx) ?? destCity?.nationId;
if (destNationId === undefined) {
return unknownOrDeny(ctx, [], '상대 국가 정보가 없습니다.');
}
@@ -206,10 +194,7 @@ export const allowDiplomacyWithTerm = (
},
});
export const allowDiplomacyStatus = (
allowList: number[],
reason: string
): Constraint => ({
export const allowDiplomacyStatus = (allowList: number[], reason: string): Constraint => ({
name: 'AllowDiplomacyStatus',
requires: (ctx) => {
const reqs: RequirementKey[] = [{ kind: 'general', id: ctx.actorId }];
+3 -14
View File
@@ -1,10 +1,4 @@
import type {
Constraint,
ConstraintContext,
ConstraintResult,
RequirementKey,
StateView,
} from './types.js';
import type { Constraint, ConstraintContext, ConstraintResult, RequirementKey, StateView } from './types.js';
export const evaluateConstraints = (
constraints: Constraint[],
@@ -12,9 +6,7 @@ export const evaluateConstraints = (
view: StateView
): ConstraintResult => {
for (const constraint of constraints) {
const missing = constraint
.requires(ctx)
.filter((req) => !view.has(req));
const missing = constraint.requires(ctx).filter((req) => !view.has(req));
if (missing.length > 0 && ctx.mode === 'precheck') {
return { kind: 'unknown', missing };
}
@@ -26,10 +18,7 @@ export const evaluateConstraints = (
return { kind: 'allow' };
};
export const collectRequirements = (
constraints: Constraint[],
ctx: ConstraintContext
): RequirementKey[] => {
export const collectRequirements = (constraints: Constraint[], ctx: ConstraintContext): RequirementKey[] => {
const keys: RequirementKey[] = [];
for (const constraint of constraints) {
keys.push(...constraint.requires(ctx));
+4 -16
View File
@@ -1,11 +1,5 @@
import type { General } from '@sammo-ts/logic/domain/entities.js';
import {
allow,
readDestGeneral,
resolveDestGeneralId,
resolveDestNationId,
unknownOrDeny,
} from './helpers.js';
import { allow, readDestGeneral, resolveDestGeneralId, resolveDestNationId, unknownOrDeny } from './helpers.js';
import type { Constraint, ConstraintContext, RequirementKey, StateView } from './types.js';
export const notBeNeutral = (): Constraint => ({
@@ -73,9 +67,7 @@ export const reqGeneralGold = (
requires: (ctx) => [{ kind: 'general', id: ctx.actorId }, ...requirements],
test: (ctx, view) => {
const generalReq: RequirementKey = { kind: 'general', id: ctx.actorId };
const missing = [generalReq, ...requirements].filter(
(req) => !view.has(req)
);
const missing = [generalReq, ...requirements].filter((req) => !view.has(req));
if (missing.length > 0) {
return unknownOrDeny(ctx, missing, '장수 정보가 없습니다.');
}
@@ -99,9 +91,7 @@ export const reqGeneralRice = (
requires: (ctx) => [{ kind: 'general', id: ctx.actorId }, ...requirements],
test: (ctx, view) => {
const generalReq: RequirementKey = { kind: 'general', id: ctx.actorId };
const missing = [generalReq, ...requirements].filter(
(req) => !view.has(req)
);
const missing = [generalReq, ...requirements].filter((req) => !view.has(req));
if (missing.length > 0) {
return unknownOrDeny(ctx, missing, '장수 정보가 없습니다.');
}
@@ -144,9 +134,7 @@ export const reqGeneralCrewMargin = (
requires: (ctx) => [{ kind: 'general', id: ctx.actorId }, ...requirements],
test: (ctx, view) => {
const generalReq: RequirementKey = { kind: 'general', id: ctx.actorId };
const missing = [generalReq, ...requirements].filter(
(req) => !view.has(req)
);
const missing = [generalReq, ...requirements].filter((req) => !view.has(req));
if (missing.length > 0) {
return unknownOrDeny(ctx, missing, '장수 정보가 없습니다.');
}
+10 -43
View File
@@ -1,26 +1,12 @@
import type { City, General, Nation, TriggerValue } from '@sammo-ts/logic/domain/entities.js';
import type {
ConstraintContext,
ConstraintResult,
RequirementKey,
StateView,
} from './types.js';
import type { ConstraintContext, ConstraintResult, RequirementKey, StateView } from './types.js';
export const allow = (): ConstraintResult => ({ kind: 'allow' });
export const unknownOrDeny = (
ctx: ConstraintContext,
missing: RequirementKey[],
reason: string
): ConstraintResult =>
ctx.mode === 'precheck'
? { kind: 'unknown', missing }
: { kind: 'deny', reason };
export const unknownOrDeny = (ctx: ConstraintContext, missing: RequirementKey[], reason: string): ConstraintResult =>
ctx.mode === 'precheck' ? { kind: 'unknown', missing } : { kind: 'deny', reason };
export const readGeneral = (
ctx: ConstraintContext,
view: StateView
): General | null => {
export const readGeneral = (ctx: ConstraintContext, view: StateView): General | null => {
const req: RequirementKey = { kind: 'general', id: ctx.actorId };
if (!view.has(req)) {
return null;
@@ -47,10 +33,7 @@ export const resolveDestGeneralId = (ctx: ConstraintContext): number | undefined
return typeof raw === 'number' ? raw : undefined;
};
export const readDestGeneral = (
ctx: ConstraintContext,
view: StateView
): General | null => {
export const readDestGeneral = (ctx: ConstraintContext, view: StateView): General | null => {
const destGeneralId = resolveDestGeneralId(ctx);
if (destGeneralId === undefined) {
return null;
@@ -78,18 +61,12 @@ export const resolveDestNationId = (ctx: ConstraintContext): number | undefined
return typeof raw === 'number' ? raw : undefined;
};
export const readDestCity = (
ctx: ConstraintContext,
view: StateView
): City | null => {
export const readDestCity = (ctx: ConstraintContext, view: StateView): City | null => {
const destCityId = resolveDestCityId(ctx);
return readCity(view, destCityId);
};
export const readNation = (
view: StateView,
id?: number
): Nation | null => {
export const readNation = (view: StateView, id?: number): Nation | null => {
if (id === undefined) {
return null;
}
@@ -100,19 +77,12 @@ export const readNation = (
return view.get(req) as Nation | null;
};
export const readMetaNumber = (
meta: Record<string, TriggerValue>,
key: string
): number | null => {
export const readMetaNumber = (meta: Record<string, TriggerValue>, key: string): number | null => {
const value = meta[key];
return typeof value === 'number' ? value : null;
};
export const readDiplomacyState = (
view: StateView,
srcNationId: number,
destNationId: number
): number | null => {
export const readDiplomacyState = (view: StateView, srcNationId: number, destNationId: number): number | null => {
const req: RequirementKey = {
kind: 'diplomacy',
srcNationId,
@@ -138,10 +108,7 @@ export const readDiplomacyState = (
return null;
};
export const readMetaNumberFromUnknown = (
meta: Record<string, unknown>,
key: string
): number | null => {
export const readMetaNumberFromUnknown = (meta: Record<string, unknown>, key: string): number | null => {
const value = meta[key];
return typeof value === 'number' ? value : null;
};
+1 -4
View File
@@ -7,10 +7,7 @@ export const alwaysFail = (reason: string): Constraint => ({
test: () => ({ kind: 'deny', reason }),
});
export const notOpeningPart = (
relYear: number,
openingPartYear: number
): Constraint => ({
export const notOpeningPart = (relYear: number, openingPartYear: number): Constraint => ({
name: 'NotOpeningPart',
requires: () => [],
test: (_ctx) => {
+5 -21
View File
@@ -1,20 +1,10 @@
import type { General, Nation } from '@sammo-ts/logic/domain/entities.js';
import {
allow,
readGeneral,
readMetaNumber,
readNation,
resolveDestNationId,
unknownOrDeny,
} from './helpers.js';
import { allow, readGeneral, readMetaNumber, readNation, resolveDestNationId, unknownOrDeny } from './helpers.js';
import type { Constraint, ConstraintContext, RequirementKey, StateView } from './types.js';
export const notWanderingNation = (): Constraint => ({
name: 'NotWanderingNation',
requires: (ctx) =>
ctx.nationId !== undefined
? [{ kind: 'nation', id: ctx.nationId }]
: [],
requires: (ctx) => (ctx.nationId !== undefined ? [{ kind: 'nation', id: ctx.nationId }] : []),
test: (ctx, view) => {
const nation = readNation(view, ctx.nationId);
if (!nation) {
@@ -31,9 +21,7 @@ export const notWanderingNation = (): Constraint => ({
},
});
export const availableStrategicCommand = (
allowTurnCnt = 0
): Constraint => ({
export const availableStrategicCommand = (allowTurnCnt = 0): Constraint => ({
name: 'AvailableStrategicCommand',
requires: (ctx) => {
const reqs: RequirementKey[] = [{ kind: 'general', id: ctx.actorId }];
@@ -92,9 +80,7 @@ export const reqNationGold = (
return unknownOrDeny(ctx, [], '국가 정보가 없습니다.');
}
const nationReq: RequirementKey = { kind: 'nation', id: nationId };
const missing = [nationReq, ...requirements].filter(
(req) => !view.has(req)
);
const missing = [nationReq, ...requirements].filter((req) => !view.has(req));
if (missing.length > 0) {
return unknownOrDeny(ctx, missing, '국가 정보가 없습니다.');
}
@@ -128,9 +114,7 @@ export const reqNationRice = (
return unknownOrDeny(ctx, [], '국가 정보가 없습니다.');
}
const nationReq: RequirementKey = { kind: 'nation', id: nationId };
const missing = [nationReq, ...requirements].filter(
(req) => !view.has(req)
);
const missing = [nationReq, ...requirements].filter((req) => !view.has(req));
if (missing.length > 0) {
return unknownOrDeny(ctx, missing, '국가 정보가 없습니다.');
}
+2 -8
View File
@@ -23,10 +23,7 @@ export const mustBeTroopLeader = (): Constraint => ({
export const reqTroopMembers = (): Constraint => ({
name: 'ReqTroopMembers',
requires: (ctx) => [
{ kind: 'general', id: ctx.actorId },
{ kind: 'generalList' },
],
requires: (ctx) => [{ kind: 'general', id: ctx.actorId }, { kind: 'generalList' }],
test: (ctx, view) => {
const generalReq: RequirementKey = { kind: 'general', id: ctx.actorId };
if (!view.has(generalReq)) {
@@ -44,10 +41,7 @@ export const reqTroopMembers = (): Constraint => ({
if (!generals) {
return unknownOrDeny(ctx, [listReq], '장수 정보가 없습니다.');
}
const hasMember = generals.some(
(entry) =>
entry.troopId === general.troopId && entry.id !== general.id
);
const hasMember = generals.some((entry) => entry.troopId === general.troopId && entry.id !== general.id);
if (hasMember) {
return allow();
}