better color selector defaults still needs every situation testing
This commit is contained in:
@@ -4392,6 +4392,45 @@ function openFilamentDialog(slots){
|
||||
return {slot_index:i,color_hex:s.color_hex,material:s.material};
|
||||
});
|
||||
|
||||
// Default mapping strategy:
|
||||
// 1) keep order where possible (row i -> nearest compatible slot i)
|
||||
// 2) keep defaults unique while compatible slots are available
|
||||
// 3) use color proximity as tie-breaker
|
||||
function _hexToRgb(hex){
|
||||
var c=(hex||'').replace('#','');
|
||||
if(c.length===3)c=c[0]+c[0]+c[1]+c[1]+c[2]+c[2];
|
||||
if(c.length<6)return [255,255,255];
|
||||
return [parseInt(c.slice(0,2),16),parseInt(c.slice(2,4),16),parseInt(c.slice(4,6),16)];
|
||||
}
|
||||
function _colorDist(a,b){
|
||||
var ar=_hexToRgb(a), br=_hexToRgb(b);
|
||||
var dr=ar[0]-br[0], dg=ar[1]-br[1], db=ar[2]-br[2];
|
||||
return (dr*dr + dg*dg + db*db);
|
||||
}
|
||||
var defaultSlotByPaint={};
|
||||
var usedDefaultSlot={};
|
||||
channels.forEach(function(gc,i){
|
||||
var compatible=_amsSlots.filter(function(s){
|
||||
return _materialsCompatible(gc.material, s.material);
|
||||
});
|
||||
if(!compatible.length){
|
||||
defaultSlotByPaint[i]=-1;
|
||||
return;
|
||||
}
|
||||
|
||||
var ranked=compatible.slice().sort(function(a,b){
|
||||
var da=Math.abs((a.slot_index||0)-i), db=Math.abs((b.slot_index||0)-i);
|
||||
if(da!==db)return da-db;
|
||||
var ca=_colorDist(gc.color_hex, a.color_hex), cb=_colorDist(gc.color_hex, b.color_hex);
|
||||
if(ca!==cb)return ca-cb;
|
||||
return (a.slot_index||0)-(b.slot_index||0);
|
||||
});
|
||||
|
||||
var chosen=ranked.find(function(s){return !usedDefaultSlot[s.slot_index];}) || ranked[0];
|
||||
defaultSlotByPaint[i]=chosen?chosen.slot_index:-1;
|
||||
if(chosen) usedDefaultSlot[chosen.slot_index]=1;
|
||||
});
|
||||
|
||||
if(!_amsSlots.length){
|
||||
body.innerHTML='<p style="color:var(--txt2);font-size:13px;text-align:center;padding:16px 0">Keine belegten AMS-Slots.<br>Druck trotzdem starten?</p>';
|
||||
} else {
|
||||
@@ -4402,8 +4441,8 @@ function openFilamentDialog(slots){
|
||||
return _materialsCompatible(gc.material, s.material);
|
||||
});
|
||||
|
||||
// Default mapping by ordinal row position into compatible loaded slots.
|
||||
var defaultSlot=compatible.length?compatible[Math.min(i, compatible.length-1)]:null;
|
||||
var defaultSlotIndex=(defaultSlotByPaint.hasOwnProperty(i)?defaultSlotByPaint[i]:-1);
|
||||
var defaultSlot=compatible.find(function(s){return s.slot_index===defaultSlotIndex;})||null;
|
||||
var opts=compatible.map(function(s){
|
||||
var sel=(defaultSlot&&s.slot_index===defaultSlot.slot_index)?'selected':'';
|
||||
return '<option value="'+s.slot_index+'" data-color="'+s.color_hex+'" data-material="'+s.material+'" '+sel+'>'+
|
||||
|
||||
Reference in New Issue
Block a user