Skip to content
Snippets Groups Projects
Commit 24e68345 authored by echicken's avatar echicken :chicken:
Browse files

Reorg

parent 36bd5ea0
No related branches found
No related tags found
No related merge requests found
import type { ICgaDefs, IKeyDefs, ISbbsDefs } from '@swag/ts4s'; import type { ICgaDefs, ISbbsDefs } from '@swag/ts4s';
import { load } from '@swag/ts4s'; import { load } from '@swag/ts4s';
import * as swindows from 'swindows'; import * as swindows from 'swindows';
import { IShellWindow } from './lib/types'; import UI from './lib/UI';
import ActivityWindow from './lib/ActivityWindow';
import MenuWindow from './lib/MenuWindow';
const sbbsdefs: ISbbsDefs = load('sbbsdefs.js'); const sbbsdefs: ISbbsDefs = load('sbbsdefs.js');
const cgadefs: ICgaDefs = load('cga_defs.js'); const cgadefs: ICgaDefs = load('cga_defs.js');
const keydefs: IKeyDefs = load('key_defs.js');
const { bbs, console, mswait } = js.global; const { bbs, console, mswait } = js.global;
const windowManager = new swindows.WindowManager(); const windowManager = new swindows.WindowManager();
const windows: IShellWindow[] = [ const ui = new UI(windowManager);
new ActivityWindow(
'Activity',
windowManager,
{ x: 0,
y: 0
},
{ width: windowManager.size.width,
height: Math.ceil(windowManager.size.height / 2)
},
),
new MenuWindow(
'Main',
`${js.exec_dir}main.ini`,
windowManager,
{ x: 0,
y: Math.floor(windowManager.size.height / 2)
},
{ width: Math.floor(windowManager.size.width / 3),
height: Math.floor(windowManager.size.height / 2)
}
),
new MenuWindow(
'Messages',
`${js.exec_dir}messages.ini`,
windowManager,
{ x: Math.floor(windowManager.size.width / 3),
y: Math.floor(windowManager.size.height / 2),
},
{ width: windowManager.size.width - (Math.floor(windowManager.size.width / 3) * 2),
height: Math.floor(windowManager.size.height / 2),
}
),
new MenuWindow(
'Games',
`${js.exec_dir}games.ini`,
windowManager,
{ x: Math.floor(windowManager.size.width / 3) + (windowManager.size.width - (Math.floor(windowManager.size.width / 3) * 2)),
y: Math.floor(windowManager.size.height / 2)
},
{ width: Math.floor(windowManager.size.width / 3),
height: Math.floor(windowManager.size.height / 2),
}
),
];
let activeWindow: number = 1;
function cycleWindows(): void {
for (const window of windows) {
window.cycle();
}
}
function focusWindow(idx: number): void {
if (idx < 0) idx = windows.length - 1;
idx = idx % windows.length;
windows[activeWindow].window.title = {
text: windows[activeWindow].window.title?.text ?? '',
attr: (cgadefs.BG_BLACK|cgadefs.WHITE) as swindows.types.attr,
alignment: swindows.defs.ALIGNMENT.LEFT,
};
windows[idx].window.title = {
text: windows[idx].window.title?.text ?? '',
attr: (cgadefs.BG_CYAN|cgadefs.LIGHTCYAN) as swindows.types.attr,
alignment: swindows.defs.ALIGNMENT.LEFT,
};
activeWindow = idx;
}
function getInput(): void {
let input = console.inkey(sbbsdefs.K_NONE);
if (input === '') return;
if (input === 'q') js.global.exit(0);
switch (input) {
case '\t':
case keydefs.KEY_RIGHT:
focusWindow(activeWindow + 1);
break;
case keydefs.KEY_LEFT:
focusWindow(activeWindow - 1);
break;
default:
windows[activeWindow].getCmd(input);
break;
}
}
function init(): void { function init(): void {
js.on_exit(`bbs.sys_status = ${bbs.sys_status};`); js.on_exit(`bbs.sys_status = ${bbs.sys_status};`);
js.on_exit(`console.attributes = ${console.attributes};`); js.on_exit(`console.attributes = ${console.attributes};`);
js.on_exit(`console.ctrlkey_passthru = ${console.ctrlkey_passthru};`); js.on_exit(`console.ctrlkey_passthru = ${console.ctrlkey_passthru};`);
js.on_exit(`windowManager.showCursor();`); js.on_exit(`windowManager.showCursor();`);
js.on_exit(`console.clear();`); js.on_exit('console.home();');
js.on_exit('console.write("\x1B[0;37;40m")');
js.on_exit('console.write("\x1B[2J")');
js.time_limit = 0; js.time_limit = 0;
bbs.sys_status |= sbbsdefs.SS_MOFF; bbs.sys_status |= sbbsdefs.SS_MOFF;
console.ctrlkey_passthru = "+UPKTG"; console.ctrlkey_passthru = "+UPKTG";
console.clear(cgadefs.BG_BLACK|cgadefs.LIGHTGRAY); console.clear(cgadefs.BG_BLACK|cgadefs.LIGHTGRAY);
windowManager.hideCursor(); windowManager.hideCursor();
focusWindow(1);
} }
function main(): void { function main(): void {
while (!js.terminated) { while (!js.terminated) {
getInput(); ui.cycle();
cycleWindows();
windowManager.refresh(); windowManager.refresh();
bbs.nodesync(); bbs.nodesync();
mswait(5); mswait(5);
......
import type { ICgaDefs, IKeyDefs, ISbbsDefs } from '@swag/ts4s';
import { load } from '@swag/ts4s';
import * as swindows from 'swindows';
import { IShellWindow } from './types';
import ActivityWindow from './ActivityWindow';
import MenuWindow from './MenuWindow';
const sbbsdefs: ISbbsDefs = load('sbbsdefs.js');
const keydefs: IKeyDefs = load('key_defs.js');
const cgadefs: ICgaDefs = load('cga_defs.js');
const { console } = js.global;
function getWindows(windowManager: swindows.WindowManager): IShellWindow[] {
const windows: IShellWindow[] = [
new ActivityWindow(
'Activity',
windowManager,
{ x: 0,
y: 0
},
{ width: windowManager.size.width,
height: Math.ceil(windowManager.size.height / 2)
},
),
new MenuWindow(
'Main',
`${js.exec_dir}main.ini`,
windowManager,
{ x: 0,
y: Math.floor(windowManager.size.height / 2)
},
{ width: Math.floor(windowManager.size.width / 3),
height: Math.floor(windowManager.size.height / 2)
}
),
new MenuWindow(
'Messages',
`${js.exec_dir}messages.ini`,
windowManager,
{ x: Math.floor(windowManager.size.width / 3),
y: Math.floor(windowManager.size.height / 2),
},
{ width: windowManager.size.width - (Math.floor(windowManager.size.width / 3) * 2),
height: Math.floor(windowManager.size.height / 2),
}
),
new MenuWindow(
'Games',
`${js.exec_dir}games.ini`,
windowManager,
{ x: Math.floor(windowManager.size.width / 3) + (windowManager.size.width - (Math.floor(windowManager.size.width / 3) * 2)),
y: Math.floor(windowManager.size.height / 2)
},
{ width: Math.floor(windowManager.size.width / 3),
height: Math.floor(windowManager.size.height / 2),
}
),
];
return windows;
}
export default class UI {
activeWindow: number = 0;
windows: IShellWindow[] = [];
constructor(windowManager: swindows.WindowManager) {
this.windows = getWindows(windowManager);
this.focusWindow(1);
}
cycle(): void {
for (const window of this.windows) {
window.cycle();
}
this.getInput();
}
focusWindow(n: number): void {
let idx = this.activeWindow + n;
if (idx < 0) {
idx = this.windows.length - 1;
} else if (idx >= this.windows.length) {
idx = 0;
}
this.windows[this.activeWindow].window.title = {
text: this.windows[this.activeWindow].window.title?.text ?? '',
attr: (cgadefs.BG_BLACK|cgadefs.WHITE) as swindows.types.attr,
alignment: swindows.defs.ALIGNMENT.LEFT,
};
this.windows[idx].window.title = {
text: this.windows[idx].window.title?.text ?? '',
attr: (cgadefs.BG_CYAN|cgadefs.LIGHTCYAN) as swindows.types.attr,
alignment: swindows.defs.ALIGNMENT.LEFT,
};
this.activeWindow = idx;
}
getInput(): void {
let input = console.inkey(sbbsdefs.K_NONE);
if (input === '') return;
if (input === 'q') js.global.exit(0);
switch (input) {
case '\t':
case keydefs.KEY_RIGHT:
this.focusWindow(1);
break;
case keydefs.KEY_LEFT:
this.focusWindow(-1);
break;
default:
this.windows[this.activeWindow].getCmd(input);
break;
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment