70 lines
2.1 KiB
JavaScript
70 lines
2.1 KiB
JavaScript
// FARMING CONTROLS - Add to Player.js
|
|
|
|
// In handleAction() method, add this code:
|
|
|
|
handleFarmingAction() {
|
|
if (!this.scene.farmingSystem) return;
|
|
|
|
const selectedSlot = this.scene.scene.get('UIScene').selectedSlot;
|
|
const inventory = this.scene.inventorySystem;
|
|
const item = inventory ? inventory.slots[selectedSlot] : null;
|
|
const itemType = item ? item.type : null;
|
|
|
|
// Get grid position player is facing
|
|
const facingX = this.gridX;
|
|
const facingY = this.gridY;
|
|
|
|
// Adjust based on direction (optional - or use mouse click position)
|
|
// For now, use tile player is standing on
|
|
|
|
// HOE - Till soil
|
|
if (itemType === 'hoe') {
|
|
const success = this.scene.farmingSystem.tillSoil(facingX, facingY);
|
|
if (success) {
|
|
// Play sound/animation
|
|
if (this.scene.soundManager) this.scene.soundManager.playDig();
|
|
}
|
|
return;
|
|
}
|
|
|
|
// SEEDS - Plant
|
|
if (itemType === 'carrot' || itemType === 'wheat') {
|
|
const success = this.scene.farmingSystem.plantSeed(facingX, facingY, itemType);
|
|
if (success) {
|
|
// Consume seed
|
|
inventory.removeItem(itemType, 1);
|
|
if (this.scene.soundManager) this.scene.soundManager.playPlant();
|
|
}
|
|
return;
|
|
}
|
|
|
|
// EMPTY HAND - Harvest
|
|
if (!itemType) {
|
|
const success = this.scene.farmingSystem.harvestCrop(facingX, facingY);
|
|
if (success) {
|
|
if (this.scene.soundManager) this.scene.soundManager.playHarvest();
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
|
|
// In Player update(), listen for SPACE or MOUSE CLICK:
|
|
// Add to existing input handling:
|
|
|
|
/*
|
|
if (this.scene.input.keyboard.checkDown(this.scene.input.keyboard.addKey('SPACE'), 300)) {
|
|
this.handleFarmingAction();
|
|
}
|
|
*/
|
|
|
|
// OR use mouse click on tile:
|
|
/*
|
|
this.scene.input.on('pointerdown', (pointer) => {
|
|
const worldPoint = this.scene.cameras.main.getWorldPoint(pointer.x, pointer.y);
|
|
const gridPos = this.scene.iso.toGrid(worldPoint.x, worldPoint.y);
|
|
|
|
// Farming action at clicked tile
|
|
this.farmAtTile(gridPos.x, gridPos.y);
|
|
});
|
|
*/
|