Changed flower message
This commit is contained in:
parent
6be0b47f9e
commit
729ea72579
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -20,6 +20,7 @@ class Forklift {
|
||||
}
|
||||
|
||||
setPath(path) {
|
||||
debugger;
|
||||
this.end = false;
|
||||
this.path = path;
|
||||
this.currentTarget = this.path[this.targetId];
|
||||
@ -27,8 +28,8 @@ class Forklift {
|
||||
}
|
||||
|
||||
nextTarget() {
|
||||
this.targetId += 1;
|
||||
if (this.targetId < this.path.length) {
|
||||
if (this.targetId < this.path.length - 1) {
|
||||
this.targetId += 1;
|
||||
this.currentTarget = this.path[this.targetId];
|
||||
} else {
|
||||
// Final destination reached
|
||||
@ -36,7 +37,6 @@ class Forklift {
|
||||
//this.removeCargo();
|
||||
this.end = true;
|
||||
this.targetId = 0;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -63,7 +63,7 @@ class Forklift {
|
||||
}
|
||||
}
|
||||
|
||||
async findPath(targetSection) {
|
||||
findPath(targetSection) {
|
||||
let data = {
|
||||
graph: magazineToGraph(),
|
||||
start_node: forklift.currentSection,
|
||||
@ -73,6 +73,7 @@ class Forklift {
|
||||
serverUrl + '/shortestPath',
|
||||
data,
|
||||
response => {
|
||||
console.log('Find path request data: ', data);
|
||||
let path = response.split('').map(Number);
|
||||
this.currentTarget = path[0];
|
||||
this.setPath(path);
|
||||
@ -86,22 +87,26 @@ class Forklift {
|
||||
|
||||
completeOrder(order) {
|
||||
this.waitUntilJobIsDone()
|
||||
.then(() => this.findPath(order.from))
|
||||
.then(() => this.waitUntilJobIsDone())
|
||||
.then(() => {
|
||||
this.setCargo(order.what)
|
||||
magazineState[order.from] = magazineState[order.from].filter((flower) => {
|
||||
return flower != order.what;
|
||||
.then(() => {
|
||||
if (this.currentSection != order.from) {
|
||||
this.findPath(order.from);
|
||||
}
|
||||
})
|
||||
this.findPath(order.to);
|
||||
})
|
||||
.then(() => this.waitUntilJobIsDone())
|
||||
.then(() => {
|
||||
magazineState[order.to].push(order.what);
|
||||
order.what.setMaxMaturity(5 + 2*order.to);
|
||||
console.log(order.message);
|
||||
this.busy = false;
|
||||
});
|
||||
.then(() => this.waitUntilJobIsDone())
|
||||
.then(() => {
|
||||
this.setCargo(order.what);
|
||||
magazineState[order.from] = magazineState[order.from].filter(flower => {
|
||||
return flower != order.what;
|
||||
});
|
||||
this.findPath(order.to);
|
||||
})
|
||||
.then(() => this.waitUntilJobIsDone())
|
||||
.then(() => {
|
||||
magazineState[order.to].push(order.what);
|
||||
order.what.setMaxMaturity(5 + 2 * order.to);
|
||||
console.log(order.message);
|
||||
this.busy = false;
|
||||
});
|
||||
}
|
||||
|
||||
waitUntilJobIsDone() {
|
||||
@ -116,7 +121,7 @@ class Forklift {
|
||||
}
|
||||
|
||||
completeOrders() {
|
||||
while(!this.queue.isEmpty()) {
|
||||
while (!this.queue.isEmpty()) {
|
||||
let order = queue.dequeue();
|
||||
this.completeOrder(order);
|
||||
}
|
||||
@ -131,6 +136,7 @@ class Forklift {
|
||||
}
|
||||
|
||||
sub(target, pos) {
|
||||
console.log(target, pos);
|
||||
return createVector(target.x - pos.x, target.y - pos.y);
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ let roads;
|
||||
let packageClaim;
|
||||
let going = false;
|
||||
let forklift;
|
||||
let magazineState = {0: [], 1: [], 2: [], 3: [], 4: [], 5: [], 6: [] };
|
||||
let magazineState = { 0: [], 1: [], 2: [], 3: [], 4: [], 5: [], 6: [] };
|
||||
|
||||
// This runs once at start
|
||||
function setup() {
|
||||
@ -22,7 +22,7 @@ function setup() {
|
||||
|
||||
// Create a forklift instance
|
||||
forklift = new Forklift(sections[0].x, sections[0].y);
|
||||
setInterval(ageFlowers, 5000)
|
||||
setInterval(ageFlowers, 5000);
|
||||
|
||||
select('#completeOrdersButton').mousePressed(forklift.completeOrders());
|
||||
}
|
||||
@ -81,10 +81,12 @@ function addOrder() {
|
||||
petalWidth: pw,
|
||||
petalLength: pl,
|
||||
};
|
||||
console.log(data)
|
||||
console.log(data);
|
||||
httpPost(serverUrl + '/classify', data, response => {
|
||||
magazineState[0].push(new Flower(response));
|
||||
forklift.completeOrder(new Order(0, magazineState[0][0], magazineState[0][0].type, 'cycki'));
|
||||
forklift.completeOrder(
|
||||
new Order(0, magazineState[0][0], magazineState[0][0].type, 'msg'),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@ -137,17 +139,22 @@ function ageFlowers() {
|
||||
for (let key of Object.keys(magazineState)) {
|
||||
for (let flower of magazineState[key]) {
|
||||
flower.grow();
|
||||
if(flower.isReady() && !flower.isOrdered()) {
|
||||
if (flower.isReady() && !flower.isOrdered()) {
|
||||
let order;
|
||||
let priority;
|
||||
if(int(key) == 0) {
|
||||
order = new Order(0, flower, int(flower), "Delivering new flower");
|
||||
if (int(key) == 0) {
|
||||
order = new Order(0, flower, int(flower), 'Delivering new flower');
|
||||
priority = 1;
|
||||
} else if(int(key) > 3) {
|
||||
order = new Order(int(key), flower, 0, "Fully grown flower ready");
|
||||
} else if (int(key) > 3) {
|
||||
order = new Order(int(key), flower, 0, 'Fully grown flower ready');
|
||||
priority = 3;
|
||||
} else {
|
||||
order = new Order(int(key), flower, (int(key) + 3), "Moving grown flower seedling");
|
||||
order = new Order(
|
||||
int(key),
|
||||
flower,
|
||||
int(key) + 3,
|
||||
'Moving grown flower seedling',
|
||||
);
|
||||
priority = 2;
|
||||
}
|
||||
forklift.queue.enqueue([order, priority]);
|
||||
|
Loading…
Reference in New Issue
Block a user