Added extended signal signs text option

+Extended signal renderering: Signs mounted on signals can now have displayed text over them (i.e. W21 sign). During the parsing, the text string is extracted from the sign name using regex from the sign's def
This commit is contained in:
izawartka 2025-07-03 16:27:25 +02:00
parent ce375cb7e2
commit 920de35b60
4 changed files with 46 additions and 4 deletions

View File

@ -99,6 +99,10 @@
fill: #111;
}
.map .signal-sign-text {
stroke: none;
}
.map svg g.nevp path {
fill: #eee;
}

View File

@ -321,6 +321,21 @@ function getBars(object, polePoints, headOffsetY) {
}
}
function getSignText(id, text, y) {
if(!text) return null;
const def = DefinedSignalSigns[id];
if(!def) return null;
return <text
key={`${id}-text`}
className="signal-sign-text"
transform={`translate(${def.textOffsetX || 0}, ${y + (def.textOffsetY || 0)})`}
style={{ fontSize: `${def.textSize || 0.15}mm` }}
textAnchor="middle"
dominantBaseline="central"
>{text}</text>;
}
function getSign(id, y) {
const def = DefinedSignalSigns[id];
if(!def) return null;
@ -342,9 +357,16 @@ function getSigns(object, polePoints, headOffsetY) {
const signs = [];
let y = headOffsetY + polePoints.signs;
for(const [key, def] of Object.entries(DefinedSignalSigns)) {
if(!object.signal_elements.signs.hasOwnProperty(key) || !DefinedSignalSigns[key]) continue;
for(const [id, def] of Object.entries(DefinedSignalSigns)) {
if(!object.signal_elements.signs.hasOwnProperty(id) || !DefinedSignalSigns[id]) continue;
const height = (def.height || 1.0);
const text = object.signal_elements.signs[id]?.text || null;
const signY = y - height / 2 + 0.1;
signs.push(getSign(id, signY, text));
const textComponent = getSignText(id, text, signY);
if(textComponent) signs.push(textComponent);
signs.push(getSign(key, y - height / 2 + 0.1));
y -= height + 0.2;

View File

@ -45,7 +45,9 @@ const Constants = {
signalElemsUnknownPrefab: true,
signalElemsRecognizedUnknownPrefab: true,
attachSignsOutOfBounds: true,
signalElemsUnknownSign: true
signalElemsUnknownSign: true,
signalElemsUnknownSignText: true,
},
errors: {
invalidSceneryInfo: true

View File

@ -111,6 +111,20 @@ export default class SignalElementsParserCommon {
}
signs[key] = true;
const def = DefinedSignalSigns[key];
if(!def.textRegex) continue;
const match = def.textRegex.exec(entry);
if(!match) {
SceneryParserLog.warn('signalElemsUnknownSignText', `Signal sign ${entry} does not match text regex for ${key}`);
continue;
}
const text = match[1]?.trim();
signs[key] = {
text: text || null,
}
}
return signs;