This commit is contained in:
2026-01-10 13:49:33 +00:00
parent 6a7151da4f
commit a6c2077be7
6 changed files with 53 additions and 35 deletions
+15 -15
View File
@@ -113,11 +113,11 @@ export const suppliedDestCity = (): Constraint => ({
requires: (ctx) =>
resolveDestCityId(ctx) !== undefined
? [
{
kind: 'destCity',
id: resolveDestCityId(ctx) ?? 0,
},
]
{
kind: 'destCity',
id: resolveDestCityId(ctx) ?? 0,
},
]
: [],
test: (ctx, view) => {
const destCity = readDestCity(ctx, view);
@@ -249,11 +249,11 @@ export const existsDestCity = (): Constraint => ({
requires: (ctx) =>
resolveDestCityId(ctx) !== undefined
? [
{
kind: 'destCity',
id: resolveDestCityId(ctx) ?? 0,
},
]
{
kind: 'destCity',
id: resolveDestCityId(ctx) ?? 0,
},
]
: [],
test: (ctx, view) => {
const destCityId = resolveDestCityId(ctx);
@@ -315,11 +315,11 @@ export const notNeutralDestCity = (): Constraint => ({
requires: (ctx) =>
resolveDestCityId(ctx) !== undefined
? [
{
kind: 'destCity',
id: resolveDestCityId(ctx) ?? 0,
},
]
{
kind: 'destCity',
id: resolveDestCityId(ctx) ?? 0,
},
]
: [],
test: (ctx, view) => {
const destCity = readDestCity(ctx, view);
+2 -2
View File
@@ -32,8 +32,8 @@ 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 };
}
@@ -31,3 +31,17 @@ export const collectRequirements = (constraints: Constraint[], ctx: ConstraintCo
}
return keys;
};
export interface ActionWithConstraints {
buildConstraints(ctx: ConstraintContext, args: unknown): Constraint[];
}
export const evaluateActionConstraints = <Args>(
action: ActionWithConstraints,
ctx: ConstraintContext,
view: StateView,
args: Args
): ConstraintResult => {
const constraints = action.buildConstraints(ctx, args);
return evaluateConstraints(constraints, ctx, view);
};
+5 -5
View File
@@ -181,11 +181,11 @@ export const existsDestGeneral = (): Constraint => ({
requires: (ctx) =>
resolveDestGeneralId(ctx) !== undefined
? [
{
kind: 'destGeneral',
id: resolveDestGeneralId(ctx) ?? 0,
},
]
{
kind: 'destGeneral',
id: resolveDestGeneralId(ctx) ?? 0,
},
]
: [],
test: (ctx, view) => {
const destGeneralId = resolveDestGeneralId(ctx);
+12 -8
View File
@@ -21,21 +21,25 @@ export const notOpeningPart = (relYear: number, openingPartYear: number): Constr
export const beOpeningPart = (): Constraint => ({
name: 'beOpeningPart',
requires: () => [
{ kind: 'env', key: 'year' },
{ kind: 'env', key: 'relYear' },
{ kind: 'env', key: 'openingPartYear' },
],
test: (_ctx, view) => {
const year = view.get({ kind: 'env', key: 'year' }) as number | undefined;
const relYear = view.get({ kind: 'env', key: 'relYear' }) as number | undefined;
const openingPartYear = view.get({ kind: 'env', key: 'openingPartYear' }) as number | undefined;
if (year === undefined || openingPartYear === undefined) {
// 정보가 없으면 제약을 무시하거나 알림
if (openingPartYear === undefined) {
return { kind: 'deny', reason: '초반 제한 중에는 불가능합니다.' };
}
if (relYear === undefined) {
return { kind: 'deny', reason: '초반 제한 중에는 불가능합니다.' };
}
if (relYear + 1 <= openingPartYear) {
return allow();
}
if (year <= openingPartYear) {
return allow();
}
return { kind: 'deny', reason: '초반이 지났습니다.' };
return { kind: 'deny', reason: '초반 제한 중에는 불가능합니다.' };
},
});
+5 -5
View File
@@ -154,11 +154,11 @@ export const existsDestNation = (): Constraint => ({
requires: (ctx) =>
resolveDestNationId(ctx) !== undefined
? [
{
kind: 'destNation',
id: resolveDestNationId(ctx) ?? 0,
},
]
{
kind: 'destNation',
id: resolveDestNationId(ctx) ?? 0,
},
]
: [],
test: (ctx, view) => {
const destNationId = resolveDestNationId(ctx);