forked from phenom/healer-man
Release Healer Man 0.1.20
This commit is contained in:
1 parent
d9bebb4e81
commit
699fc858c9
22 files changed
+551
-295
No files matched your search
+42
-16
@@ -25,30 +25,56 @@ function normalizedName(value: string): string {
|
||||
return value.toLowerCase().replace(/[^a-z0-9]+/g, "");
|
||||
}
|
||||
|
||||
/** Keep authored/server-backed WC combat; use generated kits only for unmapped fixtures. */
|
||||
/** Keep authored WC presentation and encounters while restoring its complete server population. */
|
||||
function enrichAuthoredDefinition(
|
||||
authored: DungeonDefinition,
|
||||
generated: DungeonDefinition | undefined,
|
||||
): DungeonDefinition {
|
||||
if (!generated) return authored;
|
||||
const generatedByName = new Map(
|
||||
Object.values(generated.entities).map((entity) => [normalizedName(entity.name), entity]),
|
||||
const authoredByName = new Map(
|
||||
Object.values(authored.entities).map((entity) => [normalizedName(entity.name), entity]),
|
||||
);
|
||||
const generatedEntities = Object.fromEntries(
|
||||
Object.entries(generated.entities).filter(([, entity]) => entity.kind !== "boss").map(([id, entity]) => {
|
||||
const authoredEntity = authoredByName.get(normalizedName(entity.name));
|
||||
return [
|
||||
id,
|
||||
authoredEntity
|
||||
? {
|
||||
...entity,
|
||||
visual: authoredEntity.visual,
|
||||
...(authoredEntity.combat ? { combat: authoredEntity.combat } : {}),
|
||||
}
|
||||
: entity,
|
||||
];
|
||||
}),
|
||||
);
|
||||
const generatedBossEntityIds = new Set(
|
||||
Object.entries(generated.entities)
|
||||
.filter(([, entity]) => entity.kind === "boss")
|
||||
.map(([id]) => id),
|
||||
);
|
||||
const authoredBossEntityIds = new Set(
|
||||
Object.entries(authored.entities)
|
||||
.filter(([, entity]) => entity.kind === "boss")
|
||||
.map(([id]) => id),
|
||||
);
|
||||
return {
|
||||
...authored,
|
||||
entities: Object.fromEntries(
|
||||
Object.entries(authored.entities).map(([id, entity]) => {
|
||||
const generatedEntity = generatedByName.get(normalizedName(entity.name));
|
||||
return [
|
||||
id,
|
||||
entity.combat
|
||||
? entity
|
||||
: generatedEntity?.combat
|
||||
? { ...entity, combat: generatedEntity.combat }
|
||||
: entity,
|
||||
];
|
||||
}),
|
||||
),
|
||||
entities: {
|
||||
...generatedEntities,
|
||||
...authored.entities,
|
||||
},
|
||||
staticSpawns: [
|
||||
...generated.staticSpawns.filter((spawn) => !generatedBossEntityIds.has(spawn.entityId)),
|
||||
...authored.staticSpawns,
|
||||
],
|
||||
roamingPacks: [
|
||||
...generated.roamingPacks,
|
||||
...authored.roamingPacks.filter((pack) => (
|
||||
pack.members.some((member) => authoredBossEntityIds.has(member.entityId))
|
||||
)),
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user