From 15f5bfbd847da671adcb2bbb4d71746440c6467a Mon Sep 17 00:00:00 2001 From: Hide_D Date: Tue, 19 Apr 2022 02:25:40 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=A1=9C=EA=B7=B8=EB=A5=BC=20=EB=B3=80?= =?UTF-8?q?=ED=99=98=ED=95=98=EB=8A=94=20=ED=95=A8=EC=88=98,=20=EA=B8=B0?= =?UTF-8?q?=EC=88=A0=20=EB=B3=80=ED=99=98=ED=95=98=EB=8A=94=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=EB=A5=BC=20ts=20=EC=9D=B4=EC=8B=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/ts/utilGame/formatLog.ts | 2 ++ hwe/ts/utilGame/techLevel.ts | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 hwe/ts/utilGame/techLevel.ts diff --git a/hwe/ts/utilGame/formatLog.ts b/hwe/ts/utilGame/formatLog.ts index 8491aead..3646b933 100644 --- a/hwe/ts/utilGame/formatLog.ts +++ b/hwe/ts/utilGame/formatLog.ts @@ -1,5 +1,7 @@ const regex = /<([RBGMCLSODYW]1?|1|\/)>/g; +//TODO: 에서 더 확장해서, , 형태로 뒤에 타입을 지정할 수 있도록 한다. + const convertMap: Record = { "R": 'color: red;', "B": 'color: blue;', diff --git a/hwe/ts/utilGame/techLevel.ts b/hwe/ts/utilGame/techLevel.ts new file mode 100644 index 00000000..95b58444 --- /dev/null +++ b/hwe/ts/utilGame/techLevel.ts @@ -0,0 +1,22 @@ + +import { clamp } from "lodash"; + +export const TECH_LEVEL_YEAR_GAP = 5; +export const TECH_LEVEL_STEP = 1000; + +export function isTechLimited(startYear: number, year: number, tech: number, maxTechLevel: number): boolean { + const relMaxTech = getMaxRelativeTechLevel(startYear, year, maxTechLevel); + const techLevel = convTechLevel(tech, maxTechLevel); + + return techLevel >= relMaxTech; +} + +export function convTechLevel(tech: number, maxTechLevel: number): number{ + return clamp(Math.floor(tech / TECH_LEVEL_STEP), 0, maxTechLevel); +} + + +export function getMaxRelativeTechLevel(startYear: number, year: number, maxTechLevel: number): number { + const relYear = year - startYear; + return clamp(Math.floor(relYear / TECH_LEVEL_YEAR_GAP) + 1, 1, maxTechLevel); +} \ No newline at end of file