dnd5-scripts/locationTypesList.js
2026-06-17 22:32:48 +03:00

134 lines
4.3 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//await dv.view("scripts/locations");
// Функция для создания ссылки на страницу
function getLocationName(p) {
let nameLink = `[[${p.file.name}|${p.file.name}]]`; // Создаем Wiki-ссылку
return nameLink;
}
// Функция для получения основной информации
function getMainInfo(p) {
let mainInfoParts = [];
if (p.appearance || p.race) {
let appearanceTitle = "";
if (p.appearance) {
appearanceTitle += `${p.appearance}`;
}
let appearanceTooltip = `<abbr title="${appearanceTitle}">View</abbr>`;
mainInfoParts.push(appearanceTooltip);
}
return mainInfoParts.join(" / ");
}
// Функция для получения потомков для массива локаций с дополнительными фильтрами
function getDescendantLocationsFilteredByTypeAndGoods(
dv,
targetLocations,
locationTypesArray,
goodsAndServicesArray,
basePath
) {
// Собираем все локации, которые являются потомками любых из целевых локаций
let descendantLocations = dv
.pages("#location")
// Применяем фильтры
.where((p) => {
// Проверяем, что локация не в списке целевых
if (targetLocations.includes(p.file.name)) {
return false;
}
// Проверяем, является ли локация потомком любой из целевых
if (!dv.locations.isDescendant(dv, p, targetLocations)) {
return false;
}
if (p.file.name.includes("Сэнд")) {
let y = 1;
}
// Фильтр по location-type
let locationTypeField = p["location-types"];
let locationTypes = [];
if (Array.isArray(locationTypeField)) {
locationTypes = locationTypeField;
} else if (typeof locationTypeField === "string") {
locationTypes = [locationTypeField];
}
let locationTypeMatch = locationTypesArray.some((type) =>
locationTypes.includes(type)
);
if (!locationTypeMatch) {
return false;
}
// Если goodsAndServicesArray пустой, пропускаем этот фильтр
if (goodsAndServicesArray.length === 0) {
return true;
}
// Фильтр по goods-and-services
let goodsServicesField = p["goods-and-services"];
let goodsServicesList = [];
if (Array.isArray(goodsServicesField)) {
goodsServicesList = goodsServicesField;
} else if (typeof goodsServicesField === "string") {
goodsServicesList = [goodsServicesField];
}
let goodsAndServicesMatch = goodsAndServicesArray.some((service) =>
goodsServicesList.includes(service)
);
return goodsAndServicesMatch;
})
.sort((p) => p.file.name, "asc")
.map((p) => {
let nameLink = getLocationName(p);
// Добавляем тип локации и товары/услуги в скобках после имени
let locationTypeField = p["location-types"];
let locationTypes = Array.isArray(locationTypeField)
? locationTypeField.join(", ")
: locationTypeField;
let goodsServicesField = p["goods-and-services"];
let goodsServices = Array.isArray(goodsServicesField)
? goodsServicesField.join(", ")
: goodsServicesField;
let nameWithDetails = `${nameLink} (type: ${locationTypes}; goods and services: ${goodsServices})`;
let avatarImage = dv.locations.getImageLinks(p, basePath); // Передаем basePath для формирования правильного пути
return [avatarImage, nameWithDetails]; // Изображение первой колонкой
});
return descendantLocations;
}
// Функция для отображения таблицы
function show_table(
dv,
targetLocations,
locationTypesArray,
goodsAndServicesArray,
basePath
) {
// Отображаем таблицу с найденными локациями
dv.table(
["Image", "Name (type; goods and services)"],
getDescendantLocationsFilteredByTypeAndGoods(
dv,
targetLocations,
locationTypesArray,
goodsAndServicesArray,
basePath
)
);
}
dv.locationTypesList = {
show_table,
};