debug page
parent
8f4d21c00d
commit
cbc45c1aef
|
|
@ -1,10 +1,14 @@
|
|||
export const IPC_PATH = '/tmp/dfi.dev';
|
||||
export const IPC_CLIENT_APPSAPCE = 'dfi.';
|
||||
// === [ netowkring ] ===
|
||||
export const MDNS_TYPE = 'hdn';
|
||||
|
||||
// === [ IPC DEV SERVER ] ===
|
||||
export const IPC_CLIENT_APPSPACE = MDNS_TYPE + '.';
|
||||
export const IPC_CLIENT_CONNECT_NAME = 'dev';
|
||||
export const IPC_PATH = '/tmp/' + IPC_CLIENT_APPSPACE + IPC_CLIENT_CONNECT_NAME;
|
||||
|
||||
export const IPC_QUIT_EVENT = 'app.quit';
|
||||
export const IPC_RESTART_EVENT = 'app.restart';
|
||||
export const IPC_REQUEST_RESTART = 'app.request-restart';
|
||||
|
||||
export const MDNS_TYPE = 'hdn';
|
||||
|
||||
// === [ app info ] ===
|
||||
export const APPLICATION_NAME = 'Hadean'
|
||||
|
|
@ -3,13 +3,15 @@ import EventEmitter from 'events';
|
|||
import ipc from 'node-ipc';
|
||||
import {
|
||||
IPC_CLIENT_CONNECT_NAME,
|
||||
IPC_CLIENT_APPSAPCE,
|
||||
IPC_CLIENT_APPSPACE,
|
||||
IPC_QUIT_EVENT,
|
||||
IPC_RESTART_EVENT,
|
||||
IPC_REQUEST_RESTART
|
||||
} from './Constants.js';
|
||||
|
||||
let connected = false;
|
||||
ipc.config.appspace = IPC_CLIENT_APPSPACE;
|
||||
ipc.config.silent = true;
|
||||
|
||||
const oldConsoleLog = console.log;
|
||||
|
||||
const patchLog = () => console.log = console.log.bind(console, chalk.cyan('[CLIENT]'));
|
||||
|
|
@ -23,6 +25,33 @@ class ProcessManagerClass extends EventEmitter {
|
|||
// TODO replace this with an async sortof
|
||||
// event emitter, to wait for all clean up
|
||||
|
||||
connected = false;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
ipc.connectTo(IPC_CLIENT_CONNECT_NAME, () => {
|
||||
ipc.of[IPC_CLIENT_CONNECT_NAME].on('connect', this.onConnect.bind(this));
|
||||
ipc.of[IPC_CLIENT_CONNECT_NAME].on('disconnect', this.onDisconnect.bind(this));
|
||||
ipc.of[IPC_CLIENT_CONNECT_NAME].on(IPC_REQUEST_RESTART, this.onReloadRequested.bind(this));
|
||||
});
|
||||
}
|
||||
|
||||
private onReloadRequested() {
|
||||
this.emit('reload');
|
||||
}
|
||||
|
||||
private onConnect() {
|
||||
this.connected = true;
|
||||
this.emit('change');
|
||||
patchLog();
|
||||
}
|
||||
|
||||
private onDisconnect() {
|
||||
this.connected = false;
|
||||
this.emit('change');
|
||||
restoreLog();
|
||||
}
|
||||
|
||||
quit() {
|
||||
this.emit('shutdown');
|
||||
this.processLock.then(() => {
|
||||
|
|
@ -32,43 +61,19 @@ class ProcessManagerClass extends EventEmitter {
|
|||
|
||||
restart() {
|
||||
this.emit('shutdown');
|
||||
if (connected) {
|
||||
ipc.of[name].emit(IPC_RESTART_EVENT);
|
||||
if (this.connected) {
|
||||
ipc.of[IPC_CLIENT_CONNECT_NAME].emit(IPC_RESTART_EVENT);
|
||||
}
|
||||
setTimeout(() => {
|
||||
process.exit(0);
|
||||
})
|
||||
}
|
||||
|
||||
get connected() {
|
||||
return connected;
|
||||
}
|
||||
}
|
||||
|
||||
export const ProcessManager = new ProcessManagerClass();
|
||||
|
||||
const name = IPC_CLIENT_CONNECT_NAME;
|
||||
ipc.config.appspace = IPC_CLIENT_APPSAPCE;
|
||||
ipc.config.silent = true;
|
||||
|
||||
ipc.connectTo(name, () => {
|
||||
ipc.of[name].on('connect', () => {
|
||||
connected = true;
|
||||
patchLog();
|
||||
});
|
||||
ipc.of[name].on('disconnect', () => {
|
||||
connected = false
|
||||
restoreLog();
|
||||
});
|
||||
ipc.of[name].on(IPC_REQUEST_RESTART, () => {
|
||||
ProcessManager.emit('reload');
|
||||
})
|
||||
});
|
||||
|
||||
// process.on('SIGKILL', () => ProcessManager.quit());
|
||||
process.on('SIGTERM', () => ProcessManager.quit());
|
||||
process.on('SIGINT', () => ProcessManager.quit());
|
||||
// process.on('exit', () => ProcessManager.quit());
|
||||
process.on('beforeExit', () => ProcessManager.quit());
|
||||
|
||||
// dumbass hack hahahah :)
|
||||
|
|
@ -82,5 +87,4 @@ if (process.platform === "win32") {
|
|||
// @ts-ignore dont know why, dont fuckin care
|
||||
process.emit("SIGINT");
|
||||
});
|
||||
}
|
||||
///
|
||||
}
|
||||
|
|
@ -20,6 +20,7 @@ import {
|
|||
import network from '../multiplayer/mDNS.js';
|
||||
import { Player } from '../multiplayer/Player.js';
|
||||
import { Pawn } from '../Pawn.js';
|
||||
import { ProcessManager } from '../ProcessManager.js';
|
||||
import { View } from './View.js';
|
||||
|
||||
export class GameView extends View {
|
||||
|
|
@ -29,6 +30,7 @@ export class GameView extends View {
|
|||
left: QWidget;
|
||||
right: QTabWidget;
|
||||
timeControl: TimeControl;
|
||||
debugPage: DebugPageWidget;
|
||||
|
||||
addComponents(): void {
|
||||
this.addLayout();
|
||||
|
|
@ -52,9 +54,21 @@ export class GameView extends View {
|
|||
this.layout.setColumnStretch(i, 1);
|
||||
}
|
||||
|
||||
this.debugPage = new DebugPageWidget();
|
||||
|
||||
this.right.addTab(new PawnPageWidget(), new QIcon(), 'Pawns');
|
||||
this.right.addTab(new InventoryPageWidget(), new QIcon(), 'Inventory');
|
||||
this.right.addTab(new MultiplayerPageWidget(), new QIcon(), 'Multiplayer');
|
||||
|
||||
ProcessManager.on('change', this.onProcessManagerChange.bind(this));
|
||||
}
|
||||
|
||||
onProcessManagerChange() {
|
||||
if(ProcessManager.connected) {
|
||||
this.right.addTab(this.debugPage, new QIcon(), 'Debug');
|
||||
} else {
|
||||
this.right.removeTab(this.right.tabs.indexOf(this.debugPage))
|
||||
}
|
||||
}
|
||||
|
||||
constructor(game: Game) {
|
||||
|
|
@ -196,6 +210,8 @@ class PawnPageWidget extends ScrollPanel {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO remove later, when i know i dont need it
|
||||
// class PawnPageWidget extends QListWidget {
|
||||
// constructor() {
|
||||
// super();
|
||||
|
|
@ -268,6 +284,23 @@ class MultiplayerPageWidget extends ScrollPanel {
|
|||
}
|
||||
}
|
||||
|
||||
class DebugPageWidget extends ScrollPanel {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
fill(): void {
|
||||
const reload = new QPushButton();
|
||||
reload.setText('Reload');
|
||||
reload.addEventListener('clicked', this.reload.bind(this))
|
||||
this.addWidget(reload);
|
||||
}
|
||||
|
||||
private reload() {
|
||||
ProcessManager.restart();
|
||||
}
|
||||
}
|
||||
|
||||
class TimeControl extends GridItem {
|
||||
pauseButton: QPushButton;
|
||||
normalSpeedButton: QPushButton;
|
||||
|
|
|
|||
Loading…
Reference in New Issue