mirror of
https://github.com/Pax1601/DCSOlympus.git
synced 2025-10-29 16:56:34 +00:00
Added tags to unit spawn menu
This commit is contained in:
parent
772f082913
commit
7cafeb73ca
File diff suppressed because it is too large
Load Diff
@ -124,6 +124,28 @@
|
||||
max-height: 300px;
|
||||
}
|
||||
|
||||
.ol-tag {
|
||||
background-color: #FFFFFF11;
|
||||
color: #FFFFFFDD;
|
||||
border: 1px solid #FFFFFF55;
|
||||
font-weight: normal;
|
||||
padding: 2px 5px;
|
||||
}
|
||||
|
||||
/*
|
||||
.ol-tag-CA {
|
||||
background-color: #FF000022;
|
||||
}
|
||||
|
||||
.ol-tag-Radar {
|
||||
background-color: #00FF0022;
|
||||
}
|
||||
|
||||
.ol-tag-IR {
|
||||
background-color: #0000FF22;
|
||||
}
|
||||
*/
|
||||
|
||||
.unit-loadout-list {
|
||||
min-width: 0;
|
||||
}
|
||||
@ -225,13 +247,14 @@
|
||||
column-gap: 5px;
|
||||
}
|
||||
|
||||
.unit-label-count-container>div:nth-child(1) {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
.unit-label-count-container button {
|
||||
display: flex !important;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.unit-label-count-container>div:nth-child(2) {
|
||||
font-size: large;
|
||||
.unit-label-count-container button>*:nth-child(1) {
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.unit-loadout-preview {
|
||||
|
||||
@ -87,4 +87,4 @@
|
||||
--unit-fuel-x: 0px;
|
||||
--unit-fuel-y: 22px;
|
||||
--unit-vvi-width: 4px;
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,18 +36,37 @@ export class Dropdown {
|
||||
return this.#container;
|
||||
}
|
||||
|
||||
setOptions(optionsList: string[], sort:""|"string"|"number" = "string") {
|
||||
|
||||
if ( sort === "number" ) {
|
||||
this.#optionsList = optionsList.sort( (optionA:string, optionB:string) => {
|
||||
const a = parseInt( optionA );
|
||||
const b = parseInt( optionB );
|
||||
if ( a > b )
|
||||
setOptions(optionsList: string[], sort: "" | "string" | "number" | "string+number" = "string") {
|
||||
if (sort === "number") {
|
||||
this.#optionsList = optionsList.sort((optionA: string, optionB: string) => {
|
||||
const a = parseInt(optionA);
|
||||
const b = parseInt(optionB);
|
||||
if (a > b)
|
||||
return 1;
|
||||
else
|
||||
return ( b > a ) ? -1 : 0;
|
||||
return (b > a) ? -1 : 0;
|
||||
});
|
||||
} else if ( sort === "string" ) {
|
||||
} else if (sort === "string+number") {
|
||||
this.#optionsList = optionsList.sort((optionA: string, optionB: string) => {
|
||||
var regex = /\d+/g;
|
||||
var matchesA = optionA.match(regex);
|
||||
var matchesB = optionB.match(regex);
|
||||
if ((matchesA != null && matchesA?.length > 0) && (matchesB != null && matchesB?.length > 0) && optionA[0] == optionB[0]) {
|
||||
const a = parseInt(matchesA[0] ?? 0);
|
||||
const b = parseInt(matchesB[0] ?? 0);
|
||||
if (a > b)
|
||||
return 1;
|
||||
else
|
||||
return (b > a) ? -1 : 0;
|
||||
} else {
|
||||
if (optionA > optionB)
|
||||
return 1;
|
||||
else
|
||||
return (optionB > optionA) ? -1 : 0;
|
||||
}
|
||||
|
||||
});
|
||||
} else if (sort === "string") {
|
||||
this.#optionsList = optionsList.sort();
|
||||
}
|
||||
|
||||
@ -169,17 +188,17 @@ export class Dropdown {
|
||||
}
|
||||
|
||||
#toggle() {
|
||||
this.#container.classList.contains("is-open")? this.close(): this.open();
|
||||
this.#container.classList.contains("is-open") ? this.close() : this.open();
|
||||
}
|
||||
|
||||
#createElement(defaultText: string | undefined) {
|
||||
var div = document.createElement("div");
|
||||
div.classList.add("ol-select");
|
||||
|
||||
|
||||
var value = document.createElement("div");
|
||||
value.classList.add("ol-select-value");
|
||||
value.innerText = defaultText? defaultText: "";
|
||||
|
||||
value.innerText = defaultText ? defaultText : "";
|
||||
|
||||
var options = document.createElement("div");
|
||||
options.classList.add("ol-select-options");
|
||||
|
||||
|
||||
@ -154,9 +154,28 @@ export class UnitSpawnMenu {
|
||||
this.#unitLiveryDropdown.reset();
|
||||
|
||||
if (this.#orderByRole)
|
||||
this.#unitLabelDropdown.setOptions(this.#unitDatabase.getByRole(this.spawnOptions.roleType).map((blueprint) => { return blueprint.label }));
|
||||
this.#unitLabelDropdown.setOptions(this.#unitDatabase.getByRole(this.spawnOptions.roleType).map((blueprint) => { return blueprint.label }), "string+number");
|
||||
else
|
||||
this.#unitLabelDropdown.setOptions(this.#unitDatabase.getByType(this.spawnOptions.roleType).map((blueprint) => { return blueprint.label }));
|
||||
this.#unitLabelDropdown.setOptions(this.#unitDatabase.getByType(this.spawnOptions.roleType).map((blueprint) => { return blueprint.label }), "string+number");
|
||||
|
||||
/* Add the tags to the options */
|
||||
var elements: HTMLElement[] = [];
|
||||
for (let idx = 0; idx < this.#unitLabelDropdown.getOptionElements().length; idx++) {
|
||||
let element = this.#unitLabelDropdown.getOptionElements()[idx] as HTMLElement;
|
||||
let entry = this.#unitDatabase.getByLabel(element.textContent ?? "");
|
||||
if (entry) {
|
||||
element.querySelectorAll("button")[0]?.append(...(entry.tags?.split(",").map((tag: string) => {
|
||||
tag = tag.trim();
|
||||
let el = document.createElement("div");
|
||||
el.classList.add("pill", `ol-tag`, `ol-tag-${tag.replace(/[\W_]+/g,"-")}`);
|
||||
el.textContent = tag;
|
||||
element.appendChild(el);
|
||||
return el;
|
||||
}) ?? []));
|
||||
elements.push(element);
|
||||
}
|
||||
}
|
||||
|
||||
this.#container.dispatchEvent(new Event("resize"));
|
||||
|
||||
this.spawnOptions.name = "";
|
||||
|
||||
@ -220,6 +220,7 @@ export interface UnitBlueprint {
|
||||
shotsBaseScatter?: number;
|
||||
description?: string;
|
||||
abilities?: string;
|
||||
tags?: string;
|
||||
acquisitionRange?: number;
|
||||
engagementRange?: number;
|
||||
targetingRange?: number;
|
||||
|
||||
2
scripts/python/.vscode/launch.json
vendored
2
scripts/python/.vscode/launch.json
vendored
@ -11,7 +11,7 @@
|
||||
"program": "${file}",
|
||||
"console": "integratedTerminal",
|
||||
"justMyCode": true,
|
||||
"args": ["aircraft"]
|
||||
"args": ["groundunit"]
|
||||
}
|
||||
]
|
||||
}
|
||||
35
scripts/python/convertTags.py
Normal file
35
scripts/python/convertTags.py
Normal file
@ -0,0 +1,35 @@
|
||||
import sys
|
||||
import json
|
||||
import re
|
||||
|
||||
|
||||
# The database file on which to operate is the first standard argument of the call
|
||||
if len(sys.argv) > 1:
|
||||
if (sys.argv[1] == "aircraft"):
|
||||
filename = '..\\..\\client\\public\\databases\\units\\aircraftdatabase.json'
|
||||
elif (sys.argv[1] == "helicopter"):
|
||||
filename = '..\\..\\client\\public\\databases\\units\\helicopterdatabase.json'
|
||||
elif (sys.argv[1] == "groundunit"):
|
||||
filename = '..\\..\\client\\public\\databases\\units\\groundunitdatabase.json'
|
||||
elif (sys.argv[1] == "navyunit"):
|
||||
filename = '..\\..\\client\\public\\databases\\units\\navyunitdatabase.json'
|
||||
|
||||
# Loads the database
|
||||
with open(filename) as f:
|
||||
database = json.load(f)
|
||||
|
||||
for name in database:
|
||||
label = database[name]['label']
|
||||
print(label)
|
||||
res = re.findall("\((.*?)\)", label)
|
||||
for tag in res:
|
||||
label = label.replace(f"({tag})", "")
|
||||
label = database[name]['label'] = label
|
||||
if len(res) > 0:
|
||||
database[name]["tags"] = "".join([f'{tag}{", " if i < len(res) - 1 else ""}' for i, tag in enumerate(res)])
|
||||
|
||||
# Dump everything in the database
|
||||
with open(filename, "w") as f:
|
||||
json.dump(database, f, indent=2)
|
||||
|
||||
print("Done!")
|
||||
Loading…
x
Reference in New Issue
Block a user