Better job requests
This commit is contained in:
parent
62a761d270
commit
d00a867f5f
@ -19,7 +19,7 @@ class Products {
|
||||
gridProductsAmountColumn.push('');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.gridProducts.push(gridProductsColumn);
|
||||
this.gridProductsAmount.push(gridProductsAmountColumn);
|
||||
}
|
||||
@ -34,7 +34,7 @@ class Products {
|
||||
setCanvasSize (canvas) {
|
||||
canvas.width = 2000;
|
||||
canvas.height = 900;
|
||||
}
|
||||
}
|
||||
|
||||
update(){
|
||||
this.clearCanvas();
|
||||
@ -46,7 +46,7 @@ class Products {
|
||||
for (let [y, type] of line.entries()) {
|
||||
if (type === GRID_FIELD_TYPE.SHELF) {
|
||||
let v = this.drawValue(x, y);
|
||||
this.product(x * 100, y * 100, v, x, y);
|
||||
this.product(x * 100, y * 100, v, x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -66,7 +66,7 @@ class Products {
|
||||
let fontSize = 40;
|
||||
this.ctx.font = `900 ${fontSize}px "Font Awesome 5 Free"`;
|
||||
this.ctx.textAlign = "center";
|
||||
|
||||
|
||||
// make color of icon on white -> red spectrum, where
|
||||
// white - full shelf
|
||||
// red - empty shelf
|
||||
@ -74,7 +74,7 @@ class Products {
|
||||
let color = Math.floor(t(v / 50) * 255).toString(16)
|
||||
if (color.length == 1)
|
||||
color = "0" + color
|
||||
this.ctx.fillStyle = `#ff${color}${color}`;
|
||||
this.ctx.fillStyle = `#ff${color}${color}`;
|
||||
|
||||
let productsColumn = this.gridProducts[productsKey];
|
||||
let prdct = productsColumn[productsValue];
|
||||
@ -82,11 +82,11 @@ class Products {
|
||||
this.ctx.textAlign = 'center';
|
||||
this.ctx.fillText(prdct.icon, x+50, y+60);
|
||||
}
|
||||
|
||||
|
||||
clearCanvas() {
|
||||
this.ctx.clearRect(0, 0, 2000, 900);
|
||||
}
|
||||
|
||||
|
||||
getProductAt(x, y) {
|
||||
return {
|
||||
item: this.gridProducts[x][y],
|
||||
@ -95,9 +95,9 @@ class Products {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {(product: Product, amount: number, i: number, j: number, end: () => bool) => bool} filter
|
||||
* @returns
|
||||
*
|
||||
* @param {(product: Product, amount: number, i: number, j: number, end: () => bool) => bool} filter
|
||||
* @returns
|
||||
*/
|
||||
filter(filter) {
|
||||
const list = []
|
||||
@ -108,7 +108,7 @@ class Products {
|
||||
const product = this.gridProducts[i][j]
|
||||
const amount = this.gridProductsAmount[i][j]
|
||||
|
||||
if (typeof(product) !== 'string'
|
||||
if (typeof(product) !== 'string'
|
||||
&& filter(product, amount, i, j, end)) {
|
||||
list.push({ product, amount: Number(amount), x: i, y: j })
|
||||
}
|
||||
@ -121,8 +121,8 @@ class Products {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Product} incomingProduct
|
||||
* @param {number} incomingAmount
|
||||
* @param {Product} incomingProduct
|
||||
* @param {number} incomingAmount
|
||||
* @returns {{product: Product; amount: number} | null } Old shelf content
|
||||
*/
|
||||
exchange(x, y, incomingProduct, incomingAmount) {
|
||||
@ -151,11 +151,14 @@ class Products {
|
||||
}
|
||||
|
||||
getJobRequest() {
|
||||
const maybeProduct = this.filter((_product, amount, _i, _j, end) => amount < 50 && end(true))
|
||||
const maybeProduct = this.filter((_product, amount, _i, _j, end) => amount < 50).sort((a, b) => {
|
||||
return a.amount - b.amount
|
||||
})
|
||||
console.log(maybeProduct);
|
||||
return maybeProduct.length === 0 ? null : maybeProduct[0]
|
||||
}
|
||||
|
||||
findAvailableLocationsFor(product) {
|
||||
return this.filter((p, amount) => product.equals(p) && amount < 50)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user