Allow conveyor device labels to drop on spurs/curves/inductions/extendos

isTypeCompatible now matches by conveyance family, not just SVG file.
Conveyor family includes: conveyor, spur, curved_conv, induction, extendo.
Chute family includes: chute, tipper, curved_chute.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
igurielidze 2026-03-30 18:26:39 +04:00
parent 07cee1c151
commit 2f5c43a07c

View File

@ -100,12 +100,30 @@ function hitTest(cx: number, cy: number): number | null {
return hitTestSymbols(cx, cy, layout.symbols); return hitTestSymbols(cx, cy, layout.symbols);
} }
/** Get the conveyance family for a symbol ID.
* Conveyor family: conveyor, spur, curved_conv, induction, extendo
* Chute family: chute, tipper, curved_chute */
function getConveyanceFamily(symbolId: string): string | null {
if (symbolId.startsWith('conveyor') || symbolId.startsWith('spur') ||
symbolId.startsWith('curved_conv') || symbolId.startsWith('induction') ||
symbolId.startsWith('extendo')) return 'conveyor';
if (symbolId.startsWith('chute') || symbolId.startsWith('tipper') ||
symbolId.startsWith('curved_chute')) return 'chute';
return null;
}
/** Check if a device type (symbolDef) is compatible with a placed symbol for label assignment. /** Check if a device type (symbolDef) is compatible with a placed symbol for label assignment.
* Matches by SVG file so base and _v variants are treated as the same type. */ * Matches by conveyance family so conveyor devices can drop on spurs/curves too. */
function isTypeCompatible(symbolDef: (typeof SYMBOLS)[number], placedSymbolId: string): boolean { function isTypeCompatible(symbolDef: (typeof SYMBOLS)[number], placedSymbolId: string): boolean {
const placedDef = SYMBOLS.find(s => s.id === placedSymbolId); const placedDef = SYMBOLS.find(s => s.id === placedSymbolId);
if (!placedDef) return false; if (!placedDef) return false;
return symbolDef.file === placedDef.file; // Same SVG file (base + _v variants)
if (symbolDef.file === placedDef.file) return true;
// Same conveyance family
const dragFamily = getConveyanceFamily(symbolDef.id);
const targetFamily = getConveyanceFamily(placedSymbolId);
if (dragFamily && dragFamily === targetFamily) return true;
return false;
} }
function onCanvasMousedown(e: MouseEvent) { function onCanvasMousedown(e: MouseEvent) {