Files
novafarma/old_logic/src_backup_1768938138/managers/ItemManager.js
2026-01-21 01:08:21 +01:00

39 lines
1.5 KiB
JavaScript

export class ItemManager {
constructor(scene) {
this.scene = scene;
this.basePath = 'assets/slike/items/';
this.blueprintPath = 'assets/slike/items/blueprints/';
}
/**
* Get the correct image path for an item based on the context.
* @param {string} itemPath - Relative path to the item (e.g., 'tools/axe.png')
* @param {boolean} isBuildingMode - If true, returns the ghost/blueprint version.
* @returns {string} Full path to the image.
*/
getItemImagePath(itemPath, isBuildingMode = false) {
// Remove 'assets/slike/items/' prefix if present to standardize input
let cleanPath = itemPath.replace(this.basePath, '');
if (isBuildingMode) {
// Return blueprint version: assets/slike/items/blueprints/tools/axe.png
return `${this.blueprintPath}${cleanPath}`;
} else {
// Return normal version: assets/slike/items/tools/axe.png
return `${this.basePath}${cleanPath}`;
}
}
/**
* Loads an item image into Phaser.
* @param {string} key - The cache key for the image.
* @param {string} itemPath - Relative path (e.g. 'tools/axe.png').
*/
loadItem(key, itemPath) {
// Load normal version
this.scene.load.image(key, this.getItemImagePath(itemPath, false));
// Load blueprint version automatically with _blueprint suffix
this.scene.load.image(`${key}_blueprint`, this.getItemImagePath(itemPath, true));
}
}