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:
@@ -19,6 +19,7 @@ export class Command {
|
|||||||
// Testo della riga sotto la scena, con l'eventuale bersaglio sotto il puntatore.
|
// Testo della riga sotto la scena, con l'eventuale bersaglio sotto il puntatore.
|
||||||
sentence(target = null) {
|
sentence(target = null) {
|
||||||
const g = this.game, name = target && g.targetName(target);
|
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.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 (this.verb) return `${VERB_LABELS[this.verb]}${name ? ' ' + name : '…'}`;
|
||||||
if (!target) return '';
|
if (!target) return '';
|
||||||
@@ -48,11 +49,17 @@ export class Command {
|
|||||||
if (g.skip()) return 'skip';
|
if (g.skip()) return 'skip';
|
||||||
if (g.dialogue || g.busy) return null;
|
if (g.dialogue || g.busy) return null;
|
||||||
if (look) { this.reset(); return g.act('look', id) && 'act'; }
|
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) {
|
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();
|
this.reset();
|
||||||
return ok ? 'act' : null;
|
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') {
|
if (!this.verb || this.verb === 'use' || this.verb === 'give') {
|
||||||
this.verb ??= 'use';
|
this.verb ??= 'use';
|
||||||
this.item = id;
|
this.item = id;
|
||||||
|
|||||||
@@ -96,6 +96,7 @@ export const story = {
|
|||||||
name: 'Fanta',
|
name: 'Fanta',
|
||||||
icon: { src: 'assets/icons/fanta.svg' },
|
icon: { src: 'assets/icons/fanta.svg' },
|
||||||
droppable: true,
|
droppable: true,
|
||||||
|
alone: true, // si beve subito, senza chiedere «con cosa»
|
||||||
actions: {
|
actions: {
|
||||||
look: [{ say: 'Una Fanta ghiacciata, arancione come il tramonto.' }],
|
look: [{ say: 'Una Fanta ghiacciata, arancione come il tramonto.' }],
|
||||||
use: [{ drop: 'fanta' }, { say: 'Glu glu... arancione fino alle orecchie.' }],
|
use: [{ drop: 'fanta' }, { say: 'Glu glu... arancione fino alle orecchie.' }],
|
||||||
@@ -105,6 +106,7 @@ export const story = {
|
|||||||
name: 'Coca',
|
name: 'Coca',
|
||||||
icon: { src: 'assets/icons/coca.svg' },
|
icon: { src: 'assets/icons/coca.svg' },
|
||||||
droppable: true,
|
droppable: true,
|
||||||
|
alone: true, // si beve subito, senza chiedere «con cosa»
|
||||||
actions: {
|
actions: {
|
||||||
look: [{ say: 'Una Coca col vetro appannato dal freddo.' }],
|
look: [{ say: 'Una Coca col vetro appannato dal freddo.' }],
|
||||||
use: [{ drop: 'coca' }, { say: 'Fa le bollicine nel naso. Come sempre.' }],
|
use: [{ drop: 'coca' }, { say: 'Fa le bollicine nel naso. Come sempre.' }],
|
||||||
@@ -114,6 +116,7 @@ export const story = {
|
|||||||
name: 'spuma bionda',
|
name: 'spuma bionda',
|
||||||
icon: { src: 'assets/icons/spuma.svg' },
|
icon: { src: 'assets/icons/spuma.svg' },
|
||||||
droppable: true,
|
droppable: true,
|
||||||
|
alone: true, // si beve subito, senza chiedere «con cosa»
|
||||||
actions: {
|
actions: {
|
||||||
look: [{ say: 'Una spuma bionda. Ormai la chiedono solo i nonni. E io.' }],
|
look: [{ say: 'Una spuma bionda. Ormai la chiedono solo i nonni. E io.' }],
|
||||||
use: [{ drop: 'spuma' }, { say: 'Buona come ai tempi della festa.' }],
|
use: [{ drop: 'spuma' }, { say: 'Buona come ai tempi della festa.' }],
|
||||||
|
|||||||
@@ -64,3 +64,19 @@ test('oggetto dell\'inventario: usa con, dai a, guarda', () => {
|
|||||||
c.clickItem('squama', { look: true });
|
c.clickItem('squama', { look: true });
|
||||||
assert.match(settle(g)[0].text, /cantina/);
|
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');
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user