feat: eslint 적용 및 관련 코드 일괄 수정
This commit is contained in:
@@ -28,10 +28,7 @@ const parseEnvFile = (rawText: string): EnvMap => {
|
||||
}
|
||||
const key = trimmed.slice(0, index).trim();
|
||||
let value = trimmed.slice(index + 1).trim();
|
||||
if (
|
||||
(value.startsWith('"') && value.endsWith('"')) ||
|
||||
(value.startsWith("'") && value.endsWith("'"))
|
||||
) {
|
||||
if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
|
||||
value = value.slice(1, -1);
|
||||
}
|
||||
env[key] = value;
|
||||
@@ -48,10 +45,7 @@ const loadEnvFile = async (envFile: string): Promise<EnvMap> => {
|
||||
}
|
||||
};
|
||||
|
||||
const applySchemaToDatabaseUrl = (
|
||||
url: string,
|
||||
schema: string | undefined
|
||||
): string => {
|
||||
const applySchemaToDatabaseUrl = (url: string, schema: string | undefined): string => {
|
||||
if (!schema) {
|
||||
return url;
|
||||
}
|
||||
@@ -64,25 +58,17 @@ const applySchemaToDatabaseUrl = (
|
||||
}
|
||||
};
|
||||
|
||||
export const resolveDatabaseUrl = async (
|
||||
options?: DatabaseUrlOptions
|
||||
): Promise<string> => {
|
||||
export const resolveDatabaseUrl = async (options?: DatabaseUrlOptions): Promise<string> => {
|
||||
const env = options?.env ?? process.env;
|
||||
if (env.DATABASE_URL) {
|
||||
const schema =
|
||||
options?.schema ??
|
||||
env.POSTGRES_SCHEMA ??
|
||||
env.DATABASE_SCHEMA;
|
||||
const schema = options?.schema ?? env.POSTGRES_SCHEMA ?? env.DATABASE_SCHEMA;
|
||||
return applySchemaToDatabaseUrl(env.DATABASE_URL, schema);
|
||||
}
|
||||
|
||||
const envFile = options?.envFile ?? DEFAULT_ENV_FILE;
|
||||
const fileEnv = await loadEnvFile(envFile);
|
||||
if (fileEnv.DATABASE_URL) {
|
||||
const schema =
|
||||
options?.schema ??
|
||||
fileEnv.POSTGRES_SCHEMA ??
|
||||
fileEnv.DATABASE_SCHEMA;
|
||||
const schema = options?.schema ?? fileEnv.POSTGRES_SCHEMA ?? fileEnv.DATABASE_SCHEMA;
|
||||
return applySchemaToDatabaseUrl(fileEnv.DATABASE_URL, schema);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,13 +6,7 @@ import type { MapDefinition } from '@sammo-ts/logic';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
const DEFAULT_MAP_ROOT = path.resolve(
|
||||
__dirname,
|
||||
'..',
|
||||
'..',
|
||||
'resources',
|
||||
'map'
|
||||
);
|
||||
const DEFAULT_MAP_ROOT = path.resolve(__dirname, '..', '..', 'resources', 'map');
|
||||
|
||||
export interface MapLoaderOptions {
|
||||
mapRoot?: string;
|
||||
@@ -24,28 +18,19 @@ const readJsonFile = async (filePath: string): Promise<unknown> => {
|
||||
return JSON.parse(raw) as unknown;
|
||||
};
|
||||
|
||||
const resolveMapRoot = (options?: MapLoaderOptions): string =>
|
||||
options?.mapRoot ?? DEFAULT_MAP_ROOT;
|
||||
const resolveMapRoot = (options?: MapLoaderOptions): string => options?.mapRoot ?? DEFAULT_MAP_ROOT;
|
||||
|
||||
export const resolveMapDefinitionPath = (
|
||||
mapName: string,
|
||||
options?: MapLoaderOptions
|
||||
): string => {
|
||||
export const resolveMapDefinitionPath = (mapName: string, options?: MapLoaderOptions): string => {
|
||||
const prefix = options?.filePrefix ?? 'map_';
|
||||
return path.resolve(resolveMapRoot(options), `${prefix}${mapName}.json`);
|
||||
};
|
||||
|
||||
export const loadMapDefinition = async (
|
||||
mapPath: string
|
||||
): Promise<MapDefinition> => {
|
||||
export const loadMapDefinition = async (mapPath: string): Promise<MapDefinition> => {
|
||||
const raw = await readJsonFile(mapPath);
|
||||
return raw as MapDefinition;
|
||||
};
|
||||
|
||||
export const loadMapDefinitionByName = async (
|
||||
mapName: string,
|
||||
options?: MapLoaderOptions
|
||||
): Promise<MapDefinition> => {
|
||||
export const loadMapDefinitionByName = async (mapName: string, options?: MapLoaderOptions): Promise<MapDefinition> => {
|
||||
const mapPath = resolveMapDefinitionPath(mapName, options);
|
||||
return loadMapDefinition(mapPath);
|
||||
};
|
||||
|
||||
@@ -11,13 +11,7 @@ import {
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
const DEFAULT_SCENARIO_ROOT = path.resolve(
|
||||
__dirname,
|
||||
'..',
|
||||
'..',
|
||||
'resources',
|
||||
'scenario'
|
||||
);
|
||||
const DEFAULT_SCENARIO_ROOT = path.resolve(__dirname, '..', '..', 'resources', 'scenario');
|
||||
|
||||
export interface ScenarioLoaderOptions {
|
||||
scenarioRoot?: string;
|
||||
@@ -29,29 +23,15 @@ const readJsonFile = async (filePath: string): Promise<unknown> => {
|
||||
return JSON.parse(raw) as unknown;
|
||||
};
|
||||
|
||||
const resolveScenarioRoot = (options?: ScenarioLoaderOptions): string =>
|
||||
options?.scenarioRoot ?? DEFAULT_SCENARIO_ROOT;
|
||||
const resolveScenarioRoot = (options?: ScenarioLoaderOptions): string => options?.scenarioRoot ?? DEFAULT_SCENARIO_ROOT;
|
||||
|
||||
export const resolveScenarioDefaultsPath = (
|
||||
options?: ScenarioLoaderOptions
|
||||
): string =>
|
||||
path.resolve(
|
||||
resolveScenarioRoot(options),
|
||||
options?.defaultsFileName ?? 'default.json'
|
||||
);
|
||||
export const resolveScenarioDefaultsPath = (options?: ScenarioLoaderOptions): string =>
|
||||
path.resolve(resolveScenarioRoot(options), options?.defaultsFileName ?? 'default.json');
|
||||
|
||||
export const resolveScenarioPath = (
|
||||
options: ScenarioLoaderOptions | undefined,
|
||||
scenarioId: number
|
||||
): string =>
|
||||
path.resolve(
|
||||
resolveScenarioRoot(options),
|
||||
`scenario_${scenarioId}.json`
|
||||
);
|
||||
export const resolveScenarioPath = (options: ScenarioLoaderOptions | undefined, scenarioId: number): string =>
|
||||
path.resolve(resolveScenarioRoot(options), `scenario_${scenarioId}.json`);
|
||||
|
||||
export const loadScenarioDefaults = async (
|
||||
defaultsPath: string
|
||||
): Promise<ScenarioDefaults> => {
|
||||
export const loadScenarioDefaults = async (defaultsPath: string): Promise<ScenarioDefaults> => {
|
||||
// 기본 시나리오 파일을 읽고 정규화한다.
|
||||
const raw = await readJsonFile(defaultsPath);
|
||||
return parseScenarioDefaults(raw);
|
||||
|
||||
@@ -1,13 +1,5 @@
|
||||
import {
|
||||
createGamePostgresConnector,
|
||||
type InputJsonValue,
|
||||
type TurnEngineEventCreateManyInput,
|
||||
} from '@sammo-ts/infra';
|
||||
import {
|
||||
buildScenarioBootstrap,
|
||||
type ScenarioBootstrapWarning,
|
||||
type WorldSeedPayload,
|
||||
} from '@sammo-ts/logic';
|
||||
import { createGamePostgresConnector, type InputJsonValue, type TurnEngineEventCreateManyInput } from '@sammo-ts/infra';
|
||||
import { buildScenarioBootstrap, type ScenarioBootstrapWarning, type WorldSeedPayload } from '@sammo-ts/logic';
|
||||
|
||||
import type { MapLoaderOptions } from './mapLoader.js';
|
||||
import { loadMapDefinitionByName } from './mapLoader.js';
|
||||
@@ -41,20 +33,14 @@ export interface ScenarioSeedResult {
|
||||
|
||||
const asJson = (value: unknown): InputJsonValue => value as InputJsonValue;
|
||||
|
||||
const resolveGeneralAge = (
|
||||
startYear: number | null,
|
||||
birthYear: number
|
||||
): number => {
|
||||
const resolveGeneralAge = (startYear: number | null, birthYear: number): number => {
|
||||
if (startYear === null || birthYear <= 0) {
|
||||
return 20;
|
||||
}
|
||||
return Math.max(startYear - birthYear, 0);
|
||||
};
|
||||
|
||||
const buildEventRows = (
|
||||
rows: unknown[],
|
||||
targetOverride?: string
|
||||
): TurnEngineEventCreateManyInput[] => {
|
||||
const buildEventRows = (rows: unknown[], targetOverride?: string): TurnEngineEventCreateManyInput[] => {
|
||||
const result: TurnEngineEventCreateManyInput[] = [];
|
||||
|
||||
for (const row of rows) {
|
||||
@@ -90,29 +76,17 @@ const buildEventRows = (
|
||||
};
|
||||
|
||||
// 시나리오 초기 데이터를 로드해 DB에 저장한다.
|
||||
export const seedScenarioToDatabase = async (
|
||||
options: ScenarioSeedOptions
|
||||
): Promise<ScenarioSeedResult> => {
|
||||
const scenario = await loadScenarioDefinitionById(
|
||||
options.scenarioId,
|
||||
options.scenarioOptions
|
||||
);
|
||||
const map = await loadMapDefinitionByName(
|
||||
scenario.config.environment.mapName,
|
||||
options.mapOptions
|
||||
);
|
||||
const unitSet = await loadUnitSetDefinitionByName(
|
||||
scenario.config.environment.unitSet,
|
||||
options.unitSetOptions
|
||||
);
|
||||
export const seedScenarioToDatabase = async (options: ScenarioSeedOptions): Promise<ScenarioSeedResult> => {
|
||||
const scenario = await loadScenarioDefinitionById(options.scenarioId, options.scenarioOptions);
|
||||
const map = await loadMapDefinitionByName(scenario.config.environment.mapName, options.mapOptions);
|
||||
const unitSet = await loadUnitSetDefinitionByName(scenario.config.environment.unitSet, options.unitSetOptions);
|
||||
|
||||
const { seed, warnings } = buildScenarioBootstrap({
|
||||
scenario,
|
||||
map,
|
||||
unitSet,
|
||||
options: {
|
||||
includeNeutralNationInSeed:
|
||||
options.includeNeutralNationInSeed ?? true,
|
||||
includeNeutralNationInSeed: options.includeNeutralNationInSeed ?? true,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -216,10 +190,7 @@ export const seedScenarioToDatabase = async (
|
||||
affinity: general.affinity,
|
||||
bornYear: general.birthYear,
|
||||
deadYear: general.deathYear,
|
||||
picture:
|
||||
general.picture === null
|
||||
? null
|
||||
: String(general.picture),
|
||||
picture: general.picture === null ? null : String(general.picture),
|
||||
leadership: general.stats.leadership,
|
||||
strength: general.stats.strength,
|
||||
intel: general.stats.intelligence,
|
||||
@@ -232,10 +203,7 @@ export const seedScenarioToDatabase = async (
|
||||
bookCode: general.book ?? 'None',
|
||||
itemCode: general.item ?? 'None',
|
||||
turnTime: now,
|
||||
age: resolveGeneralAge(
|
||||
scenario.startYear ?? null,
|
||||
general.birthYear
|
||||
),
|
||||
age: resolveGeneralAge(scenario.startYear ?? null, general.birthYear),
|
||||
personalCode: general.personality ?? 'None',
|
||||
specialCode: general.special ?? 'None',
|
||||
special2Code: general.specialWar ?? 'None',
|
||||
@@ -305,10 +273,7 @@ export const seedScenarioToDatabase = async (
|
||||
});
|
||||
}
|
||||
|
||||
const eventRows = [
|
||||
...buildEventRows(seed.events),
|
||||
...buildEventRows(seed.initialEvents, 'initial'),
|
||||
];
|
||||
const eventRows = [...buildEventRows(seed.events), ...buildEventRows(seed.initialEvents, 'initial')];
|
||||
if (eventRows.length > 0) {
|
||||
await prisma.event.createMany({
|
||||
data: eventRows,
|
||||
|
||||
@@ -6,13 +6,7 @@ import { parseUnitSetDefinition, type UnitSetDefinition } from '@sammo-ts/logic'
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
const DEFAULT_UNIT_SET_ROOT = path.resolve(
|
||||
__dirname,
|
||||
'..',
|
||||
'..',
|
||||
'resources',
|
||||
'unitset'
|
||||
);
|
||||
const DEFAULT_UNIT_SET_ROOT = path.resolve(__dirname, '..', '..', 'resources', 'unitset');
|
||||
|
||||
export interface UnitSetLoaderOptions {
|
||||
unitSetRoot?: string;
|
||||
@@ -24,20 +18,14 @@ const readJsonFile = async (filePath: string): Promise<unknown> => {
|
||||
return JSON.parse(raw) as unknown;
|
||||
};
|
||||
|
||||
const resolveUnitSetRoot = (options?: UnitSetLoaderOptions): string =>
|
||||
options?.unitSetRoot ?? DEFAULT_UNIT_SET_ROOT;
|
||||
const resolveUnitSetRoot = (options?: UnitSetLoaderOptions): string => options?.unitSetRoot ?? DEFAULT_UNIT_SET_ROOT;
|
||||
|
||||
export const resolveUnitSetDefinitionPath = (
|
||||
unitSetName: string,
|
||||
options?: UnitSetLoaderOptions
|
||||
): string => {
|
||||
export const resolveUnitSetDefinitionPath = (unitSetName: string, options?: UnitSetLoaderOptions): string => {
|
||||
const prefix = options?.filePrefix ?? 'unitset_';
|
||||
return path.resolve(resolveUnitSetRoot(options), `${prefix}${unitSetName}.json`);
|
||||
};
|
||||
|
||||
export const loadUnitSetDefinition = async (
|
||||
unitSetPath: string
|
||||
): Promise<UnitSetDefinition> => {
|
||||
export const loadUnitSetDefinition = async (unitSetPath: string): Promise<UnitSetDefinition> => {
|
||||
const raw = await readJsonFile(unitSetPath);
|
||||
return parseUnitSetDefinition(raw);
|
||||
};
|
||||
@@ -49,4 +37,3 @@ export const loadUnitSetDefinitionByName = async (
|
||||
const unitSetPath = resolveUnitSetDefinitionPath(unitSetName, options);
|
||||
return loadUnitSetDefinition(unitSetPath);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user