@@ -1,10 +1,11 @@
|
||||
import { forceShow } from '../utils';
|
||||
import { structureCollection } from './Structure/StructureCollection';
|
||||
import { instanceCollection } from './Instance/InstanceCollection';
|
||||
import { MenuFormBuilder } from './MenuFormBuilder';
|
||||
import { InstanceForm } from './Instance/InstanceForm';
|
||||
import { BuilderForm } from './Builder/BuilderForm';
|
||||
import { InstanceExistsError } from './Errors/InstanceExistsError';
|
||||
import { StructureNotFoundError } from './Errors/StructureNotFoundError';
|
||||
import { getDefaultRenderMode } from '../options/defaultRenderMode';
|
||||
|
||||
export class MenuForm {
|
||||
constructor(player, { jumpToInstance = false, instanceName = void 0 } = {}) {
|
||||
@@ -15,7 +16,7 @@ export class MenuForm {
|
||||
async show(jumpToInstance = false, instanceName = void 0) {
|
||||
if (jumpToInstance) {
|
||||
if (!instanceName)
|
||||
instanceName = structureCollection.getStructure(this.player.dimension.id, this.player.location, { useActiveLayer: false })?.getName();
|
||||
instanceName = instanceCollection.getInstanceAt(this.player.dimension.id, this.player.location, { useActiveLayer: false })?.getName();
|
||||
if (instanceName) {
|
||||
new InstanceForm(this.player, instanceName);
|
||||
return;
|
||||
@@ -29,19 +30,20 @@ export class MenuForm {
|
||||
|
||||
async getInstanceNameFromForm() {
|
||||
try {
|
||||
return forceShow(this.player, MenuFormBuilder.buildAllInstanceName()).then((response) => {
|
||||
const instanceNames = instanceCollection.getInstanceNamesSortedByEnabled();
|
||||
return forceShow(this.player, MenuFormBuilder.buildAllInstanceName(instanceNames)).then((response) => {
|
||||
if (response.canceled)
|
||||
return void 0;
|
||||
let selection = response.selection;
|
||||
if (selection === 0) {
|
||||
new BuilderForm(this.player);
|
||||
return void 0;
|
||||
} else if (selection == structureCollection.getInstanceNames().length + 2) {
|
||||
} else if (selection == instanceNames.length + 2) {
|
||||
MenuFormBuilder.buildHowTo().show(this.player);
|
||||
return void 0;
|
||||
} else {
|
||||
selection--;
|
||||
const selectedInstanceName = structureCollection.getInstanceNames()[selection];
|
||||
const selectedInstanceName = instanceNames[selection];
|
||||
return selectedInstanceName || this.createNewInstance();
|
||||
}
|
||||
});
|
||||
@@ -65,7 +67,7 @@ export class MenuForm {
|
||||
if (!structureId)
|
||||
return void 0;
|
||||
try {
|
||||
structureCollection.add(instanceName, structureId);
|
||||
instanceCollection.add(instanceName, structureId, { renderMode: getDefaultRenderMode(this.player.id) });
|
||||
} catch (error) {
|
||||
if (error instanceof InstanceExistsError || error instanceof StructureNotFoundError) {
|
||||
error.sendTo(this.player);
|
||||
@@ -81,7 +83,9 @@ export class MenuForm {
|
||||
return MenuFormBuilder.buildAllStructures().show(this.player).then((response) => {
|
||||
if (response.canceled)
|
||||
return void 0;
|
||||
const selectedStructureId = structureCollection.getWorldStructureIds()[response.selection];
|
||||
const worldStructureIds = instanceCollection.getWorldStructureIds();
|
||||
worldStructureIds.sort((a, b) => a.localeCompare(b));
|
||||
const selectedStructureId = worldStructureIds[response.selection];
|
||||
return selectedStructureId || this.getOtherStructureId();
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user