現在地テキスト表示関連の機能を統合化

This commit is contained in:
harukin-expo-dev-env
2024-10-17 11:52:17 +00:00
parent bf7e113862
commit b41c02ca76
3 changed files with 54 additions and 32 deletions

View File

@@ -0,0 +1,33 @@
type returnBetweenType = {
isBetween: true;
Pos: {
from: string;
to: string;
};
};
type returnCurrentType = {
isBetween: false;
Pos: {
Pos: string;
};
};
export type trainDataType = {
Pos?: string;
Direction?: number;
};
type trainData = (
trainData: trainDataType
) => returnBetweenType | returnCurrentType;
export const trainPosition: trainData = (trainData) => {
if (!trainData?.Pos) return { isBetween: false, Pos: { Pos: "" } };
const { Pos, Direction } = trainData;
if (Pos.match("")) {
const [topST, downST] = Pos.replace("(下り)", "")
.replace("(上り)", "")
.split("");
const from = Direction == 1 ? topST : downST;
const to = Direction == 1 ? downST : topST;
return { isBetween: true, Pos: { from, to } };
} else return { isBetween: false, Pos: { Pos } };
};