File size: 1,035 Bytes
970fc3e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | const CAST_SIZE = 5;
function castSlots(actors) {
if (actors.length > CAST_SIZE) throw new Error(`This demo uses ${CAST_SIZE} actors. Remove extra actors first; existing actors are not deleted automatically.`);
const used = /* @__PURE__ */ new Set();
for (const actor of actors) if (actor.castSlot !== void 0) {
if (!Number.isInteger(actor.castSlot) || actor.castSlot < 1 || actor.castSlot > CAST_SIZE || used.has(actor.castSlot)) throw new Error("Invalid or duplicate actor motion slot");
used.add(actor.castSlot);
}
return actors.map((actor) => {
if (actor.castSlot !== void 0) return { ...actor };
const slot = Array.from({ length: CAST_SIZE }, (_, i) => i + 1).find((i) => !used.has(i));
used.add(slot);
return { ...actor, castSlot: slot };
});
}
function nextCastSlot(actors) {
const used = new Set(castSlots(actors).map((a) => a.castSlot));
return Array.from({ length: CAST_SIZE }, (_, i) => i + 1).find((i) => !used.has(i)) ?? null;
}
export {
CAST_SIZE,
castSlots,
nextCastSlot
};
|