Le bibite si bevono con un clic; un oggetto cliccato due volte si usa da solo

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017egeN2amL84ErjfgQFtEDn
This commit is contained in:
2026-10-24 00:58:53 +02:00
co-authored by Claude Opus 5.5
parent 2d32e552f8
commit 7ee27c28cd
3 changed files with 27 additions and 1 deletions
+8 -1
View File
@@ -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;
+3
View File
@@ -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.' }],
+16
View File
@@ -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');
});