mirror of
https://github.com/Pax1601/DCSOlympus.git
synced 2025-10-29 16:56:34 +00:00
Merge branch 'main' of https://github.com/Pax1601/DCSOlympus
This commit is contained in:
commit
99dc61799f
11
client/src/context/context.ts
Normal file
11
client/src/context/context.ts
Normal file
@ -0,0 +1,11 @@
|
||||
export interface ContextInterface {
|
||||
|
||||
}
|
||||
|
||||
export class Context {
|
||||
|
||||
constructor( config:ContextInterface ) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
43
client/src/context/contextmanager.ts
Normal file
43
client/src/context/contextmanager.ts
Normal file
@ -0,0 +1,43 @@
|
||||
import { Manager } from "../other/manager";
|
||||
import { Context, ContextInterface } from "./context";
|
||||
|
||||
export class ContextManager extends Manager {
|
||||
|
||||
#currentContext!:string;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
add( name:string, contextConfig:ContextInterface ) {
|
||||
super.add( name, new Context( contextConfig ) );
|
||||
|
||||
if ( Object.values( this.getAll() ).length === 1 ) {
|
||||
this.#currentContext = name;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
currentContextIs( contextName:string ) {
|
||||
return contextName === this.#currentContext;
|
||||
}
|
||||
|
||||
getCurrentContext() {
|
||||
const contexts = this.getAll();
|
||||
|
||||
return ( contexts.hasOwnProperty( this.#currentContext ) ) ? contexts[this.#currentContext] : false;
|
||||
}
|
||||
|
||||
setContext( contextName:string ) {
|
||||
|
||||
if ( !this.get( contextName ) ) {
|
||||
console.error( `setContext(): context name "${contextName}" does not exist.` );
|
||||
return false;
|
||||
}
|
||||
this.#currentContext = contextName;
|
||||
|
||||
console.log( `Setting context to "${this.#currentContext}".` );
|
||||
}
|
||||
|
||||
}
|
||||
15
client/src/context/contextmenumanager.ts
Normal file
15
client/src/context/contextmenumanager.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { ContextMenu } from "../contextmenus/contextmenu";
|
||||
import { Manager } from "../other/manager";
|
||||
|
||||
export class ContextMenuManager extends Manager {
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
add( name:string, contextMenu:ContextMenu ) {
|
||||
super.add( name, contextMenu );
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@ -263,6 +263,7 @@ export interface Listener {
|
||||
export interface ShortcutOptions {
|
||||
altKey?: boolean;
|
||||
callback: CallableFunction;
|
||||
context?: string;
|
||||
ctrlKey?: boolean;
|
||||
name?: string;
|
||||
shiftKey?: boolean;
|
||||
|
||||
@ -25,6 +25,8 @@ import { groundUnitDatabase } from "./unit/databases/groundunitdatabase";
|
||||
import { navyUnitDatabase } from "./unit/databases/navyunitdatabase";
|
||||
import { ConfigurationOptions } from "./interfaces";
|
||||
import { UnitListPanel } from "./panels/unitlistpanel";
|
||||
import { ContextManager } from "./context/contextmanager";
|
||||
import { Context } from "./context/context";
|
||||
|
||||
export class OlympusApp {
|
||||
/* Global data */
|
||||
@ -34,13 +36,14 @@ export class OlympusApp {
|
||||
#map: Map | null = null;
|
||||
|
||||
/* Managers */
|
||||
#contextManager!: ContextManager;
|
||||
#dialogManager!: Manager;
|
||||
#missionManager: MissionManager | null = null;
|
||||
#panelsManager: Manager | null = null;
|
||||
#pluginsManager: PluginsManager | null = null;
|
||||
#popupsManager: Manager | null = null;
|
||||
#serverManager: ServerManager | null = null;
|
||||
#shortcutManager: ShortcutManager | null = null;
|
||||
#shortcutManager!: ShortcutManager;
|
||||
#toolbarsManager: Manager | null = null;
|
||||
#unitsManager: UnitsManager | null = null;
|
||||
#weaponsManager: WeaponsManager | null = null;
|
||||
@ -58,6 +61,14 @@ export class OlympusApp {
|
||||
return this.#map as Map;
|
||||
}
|
||||
|
||||
getCurrentContext() {
|
||||
return this.getContextManager().getCurrentContext() as Context;
|
||||
}
|
||||
|
||||
getContextManager() {
|
||||
return this.#contextManager as ContextManager;
|
||||
}
|
||||
|
||||
getServerManager() {
|
||||
return this.#serverManager as ServerManager;
|
||||
}
|
||||
@ -166,6 +177,10 @@ export class OlympusApp {
|
||||
|
||||
start() {
|
||||
/* Initialize base functionalitites */
|
||||
|
||||
this.#contextManager = new ContextManager();
|
||||
this.#contextManager.add( "olympus", {} );
|
||||
|
||||
this.#map = new Map('map-container');
|
||||
|
||||
this.#missionManager = new MissionManager();
|
||||
@ -251,22 +266,28 @@ export class OlympusApp {
|
||||
|
||||
const shortcutManager = this.getShortcutManager();
|
||||
shortcutManager.addKeyboardShortcut("toggleDemo", {
|
||||
"altKey": false,
|
||||
"callback": () => {
|
||||
this.getServerManager().toggleDemoEnabled();
|
||||
},
|
||||
"code": "KeyT"
|
||||
"code": "KeyT",
|
||||
"context": "olympus",
|
||||
"ctrlKey": false,
|
||||
"shiftKey": false
|
||||
}).addKeyboardShortcut("togglePause", {
|
||||
"altKey": false,
|
||||
"callback": () => {
|
||||
this.getServerManager().setPaused(!this.getServerManager().getPaused());
|
||||
},
|
||||
"code": "Space",
|
||||
"context": "olympus",
|
||||
"ctrlKey": false
|
||||
}).addKeyboardShortcut("deselectAll", {
|
||||
"callback": (ev: KeyboardEvent) => {
|
||||
this.getUnitsManager().deselectAllUnits();
|
||||
},
|
||||
"code": "Escape"
|
||||
"code": "Escape",
|
||||
"context": "olympus"
|
||||
}).addKeyboardShortcut("toggleUnitLabels", {
|
||||
"altKey": false,
|
||||
"callback": () => {
|
||||
@ -276,6 +297,7 @@ export class OlympusApp {
|
||||
}
|
||||
},
|
||||
"code": "KeyL",
|
||||
"context": "olympus",
|
||||
"ctrlKey": false,
|
||||
"shiftKey": false
|
||||
}).addKeyboardShortcut("toggleAcquisitionRings", {
|
||||
@ -287,6 +309,7 @@ export class OlympusApp {
|
||||
}
|
||||
},
|
||||
"code": "KeyE",
|
||||
"context": "olympus",
|
||||
"ctrlKey": false,
|
||||
"shiftKey": false
|
||||
}).addKeyboardShortcut("toggleEngagementRings", {
|
||||
@ -298,6 +321,7 @@ export class OlympusApp {
|
||||
}
|
||||
},
|
||||
"code": "KeyQ",
|
||||
"context": "olympus",
|
||||
"ctrlKey": false,
|
||||
"shiftKey": false
|
||||
}).addKeyboardShortcut("toggleHideShortEngagementRings", {
|
||||
@ -309,6 +333,7 @@ export class OlympusApp {
|
||||
}
|
||||
},
|
||||
"code": "KeyR",
|
||||
"context": "olympus",
|
||||
"ctrlKey": false,
|
||||
"shiftKey": false
|
||||
}).addKeyboardShortcut("toggleFillEngagementRings", {
|
||||
@ -320,6 +345,7 @@ export class OlympusApp {
|
||||
}
|
||||
},
|
||||
"code": "KeyF",
|
||||
"context": "olympus",
|
||||
"ctrlKey": false,
|
||||
"shiftKey": false
|
||||
});
|
||||
@ -331,6 +357,7 @@ export class OlympusApp {
|
||||
this.getMap().handleMapPanning(ev);
|
||||
},
|
||||
"code": code,
|
||||
"context": "olympus",
|
||||
"ctrlKey": false,
|
||||
"event": "keydown"
|
||||
});
|
||||
@ -339,7 +366,8 @@ export class OlympusApp {
|
||||
"callback": (ev: KeyboardEvent) => {
|
||||
this.getMap().handleMapPanning(ev);
|
||||
},
|
||||
"code": code
|
||||
"code": code,
|
||||
"context": "olympus"
|
||||
});
|
||||
});
|
||||
|
||||
@ -360,10 +388,8 @@ export class OlympusApp {
|
||||
},
|
||||
"code": code
|
||||
});
|
||||
});
|
||||
|
||||
// Stop hotgroup controls sending the browser to another tab
|
||||
digits.forEach(code => {
|
||||
// Stop hotgroup controls sending the browser to another tab
|
||||
document.addEventListener("keydown", (ev: KeyboardEvent) => {
|
||||
if (ev.code === code && ev.ctrlKey === true && ev.altKey === false && ev.shiftKey === false) {
|
||||
ev.preventDefault();
|
||||
|
||||
@ -1,7 +1,11 @@
|
||||
import { Context } from "../context/context";
|
||||
|
||||
export class Manager {
|
||||
|
||||
#items: { [key: string]: any } = {};
|
||||
|
||||
constructor() {
|
||||
|
||||
}
|
||||
|
||||
add(name: string, item: any) {
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import { getApp } from "..";
|
||||
import { ShortcutKeyboardOptions, ShortcutMouseOptions, ShortcutOptions } from "../interfaces";
|
||||
import { keyEventWasInInput } from "../other/utils";
|
||||
|
||||
@ -19,6 +20,10 @@ export class ShortcutKeyboard extends Shortcut {
|
||||
super(config);
|
||||
|
||||
document.addEventListener(config.event, (ev: any) => {
|
||||
if ( typeof config.context === "string" && !getApp().getContextManager().currentContextIs( config.context ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ev instanceof KeyboardEvent === false || keyEventWasInInput(ev)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import { ShortcutKeyboardOptions, ShortcutMouseOptions } from "../interfaces";
|
||||
import { Manager } from "../other/manager";
|
||||
|
||||
import { ShortcutKeyboard, ShortcutMouse } from "./shortcut";
|
||||
|
||||
export class ShortcutManager extends Manager {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user