From 7ee27c28cda4ef34ff3dd9555058959ca7b74950 Mon Sep 17 00:00:00 2001 From: Andrea Manzi Date: Sat, 24 Oct 2026 00:58:53 +0200 Subject: [PATCH] Le bibite si bevono con un clic; un oggetto cliccato due volte si usa da solo Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_017egeN2amL84ErjfgQFtEDn --- src/engine/command.js | 9 ++++++++- src/story/story.js | 3 +++ tests/command.test.mjs | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/engine/command.js b/src/engine/command.js index b8992af..94a602e 100644 --- a/src/engine/command.js +++ b/src/engine/command.js @@ -19,6 +19,7 @@ export class Command { // Testo della riga sotto la scena, con l'eventuale bersaglio sotto il puntatore. sentence(target = null) { const g = this.game, name = target && g.targetName(target); + if (this.item && target === this.item && this.verb === 'use') return `${VERB_LABELS.use} ${g.itemName(this.item)}`; if (this.item) return `${VERB_LABELS[this.verb]} ${g.itemName(this.item)} ${this.verb === 'give' ? 'a' : 'con'}${name ? ' ' + name : '…'}`; if (this.verb) return `${VERB_LABELS[this.verb]}${name ? ' ' + name : '…'}`; if (!target) return ''; @@ -48,11 +49,17 @@ export class Command { if (g.skip()) return 'skip'; if (g.dialogue || g.busy) return null; if (look) { this.reset(); return g.act('look', id) && 'act'; } + // Di nuovo sullo stesso oggetto: lo si usa da solo (bere la Coca, mangiare il ghiacciolo). if (this.item) { - const ok = this.item !== id && g.act('use', id, this.item); + const ok = this.item === id ? this.verb === 'use' && g.act('use', id) : g.act('use', id, this.item); this.reset(); return ok ? 'act' : null; } + // Gli oggetti che si usano solo da soli (`alone`, le bibite) non chiedono «con cosa». + if ((!this.verb || this.verb === 'use') && g.story.items[id]?.alone) { + this.reset(); + return g.act('use', id) && 'act'; + } if (!this.verb || this.verb === 'use' || this.verb === 'give') { this.verb ??= 'use'; this.item = id; diff --git a/src/story/story.js b/src/story/story.js index f6f2b07..6c507e5 100644 --- a/src/story/story.js +++ b/src/story/story.js @@ -96,6 +96,7 @@ export const story = { name: 'Fanta', icon: { src: 'assets/icons/fanta.svg' }, droppable: true, + alone: true, // si beve subito, senza chiedere «con cosa» actions: { look: [{ say: 'Una Fanta ghiacciata, arancione come il tramonto.' }], use: [{ drop: 'fanta' }, { say: 'Glu glu... arancione fino alle orecchie.' }], @@ -105,6 +106,7 @@ export const story = { name: 'Coca', icon: { src: 'assets/icons/coca.svg' }, droppable: true, + alone: true, // si beve subito, senza chiedere «con cosa» actions: { look: [{ say: 'Una Coca col vetro appannato dal freddo.' }], use: [{ drop: 'coca' }, { say: 'Fa le bollicine nel naso. Come sempre.' }], @@ -114,6 +116,7 @@ export const story = { name: 'spuma bionda', icon: { src: 'assets/icons/spuma.svg' }, droppable: true, + alone: true, // si beve subito, senza chiedere «con cosa» actions: { look: [{ say: 'Una spuma bionda. Ormai la chiedono solo i nonni. E io.' }], use: [{ drop: 'spuma' }, { say: 'Buona come ai tempi della festa.' }], diff --git a/tests/command.test.mjs b/tests/command.test.mjs index db1c9eb..afc9d5f 100644 --- a/tests/command.test.mjs +++ b/tests/command.test.mjs @@ -64,3 +64,19 @@ test('oggetto dell\'inventario: usa con, dai a, guarda', () => { c.clickItem('squama', { look: true }); assert.match(settle(g)[0].text, /cantina/); }); + +test('un oggetto si usa da solo: cliccandolo due volte, o subito se è una bibita', () => { + const g = new Game(story); + g.go('tennis_chiesa'); + settle(g); + g.state.inventory.push('coca', 'ghiacciolo'); + const c = new Command(g); + assert.equal(c.clickItem('coca'), 'act', 'la Coca si beve al primo clic'); + settle(g); + assert.ok(!g.state.inventory.includes('coca')); + assert.equal(c.clickItem('ghiacciolo'), 'select'); + assert.equal(c.sentence('ghiacciolo'), 'Usa ghiacciolo', 'di nuovo sullo stesso oggetto: usalo da solo'); + assert.equal(c.clickItem('ghiacciolo'), 'act'); + const said = settle(g).map(s => s.text); + assert.ok(said.some(t => t.includes('cedrata')), 'il ghiacciolo da solo dice che vuole la cedrata'); +});