import { playSfx } from '../data/sfxSpecs';
import { MenuSceneBase, Panel, PixelText } from '@rpg/engine';
import { Game } from '../Game';
import { inventoryItems, questLog } from '../data/quests';
/**
* Сумка и журнал квестов (панель поверх локации, push/pop).
* Содержимое собирается из флагов/варов GameState при каждом открытии.
* Список-просмотр без курсора: закрытие — Esc/инвентарь (через каркас).
*/
export class InventoryScene extends MenuSceneBase {
constructor(
private game: Game,
private onBack: () => void
) {
super(
{ input: game.engine.input, inputBlocked: () => game.scenes.transitioning },
{ up: 'up', down: 'down', confirm: 'advance', cancel: 'menu', extra: ['inventory'] }
);
}
protected build(): void {
const panel = new Panel({ width: 280, height: 180 });
panel.position.set((Game.VIRTUAL_W - 280) / 2, (Game.VIRTUAL_H - 180) / 2);
const title = new PixelText({ text: 'ЗВОНАРЬ', size: 14, color: 0xd8c79a });
title.anchor.set(0.5);
title.position.set(140, 16);
panel.addChild(title);
const addLine = (text: string, color: number, x: number, y: number): void => {
const t = new PixelText({ text, size: 10, color });
t.position.set(x, y);
panel.addChild(t);
};
// Инвентарь
addLine('Сумка', 0x999988, 16, 36);
let y = 50;
for (const item of inventoryItems(this.game.inventory)) {
addLine(item, 0xd8c79a, 24, y);
y += 13;
}
// Журнал квестов
addLine('Журнал', 0x999988, 16, y + 6);
y += 21;
for (const entry of questLog(this.game.state)) {
const mark = entry.done ? 'x' : '·';
addLine(`[${mark}] ${entry.text}`, entry.done ? 0xd8c79a : 0xaaaaaa, 24, y);
y += 13;
}
const hint = new PixelText({ text: 'Esc — назад', size: 9, color: 0x777788 });
hint.anchor.set(0.5);
hint.position.set(140, 168);
panel.addChild(hint);
this.view.addChild(panel);
this.game.renderer.uiRoot.addChild(this.view);
}
/** Esc или клавиша инвентаря — назад в локацию. */
protected onCancel(): void {
this.close();
}
protected onAction(action: string): void {
if (action === 'inventory') this.close();
}
private close(): void {
playSfx(this.game.audio, 'sfx/ui_click');
this.onBack();
}
}