fix(scenes) 种田系统测试,添加按钮等

This commit is contained in:
wvellichor committed 2026-01-10 05:31:51 +08:00
1 parent ce4e04740a
commit 761a9338ba
19 files changed
+1248 -86

No files matched your search

+17 -11
View File
@@ -150,13 +150,21 @@ export default class Item extends Phaser.GameObjects.Sprite {
* @param {Object} user - 使用物品的单位
*/
useFromInventory(user) {
// 从用户对象中获取场景引用
if (user && user.scene) {
this.scene = user.scene;
}
// 使用物品
this.use(user);
// 从背包中移除物品
if (user.inventory) {
user.inventory.removeItem(this.id);
}
// 注意:物品的具体使用方法(如useSeed)中已经处理了从背包移除的逻辑
}
/**
* 设置物品的场景引用
* @param {Object} scene - 场景对象
*/
setScene(scene) {
this.scene = scene;
}
/**
@@ -210,16 +218,14 @@ export default class Item extends Phaser.GameObjects.Sprite {
console.log('DEBUG: 触发 plant-seed 事件');
this.scene.events.emit('plant-seed', this, user);
// 从背包中移除种子
if (user.inventory) {
console.log(`DEBUG: 从背包中移除种子 ${this.id}`);
user.inventory.removeItem(this.id);
}
// 注意:不立即从背包中移除种子,而是在实际种植时移除
// 这样用户可以取消种植而不会失去种子
// 显示种植提示
this.scene.events.emit('show-message', `准备种植 ${this.name}`);
} else {
console.log('DEBUG: 种子不可种植');
console.log(`DEBUG: ${this.name} 不可种植`);
this.scene.events.emit('show-message', `${this.name} 不可种植`);
}
}