feat: replace custom clamp function with es-toolkit's clamp in multiple files
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import type { TurnDiplomacy } from './types.js';
|
||||
import { clamp } from 'es-toolkit';
|
||||
|
||||
// 외교 상태 코드 (legacy 기준).
|
||||
export const DIPLOMACY_STATE = {
|
||||
@@ -14,9 +15,6 @@ export const DEFAULT_WAR_TERM = 6;
|
||||
// TODO: 불가침 제의/수락 등 외교 커맨드 전환 규칙을 이 모듈에 추가 예정.
|
||||
const MAX_WAR_TERM = 13;
|
||||
|
||||
const clamp = (value: number, min: number, max: number): number =>
|
||||
Math.min(max, Math.max(min, value));
|
||||
|
||||
export const buildDiplomacyKey = (srcNationId: number, destNationId: number): string =>
|
||||
`${srcNationId}:${destNationId}`;
|
||||
|
||||
|
||||
@@ -1,16 +1,9 @@
|
||||
import type { RNG } from './RNG.js';
|
||||
import { clamp } from 'es-toolkit';
|
||||
|
||||
const maxSafeInt = Number.MAX_SAFE_INTEGER;
|
||||
|
||||
const clamp01 = (value: number): number => {
|
||||
if (value < 0) {
|
||||
return 0;
|
||||
}
|
||||
if (value > 1) {
|
||||
return 1;
|
||||
}
|
||||
return value;
|
||||
};
|
||||
const clamp01 = (value: number): number => clamp(value, 0, 1);
|
||||
|
||||
// 테스트에서 0/1만 고정으로 뽑기 위한 RNG
|
||||
export class ConstantRNG implements RNG {
|
||||
|
||||
@@ -15,6 +15,7 @@ import type {
|
||||
import type { TurnCommandEnv } from '@sammo-ts/logic/actions/turn/commandEnv.js';
|
||||
import { defaultActionContextBuilder } from '@sammo-ts/logic/actions/turn/actionContext.js';
|
||||
import type { GeneralTurnCommandSpec } from './index.js';
|
||||
import { clamp } from 'es-toolkit';
|
||||
|
||||
export interface BoostMoraleArgs {}
|
||||
|
||||
@@ -28,9 +29,6 @@ const ACTION_NAME = '사기 진작';
|
||||
const DEFAULT_ATMOS_DELTA = 5;
|
||||
const DEFAULT_MAX_ATMOS = 100;
|
||||
|
||||
const clamp = (value: number, min: number, max: number): number =>
|
||||
Math.min(Math.max(value, min), max);
|
||||
|
||||
export class ActionDefinition<
|
||||
TriggerState extends GeneralTriggerState = GeneralTriggerState
|
||||
> implements GeneralActionDefinition<TriggerState, BoostMoraleArgs> {
|
||||
|
||||
@@ -34,6 +34,7 @@ import type {
|
||||
import type { TurnCommandEnv } from '@sammo-ts/logic/actions/turn/commandEnv.js';
|
||||
import { defaultActionContextBuilder } from '@sammo-ts/logic/actions/turn/actionContext.js';
|
||||
import type { GeneralTurnCommandSpec } from './index.js';
|
||||
import { clamp } from 'es-toolkit';
|
||||
|
||||
export type DomesticCriticalPick = 'fail' | 'normal' | 'success';
|
||||
|
||||
@@ -89,9 +90,6 @@ const getMetaNumber = (
|
||||
return typeof raw === 'number' ? raw : null;
|
||||
};
|
||||
|
||||
const clamp = (value: number, min: number, max: number): number =>
|
||||
Math.min(Math.max(value, min), max);
|
||||
|
||||
const randomRange = (rng: RandomGenerator, min: number, max: number): number =>
|
||||
min + (max - min) * rng.nextFloat();
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ import { LogCategory, LogFormat, LogScope } from '@sammo-ts/logic/logging/types.
|
||||
import type { TurnCommandEnv } from '@sammo-ts/logic/actions/turn/commandEnv.js';
|
||||
import { defaultActionContextBuilder } from '@sammo-ts/logic/actions/turn/actionContext.js';
|
||||
import type { GeneralTurnCommandSpec } from './index.js';
|
||||
import { clamp } from 'es-toolkit';
|
||||
|
||||
export interface FireAttackArgs {
|
||||
destCityId: number;
|
||||
@@ -108,9 +109,6 @@ const DEFAULT_MAX_PROB = 0.5;
|
||||
const INJURY_MAX = 80;
|
||||
const CITY_STATE_BURNING = 32;
|
||||
|
||||
const clamp = (value: number, min: number, max: number): number =>
|
||||
Math.min(Math.max(value, min), max);
|
||||
|
||||
const randomRangeInt = (
|
||||
rng: RandomGenerator,
|
||||
min: number,
|
||||
|
||||
@@ -15,6 +15,7 @@ import type {
|
||||
import type { TurnCommandEnv } from '@sammo-ts/logic/actions/turn/commandEnv.js';
|
||||
import { defaultActionContextBuilder } from '@sammo-ts/logic/actions/turn/actionContext.js';
|
||||
import type { GeneralTurnCommandSpec } from './index.js';
|
||||
import { clamp } from 'es-toolkit';
|
||||
|
||||
export interface TrainingArgs {}
|
||||
|
||||
@@ -28,9 +29,6 @@ const ACTION_NAME = '훈련';
|
||||
const DEFAULT_TRAIN_DELTA = 5;
|
||||
const DEFAULT_MAX_TRAIN = 100;
|
||||
|
||||
const clamp = (value: number, min: number, max: number): number =>
|
||||
Math.min(Math.max(value, min), max);
|
||||
|
||||
export class ActionDefinition<
|
||||
TriggerState extends GeneralTriggerState = GeneralTriggerState
|
||||
> implements GeneralActionDefinition<TriggerState, TrainingArgs> {
|
||||
|
||||
@@ -20,6 +20,7 @@ import type {
|
||||
GeneralActionOutcome,
|
||||
GeneralActionResolveContext,
|
||||
} from '@sammo-ts/logic/actions/engine.js';
|
||||
import { clamp } from 'es-toolkit';
|
||||
|
||||
export interface CityDevelopmentArgs {}
|
||||
|
||||
@@ -37,9 +38,6 @@ export interface CityDevelopmentConfig {
|
||||
baseAmount: number;
|
||||
}
|
||||
|
||||
const clamp = (value: number, min: number, max: number): number =>
|
||||
Math.min(Math.max(value, min), max);
|
||||
|
||||
const readNumber = (value: unknown): number | null =>
|
||||
typeof value === 'number' && Number.isFinite(value) ? value : null;
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ import type { TurnCommandEnv } from '@sammo-ts/logic/actions/turn/commandEnv.js'
|
||||
import type { NationTurnCommandSpec } from './index.js';
|
||||
import { JosaUtil } from '@sammo-ts/common';
|
||||
import type { ActionContextBuilder } from '@sammo-ts/logic/actions/turn/actionContext.js';
|
||||
import { clamp } from 'es-toolkit';
|
||||
|
||||
export interface AwardArgs {
|
||||
isGold: boolean;
|
||||
@@ -68,9 +69,6 @@ const roundToUnit = (value: number, unit: number): number =>
|
||||
const formatNumber = (value: number): string =>
|
||||
value.toLocaleString('en-US');
|
||||
|
||||
const clamp = (value: number, min: number, max: number): number =>
|
||||
Math.min(Math.max(value, min), max);
|
||||
|
||||
const normalizeAmount = (
|
||||
amount: number,
|
||||
env: AwardEnvironment
|
||||
|
||||
Reference in New Issue
Block a user