Follow feature completed

This commit is contained in:
Pax1601
2023-04-19 10:19:56 +02:00
parent cfd98e74ea
commit f24c57cc18
10 changed files with 117 additions and 77 deletions

View File

@@ -1,7 +1,9 @@
import { getUnitsManager } from "..";
import { deg2rad } from "../other/utils";
import { ContextMenu } from "./contextmenu";
export class UnitContextMenu extends ContextMenu {
#callback: CallableFunction | null = null;
#customFormationCallback: CallableFunction | null = null;
constructor(id: string) {
super(id);
@@ -19,17 +21,28 @@ export class UnitContextMenu extends ContextMenu {
clock++;
}
var angleDeg = 360 - (clock - 1) * 45;
var distance = parseInt((<HTMLInputElement> dialog.querySelector(`#distance`)?.querySelector("input")).value);
var upDown = parseInt((<HTMLInputElement> dialog.querySelector(`#up-down`)?.querySelector("input")).value);
var asd= 1;
var angleRad = deg2rad(angleDeg);
var distance = parseInt((<HTMLInputElement> dialog.querySelector(`#distance`)?.querySelector("input")).value) * 0.3048;
var upDown = parseInt((<HTMLInputElement> dialog.querySelector(`#up-down`)?.querySelector("input")).value) * 0.3048;
}
// X: front-rear, positive front
// Y: top-bottom, positive top
// Z: left-right, positive right
if (this.#callback)
this.#callback()
var x = distance * Math.cos(angleRad);
var y = upDown;
var z = distance * Math.sin(angleRad);
if (this.#customFormationCallback)
this.#customFormationCallback({"x": x, "y": y, "z": z})
}
})
}
setCustomFormationCallback(callback: CallableFunction) {
this.#customFormationCallback = callback;
}
setOptions(options: {[key: string]: string}, callback: CallableFunction)
{
this.getContainer()?.replaceChildren(...Object.keys(options).map((option: string, idx: number) =>