mirror of
https://github.com/Pax1601/DCSOlympus.git
synced 2025-10-29 16:56:34 +00:00
Converted for plugin use
This commit is contained in:
parent
0954bf2923
commit
83769bf539
16
client/@types/olympus/index.d.ts
vendored
16
client/@types/olympus/index.d.ts
vendored
@ -588,11 +588,11 @@ declare module "interfaces" {
|
||||
name?: string;
|
||||
shiftKey?: boolean;
|
||||
}
|
||||
export interface KeyboardShortcutOptions extends ShortcutOptions {
|
||||
export interface ShortcutKeyboardOptions extends ShortcutOptions {
|
||||
code: string;
|
||||
event?: "keydown" | "keyup";
|
||||
}
|
||||
export interface MouseShortcutOptions extends ShortcutOptions {
|
||||
export interface ShortcutMouseOptions extends ShortcutOptions {
|
||||
button: number;
|
||||
event: "mousedown" | "mouseup";
|
||||
}
|
||||
@ -1493,26 +1493,28 @@ declare module "plugin/pluginmanager" {
|
||||
}
|
||||
}
|
||||
declare module "shortcut/shortcut" {
|
||||
import { KeyboardShortcutOptions, MouseShortcutOptions, ShortcutOptions } from "interfaces";
|
||||
import { ShortcutKeyboardOptions, ShortcutMouseOptions, ShortcutOptions } from "interfaces";
|
||||
export abstract class Shortcut {
|
||||
#private;
|
||||
constructor(config: ShortcutOptions);
|
||||
getConfig(): ShortcutOptions;
|
||||
}
|
||||
export class ShortcutKeyboard extends Shortcut {
|
||||
constructor(config: KeyboardShortcutOptions);
|
||||
constructor(config: ShortcutKeyboardOptions);
|
||||
}
|
||||
export class ShortcutMouse extends Shortcut {
|
||||
constructor(config: MouseShortcutOptions);
|
||||
constructor(config: ShortcutMouseOptions);
|
||||
}
|
||||
}
|
||||
declare module "shortcut/shortcutmanager" {
|
||||
import { ShortcutKeyboardOptions, ShortcutMouseOptions } from "interfaces";
|
||||
import { Manager } from "other/manager";
|
||||
import { Shortcut } from "shortcut/shortcut";
|
||||
export class ShortcutManager extends Manager {
|
||||
#private;
|
||||
constructor();
|
||||
add(name: string, shortcut: Shortcut): this;
|
||||
add(name: string, shortcut: any): this;
|
||||
addKeyboardShortcut(name: string, shortcutKeyboardOptions: ShortcutKeyboardOptions): this;
|
||||
addMouseShortcut(name: string, shortcutMouseOptions: ShortcutMouseOptions): this;
|
||||
getKeysBeingHeld(): string[];
|
||||
keyComboMatches(combo: string[]): boolean;
|
||||
onKeyDown(callback: CallableFunction): void;
|
||||
|
||||
5420
client/package-lock.json
generated
5420
client/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,3 +1,5 @@
|
||||
import { OlympusPlugin } from "interfaces";
|
||||
|
||||
const SHOW_CONTROL_TIPS = "Show control tips"
|
||||
|
||||
export class ControlTipsPlugin implements OlympusPlugin {
|
||||
@ -41,7 +43,7 @@ export class ControlTipsPlugin implements OlympusPlugin {
|
||||
this.#updateTips();
|
||||
});
|
||||
|
||||
document.addEventListener("unitDeselection", (ev: CustomEvent) => {
|
||||
document.addEventListener("unitDeselection", (ev: CustomEventInit ) => {
|
||||
this.#updateTips();
|
||||
});
|
||||
|
||||
@ -55,7 +57,7 @@ export class ControlTipsPlugin implements OlympusPlugin {
|
||||
this.#updateTips();
|
||||
});
|
||||
|
||||
document.addEventListener("unitSelection", (ev: CustomEvent) => {
|
||||
document.addEventListener("unitSelection", (ev: CustomEventInit ) => {
|
||||
this.#updateTips();
|
||||
});
|
||||
|
||||
|
||||
@ -258,12 +258,12 @@ export interface ShortcutOptions {
|
||||
shiftKey?: boolean;
|
||||
}
|
||||
|
||||
export interface KeyboardShortcutOptions extends ShortcutOptions {
|
||||
export interface ShortcutKeyboardOptions extends ShortcutOptions {
|
||||
code: string;
|
||||
event?: "keydown" | "keyup";
|
||||
}
|
||||
|
||||
export interface MouseShortcutOptions extends ShortcutOptions {
|
||||
export interface ShortcutMouseOptions extends ShortcutOptions {
|
||||
button: number;
|
||||
event: "mousedown" | "mouseup";
|
||||
}
|
||||
|
||||
@ -236,22 +236,22 @@ export class OlympusApp {
|
||||
});
|
||||
|
||||
const shortcutManager = this.getShortcutManager();
|
||||
shortcutManager.add("toggleDemo", new ShortcutKeyboard({
|
||||
shortcutManager.addKeyboardShortcut("toggleDemo", {
|
||||
"callback": () => {
|
||||
this.getServerManager().toggleDemoEnabled();
|
||||
},
|
||||
"code": "KeyT"
|
||||
})).add("togglePause", new ShortcutKeyboard({
|
||||
}).addKeyboardShortcut("togglePause", {
|
||||
"altKey": false,
|
||||
"callback": () => {
|
||||
this.getServerManager().setPaused(!this.getServerManager().getPaused());
|
||||
},
|
||||
"code": "Space",
|
||||
"ctrlKey": false
|
||||
}));
|
||||
});
|
||||
|
||||
["KeyW", "KeyA", "KeyS", "KeyD", "ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].forEach(code => {
|
||||
shortcutManager.add(`pan${code}keydown`, new ShortcutKeyboard({
|
||||
shortcutManager.addKeyboardShortcut(`pan${code}keydown`, {
|
||||
"altKey": false,
|
||||
"callback": (ev: KeyboardEvent) => {
|
||||
this.getMap().handleMapPanning(ev);
|
||||
@ -259,20 +259,20 @@ export class OlympusApp {
|
||||
"code": code,
|
||||
"ctrlKey": false,
|
||||
"event": "keydown"
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
["KeyW", "KeyA", "KeyS", "KeyD", "ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].forEach(code => {
|
||||
shortcutManager.add(`pan${code}keyup`, new ShortcutKeyboard({
|
||||
shortcutManager.addKeyboardShortcut(`pan${code}keyup`, {
|
||||
"callback": (ev: KeyboardEvent) => {
|
||||
this.getMap().handleMapPanning(ev);
|
||||
},
|
||||
"code": code
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
["Digit1", "Digit2", "Digit3", "Digit4", "Digit5", "Digit6", "Digit7", "Digit8", "Digit9"].forEach(code => {
|
||||
shortcutManager.add(`hotgroup${code}`, new ShortcutKeyboard({
|
||||
shortcutManager.addKeyboardShortcut(`hotgroup${code}`, {
|
||||
"callback": (ev: KeyboardEvent) => {
|
||||
if (ev.ctrlKey && ev.shiftKey)
|
||||
this.getUnitsManager().selectedUnitsAddToHotgroup(parseInt(ev.code.substring(5)));
|
||||
@ -282,7 +282,7 @@ export class OlympusApp {
|
||||
this.getUnitsManager().selectUnitsByHotgroup(parseInt(ev.code.substring(5)));
|
||||
},
|
||||
"code": code
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
// TODO: move from here in dedicated class
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { KeyboardShortcutOptions, MouseShortcutOptions, ShortcutOptions } from "../interfaces";
|
||||
import { ShortcutKeyboardOptions, ShortcutMouseOptions, ShortcutOptions } from "../interfaces";
|
||||
import { keyEventWasInInput } from "../other/utils";
|
||||
|
||||
export abstract class Shortcut {
|
||||
@ -14,7 +14,7 @@ export abstract class Shortcut {
|
||||
}
|
||||
|
||||
export class ShortcutKeyboard extends Shortcut {
|
||||
constructor(config: KeyboardShortcutOptions) {
|
||||
constructor(config: ShortcutKeyboardOptions) {
|
||||
config.event = config.event || "keyup";
|
||||
super(config);
|
||||
|
||||
@ -37,7 +37,7 @@ export class ShortcutKeyboard extends Shortcut {
|
||||
}
|
||||
|
||||
export class ShortcutMouse extends Shortcut {
|
||||
constructor(config: MouseShortcutOptions) {
|
||||
constructor(config: ShortcutMouseOptions) {
|
||||
super(config);
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,6 @@
|
||||
import { ShortcutKeyboardOptions, ShortcutMouseOptions } from "../interfaces";
|
||||
import { Manager } from "../other/manager";
|
||||
import { Shortcut } from "./shortcut";
|
||||
import { Shortcut, ShortcutKeyboard, ShortcutMouse } from "./shortcut";
|
||||
|
||||
export class ShortcutManager extends Manager {
|
||||
|
||||
@ -25,8 +26,18 @@ export class ShortcutManager extends Manager {
|
||||
|
||||
}
|
||||
|
||||
add(name: string, shortcut: Shortcut) {
|
||||
super.add(name, shortcut);
|
||||
add( name: string, shortcut:any ) {
|
||||
console.error( "ShortcutManager:add() cannot be used. Use addKeyboardShortcut or addMouseShortcut." );
|
||||
return this;
|
||||
}
|
||||
|
||||
addKeyboardShortcut( name:string, shortcutKeyboardOptions:ShortcutKeyboardOptions ) {
|
||||
super.add( name, new ShortcutKeyboard( shortcutKeyboardOptions ) );
|
||||
return this;
|
||||
}
|
||||
|
||||
addMouseShortcut( name:string, shortcutMouseOptions:ShortcutMouseOptions ) {
|
||||
super.add( name, new ShortcutMouse( shortcutMouseOptions ) );
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user