Skip to content

Commit

Permalink
Add try catch in case gm is not downloaded
Browse files Browse the repository at this point in the history
  • Loading branch information
alexemanuelol committed Jul 30, 2023
1 parent 5b6ccdb commit 1610ba6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 35 deletions.
3 changes: 2 additions & 1 deletion src/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@
"connectionRefusedTo": "Connection refused to: {id}.",
"connectionsCap": "CONNECTIONS",
"container": "Container",
"couldNotAddStepTracers": "Could not add step tracers.",
"couldNotAppendMapMarkers": "Could not append map markers, rustplus info instance is not set.",
"couldNotAppendMapMonuments": "Could not append map monuments, rustplus info instance is not set.",
"couldNotAppendMapTracers": "Could not append map tracers, rustplus info instance is not set.",
Expand Down Expand Up @@ -619,4 +620,4 @@
"wipeDetected": "Wipe detected!",
"youAreAlreadyLeader": "You are already leader.",
"youAreNotPairedWithServer": "Leader command does not work because you're not paired with the server."
}
}
74 changes: 40 additions & 34 deletions src/structures/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,49 +410,55 @@ class Map {
await this.mapMarkerImageMeta.map.jimp.writeAsync(
this.mapMarkerImageMeta.map.image.replace('clean.png', 'full.png'));

const image = Gm(this.mapMarkerImageMeta.map.image.replace('clean.png', 'full.png'));
try {
const image = Gm(this.mapMarkerImageMeta.map.image.replace('clean.png', 'full.png'));

if (this.rustplus.info === null) {
this.rustplus.log(Client.client.intlGet(null, 'warningCap'),
Client.client.intlGet(null, 'couldNotAppendMapTracers'));
return;
}

if (!markers) return;
if (this.rustplus.info === null) {
this.rustplus.log(Client.client.intlGet(null, 'warningCap'),
Client.client.intlGet(null, 'couldNotAppendMapTracers'));
return;
}

/* Tracer for CargoShip */
image.stroke(Constants.COLOR_CARGO_TRACER, 2);
for (const [id, coords] of Object.entries(this.rustplus.cargoShipTracers)) {
let prev = null;
for (const point of coords) {
if (prev === null) {
if (!markers) return;

/* Tracer for CargoShip */
image.stroke(Constants.COLOR_CARGO_TRACER, 2);
for (const [id, coords] of Object.entries(this.rustplus.cargoShipTracers)) {
let prev = null;
for (const point of coords) {
if (prev === null) {
prev = point;
continue;
}
const point1 = this.calculateImageXY(prev);
const point2 = this.calculateImageXY(point);
image.drawLine(point1.x, point1.y, point2.x, point2.y);
prev = point;
continue;
}
const point1 = this.calculateImageXY(prev);
const point2 = this.calculateImageXY(point);
image.drawLine(point1.x, point1.y, point2.x, point2.y);
prev = point;
}
}

/* Tracer for Patrol Helicopter */
image.stroke(Constants.COLOR_PATROL_HELICOPTER_TRACER, 2);
for (const [id, coords] of Object.entries(this.rustplus.patrolHelicopterTracers)) {
let prev = null;
for (const point of coords) {
if (prev === null) {
/* Tracer for Patrol Helicopter */
image.stroke(Constants.COLOR_PATROL_HELICOPTER_TRACER, 2);
for (const [id, coords] of Object.entries(this.rustplus.patrolHelicopterTracers)) {
let prev = null;
for (const point of coords) {
if (prev === null) {
prev = point;
continue;
}
const point1 = this.calculateImageXY(prev);
const point2 = this.calculateImageXY(point);
image.drawLine(point1.x, point1.y, point2.x, point2.y);
prev = point;
continue;
}
const point1 = this.calculateImageXY(prev);
const point2 = this.calculateImageXY(point);
image.drawLine(point1.x, point1.y, point2.x, point2.y);
prev = point;
}
}

await this.gmWriteAsync(image, this.mapMarkerImageMeta.map.image.replace('clean.png', 'full.png'));
await this.gmWriteAsync(image, this.mapMarkerImageMeta.map.image.replace('clean.png', 'full.png'));
}
catch (error) {
this.rustplus.log(Client.client.intlGet(null, 'warningCap'),
Client.client.intlGet(null, 'couldNotAddStepTracers'));
}
}

getMarkerImageMetaByType(type) {
Expand Down Expand Up @@ -495,4 +501,4 @@ class Map {
}
}

module.exports = Map;
module.exports = Map;

0 comments on commit 1610ba6

Please sign in to comment.