28 lines
842 B
JavaScript
28 lines
842 B
JavaScript
|
|
import path from "path";
|
||
|
|
|
||
|
|
export function normalizeBackgroundTileId(value, idToSymbol = null) {
|
||
|
|
const normalizedId = String(value || "").trim();
|
||
|
|
if (!normalizedId) {
|
||
|
|
return "";
|
||
|
|
}
|
||
|
|
if (idToSymbol instanceof Map && idToSymbol.size > 0 && !idToSymbol.has(normalizedId)) {
|
||
|
|
return "";
|
||
|
|
}
|
||
|
|
return normalizedId;
|
||
|
|
}
|
||
|
|
|
||
|
|
export function areRowsOnlyFillChar(rows, fillChar = ".") {
|
||
|
|
if (!Array.isArray(rows) || rows.length === 0) {
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
return rows.every((row) => {
|
||
|
|
const normalizedRow = String(row || "");
|
||
|
|
return normalizedRow.length === 0 || normalizedRow.split("").every((ch) => ch === fillChar);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
export function resolveContentPath(contentRoot, relativePath) {
|
||
|
|
const normalized = String(relativePath || "").replace(/\\/g, "/").replace(/^\/+/, "");
|
||
|
|
return path.resolve(contentRoot, normalized);
|
||
|
|
}
|