feat(control): трекер инициативы в отдельном окне

Очередь NPC/игроков с DnD, курсором на сцене, состояниями и запасом; сброс при смене сцены.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Ivan Fontosh
2026-09-04 10:09:51 +08:00
parent db1168a46c
commit 86d6d157f0
28 changed files with 1783 additions and 4 deletions
@@ -60,6 +60,14 @@ void test('createWindows: окно таймера закрывается с mult
assert.match(src, /closePlaySessionAuxiliaryWindows[\s\S]*closeTimerWindow/);
});
void test('createWindows: окно инициативы закрывается с multi-window', () => {
const src = readCreateWindows();
assert.ok(src.includes('openInitiativeWindow'));
assert.ok(src.includes('closeInitiativeWindow'));
assert.ok(src.includes("createWindow('initiative'"));
assert.match(src, /closePlaySessionAuxiliaryWindows[\s\S]*closeInitiativeWindow/);
});
void test('createWindows: окно НПС закрывается с multi-window', () => {
const src = readCreateWindows();
assert.ok(src.includes('openNpcsWindow'));
+51
View File
@@ -22,6 +22,7 @@ export type WindowKind =
| 'materials'
| 'playlists'
| 'timer'
| 'initiative'
| 'npcsEditor'
| 'sceneEditor'
| 'tokenPathEditor'
@@ -64,6 +65,10 @@ const PLAYLISTS_WINDOW_HEIGHT = 800;
const TIMER_WINDOW_WIDTH = 360;
const TIMER_WINDOW_HEIGHT = 420;
/** Окно трекера инициативы. */
const INITIATIVE_WINDOW_WIDTH = 920;
const INITIATIVE_WINDOW_HEIGHT = 420;
/** Редактор НПС — как основной редактор, шире инспектор. */
const NPCS_EDITOR_WINDOW_WIDTH = 1400;
const NPCS_EDITOR_WINDOW_HEIGHT = 860;
@@ -175,6 +180,7 @@ function closePlaySessionAuxiliaryWindows(): void {
closeMaterialsWindow();
closePlaylistsWindow();
closeTimerWindow();
closeInitiativeWindow();
closeNpcsWindow();
}
@@ -227,6 +233,8 @@ function pageNameForKind(kind: WindowKind): string {
return 'playlists.html';
case 'timer':
return 'timer.html';
case 'initiative':
return 'initiative.html';
case 'npcsEditor':
return 'npcsEditor.html';
case 'sceneEditor':
@@ -304,6 +312,7 @@ function windowSizeForKind(kind: WindowKind): { width: number; height: number }
if (kind === 'materials') return { width: MATERIALS_WINDOW_WIDTH, height: MATERIALS_WINDOW_HEIGHT };
if (kind === 'playlists') return { width: PLAYLISTS_WINDOW_WIDTH, height: PLAYLISTS_WINDOW_HEIGHT };
if (kind === 'timer') return { width: TIMER_WINDOW_WIDTH, height: TIMER_WINDOW_HEIGHT };
if (kind === 'initiative') return { width: INITIATIVE_WINDOW_WIDTH, height: INITIATIVE_WINDOW_HEIGHT };
if (kind === 'npcsEditor') return { width: NPCS_EDITOR_WINDOW_WIDTH, height: NPCS_EDITOR_WINDOW_HEIGHT };
if (kind === 'sceneEditor') return { width: 1280, height: 800 };
if (kind === 'tokenPathEditor') return { width: 1100, height: 760 };
@@ -620,6 +629,13 @@ export function closeTimerWindow(): void {
}
}
export function closeInitiativeWindow(): void {
const win = windows.get('initiative');
if (win && !win.isDestroyed()) {
win.close();
}
}
export function closeNpcsEditorWindow(): void {
const win = windows.get('npcsEditor');
if (win && !win.isDestroyed()) {
@@ -839,6 +855,41 @@ export function openTimerWindow(): void {
});
}
export function openInitiativeWindow(opts?: { onClosed?: () => void }): void {
const existing = windows.get('initiative');
if (existing && !existing.isDestroyed()) {
if (existing.isMinimized()) existing.restore();
existing.show();
existing.focus();
existing.moveTop();
return;
}
const parent = windows.get('control') ?? windows.get('presentation');
const win = createWindow('initiative', parent ? { parent } : undefined);
if (opts?.onClosed) {
win.once('closed', () => {
opts.onClosed?.();
});
}
const { width, height } = win.getBounds();
const display = screen.getDisplayMatching(parent?.getBounds() ?? win.getBounds());
const { x, y, width: dw, height: dh } = display.workArea;
win.setBounds({
x: Math.round(x + Math.max(0, (dw - width) / 2)),
y: Math.round(y + Math.max(0, (dh - height) / 2)),
width,
height,
});
win.webContents.once('did-finish-load', () => {
if (!win.isDestroyed()) {
win.show();
win.focus();
win.moveTop();
}
});
}
function positionNpcsEditorWindow(win: BrowserWindow): void {
const parent = windows.get('editor');
const { width, height } = win.getBounds();