From ea39f0051589e1abf1e5a3519a996f229363d278 Mon Sep 17 00:00:00 2001 From: harukin-expo-dev-env Date: Sat, 22 Mar 2025 09:27:38 +0000 Subject: [PATCH] =?UTF-8?q?=E5=88=97=E8=BB=8A=E8=A1=A8=E7=A4=BA=E3=81=AE?= =?UTF-8?q?=E3=83=AD=E3=82=B8=E3=83=83=E3=82=AF=E3=82=92relative=E3=81=AA?= =?UTF-8?q?=E3=82=82=E3=81=AE=E3=81=8B=E3=82=89customTrainData=E7=B5=8C?= =?UTF-8?q?=E7=94=B1=E3=81=AE=E3=82=82=E3=81=AE=E3=81=AB=E7=B5=B1=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EachTrainInfoCore/HeaderText.tsx | 126 +++++++----------- components/custom-train-data.ts | 81 +++++++---- 2 files changed, 101 insertions(+), 106 deletions(-) diff --git a/components/ActionSheetComponents/EachTrainInfoCore/HeaderText.tsx b/components/ActionSheetComponents/EachTrainInfoCore/HeaderText.tsx index 3651ffc..c030f9c 100644 --- a/components/ActionSheetComponents/EachTrainInfoCore/HeaderText.tsx +++ b/components/ActionSheetComponents/EachTrainInfoCore/HeaderText.tsx @@ -7,6 +7,7 @@ import { migrateTrainName } from "../../../lib/eachTrainInfoCoreLib/migrateTrain import { TrainIconStatus } from "./trainIconStatus"; import { TrainViewIcon } from "./trainViewIcon"; import { OneManText } from "./HeaderTextParts/OneManText"; +import { customTrainDataDetector } from "@/components/custom-train-data"; type Props = { data: { trainNum: string; limited: string }; @@ -38,86 +39,58 @@ export const HeaderText: FC = ({ }) => { 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(() => { - if (!limited) return ""; - const limitedArray = limited.split(":"); - const [type, fontAvailable] = (() => { - const d = getType(limitedArray[0]); - switch (true) { - case !!d: - return [d, true]; - case !!trainNum.includes("T"): - return ["単機回送", false]; - case !!trainNum.includes("R"): - case !!trainNum.includes("E"): - case !!trainNum.includes("L"): - case !!trainNum.includes("A"): - case !!trainNum.includes("B"): - return ["回送", false]; - case !!trainNum.includes("H"): - return ["試運転", false]; - case !!trainNum.match("D"): - case !!trainNum.match("M"): - return ["普通", true]; - case !!freightDetect(trainNum): - return [freightDetect(trainNum), false]; - default: - return ["", false]; + const customTrainData = customTrainDataDetector(trainNum); + const [type, fontAvailable, isOneMan] = (() => { + switch (customTrainData.type) { + case "LTDEXP": + return ["特急", true, false]; + case "Rapid": + return ["快速", true, false]; + case "Normal": + return ["普通", true, false]; + case "OneManRapid": + return ["快速", true, true]; + case "OneMan": + return ["普通", true, true]; + case "NightLTDEXP": + return ["特急", true, false]; + case "SPCL": + return ["臨時", false, false]; + case "SPCL_EXP": + return ["臨時特急", false, false]; + case "SPCL_Rapid": + return ["臨時快速", true, false]; + case "SPCL_Normal": + return ["臨時", true, 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) { - 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]; default: // 行先がある場合は、行先を取得 @@ -130,8 +103,7 @@ export const HeaderText: FC = ({ isOneMan, ]; } - }, [limited, trainData]); - + }, [trainData]); return ( @@ -144,7 +116,7 @@ export const HeaderText: FC = ({ fontSize: 20, color: "white", fontFamily: fontAvailable ? "JR-Nishi" : undefined, - fontWeight: !fontAvailable ?"bold":undefined, + fontWeight: !fontAvailable ? "bold" : undefined, marginRight: 5, }} > diff --git a/components/custom-train-data.ts b/components/custom-train-data.ts index 5a326f1..8be51e5 100644 --- a/components/custom-train-data.ts +++ b/components/custom-train-data.ts @@ -703,8 +703,8 @@ export const customTrainDataDetector = (TrainNumber: string) => { }; case "9174M": return { - type: "SPCL", - trainName: "[快速]マリンライナー94号", + type: "SPCL_Rapid", + trainName: "マリンライナー94号", trainIcon: "https://storage.haruk.in/s5001.png", infoUrl: "http://jr-shikoku.co.jp/01_trainbus/vehicle-info/marine.html", trainNumDistance: null, @@ -712,15 +712,25 @@ export const customTrainDataDetector = (TrainNumber: string) => { }; case "9395D": return { - type: "SPCL", - trainName: "普通列車", - trainIcon: "", - infoUrl: "", + type: "SPCL_Normal", + trainName: "", + trainIcon: null, + infoUrl: null, trainNumDistance: null, info: "WEST LIVE TOUR 2025臨 3/21,22のみ運転", }; 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(/^5[1-7]\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, info: null, }; - else - return { - type: "Normal", - trainName: "", - trainIcon: null, - infoUrl: null, - trainNumDistance: null, - info: null, - }; - break; + else if ( + new RegExp(/^[1-9]\d\d[DM]$/).test(TrainNumber) || + new RegExp(/^1[26]\d\d[DM]$/).test(TrainNumber) || + new RegExp(/^6\d\d\d[DM]$/).test(TrainNumber) + ){ + return { + type: "Normal", + trainName: "", + trainIcon: null, + infoUrl: null, + trainNumDistance: null, + info: null, + }; + } else { + return { + type: "Other", + trainName: "", + trainIcon: null, + infoUrl: null, + trainNumDistance: null, + info: null, + }; + } } }; export const getJRF = (num: string) => { switch (num) { case "71": - return "東京(タ)→高松(タ)\\n"; + return "東京(タ)→高松(タ)"; case "73": case "75": - return "大阪(タ)→高松(タ)\\n"; + return "大阪(タ)→高松(タ)"; case "3079": - return "高松(タ)→伊予三島\\n"; + return "高松(タ)→伊予三島"; case "3071": case "3077": - return "高松(タ)→新居浜\\n"; + return "高松(タ)→新居浜"; case "3073": - return "高松(タ)→松山貨物\\n"; + return "高松(タ)→松山貨物"; case "70": - return "高松(タ)→東京(タ)\\n"; + return "高松(タ)→東京(タ)"; case "74": case "76": - return "高松(タ)→大阪(タ)\\n"; + return "高松(タ)→大阪(タ)"; case "3078": - return "伊予三島→高松(タ)\\n"; + return "伊予三島→高松(タ)"; case "3070": - return "新居浜→高松(タ)\\n"; + return "新居浜→高松(タ)"; case "3076": - return "新居浜→高松(タ)\\n"; + return "新居浜→高松(タ)"; case "3072": - return "松山貨物→高松(タ)\\n"; + return "松山貨物→高松(タ)"; case "9070": - return "臨時貨物\\n"; + return "臨時"; default: return null; }