4 changed files with 123 additions and 3 deletions
@ -0,0 +1,68 @@ |
|||
import type Viewport from '@/core/engine/Viewport.ts' |
|||
|
|||
/** |
|||
* 运行时管理器, 管理运行时的各种数据 |
|||
*/ |
|||
export default class RuntimeManager { |
|||
private viewport: Viewport |
|||
private readonly storeRackMap = new Map<string, Set<string>>() |
|||
|
|||
init(viewport: Viewport): void { |
|||
this.viewport = viewport |
|||
} |
|||
|
|||
/** |
|||
* 在指定的货架位置添加存储项 |
|||
* @param rackId 货架ID |
|||
* @param itemId 存储项ID |
|||
*/ |
|||
addStoreAt(rackId: string, itemId: string): void { |
|||
if (!this.storeRackMap.has(rackId)) { |
|||
this.storeRackMap.set(rackId, new Set()) |
|||
} |
|||
this.storeRackMap.get(rackId).add(itemId) |
|||
} |
|||
|
|||
/** |
|||
* 从指定的货架位置移除存储项 |
|||
* @param rackId 货架ID |
|||
* @param itemId 存储项ID |
|||
*/ |
|||
removeStoreAt(rackId: string, itemId: string): void { |
|||
const rack = this.storeRackMap.get(rackId) |
|||
if (rack) { |
|||
rack.delete(itemId) |
|||
if (rack.size === 0) { |
|||
this.storeRackMap.delete(rackId) |
|||
} |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 获取指定货架位置的所有存储项 |
|||
* @param rackId 货架ID |
|||
*/ |
|||
getItemsByRack(rackId: string): Set<string> | undefined { |
|||
return this.storeRackMap.get(rackId) |
|||
} |
|||
|
|||
/** |
|||
* 移除指定货架 |
|||
* @param rackId 货架ID |
|||
*/ |
|||
removeRack(rackId: string): void { |
|||
this.storeRackMap.delete(rackId) |
|||
} |
|||
|
|||
/** |
|||
* 清空所有存储项 |
|||
*/ |
|||
clear() { |
|||
this.storeRackMap.clear() |
|||
} |
|||
|
|||
dispose(): void { |
|||
this.viewport = null |
|||
this.storeRackMap.clear() |
|||
} |
|||
} |
|||
Loading…
Reference in new issue