現在地テキスト表示関連の機能を統合化
This commit is contained in:
33
lib/trainPositionTextArray.ts
Normal file
33
lib/trainPositionTextArray.ts
Normal 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 } };
|
||||
};
|
Reference in New Issue
Block a user