Skip to content

Commit

Permalink
error message when trying to add a 32th zone
Browse files Browse the repository at this point in the history
  • Loading branch information
le-jeu committed Nov 13, 2024
1 parent dcce3af commit 93b91cc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/code/dialogs/opSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,13 @@ class OpSettingDialog extends WDialog {
const buttonSection = L.DomUtil.create("div", "buttonset", tab);
const buttons: { [label: string]: () => void } = {};
buttons[wX("ADD_ZONE")] = () => {
if (getSelectedOperation().canWrite()) getSelectedOperation().addZone();
if (getSelectedOperation().canWrite()) {
try {
getSelectedOperation().addZone();
} catch (e) {
displayError("Wasabee: " + e.toString());
}
}
};
buttons[wX("SET_MARKERS_ZONES")] = () => {
if (getSelectedOperation().canWrite()) setMarkersToZones();
Expand Down
13 changes: 12 additions & 1 deletion src/code/model/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,18 @@ export default class WasabeeOp extends Evented implements IOperation {
for (const z of this.zones) {
ids.add(z.id);
}
const newid = Math.max(...ids) + 1;
let newid = Math.max(...ids) + 1;
if (newid >= 32) {
for (let i = 1; i < 32; i++) {
if (!ids.has(i)) {
newid = i;
break;
}
}
if (newid >= 32) {
throw Error("Max number of zones exceeded (31)")
}
}
this.zones.push(new WasabeeZone({ id: newid, name: `${newid}` }));
this.update(true);
return newid;
Expand Down

0 comments on commit 93b91cc

Please sign in to comment.