UNPKG

@minecraft/creator-tools

Version:

Minecraft Creator Tools command line and libraries.

183 lines (182 loc) 5.36 kB
/** * ARCHITECTURE DOCUMENTATION: ManagedWorld - World Entity * ======================================================== * * ManagedWorld represents a Minecraft world that is tracked by the backup system. * Each world has a unique 8-character ID and can have multiple backups. * * ## Lifecycle * * 1. Create: `ManagedWorld.create(friendlyName)` generates a new ID * 2. Load: `ManagedWorld.load(folder)` loads from existing world.json * 3. Backup: `world.createBackup(sourcePath, options)` creates a new backup * 4. Restore: `world.restoreBackup(backupId, targetPath)` restores a backup * 5. Export: `world.exportMcWorld(backupId, outputPath)` creates .mcworld file * * ## Storage * * Each ManagedWorld has a folder at: worlds/{worldId}/ * - world.json: World metadata (IManagedWorldData) * - world{timestamp}/: Backup folders * * ## Related Files * * - IWorldBackupData.ts: Data interfaces * - WorldBackup.ts: Individual backup class * - WorldBackupManager.ts: Central management service */ import IFolder from "../storage/IFolder"; import { IManagedWorldData, IWorldSummary } from "./IWorldBackupData"; import WorldBackup from "./WorldBackup"; export default class ManagedWorld { private _data; private _folder; private _backups; private _backupsLoaded; /** * Get the unique world ID. */ get id(): string; /** * Alias for id (for consistency with some API usage). */ get worldId(): string; /** * Get the user-visible friendly name. */ get friendlyName(): string; /** * Set the user-visible friendly name. */ set friendlyName(value: string); /** * Get the description. */ get description(): string | undefined; /** * Set the description. */ set description(value: string | undefined); /** * Get the creation timestamp. */ get createdAt(): Date; /** * Get the last modified timestamp. */ get lastModified(): Date; /** * Get the initial configuration hash. */ get initialConfigurationHash(): string | undefined; /** * Set the initial configuration hash. */ set initialConfigurationHash(value: string | undefined); /** * Get optional notes. */ get notes(): string | undefined; /** * Set optional notes. */ set notes(value: string | undefined); /** * Get tags for organization. */ get tags(): string[]; /** * Set tags for organization. */ set tags(value: string[]); /** * Get the folder containing this world's data. */ get folder(): IFolder; /** * Get the raw data object. */ get data(): IManagedWorldData; /** * Get the list of backups (must call loadBackups first). */ get backups(): WorldBackup[]; /** * Private constructor - use static factory methods. */ private constructor(); /** * Generate a random 8-character world ID. */ static generateId(): string; /** * Validate a world ID format. */ static isValidId(id: string): boolean; /** * Create a new managed world. * * @param friendlyName User-visible name for the world * @param parentFolder The worlds container folder * @param configurationHash Optional initial configuration hash * @returns The newly created ManagedWorld */ static create(friendlyName: string, parentFolder: IFolder, configurationHash?: string): Promise<ManagedWorld>; /** * Load an existing managed world from a folder. * * @param folder The world folder (e.g., worlds/a3k9m2p1/) * @returns The loaded ManagedWorld, or undefined if invalid */ static load(folder: IFolder): Promise<ManagedWorld | undefined>; /** * Save the world metadata to world.json. */ save(): Promise<void>; /** * Load all backups for this world. */ loadBackups(): Promise<WorldBackup[]>; /** * Get the latest backup for this world. */ getLatestBackup(): Promise<WorldBackup | undefined>; /** * Get a specific backup by ID. */ getBackup(backupId: string): Promise<WorldBackup | undefined>; /** * Get summary info for the manifest. */ getSummary(): IWorldSummary; /** * Delete a backup. * * @param backupId The backup ID to delete * @returns True if deleted, false if not found */ deleteBackup(backupId: string): Promise<boolean>; /** * Prune old backups, keeping only the specified count. * Before deleting, consolidates any remaining backups that depend on files * in the backups being deleted. * * @param keepCount Number of backups to keep * @returns Number of backups deleted */ pruneBackups(keepCount: number): Promise<number>; /** * Delete this world and all its backups. */ delete(): Promise<boolean>; /** * Register a new backup folder (called by WorldBackupManager). * Note: This invalidates the backup cache so the next loadBackups() reloads from disk * to ensure the in-memory folder structure is synchronized. */ registerBackup(backup: WorldBackup): void; /** * Invalidate the backup cache to force reload. */ invalidateBackupCache(): void; }