fix(houseofrc): match a class by whole words, e.g. 4wd to 4WD Buggy (1.81.1)
This commit is contained in:
1 parent
b0f2b92c04
commit
cdeb6b0402
5 files changed
+22
-5
No files matched your search
+10
-2
@@ -105,7 +105,15 @@ export function applyHouseOfRcEntries(drivers, plan, { classId, selected, makeDr
|
||||
return { driverIds, entryIds };
|
||||
}
|
||||
|
||||
// Our class for a House of RC class: same name (ignoring case and spaces), else none.
|
||||
// Our class for a House of RC class: the same name (ignoring case and spaces), else the one
|
||||
// class whose name holds the other as whole words ("4wd" ~ "4WD Buggy"), else none.
|
||||
export function matchHouseOfRcClass(classes = [], name = "") {
|
||||
return classes.find((item) => sameText(item.name, name))?.id || "";
|
||||
const exact = classes.find((item) => sameText(item.name, name));
|
||||
if (exact) return exact.id;
|
||||
const words = (text) => String(text || "").toLocaleLowerCase().split(/[^\p{L}\p{N}.]+/u).filter(Boolean);
|
||||
const wanted = words(name);
|
||||
if (!wanted.length) return "";
|
||||
const holds = (outer, inner) => inner.length <= outer.length && outer.some((_word, index) => inner.every((word, offset) => outer[index + offset] === word));
|
||||
const candidates = classes.filter((item) => { const own = words(item.name); return holds(own, wanted) || holds(wanted, own); });
|
||||
return candidates.length === 1 ? candidates[0].id : "";
|
||||
}
|
||||
Reference in new issue
Block a user