mirror of
https://github.com/Pax1601/DCSOlympus.git
synced 2025-10-29 16:56:34 +00:00
Added logs on client
Airplanes are now shown with silhouettes
This commit is contained in:
@@ -33,7 +33,7 @@ export function getLoadoutNamesByRole(aircraft: string, role: string)
|
||||
|
||||
export function getLoadoutsByName(aircraft: string, loadoutName: string)
|
||||
{
|
||||
//@ts-ignore
|
||||
//@ts-ignore TODO
|
||||
for (let loadout of aircraftDatabase[aircraft]["loadouts"])
|
||||
{
|
||||
if (loadout["name"] === loadoutName)
|
||||
@@ -44,7 +44,21 @@ export function getLoadoutsByName(aircraft: string, loadoutName: string)
|
||||
return null;
|
||||
}
|
||||
|
||||
export function getUnitLabel(name: string)
|
||||
export function getAircraftNameByLabel(label: string)
|
||||
{
|
||||
for (let name in aircraftDatabase)
|
||||
{
|
||||
//@ts-ignore TODO
|
||||
if (aircraftDatabase[name]["label"] === label)
|
||||
{
|
||||
return name;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
export function getAircraftLabelByName(name: string)
|
||||
{
|
||||
//@ts-ignore TODO
|
||||
return aircraftDatabase[name] === undefined? name: aircraftDatabase[name].label;
|
||||
@@ -1239,4 +1253,165 @@ export var aircraftDatabase = {
|
||||
}
|
||||
]
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export function getAircrafImage(name: string)
|
||||
{
|
||||
var results = []
|
||||
for (let imageName of imageNames) {
|
||||
var score = similarity(imageName, name);
|
||||
results.push({score: score, imageName: imageName});
|
||||
}
|
||||
|
||||
var bestResult = null;
|
||||
for (let result of results)
|
||||
{
|
||||
if (bestResult == null)
|
||||
bestResult = result;
|
||||
else {
|
||||
if (result.score > bestResult.score)
|
||||
bestResult = result;
|
||||
}
|
||||
}
|
||||
return bestResult?.imageName + ".png";
|
||||
}
|
||||
|
||||
function similarity(s1: string, s2: string) {
|
||||
var longer = s1;
|
||||
var shorter = s2;
|
||||
if (s1.length < s2.length) {
|
||||
longer = s2;
|
||||
shorter = s1;
|
||||
}
|
||||
var longerLength = longer.length;
|
||||
if (longerLength == 0) {
|
||||
return 1.0;
|
||||
}
|
||||
return (longerLength - editDistance(longer, shorter)) / longerLength;
|
||||
}
|
||||
|
||||
function editDistance(s1: string, s2: string) {
|
||||
s1 = s1.toLowerCase();
|
||||
s2 = s2.toLowerCase();
|
||||
|
||||
var costs = new Array();
|
||||
for (var i = 0; i <= s1.length; i++) {
|
||||
var lastValue = i;
|
||||
for (var j = 0; j <= s2.length; j++) {
|
||||
if (i == 0)
|
||||
costs[j] = j;
|
||||
else {
|
||||
if (j > 0) {
|
||||
var newValue = costs[j - 1];
|
||||
if (s1.charAt(i - 1) != s2.charAt(j - 1))
|
||||
newValue = Math.min(Math.min(newValue, lastValue),
|
||||
costs[j]) + 1;
|
||||
costs[j - 1] = lastValue;
|
||||
lastValue = newValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (i > 0)
|
||||
costs[s2.length] = lastValue;
|
||||
}
|
||||
return costs[s2.length];
|
||||
}
|
||||
|
||||
var imageNames = [
|
||||
'a-10',
|
||||
'a-20',
|
||||
'a-29',
|
||||
'a-4',
|
||||
'a-400',
|
||||
'a-50',
|
||||
'a-6',
|
||||
'ah-1',
|
||||
'ah-64',
|
||||
'an-26',
|
||||
'av8bna',
|
||||
'b-1',
|
||||
'b-17',
|
||||
'b-2',
|
||||
'b-52',
|
||||
'b707',
|
||||
'bf109',
|
||||
'bomb',
|
||||
'c-101',
|
||||
'c-130',
|
||||
'c-17',
|
||||
'c-5',
|
||||
'ch-47',
|
||||
'ch-53',
|
||||
'christeneagleii',
|
||||
'e-2',
|
||||
'e-3',
|
||||
'eurofighter',
|
||||
'f-111',
|
||||
'f-117',
|
||||
'f-14',
|
||||
'f-15',
|
||||
'f-16',
|
||||
'f-18',
|
||||
'f-22',
|
||||
'f-35',
|
||||
'f-4',
|
||||
'f-5',
|
||||
'f-86',
|
||||
'fw190',
|
||||
'general1',
|
||||
'gripen',
|
||||
'h-6',
|
||||
'hawk',
|
||||
'helicopter1',
|
||||
'i-16',
|
||||
'il-76',
|
||||
'j-10',
|
||||
'j-20',
|
||||
'j-7',
|
||||
'jf-17',
|
||||
'ju-88',
|
||||
'ka-27',
|
||||
'ka-50',
|
||||
'kc-10',
|
||||
'kc-135',
|
||||
'l-159',
|
||||
'l-39',
|
||||
'm2000',
|
||||
'mi-24',
|
||||
'mi-26',
|
||||
'mi-28',
|
||||
'mi-8',
|
||||
'mig-15',
|
||||
'mig-19',
|
||||
'mig-21',
|
||||
'mig-23',
|
||||
'mig-25',
|
||||
'mig-29',
|
||||
'mosquito',
|
||||
'multiengine',
|
||||
'oh-58',
|
||||
'p-47',
|
||||
'p-51',
|
||||
'rafale',
|
||||
'rq-1',
|
||||
'rq-4',
|
||||
's-3',
|
||||
'sa-342',
|
||||
'spitfire',
|
||||
'su-17',
|
||||
'su-24',
|
||||
'su-25',
|
||||
'su-27',
|
||||
'su-34',
|
||||
'su-57',
|
||||
'tornado',
|
||||
'tu-160',
|
||||
'tu-22',
|
||||
'tu-95',
|
||||
'u-28',
|
||||
'uh-1',
|
||||
'uh-60',
|
||||
'viggen',
|
||||
'yak-40',
|
||||
'yak-52'
|
||||
]
|
||||
@@ -205,72 +205,3 @@ unitTypes.vehicles.Unarmed = [
|
||||
"ZIL-131 KUNG",
|
||||
"ZIL-4331"
|
||||
]
|
||||
|
||||
/* AIRPLANES */
|
||||
unitTypes.air = {}
|
||||
|
||||
unitTypes.air.CAP = [
|
||||
"F-4E",
|
||||
"F/A-18C",
|
||||
"MiG-29S",
|
||||
"F-14A",
|
||||
"Su-27",
|
||||
"MiG-23MLD",
|
||||
"Su-33",
|
||||
"MiG-25RBT",
|
||||
"Su-30",
|
||||
"MiG-31",
|
||||
"Mirage 2000-5",
|
||||
"F-15C",
|
||||
"F-5E",
|
||||
"F-16C bl.52d",
|
||||
]
|
||||
|
||||
unitTypes.air.CAS = [
|
||||
"Tornado IDS",
|
||||
"F-4E",
|
||||
"F/A-18C",
|
||||
"MiG-27K",
|
||||
"A-10C",
|
||||
"Su-25",
|
||||
"Su-34",
|
||||
"Su-17M4",
|
||||
"F-15E",
|
||||
]
|
||||
|
||||
unitTypes.air.strike = [
|
||||
"Tu-22M3",
|
||||
"B-52H",
|
||||
"F-111F",
|
||||
"Tu-95MS",
|
||||
"Su-24M",
|
||||
"Tu-160",
|
||||
"F-117A",
|
||||
"B-1B",
|
||||
"Tu-142",
|
||||
]
|
||||
|
||||
unitTypes.air.tanker = [
|
||||
"S-3B Tanker",
|
||||
"KC-135",
|
||||
"IL-78M",
|
||||
]
|
||||
|
||||
unitTypes.air.awacs = [
|
||||
"A-50",
|
||||
"E-3A",
|
||||
"E-2D",
|
||||
]
|
||||
|
||||
unitTypes.air.drone = [
|
||||
"MQ-1A Predator",
|
||||
"MQ-9 Reaper",
|
||||
]
|
||||
|
||||
unitTypes.air.transport = [
|
||||
"C-130",
|
||||
"An-26B",
|
||||
"An-30M",
|
||||
"C-17A",
|
||||
"IL-76MD",
|
||||
]
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as L from 'leaflet'
|
||||
import { getMap } from '..'
|
||||
import { getUnitLabel } from './aircraftDatabase'
|
||||
import { getAircrafImage, getAircraftLabelByName } from './aircraftDatabase'
|
||||
import { AirUnit, GroundUnit, NavyUnit, Weapon } from './unit'
|
||||
|
||||
export interface MarkerOptions {
|
||||
@@ -30,7 +30,7 @@ export class UnitMarker extends L.Marker {
|
||||
constructor(options: MarkerOptions) {
|
||||
super(new L.LatLng(0, 0), { riseOnHover: true });
|
||||
this.#unitName = options.unitName;
|
||||
this.#name = getUnitLabel(options.name);
|
||||
this.#name = getAircraftLabelByName(options.name);
|
||||
this.#human = options.human;
|
||||
this.#AI = options.AI;
|
||||
|
||||
@@ -45,20 +45,21 @@ export class UnitMarker extends L.Marker {
|
||||
coalition = "neutral"
|
||||
|
||||
var icon = new L.DivIcon({
|
||||
html: `<table class="unit-marker-container" id="container">
|
||||
html: `<table class="ol-unit-marker-container" id="container">
|
||||
<tr>
|
||||
<td>
|
||||
<div class="${coalition}" id="background"></div>
|
||||
<div class="${coalition}" id="ring"></div>
|
||||
<div class="unit-marker-icon" id="icon"><img class="${coalition} unit-marker-image" src="${img}"></div>
|
||||
<div class="unit-marker-unitName" id="unitName">${this.#unitName}</div>
|
||||
<div class="unit-marker-altitude" id="altitude"></div>
|
||||
<div class="unit-marker-speed" id="speed"></div>
|
||||
<div class="unit-marker-name" id="name">${this.#name}</div>
|
||||
<div class="ol-unit-marker-icon" id="icon"><img class="${coalition} ol-unit-marker-image" src="${img}"></div>
|
||||
<div class="ol-unit-marker-unitName" id="unitName">${this.#unitName}</div>
|
||||
<div class="ol-unit-marker-altitude" id="altitude"></div>
|
||||
<div class="ol-unit-marker-speed" id="speed"></div>
|
||||
<div class="ol-unit-marker-name" id="name">${this.#name}</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>`,
|
||||
className: 'unit-marker'
|
||||
className: 'ol-unit-marker',
|
||||
iconAnchor: [30, 30]
|
||||
});
|
||||
this.setIcon(icon);
|
||||
}
|
||||
@@ -109,16 +110,16 @@ export class UnitMarker extends L.Marker {
|
||||
|
||||
if (!this.#alive)
|
||||
{
|
||||
this.getElement()?.querySelector("#icon")?.classList.add("unit-marker-dead");
|
||||
this.getElement()?.querySelector("#icon")?.classList.add("ol-unit-marker-dead");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setSelected(selected: boolean) {
|
||||
this.#selected = selected;
|
||||
this.getElement()?.querySelector("#icon")?.classList.remove("unit-marker-hovered");
|
||||
this.getElement()?.querySelector("#ring")?.classList.toggle("unit-marker-selected", selected);
|
||||
this.getElement()?.querySelector("#background")?.classList.toggle("unit-marker-selected", selected);
|
||||
this.getElement()?.querySelector("#icon")?.classList.remove("ol-unit-marker-hovered");
|
||||
this.getElement()?.querySelector("#ring")?.classList.toggle("ol-unit-marker-selected", selected);
|
||||
this.getElement()?.querySelector("#background")?.classList.toggle("ol-unit-marker-selected", selected);
|
||||
}
|
||||
|
||||
getSelected() {
|
||||
@@ -126,7 +127,11 @@ export class UnitMarker extends L.Marker {
|
||||
}
|
||||
|
||||
setHovered(hovered: boolean) {
|
||||
this.getElement()?.querySelector("#icon")?.classList.toggle("unit-marker-hovered", hovered && this.#alive);
|
||||
this.getElement()?.querySelector("#icon")?.classList.toggle("ol-unit-marker-hovered", hovered && this.#alive);
|
||||
}
|
||||
|
||||
getName() {
|
||||
return this.#name;
|
||||
}
|
||||
|
||||
getHuman() {
|
||||
@@ -166,19 +171,22 @@ export class AirUnitMarker extends UnitMarker {
|
||||
else
|
||||
return "minimal";
|
||||
}
|
||||
}
|
||||
|
||||
export class AircraftMarker extends AirUnitMarker {
|
||||
getUnitImage()
|
||||
{
|
||||
return new Image().src = "images/units/" + getAircrafImage(this.getName());
|
||||
}
|
||||
}
|
||||
|
||||
export class HelicopterMarker extends AirUnitMarker {
|
||||
getUnitImage()
|
||||
{
|
||||
return new Image().src = "images/units/airUnit.png"
|
||||
}
|
||||
}
|
||||
|
||||
export class AircraftMarker extends AirUnitMarker {
|
||||
}
|
||||
|
||||
export class HelicopterMarker extends AirUnitMarker {
|
||||
}
|
||||
|
||||
export class GroundUnitMarker extends UnitMarker {
|
||||
/* Are user driven units recognized as human? */
|
||||
getVisibility() {
|
||||
|
||||
Reference in New Issue
Block a user