This commit is contained in:
44
src/components/npcRenderUtils.ts
Normal file
44
src/components/npcRenderUtils.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import type { Encounter, FacingDirection } from '../types';
|
||||
|
||||
const DEFAULT_NPC_SCENE_OVERLAY_OFFSETS = {
|
||||
hpTop: -40,
|
||||
nameTop: -20,
|
||||
dialogueTop: -56,
|
||||
};
|
||||
|
||||
const GENERIC_NPC_SCENE_OVERLAY_OFFSETS = {
|
||||
hpTop: -24,
|
||||
nameTop: -8,
|
||||
dialogueTop: -48,
|
||||
};
|
||||
|
||||
export const GENERIC_NPC_SCENE_FOOT_OFFSET_PX = -30;
|
||||
|
||||
export function isGenericNpcEncounter(encounter: Encounter | null | undefined) {
|
||||
return Boolean(encounter && encounter.kind !== 'treasure' && !encounter.characterId && !encounter.monsterPresetId);
|
||||
}
|
||||
|
||||
export function invertFacing(facing: FacingDirection): FacingDirection {
|
||||
return facing === 'left' ? 'right' : 'left';
|
||||
}
|
||||
|
||||
export function getRenderableNpcFacing(
|
||||
encounter: Encounter | null | undefined,
|
||||
facing: FacingDirection,
|
||||
options?: { medievalVisual?: boolean },
|
||||
): FacingDirection {
|
||||
const medieval =
|
||||
options?.medievalVisual ??
|
||||
Boolean(encounter && encounter.kind !== 'treasure' && isGenericNpcEncounter(encounter));
|
||||
return medieval ? invertFacing(facing) : facing;
|
||||
}
|
||||
|
||||
export function getNpcSceneFootOffset(encounter: Encounter | null | undefined) {
|
||||
return isGenericNpcEncounter(encounter) ? GENERIC_NPC_SCENE_FOOT_OFFSET_PX : 0;
|
||||
}
|
||||
|
||||
export function getNpcSceneOverlayOffsets(encounter: Encounter | null | undefined) {
|
||||
return isGenericNpcEncounter(encounter)
|
||||
? GENERIC_NPC_SCENE_OVERLAY_OFFSETS
|
||||
: DEFAULT_NPC_SCENE_OVERLAY_OFFSETS;
|
||||
}
|
||||
Reference in New Issue
Block a user