remove getByType out of lables.ts

This commit is contained in:
StempunkDev 2026-03-27 20:18:50 +01:00
parent 967e8897ed
commit 9b4add5071
3 changed files with 13 additions and 19 deletions

View file

@ -1,4 +1,3 @@
declare global {
var Labels: LabelsModule;
}
@ -61,10 +60,6 @@ class LabelsModule {
return pack.labels.find((l) => l.i === id);
}
getByType(type: LabelData["type"]): LabelData[] {
return pack.labels.filter((l) => l.type === type);
}
getByGroup(group: string): LabelData[] {
return pack.labels.filter(
(l) => (l.type === "burg" || l.type === "custom") && l.group === group,
@ -189,7 +184,7 @@ class LabelsModule {
group,
text: burg.name!,
x: burg.x,
y: burg.y
y: burg.y,
});
}

View file

@ -20,7 +20,8 @@ export function drawBurgLabels(): void {
// Get all burg labels grouped by group name
const burgLabelsByGroup = new Map<string, BurgLabelData[]>();
for (const label of Labels.getByType("burg").map((l) => l as BurgLabelData)) {
for (const label of Labels.getAll()) {
if (label.type !== "burg") continue;
if (!burgLabelsByGroup.has(label.group)) {
burgLabelsByGroup.set(label.group, []);
}
@ -52,7 +53,7 @@ export function drawBurgLabels(): void {
}
TIME && console.timeEnd("drawBurgLabels");
};
}
export function drawBurgLabel(burg: Burg): void {
// TODO: remove label group dependency - for now, if group is missing, redraw all labels to recreate the group
@ -81,12 +82,12 @@ export function drawBurgLabel(burg: Burg): void {
.attr("dx", `${dx}em`)
.attr("dy", `${dy}em`)
.text(burg.name!);
};
}
export function removeBurgLabel(burgId: number): void {
const existingLabel = document.getElementById(`burgLabel${burgId}`);
if (existingLabel) existingLabel.remove();
};
}
function createLabelGroups(): void {
// save existing styles and remove all groups
@ -115,4 +116,4 @@ function createLabelGroups(): void {
});
group.attr("id", name);
}
}
}

View file

@ -45,14 +45,12 @@ const stateLabelsRenderer = (list?: number[]): void => {
const { states } = pack;
// Get labels to render
const labelsToRender = list
? Labels.getAll()
.filter(
(l) =>
l.type === "state" && list.includes((l as StateLabelData).stateId),
)
.map((l) => l as StateLabelData)
: Labels.getByType("state").map((l) => l as StateLabelData);
const labelsToRender: StateLabelData[] =
list && list.length > 0
? list
.map((idx) => Labels.get(idx))
.filter((label) => label?.type === "state")
: Labels.getAll().filter((label) => label.type === "state");
const letterLength = checkExampleLetterLength();
drawLabelPath(letterLength, labelsToRender);