feat: add poc
This commit is contained in:
parent
43d27b04d9
commit
4a4fa05ce4
53 changed files with 6191 additions and 0 deletions
71
src/components/Inventory.js
Normal file
71
src/components/Inventory.js
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
import { Component } from '../core/Component.js';
|
||||
|
||||
export class Inventory extends Component {
|
||||
constructor() {
|
||||
super('Inventory');
|
||||
this.items = []; // Array of item objects
|
||||
this.maxSize = 20;
|
||||
this.equipped = {
|
||||
weapon: null,
|
||||
armor: null,
|
||||
accessory: null
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an item to inventory
|
||||
*/
|
||||
addItem(item) {
|
||||
if (this.items.length < this.maxSize) {
|
||||
this.items.push(item);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an item
|
||||
*/
|
||||
removeItem(itemId) {
|
||||
const index = this.items.findIndex(item => item.id === itemId);
|
||||
if (index > -1) {
|
||||
return this.items.splice(index, 1)[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Equip an item
|
||||
*/
|
||||
equipItem(itemId, slot) {
|
||||
const item = this.items.find(i => i.id === itemId);
|
||||
if (!item) return false;
|
||||
|
||||
// Unequip current item in slot
|
||||
if (this.equipped[slot]) {
|
||||
this.items.push(this.equipped[slot]);
|
||||
}
|
||||
|
||||
// Equip new item
|
||||
this.equipped[slot] = item;
|
||||
const index = this.items.indexOf(item);
|
||||
if (index > -1) {
|
||||
this.items.splice(index, 1);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unequip an item
|
||||
*/
|
||||
unequipItem(slot) {
|
||||
if (this.equipped[slot]) {
|
||||
this.items.push(this.equipped[slot]);
|
||||
this.equipped[slot] = null;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue