Files
entity-descriptions/src/entities/partial/rated/activatable/nonModifiableSuffix.ts
T

92 lines
2.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { mapNullable } from "@optolith/helpers/nullable"
import { assertExhaustive } from "@optolith/helpers/typeSafety"
import { UI } from "optolith-database-schema/types/UI"
import { LocaleEnvironment } from "../../../../helpers/locale.js"
import { responsive, ResponsiveTextSize } from "../../responsiveText.js"
import { Entity } from "./entity.js"
/**
* A parameter that is designed to be modifiable.
*/
export enum ModifiableParameter {
CastingTime,
Cost,
Range,
}
const translationKeyForNonModifiableSuffix: {
[key in Entity]:
| {
[key in ModifiableParameter]: keyof UI
}
| undefined
} = {
[Entity.Spell]: {
[ModifiableParameter.CastingTime]:
" (you cannot use a modification on this spells casting time)",
[ModifiableParameter.Cost]:
" (you cannot use a modification on this spells cost)",
[ModifiableParameter.Range]:
" (you cannot use a modification on this spells range)",
},
[Entity.Ritual]: {
[ModifiableParameter.CastingTime]:
" (you cannot use a modification on this rituals ritual time)",
[ModifiableParameter.Cost]:
" (you cannot use a modification on this rituals cost)",
[ModifiableParameter.Range]:
" (you cannot use a modification on this rituals range)",
},
[Entity.LiturgicalChant]: {
[ModifiableParameter.CastingTime]:
" (you cannot use a modification on this chants liturgical time)",
[ModifiableParameter.Cost]:
" (you cannot use a modification on this chants cost)",
[ModifiableParameter.Range]:
" (you cannot use a modification on this chants range)",
},
[Entity.Ceremony]: {
[ModifiableParameter.CastingTime]:
" (you cannot use a modification on this ceremonys ceremonial time)",
[ModifiableParameter.Cost]:
" (you cannot use a modification on this ceremonys cost)",
[ModifiableParameter.Range]:
" (you cannot use a modification on this ceremonys range)",
},
[Entity.Cantrip]: undefined,
[Entity.Blessing]: undefined,
}
/**
* Returns the suffix for the text of a non-modifiable parameter that indicates
* that the parameter cannot be modified.
*/
export const getNonModifiableSuffixTranslation = (
locale: LocaleEnvironment,
entity: Entity,
param: ModifiableParameter,
responsiveTextSize: ResponsiveTextSize
): string =>
responsive(
responsiveTextSize,
() =>
mapNullable(
translationKeyForNonModifiableSuffix[entity]?.[param],
(key) => locale.translate(key)
) ?? "",
() => {
switch (entity) {
case Entity.Spell:
case Entity.Ritual:
case Entity.LiturgicalChant:
case Entity.Ceremony:
return locale.translate(" (cannot modify)")
case Entity.Cantrip:
case Entity.Blessing:
return ""
default:
return assertExhaustive(entity)
}
}
)