mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2026-04-04 06:27:24 +02:00
remove getByType out of lables.ts
This commit is contained in:
parent
967e8897ed
commit
9b4add5071
3 changed files with 13 additions and 19 deletions
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
var Labels: LabelsModule;
|
var Labels: LabelsModule;
|
||||||
}
|
}
|
||||||
|
|
@ -61,10 +60,6 @@ class LabelsModule {
|
||||||
return pack.labels.find((l) => l.i === id);
|
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[] {
|
getByGroup(group: string): LabelData[] {
|
||||||
return pack.labels.filter(
|
return pack.labels.filter(
|
||||||
(l) => (l.type === "burg" || l.type === "custom") && l.group === group,
|
(l) => (l.type === "burg" || l.type === "custom") && l.group === group,
|
||||||
|
|
@ -189,7 +184,7 @@ class LabelsModule {
|
||||||
group,
|
group,
|
||||||
text: burg.name!,
|
text: burg.name!,
|
||||||
x: burg.x,
|
x: burg.x,
|
||||||
y: burg.y
|
y: burg.y,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,8 @@ export function drawBurgLabels(): void {
|
||||||
|
|
||||||
// Get all burg labels grouped by group name
|
// Get all burg labels grouped by group name
|
||||||
const burgLabelsByGroup = new Map<string, BurgLabelData[]>();
|
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)) {
|
if (!burgLabelsByGroup.has(label.group)) {
|
||||||
burgLabelsByGroup.set(label.group, []);
|
burgLabelsByGroup.set(label.group, []);
|
||||||
}
|
}
|
||||||
|
|
@ -52,7 +53,7 @@ export function drawBurgLabels(): void {
|
||||||
}
|
}
|
||||||
|
|
||||||
TIME && console.timeEnd("drawBurgLabels");
|
TIME && console.timeEnd("drawBurgLabels");
|
||||||
};
|
}
|
||||||
|
|
||||||
export function drawBurgLabel(burg: Burg): void {
|
export function drawBurgLabel(burg: Burg): void {
|
||||||
// TODO: remove label group dependency - for now, if group is missing, redraw all labels to recreate the group
|
// 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("dx", `${dx}em`)
|
||||||
.attr("dy", `${dy}em`)
|
.attr("dy", `${dy}em`)
|
||||||
.text(burg.name!);
|
.text(burg.name!);
|
||||||
};
|
}
|
||||||
|
|
||||||
export function removeBurgLabel(burgId: number): void {
|
export function removeBurgLabel(burgId: number): void {
|
||||||
const existingLabel = document.getElementById(`burgLabel${burgId}`);
|
const existingLabel = document.getElementById(`burgLabel${burgId}`);
|
||||||
if (existingLabel) existingLabel.remove();
|
if (existingLabel) existingLabel.remove();
|
||||||
};
|
}
|
||||||
|
|
||||||
function createLabelGroups(): void {
|
function createLabelGroups(): void {
|
||||||
// save existing styles and remove all groups
|
// save existing styles and remove all groups
|
||||||
|
|
@ -115,4 +116,4 @@ function createLabelGroups(): void {
|
||||||
});
|
});
|
||||||
group.attr("id", name);
|
group.attr("id", name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,14 +45,12 @@ const stateLabelsRenderer = (list?: number[]): void => {
|
||||||
const { states } = pack;
|
const { states } = pack;
|
||||||
|
|
||||||
// Get labels to render
|
// Get labels to render
|
||||||
const labelsToRender = list
|
const labelsToRender: StateLabelData[] =
|
||||||
? Labels.getAll()
|
list && list.length > 0
|
||||||
.filter(
|
? list
|
||||||
(l) =>
|
.map((idx) => Labels.get(idx))
|
||||||
l.type === "state" && list.includes((l as StateLabelData).stateId),
|
.filter((label) => label?.type === "state")
|
||||||
)
|
: Labels.getAll().filter((label) => label.type === "state");
|
||||||
.map((l) => l as StateLabelData)
|
|
||||||
: Labels.getByType("state").map((l) => l as StateLabelData);
|
|
||||||
|
|
||||||
const letterLength = checkExampleLetterLength();
|
const letterLength = checkExampleLetterLength();
|
||||||
drawLabelPath(letterLength, labelsToRender);
|
drawLabelPath(letterLength, labelsToRender);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue