UNPKG

@minecraft/creator-tools

Version:

Minecraft Creator Tools command line and libraries.

157 lines (156 loc) 5.78 kB
"use strict"; // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const CreatorTools_1 = require("./CreatorTools"); const IMinecraft_1 = require("./IMinecraft"); const AppServiceProxy_1 = __importDefault(require("../core/AppServiceProxy")); const ste_events_1 = require("ste-events"); const Utilities_1 = __importDefault(require("../core/Utilities")); const GameStateManager_1 = __importDefault(require("../minecraft/GameStateManager")); const Log_1 = __importDefault(require("../core/Log")); const ICreatorToolsData_1 = require("./ICreatorToolsData"); const ProjectExporter_1 = __importDefault(require("./ProjectExporter")); class DeploymentStorageMinecraft { _creatorTools; state; _onStateChanged = new ste_events_1.EventDispatcher(); _onRefreshed = new ste_events_1.EventDispatcher(); _project; _gameStateManager; errorStatus; errorMessage; worldFolder; projectFolder; worldContentStorage; worldProject; _onWorldFolderReady = new ste_events_1.EventDispatcher(); _onProjectFolderReady = new ste_events_1.EventDispatcher(); _onMessage = new ste_events_1.EventDispatcher(); get onWorldFolderReady() { return this._onWorldFolderReady.asEvent(); } get onProjectFolderReady() { return this._onProjectFolderReady.asEvent(); } get onMessage() { return this._onMessage.asEvent(); } get canDeployFiles() { return true; } get onRefreshed() { return this._onRefreshed.asEvent(); } get onStateChanged() { return this._onStateChanged.asEvent(); } constructor(creatorTools) { this._creatorTools = creatorTools; this._gameStateManager = new GameStateManager_1.default(this._creatorTools); this.state = CreatorTools_1.CreatorToolsMinecraftState.none; } async updateStatus() { return this.state; } get activeProject() { return this._project; } set activeProject(newProject) { this._project = newProject; } get gameStateManager() { return this._gameStateManager; } notifyStateChanged(newVal) { this.state = newVal; this._onStateChanged.dispatch(this, newVal); } async initialize() { await this.start(); } async prepare(force) { return; } async runCommand(command) { return undefined; } async runActionSet(actionSet) { return undefined; } processExternalMessage(command, data) { } async pushWorld() { if (!this._creatorTools || this._creatorTools.deploymentStorage === null || !this._project) { return; } const worldFolderName = this._project.deployWorldId; const worldDisplayName = this._project.name + " _mct"; const worldsFolder = await ProjectExporter_1.default.ensureMinecraftWorldsFolder(this._creatorTools); if (!worldsFolder) { Log_1.default.debug("Could not find a Minecraft world."); return; } const worldFolder = worldsFolder.ensureFolder(worldFolderName); await worldFolder.ensureExists(); await ProjectExporter_1.default.syncFlatPackRefWorldTo(this._creatorTools, this._project, worldFolder, worldDisplayName); await worldFolder.saveAll(); await this._project.save(); return worldDisplayName; } async syncWithDeployment() { const deploymentTarget = this._creatorTools.defaultDeploymentTarget; if (deploymentTarget === undefined || deploymentTarget.storage == null || deploymentTarget.deployBehaviorPacksFolder == null || this._creatorTools.minecraftGameMode === ICreatorToolsData_1.MinecraftGameConnectionMode.remoteMinecraft) { throw new Error("This instance doesn't support deployment"); } if (!this._project) { return; } let isAvailable = deploymentTarget.storage.available; if (isAvailable === undefined) { isAvailable = await deploymentTarget.storage.getAvailable(); } if (!isAvailable) { return; } const deployFolderExists = await deploymentTarget.deployBehaviorPacksFolder.exists(); if (deployFolderExists) { await ProjectExporter_1.default.deployProject(this._creatorTools, this._project, deploymentTarget.storage.rootFolder); } } canPrepare() { return true; } async prepareAndStart(push) { let worldName = undefined; if (push.project) { this._project = push.project; await this.syncWithDeployment(); } if (push.worldType) { worldName = await this.pushWorld(); } await this.start(); return { type: IMinecraft_1.PrepareAndStartResultType.started, worldName: worldName, }; } async stop() { } async start() { if (!AppServiceProxy_1.default.hasAppService && Utilities_1.default.isDebug) { this.notifyStateChanged(CreatorTools_1.CreatorToolsMinecraftState.stopped); } else if (this.state === CreatorTools_1.CreatorToolsMinecraftState.none || this.state === CreatorTools_1.CreatorToolsMinecraftState.error || this.state === CreatorTools_1.CreatorToolsMinecraftState.disconnected) { this.notifyStateChanged(CreatorTools_1.CreatorToolsMinecraftState.initializing); } } } exports.default = DeploymentStorageMinecraft;