mirror of
https://github.com/maziggy/bambuddy.git
synced 2026-10-18 11:56:01 +02:00
● Add prefer lowest remaining filament in auto-matching (#805)
When multiple AMS spools match the same type/color criteria, an optional setting now prefers the spool with the lowest remaining filament. This helps consume partial spools before starting new ones. Sorting applies to all matching paths: queue scheduler, print modal, and multi-printer mapping. Unknown remain values (-1) sort to end.
This commit is contained in:
@@ -203,10 +203,19 @@ export function isPlaceholderDate(scheduledTime: string | null | undefined): boo
|
||||
*/
|
||||
export function autoMatchFilament(
|
||||
req: { type?: string; color?: string; nozzle_id?: number | null },
|
||||
loadedFilaments: { globalTrayId: number; type?: string; color?: string; extruderId?: number }[],
|
||||
loadedFilaments: { globalTrayId: number; type?: string; color?: string; extruderId?: number; remain?: number }[],
|
||||
usedTrayIds: Set<number>,
|
||||
preferLowest?: boolean,
|
||||
): typeof loadedFilaments[number] | undefined {
|
||||
const nozzleFilaments = filterFilamentsByNozzle(loadedFilaments, req.nozzle_id);
|
||||
let nozzleFilaments = filterFilamentsByNozzle(loadedFilaments, req.nozzle_id);
|
||||
|
||||
if (preferLowest) {
|
||||
nozzleFilaments = [...nozzleFilaments].sort((a, b) => {
|
||||
const ra = (a.remain ?? -1) >= 0 ? (a.remain ?? -1) : 101;
|
||||
const rb = (b.remain ?? -1) >= 0 ? (b.remain ?? -1) : 101;
|
||||
return ra - rb;
|
||||
});
|
||||
}
|
||||
|
||||
const exactMatch = nozzleFilaments.find(
|
||||
(f) =>
|
||||
|
||||
Reference in New Issue
Block a user