Extended signal renderer tweaks

*Cleaned up ExtendedSignalsHelper
*Moved extended signal signs height calculations to a separate function
*Fixed mechanical signals arms being rendered in a wrong position
This commit is contained in:
izawartka 2025-07-04 20:23:32 +02:00
parent dd409b0533
commit 51f99d528f
3 changed files with 25 additions and 9 deletions

View File

@ -303,7 +303,7 @@ function SignalSigns(object, {polePoints, headOffsetY}) {
if(!object.signal_elements.signs.hasOwnProperty(id) || !DefinedSignalSigns[id]) continue;
const height = (def.height || C.SIGN_DEFAULT_HEIGHT);
const text = object.signal_elements.signs[id]?.text || null;
const signY = y - height / 2 + C.STROKE_WIDTH / 2;
const signY = y - height / 2;
signs.push(SignalSign(id, signY, text));

View File

@ -9,7 +9,7 @@ const ExtendedSignalsConstants = {
HEAD_UNIT_UNUSED_SIZE_1: 0.2,
HEAD_UNIT_UNUSED_SIZE_2: 0.5,
MECH_SECOND_ARM_OFFSET: 3.5,
MECH_ARM_X_OFF: -1.314,
MECH_ARM_X_OFF: 1.314,
BAR_HALF_W: 0.6,
BAR_HALF_H: 0.2,
OVERHEAD_FRAME_HALF_W: 1.0,

View File

@ -6,11 +6,12 @@ export default class ExtendedSignalsHelper {
static getPointsData(object) {
const halfBaseWidth = this._getHalfBaseWidth(object);
const headOffsetX = this._getHeadOffsetX(object);
const polePoints = this._getPolePoints(object, headOffsetX);
const signsHeight = this._getSignsHeight(object);
const polePoints = this._getPolePoints(object, headOffsetX, signsHeight);
const headOffsetY = this._getHeadOffsetY(object, polePoints);
return {
halfBaseWidth, headOffsetX, polePoints, headOffsetY
halfBaseWidth, headOffsetX, signsHeight, polePoints, headOffsetY
};
}
@ -52,7 +53,7 @@ export default class ExtendedSignalsHelper {
}
}
static _getPolePoints(object, headOffsetX) {
static _getPolePoints(object, headOffsetX, signsHeight) {
const isDwarf = object.signal_elements.isDwarf();
if(isDwarf) return null;
@ -60,10 +61,11 @@ export default class ExtendedSignalsHelper {
const isMechanical = object.signal_elements.isMechanical();
const polePoints = {};
polePoints.zigzag = headOffsetX !== 0 ? C.ZIGZAG_OFFSET : 0;
if(isMechanical) polePoints.zigzag += C.MECH_OFFSET;
polePoints.bars = polePoints.zigzag;
polePoints.bars = polePoints.zigzag;
switch(object.signal_elements.bar) {
case SignalElementsEnums.BarType.YELLOW:
case SignalElementsEnums.BarType.GREEN:
@ -76,8 +78,8 @@ export default class ExtendedSignalsHelper {
break;
}
const signsHeight = Object.keys(object.signal_elements.signs).map(key => (DefinedSignalSigns[key]?.height || C.SIGN_DEFAULT_HEIGHT) + C.ELEM_SPACING).reduce((a, b) => a + b, 0) || 0;
polePoints.signs = polePoints.bars + signsHeight;
polePoints.end = polePoints.signs;
if(isMechanical) polePoints.end = Math.max(polePoints.end + C.POLE_HEIGHT_ADDITION, C.POLE_HEIGHT_MECH_MINIMAL);
else if(!isOverhead) polePoints.end = Math.max(polePoints.signs + C.POLE_HEIGHT_ADDITION, C.POLE_HEIGHT_MINIMAL);
@ -85,4 +87,18 @@ export default class ExtendedSignalsHelper {
return polePoints;
}
static _getSignsHeight(object) {
let y = C.HALF_STROKE_WIDTH;
for(const key in object.signal_elements.signs) {
const sign = DefinedSignalSigns[key];
if(!sign) continue;
const height = sign.height || C.SIGN_DEFAULT_HEIGHT;
y += height + C.ELEM_SPACING;
}
return y;
}
}