列車表示のロジックをrelativeなものからcustomTrainData経由のものに統一
This commit is contained in:
parent
3e12371b16
commit
ea39f00515
@ -7,6 +7,7 @@ import { migrateTrainName } from "../../../lib/eachTrainInfoCoreLib/migrateTrain
|
|||||||
import { TrainIconStatus } from "./trainIconStatus";
|
import { TrainIconStatus } from "./trainIconStatus";
|
||||||
import { TrainViewIcon } from "./trainViewIcon";
|
import { TrainViewIcon } from "./trainViewIcon";
|
||||||
import { OneManText } from "./HeaderTextParts/OneManText";
|
import { OneManText } from "./HeaderTextParts/OneManText";
|
||||||
|
import { customTrainDataDetector } from "@/components/custom-train-data";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
data: { trainNum: string; limited: string };
|
data: { trainNum: string; limited: string };
|
||||||
@ -38,86 +39,58 @@ export const HeaderText: FC<Props> = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const { limited, trainNum } = data;
|
const { limited, trainNum } = data;
|
||||||
|
|
||||||
// 貨物の判定
|
|
||||||
const freightDetect = (num:string)=>{
|
|
||||||
switch(num){
|
|
||||||
case "71":
|
|
||||||
return "貨物 東京(タ)→高松(タ)";
|
|
||||||
case "73":
|
|
||||||
case "75":
|
|
||||||
return "貨物 大阪(タ)→高松(タ)";
|
|
||||||
case "3079":
|
|
||||||
return "貨物 高松(タ)→伊予三島";
|
|
||||||
case "3071":
|
|
||||||
case "3077":
|
|
||||||
return "貨物 高松(タ)→新居浜";
|
|
||||||
case "3073":
|
|
||||||
return "貨物 高松(タ)→松山貨物";
|
|
||||||
case "70":
|
|
||||||
return "貨物 高松(タ)→東京(タ)";
|
|
||||||
case "74":
|
|
||||||
case "76":
|
|
||||||
return "貨物 高松(タ)→大阪(タ)";
|
|
||||||
case "3078":
|
|
||||||
return "貨物 伊予三島→高松(タ)";
|
|
||||||
case "3070":
|
|
||||||
return "貨物 新居浜→高松(タ)";
|
|
||||||
case "3076":
|
|
||||||
return "貨物 新居浜→高松(タ)";
|
|
||||||
case "3072":
|
|
||||||
return "貨物 松山貨物→高松(タ)";
|
|
||||||
case "9070":
|
|
||||||
return "貨物 臨時";
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 列車名、種別、フォントの取得
|
// 列車名、種別、フォントの取得
|
||||||
const [typeName, trainName, fontAvailable, isOneMan] = useMemo(() => {
|
const [typeName, trainName, fontAvailable, isOneMan] = useMemo(() => {
|
||||||
if (!limited) return "";
|
const customTrainData = customTrainDataDetector(trainNum);
|
||||||
const limitedArray = limited.split(":");
|
const [type, fontAvailable, isOneMan] = (() => {
|
||||||
const [type, fontAvailable] = (() => {
|
switch (customTrainData.type) {
|
||||||
const d = getType(limitedArray[0]);
|
case "LTDEXP":
|
||||||
switch (true) {
|
return ["特急", true, false];
|
||||||
case !!d:
|
case "Rapid":
|
||||||
return [d, true];
|
return ["快速", true, false];
|
||||||
case !!trainNum.includes("T"):
|
case "Normal":
|
||||||
return ["単機回送", false];
|
return ["普通", true, false];
|
||||||
case !!trainNum.includes("R"):
|
case "OneManRapid":
|
||||||
case !!trainNum.includes("E"):
|
return ["快速", true, true];
|
||||||
case !!trainNum.includes("L"):
|
case "OneMan":
|
||||||
case !!trainNum.includes("A"):
|
return ["普通", true, true];
|
||||||
case !!trainNum.includes("B"):
|
case "NightLTDEXP":
|
||||||
return ["回送", false];
|
return ["特急", true, false];
|
||||||
case !!trainNum.includes("H"):
|
case "SPCL":
|
||||||
return ["試運転", false];
|
return ["臨時", false, false];
|
||||||
case !!trainNum.match("D"):
|
case "SPCL_EXP":
|
||||||
case !!trainNum.match("M"):
|
return ["臨時特急", false, false];
|
||||||
return ["普通", true];
|
case "SPCL_Rapid":
|
||||||
case !!freightDetect(trainNum):
|
return ["臨時快速", true, false];
|
||||||
return [freightDetect(trainNum), false];
|
case "SPCL_Normal":
|
||||||
default:
|
return ["臨時", true, false];
|
||||||
return ["", false];
|
case "Freight":
|
||||||
|
return ["貨物", false, false];
|
||||||
|
case "Other":
|
||||||
|
switch (true) {
|
||||||
|
case !!trainNum.includes("T"):
|
||||||
|
return ["単機回送", false, false];
|
||||||
|
case !!trainNum.includes("R"):
|
||||||
|
case !!trainNum.includes("E"):
|
||||||
|
case !!trainNum.includes("L"):
|
||||||
|
case !!trainNum.includes("A"):
|
||||||
|
case !!trainNum.includes("B"):
|
||||||
|
return ["回送", false, false];
|
||||||
|
case !!trainNum.includes("H"):
|
||||||
|
return ["試運転", false, false];
|
||||||
|
}
|
||||||
|
return ["", false, false];
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
const isOneMan = (() => {
|
|
||||||
const OneManRegex = new RegExp(/^4[1-9]\d\d[DM]$/);
|
|
||||||
const OneManRegex2 = new RegExp(/^5[1-7]\d\d[DM]$/);
|
|
||||||
const OneManRegex3 = new RegExp(/^3[2-9]\d\d[DM]$/);
|
|
||||||
return !!(
|
|
||||||
OneManRegex.test(trainNum) ||
|
|
||||||
OneManRegex2.test(trainNum) ||
|
|
||||||
OneManRegex3.test(trainNum)
|
|
||||||
);
|
|
||||||
})();
|
|
||||||
switch (true) {
|
switch (true) {
|
||||||
case !!limitedArray[1]:
|
case customTrainData.trainName !== "":
|
||||||
// 特急の場合は、列車名を取得
|
// 特急の場合は、列車名を取得
|
||||||
return [type, migrateTrainName(limitedArray[1]), fontAvailable, isOneMan];
|
// 列番対称データがある場合はそれから列車番号を取得
|
||||||
case trainData.length == 0:
|
const distance = customTrainData.trainNumDistance;
|
||||||
// 特急以外の場合は、列車番号を取得
|
const number = distance !== null ? ` ${parseInt(trainNum) - distance}号` : "";
|
||||||
|
const trainName = customTrainData.trainName + number;
|
||||||
|
return [type, trainName, fontAvailable, isOneMan];
|
||||||
|
case trainData[trainData.length - 1] === undefined:
|
||||||
return [type, "", fontAvailable, isOneMan];
|
return [type, "", fontAvailable, isOneMan];
|
||||||
default:
|
default:
|
||||||
// 行先がある場合は、行先を取得
|
// 行先がある場合は、行先を取得
|
||||||
@ -130,8 +103,7 @@ export const HeaderText: FC<Props> = ({
|
|||||||
isOneMan,
|
isOneMan,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}, [limited, trainData]);
|
}, [trainData]);
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={{ padding: 10, flexDirection: "row", alignItems: "center" }}>
|
<View style={{ padding: 10, flexDirection: "row", alignItems: "center" }}>
|
||||||
@ -144,7 +116,7 @@ export const HeaderText: FC<Props> = ({
|
|||||||
fontSize: 20,
|
fontSize: 20,
|
||||||
color: "white",
|
color: "white",
|
||||||
fontFamily: fontAvailable ? "JR-Nishi" : undefined,
|
fontFamily: fontAvailable ? "JR-Nishi" : undefined,
|
||||||
fontWeight: !fontAvailable ?"bold":undefined,
|
fontWeight: !fontAvailable ? "bold" : undefined,
|
||||||
marginRight: 5,
|
marginRight: 5,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
@ -703,8 +703,8 @@ export const customTrainDataDetector = (TrainNumber: string) => {
|
|||||||
};
|
};
|
||||||
case "9174M":
|
case "9174M":
|
||||||
return {
|
return {
|
||||||
type: "SPCL",
|
type: "SPCL_Rapid",
|
||||||
trainName: "[快速]マリンライナー94号",
|
trainName: "マリンライナー94号",
|
||||||
trainIcon: "https://storage.haruk.in/s5001.png",
|
trainIcon: "https://storage.haruk.in/s5001.png",
|
||||||
infoUrl: "http://jr-shikoku.co.jp/01_trainbus/vehicle-info/marine.html",
|
infoUrl: "http://jr-shikoku.co.jp/01_trainbus/vehicle-info/marine.html",
|
||||||
trainNumDistance: null,
|
trainNumDistance: null,
|
||||||
@ -712,15 +712,25 @@ export const customTrainDataDetector = (TrainNumber: string) => {
|
|||||||
};
|
};
|
||||||
case "9395D":
|
case "9395D":
|
||||||
return {
|
return {
|
||||||
type: "SPCL",
|
type: "SPCL_Normal",
|
||||||
trainName: "普通列車",
|
trainName: "",
|
||||||
trainIcon: "",
|
trainIcon: null,
|
||||||
infoUrl: "",
|
infoUrl: null,
|
||||||
trainNumDistance: null,
|
trainNumDistance: null,
|
||||||
info: "WEST LIVE TOUR 2025臨 3/21,22のみ運転",
|
info: "WEST LIVE TOUR 2025臨 3/21,22のみ運転",
|
||||||
};
|
};
|
||||||
default:
|
default:
|
||||||
if (
|
if(getJRF(TrainNumber) !== null){
|
||||||
|
return {
|
||||||
|
type: "Freight",
|
||||||
|
trainName: getJRF(TrainNumber),
|
||||||
|
trainIcon: "https://storage.haruk.in/ef210a.png",
|
||||||
|
infoUrl: null,
|
||||||
|
trainNumDistance: null,
|
||||||
|
info: getJRF(TrainNumber),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else if (
|
||||||
new RegExp(/^4[1-9]\d\d[DM]$/).test(TrainNumber) ||
|
new RegExp(/^4[1-9]\d\d[DM]$/).test(TrainNumber) ||
|
||||||
new RegExp(/^5[1-7]\d\d[DM]$/).test(TrainNumber) ||
|
new RegExp(/^5[1-7]\d\d[DM]$/).test(TrainNumber) ||
|
||||||
new RegExp(/^3[2-9]\d\d[DM]$/).test(TrainNumber)
|
new RegExp(/^3[2-9]\d\d[DM]$/).test(TrainNumber)
|
||||||
@ -733,47 +743,60 @@ export const customTrainDataDetector = (TrainNumber: string) => {
|
|||||||
trainNumDistance: null,
|
trainNumDistance: null,
|
||||||
info: null,
|
info: null,
|
||||||
};
|
};
|
||||||
else
|
else if (
|
||||||
return {
|
new RegExp(/^[1-9]\d\d[DM]$/).test(TrainNumber) ||
|
||||||
type: "Normal",
|
new RegExp(/^1[26]\d\d[DM]$/).test(TrainNumber) ||
|
||||||
trainName: "",
|
new RegExp(/^6\d\d\d[DM]$/).test(TrainNumber)
|
||||||
trainIcon: null,
|
){
|
||||||
infoUrl: null,
|
return {
|
||||||
trainNumDistance: null,
|
type: "Normal",
|
||||||
info: null,
|
trainName: "",
|
||||||
};
|
trainIcon: null,
|
||||||
break;
|
infoUrl: null,
|
||||||
|
trainNumDistance: null,
|
||||||
|
info: null,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
type: "Other",
|
||||||
|
trainName: "",
|
||||||
|
trainIcon: null,
|
||||||
|
infoUrl: null,
|
||||||
|
trainNumDistance: null,
|
||||||
|
info: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
export const getJRF = (num: string) => {
|
export const getJRF = (num: string) => {
|
||||||
switch (num) {
|
switch (num) {
|
||||||
case "71":
|
case "71":
|
||||||
return "東京(タ)→高松(タ)\\n";
|
return "東京(タ)→高松(タ)";
|
||||||
case "73":
|
case "73":
|
||||||
case "75":
|
case "75":
|
||||||
return "大阪(タ)→高松(タ)\\n";
|
return "大阪(タ)→高松(タ)";
|
||||||
case "3079":
|
case "3079":
|
||||||
return "高松(タ)→伊予三島\\n";
|
return "高松(タ)→伊予三島";
|
||||||
case "3071":
|
case "3071":
|
||||||
case "3077":
|
case "3077":
|
||||||
return "高松(タ)→新居浜\\n";
|
return "高松(タ)→新居浜";
|
||||||
case "3073":
|
case "3073":
|
||||||
return "高松(タ)→松山貨物\\n";
|
return "高松(タ)→松山貨物";
|
||||||
case "70":
|
case "70":
|
||||||
return "高松(タ)→東京(タ)\\n";
|
return "高松(タ)→東京(タ)";
|
||||||
case "74":
|
case "74":
|
||||||
case "76":
|
case "76":
|
||||||
return "高松(タ)→大阪(タ)\\n";
|
return "高松(タ)→大阪(タ)";
|
||||||
case "3078":
|
case "3078":
|
||||||
return "伊予三島→高松(タ)\\n";
|
return "伊予三島→高松(タ)";
|
||||||
case "3070":
|
case "3070":
|
||||||
return "新居浜→高松(タ)\\n";
|
return "新居浜→高松(タ)";
|
||||||
case "3076":
|
case "3076":
|
||||||
return "新居浜→高松(タ)\\n";
|
return "新居浜→高松(タ)";
|
||||||
case "3072":
|
case "3072":
|
||||||
return "松山貨物→高松(タ)\\n";
|
return "松山貨物→高松(タ)";
|
||||||
case "9070":
|
case "9070":
|
||||||
return "臨時貨物\\n";
|
return "臨時";
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user