Attached signs rendering
+Added rendering of signs attached to signals. If a sign is attached to a signal, attachedAs is set in the sign's def and signal has SignalElements, the sign is no longer rendered on the Signs layer but appears on the signal pole (ifextended signal rendering is enabled) +Added definitions and icons for signal signs W1 and W18 *Extracted sign attaching logic into attachSign function
This commit is contained in:
parent
02a9a11dba
commit
8f297df233
7
public/assets/signal_signs/w1.svg
Normal file
7
public/assets/signal_signs/w1.svg
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg width="100mm" height="100mm" version="1.1" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="m45.2 35.04c-2.6315 0-4.8 2.3853-4.8 5.28v19.36c0 2.8947 2.1685 5.28 4.8 5.28h9.6c2.6315 0 4.8-2.3853 4.8-5.28v-19.36c0-2.8947-2.1685-5.28-4.8-5.28z" class="background"/>
|
||||
<path d="m44 33c-3.2894 0-6 2.7106-6 6v22c0 3.2894 2.7106 6 6 6h12c3.2894 0 6-2.7106 6-6v-22c0-3.2894-2.7106-6-6-6zm0 4h12c1.1426 0 2 0.8574 2 2v22c0 1.1426-0.8574 2-2 2h-12c-1.1426 0-2-0.8574-2-2v-22c0-1.1426 0.8574-2 2-2z"/>
|
||||
<path d="m42.888 34.051a1.5 1.5 0 0 0-1.1386 0.15039 1.5 1.5 0 0 0-0.54885 2.0488l7.5 13a1.5002 1.5002 0 0 0 2.5976 0l7.5-13a1.5 1.5 0 0 0-0.54885-2.0488 1.5 1.5 0 0 0-2.0488 0.54885l-6.201 10.749-6.201-10.749a1.5 1.5 0 0 0-0.91015-0.6992z"/>
|
||||
<path d="m50 50a1.5002 1.5002 0 0 0-1.2988 0.75l-7.5 13a1.5 1.5 0 0 0 0.54885 2.0488 1.5 1.5 0 0 0 2.0488-0.54885l6.201-10.749 6.201 10.749a1.5 1.5 0 0 0 2.0488 0.54885 1.5 1.5 0 0 0 0.54885-2.0488l-7.5-13a1.5002 1.5002 0 0 0-1.2988-0.75z"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.0 KiB |
7
public/assets/signal_signs/w18.svg
Normal file
7
public/assets/signal_signs/w18.svg
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg width="100mm" height="100mm" version="1.1" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="m39.458 39.458h21.084v21.084h-21.084z" class="background"/>
|
||||
<path d="m41.732 36.771c-2.7197 0-4.9609 2.2412-4.9609 4.9609v16.536c0 2.7197 2.2412 4.9609 4.9609 4.9609h16.536c2.7197 0 4.9609-2.2412 4.9609-4.9609v-16.536c0-2.7197-2.2412-4.9609-4.9609-4.9609zm0 3.3073h16.536c0.94473 0 1.6536 0.70892 1.6536 1.6536v16.536c0 0.94473-0.70892 1.6536-1.6536 1.6536h-16.536c-0.94473 0-1.6536-0.70892-1.6536-1.6536v-16.536c0-0.94473 0.70892-1.6536 1.6536-1.6536z" />
|
||||
<path d="m50 42.559c-4.0951 0-7.4414 3.3463-7.4414 7.4414s3.3463 7.4414 7.4414 7.4414 7.4414-3.3463 7.4414-7.4414-3.3463-7.4414-7.4414-7.4414zm0 2.4805c2.7546 0 4.9609 2.2064 4.9609 4.9609s-2.2064 4.9609-4.9609 4.9609-4.9609-2.2064-4.9609-4.9609 2.2064-4.9609 4.9609-4.9609z" />
|
||||
<path d="m52.48 50c0 1.3699-1.1105 2.4805-2.4805 2.4805s-2.4805-1.1105-2.4805-2.4805 1.1105-2.4805 2.4805-2.4805 2.4805 1.1105 2.4805 2.4805z" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.0 KiB |
@ -3,6 +3,7 @@ import { ReactSVG } from 'react-svg'
|
||||
export default function SignRenderer(props) {
|
||||
const { object } = props;
|
||||
if(!object.def) return null;
|
||||
if(object.attached_skip_rendering) return null;
|
||||
|
||||
const [x, y] = object.pos.toSVGCoords();
|
||||
|
||||
|
||||
@ -43,6 +43,22 @@ function getGridCellPositions(pos, scenery, gridSize, maxDist) {
|
||||
return positions;
|
||||
}
|
||||
|
||||
function attach(sign, signal) {
|
||||
if(Constants.parser.logAttachedSigns) {
|
||||
const distance = sign.pos.distanceExcludeY(signal.pos);
|
||||
console.log(`Attaching sign ${sign.name} (${sign.id}) to signal ${signal.name} (${signal.id}) at distance ${distance.toFixed(2)} m`);
|
||||
}
|
||||
|
||||
sign.attached_to = signal;
|
||||
signal.attached_signs.push(sign);
|
||||
|
||||
const attachAs = sign.def?.attachAs || null;
|
||||
if(!attachAs || !signal.signal_elements) return;
|
||||
|
||||
sign.attached_skip_rendering = true;
|
||||
signal.signal_elements.signs[attachAs] = true;
|
||||
}
|
||||
|
||||
export function attachSigns(scenery) {
|
||||
const maxDistSq = Constants.parser.attachSignsMaxDistanceZ ** 2 + Constants.parser.attachSignsMaxDistanceX ** 2;
|
||||
const maxDist = Math.sqrt(maxDistSq);
|
||||
@ -89,11 +105,6 @@ export function attachSigns(scenery) {
|
||||
|
||||
if(!closestSignal) continue;
|
||||
|
||||
if(Constants.parser.logAttachedSigns) {
|
||||
console.log(`Attaching sign ${trackObject.name} (${trackObject.id}) to signal ${closestSignal.name} (${closestSignal.id}) at distance ${Math.sqrt(closestDistanceSq).toFixed(2)} m`);
|
||||
}
|
||||
|
||||
trackObject.attached_to = closestSignal;
|
||||
closestSignal.attached_signs.push(trackObject);
|
||||
attach(trackObject, closestSignal);
|
||||
}
|
||||
}
|
||||
@ -1,8 +1,13 @@
|
||||
const DefinedSignalSigns = {
|
||||
"w24": {
|
||||
"regex": /^(?:wsk_)?w24(?:\D)?.*$/,
|
||||
"name": "W24",
|
||||
"icon": "w24.svg",
|
||||
"w1": {
|
||||
"regex": /^(?:wsk_)?w1(?:\D)?.*$/,
|
||||
"name": "W1",
|
||||
"icon": "w1.svg",
|
||||
},
|
||||
"w18": {
|
||||
"regex": /^(?:wsk_)?w18(?:\D)?.*$/,
|
||||
"name": "W18",
|
||||
"icon": "w18.svg",
|
||||
},
|
||||
"w19": {
|
||||
"regex": /^(?:wsk_)?w19(?:\D)?.*$/,
|
||||
@ -13,7 +18,12 @@ const DefinedSignalSigns = {
|
||||
"regex": /^(?:wsk_)?w20(?:\D)?.*$/,
|
||||
"name": "W20",
|
||||
"icon": "w20.svg",
|
||||
}
|
||||
},
|
||||
"w24": {
|
||||
"regex": /^(?:wsk_)?w24(?:\D)?.*$/,
|
||||
"name": "W24",
|
||||
"icon": "w24.svg",
|
||||
},
|
||||
};
|
||||
|
||||
export default DefinedSignalSigns;
|
||||
|
||||
@ -190,22 +190,26 @@ const DefinedSigns = {
|
||||
"w18": {
|
||||
"name": "W18",
|
||||
"icon": "w18.svg",
|
||||
"offsetY": 3.89
|
||||
"offsetY": 3.89,
|
||||
"attachAs": "w18",
|
||||
},
|
||||
"w19": {
|
||||
"name": "W19",
|
||||
"icon": "w19.svg",
|
||||
"offsetY": 3.89
|
||||
"offsetY": 3.89,
|
||||
"attachAs": "w19"
|
||||
},
|
||||
"w20": {
|
||||
"name": "W20",
|
||||
"icon": "w20.svg",
|
||||
"offsetY": 3.89
|
||||
"offsetY": 3.89,
|
||||
"attachAs": "w20"
|
||||
},
|
||||
"w1": {
|
||||
"name": "W1",
|
||||
"icon": "w1.svg",
|
||||
"offsetY": 3.89
|
||||
"offsetY": 3.89,
|
||||
"attachAs": "w1"
|
||||
},
|
||||
"latarnia_w4": {alias: "w4"},
|
||||
"w4": {
|
||||
|
||||
@ -8,6 +8,7 @@ export default class Sign extends TrackObject {
|
||||
data;
|
||||
def;
|
||||
attached_to = null;
|
||||
attached_skip_rendering = false;
|
||||
|
||||
constructor(id, prefab_name, pos, rot, track_id, name, data) {
|
||||
super(id, prefab_name, pos, rot, track_id, name);
|
||||
|
||||
@ -124,6 +124,10 @@ export default class Vector3 {
|
||||
return Math.sqrt(this.distanceSq(other));
|
||||
}
|
||||
|
||||
distanceExcludeY(other) {
|
||||
return Math.sqrt(this.distanceSqExcludeY(other));
|
||||
}
|
||||
|
||||
mannhattanDistance(other) {
|
||||
return Math.abs(this.x - other.x) + Math.abs(this.y - other.y) + Math.abs(this.z - other.z);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user