${game.i18n.localize("DD.ClearAllDialogContent")}
`,yes:()=>this.dungeon?.deleteAll()})}async generate(e){this.dungeon?await this.dungeon.deleteAll():await this.createNewDungeon(),await(async(e,t={})=>{try{switch(t.algorithm){case"2d-dungeon":await hc(e,t);break;case"rot-js-cellular":await cc(e,t);break;case"dungeoneer":await uc(e,t)}}catch(e){console.error(e),ui.notifications.error("Error generating dungeon... please try again.")}})(this.dungeon,e)}async loadDungeon(){const{journalEntry:t,note:i}=await(()=>{for(const t of canvas.scene.notes){const i=game.journal.get(t.entryId);if(i&&i.getFlag(e,"dungeonVersion"))return{journalEntry:i,note:t}}return{journalEntry:null,note:null}})();t?(this.dungeon=new So(t,i),await this.dungeon.loadFromJournalEntry(),this.addChildAt(this.dungeon,0)):this.dungeon=null}async createNewDungeon(){await(async()=>{const e=await gc();return{journalEntry:e,note:await mc(e)}})(),await this.loadDungeon()}async draw(){return await super.draw(),this}_onClickLeft(e){const{preview:t,drawingsState:i,destination:n}=e.interactionData;if(i>=1&&t.isPolygon){let i=n;return!e.shiftKey&&(i=canvas.grid.getSnappedPosition(i.x,i.y,this.gridPrecision)),t._addPoint(i,!1),t._chain=!0,t.refresh()}super._onClickLeft(e)}_onClickLeft2(e){const{drawingsState:t,preview:i}=e.interactionData;if(t>=1&&i.isPolygon)return e.interactionData.drawingsState=2,this._onDragLeftDrop(e);super._onClickLeft2(e)}async _onDragLeftStart(e){await super._onDragLeftStart(e);const t=e.interactionData,i=this._getNewDrawingData(e.interactionData.origin),n=new DrawingDocument(i,{parent:canvas.scene}),r=new Drawing(n);return t.preview=this.preview.addChild(r),t.drawingsState=1,r.draw()}_onDragLeftMove(e){const{preview:t,drawingsState:i}=e.interactionData;if(t&&!t._destroyed&&(null===t.parent&&this.preview.addChild(t),i>=1)){"freehand"===game.activeDungeonDrawTool?((e,t)=>{const{destination:i}=t.interactionData,n=i,r=Date.now()-e._drawTime