@optolith/entity-descriptions 0.1.1 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/lib/entities/combatTechnique.d.ts +4 -4
  3. package/lib/entities/combatTechnique.js +7 -7
  4. package/lib/entities/experienceLevel.d.ts +1 -1
  5. package/lib/entities/experienceLevel.js +3 -3
  6. package/lib/entities/focusRule.d.ts +8 -0
  7. package/lib/entities/focusRule.js +18 -0
  8. package/lib/entities/liturgicalChant.d.ts +6 -6
  9. package/lib/entities/liturgicalChant.js +27 -56
  10. package/lib/entities/optionalRule.d.ts +5 -0
  11. package/lib/entities/optionalRule.js +16 -0
  12. package/lib/entities/partial/rated/activatable/castingTime.d.ts +3 -15
  13. package/lib/entities/partial/rated/activatable/castingTime.js +19 -34
  14. package/lib/entities/partial/rated/activatable/checkResultBased.d.ts +1 -1
  15. package/lib/entities/partial/rated/activatable/checkResultBased.js +2 -2
  16. package/lib/entities/partial/rated/activatable/cost.d.ts +3 -19
  17. package/lib/entities/partial/rated/activatable/cost.js +82 -99
  18. package/lib/entities/partial/rated/activatable/duration.d.ts +5 -24
  19. package/lib/entities/partial/rated/activatable/duration.js +40 -57
  20. package/lib/entities/partial/rated/activatable/effect.d.ts +3 -3
  21. package/lib/entities/partial/rated/activatable/effect.js +7 -7
  22. package/lib/entities/partial/rated/activatable/index.d.ts +5 -33
  23. package/lib/entities/partial/rated/activatable/index.js +23 -41
  24. package/lib/entities/partial/rated/activatable/isMinimumMaximum.d.ts +20 -0
  25. package/lib/entities/partial/rated/activatable/isMinimumMaximum.js +19 -0
  26. package/lib/entities/partial/rated/activatable/nonModifiableSuffix.d.ts +16 -0
  27. package/lib/entities/partial/rated/activatable/nonModifiableSuffix.js +55 -0
  28. package/lib/entities/partial/rated/activatable/parensIf.d.ts +1 -1
  29. package/lib/entities/partial/rated/activatable/parensIf.js +3 -1
  30. package/lib/entities/partial/rated/activatable/range.d.ts +4 -20
  31. package/lib/entities/partial/rated/activatable/range.js +59 -100
  32. package/lib/entities/partial/rated/activatable/speed.d.ts +1 -1
  33. package/lib/entities/partial/rated/activatable/speed.js +1 -1
  34. package/lib/entities/partial/rated/activatable/targetCategory.d.ts +3 -7
  35. package/lib/entities/partial/rated/activatable/targetCategory.js +30 -26
  36. package/lib/entities/partial/rated/improvementCost.d.ts +2 -2
  37. package/lib/entities/partial/rated/skillCheck.d.ts +2 -2
  38. package/lib/entities/partial/responsiveText.d.ts +7 -4
  39. package/lib/entities/partial/responsiveText.js +8 -2
  40. package/lib/entities/partial/units/energy.d.ts +12 -0
  41. package/lib/entities/partial/units/energy.js +30 -0
  42. package/lib/entities/partial/units/length.d.ts +8 -0
  43. package/lib/entities/partial/units/length.js +12 -0
  44. package/lib/entities/partial/units/timeSpan.d.ts +8 -0
  45. package/lib/entities/partial/units/timeSpan.js +22 -0
  46. package/lib/entities/skill.d.ts +2 -2
  47. package/lib/entities/skill.js +3 -3
  48. package/lib/entities/spell.d.ts +6 -6
  49. package/lib/entities/spell.js +27 -56
  50. package/lib/helpers/locale.d.ts +8 -0
  51. package/lib/helpers/locale.js +1 -0
  52. package/lib/index.d.ts +45 -1
  53. package/lib/index.js +22 -1
  54. package/lib/references/index.d.ts +4 -0
  55. package/lib/references/index.js +46 -0
  56. package/lib/references/occurrence.d.ts +4 -0
  57. package/lib/references/occurrence.js +3 -0
  58. package/lib/references/page.d.ts +23 -0
  59. package/lib/references/page.js +61 -0
  60. package/lib/references/pageRange.d.ts +30 -0
  61. package/lib/references/pageRange.js +58 -0
  62. package/package.json +7 -3
  63. package/lib/entities/partial/rated/activatable/isMaximum.d.ts +0 -6
  64. package/lib/entities/partial/rated/activatable/isMaximum.js +0 -10
  65. package/lib/entities/partial/rated/activatable/modifiableParameter.d.ts +0 -8
  66. package/lib/entities/partial/rated/activatable/modifiableParameter.js +0 -9
  67. package/lib/entities/partial/rated/activatable/nonModifiable.d.ts +0 -9
  68. package/lib/entities/partial/rated/activatable/nonModifiable.js +0 -75
  69. package/lib/entities/partial/rated/activatable/units.d.ts +0 -13
  70. package/lib/entities/partial/rated/activatable/units.js +0 -53
  71. package/lib/libraryEntry.d.ts +0 -52
  72. package/lib/libraryEntry.js +0 -17
@@ -1,165 +1,148 @@
1
1
  import { mapNullable, mapNullableDefault } from "@optolith/helpers/nullable";
2
2
  import { assertExhaustive } from "@optolith/helpers/typeSafety";
3
- import { getResponsiveText, getResponsiveTextOptional, replaceTextIfRequested, responsive, } from "../../responsiveText.js";
3
+ import { appendNoteIfRequested, getResponsiveText, replaceTextIfRequested, responsive, } from "../../responsiveText.js";
4
+ import { formatEnergyByEntity } from "../../units/energy.js";
5
+ import { formatTimeSpan } from "../../units/timeSpan.js";
4
6
  import { MISSING_VALUE } from "../../unknown.js";
5
- import { ModifiableParameter } from "./modifiableParameter.js";
6
- import { getTextForNonModifiableSuffix } from "./nonModifiable.js";
7
- import { getModifiableBySpeed, Speed } from "./speed.js";
8
- import { formatCost, formatTimeSpan } from "./units.js";
9
- const getTextForModifiableOneTimeCost = (deps, value, env) => mapNullable(deps.getSkillModificationLevelById(value.initial_modification_level), (modificationLevel) => {
10
- const cost = getModifiableBySpeed(modificationLevel, env.speed, (config) => config.cost, (config) => config.cost);
11
- return replaceTextIfRequested(value.translations, formatCost(deps.translate, env.entity, cost), deps.translateMap, env.responsiveText);
7
+ import { wrapIfMinimum } from "./isMinimumMaximum.js";
8
+ import { getNonModifiableSuffixTranslation, ModifiableParameter, } from "./nonModifiableSuffix.js";
9
+ import { getModifiableBySpeed } from "./speed.js";
10
+ const getModifiableOneTimeCostTranslation = (getSkillModificationLevelById, locale, responsiveTextSize, entity, speed, value) => mapNullable(getSkillModificationLevelById(value.initial_modification_level), (modificationLevel) => {
11
+ const cost = getModifiableBySpeed((config) => config.cost, (config) => config.cost, speed, modificationLevel);
12
+ return replaceTextIfRequested("replacement", value.translations, locale.translateMap, responsiveTextSize, formatEnergyByEntity(locale, entity, cost));
12
13
  }) ?? MISSING_VALUE;
13
- const getMinimumText = (isMinimum, translate, responsiveText) => isMinimum !== true
14
- ? ""
15
- : responsive(responsiveText, () => translate("at least "), () => translate("min. "));
16
- const getTextForNonModifiableOneTimeCostPerCountable = (deps, value, env) => mapNullable(value, (perCountable) => {
17
- const countableText = responsive(env.responsiveText, (entity) => deps.translate(" per {0}", entity), (entity) => deps.translate("/{0}", entity), getResponsiveText(deps.translateMap(perCountable.translations)?.countable, env.responsiveText));
18
- const minimumTotalText = mapNullable(perCountable.minimum_total, (minimumTotal) => deps.translate(", minimum of {0}", deps.formatCost(minimumTotal))) ?? "";
14
+ const getNonModifiableOneTimeCostPerCountableTranslation = (formatCost, locale, responsiveTextSize, value) => mapNullable(value, (perCountable) => {
15
+ const entity = getResponsiveText(locale.translateMap(perCountable.translations)?.countable, responsiveTextSize);
16
+ const countableText = responsive(responsiveTextSize, () => locale.translate(" per {0}", entity), () => locale.translate("/{0}", entity));
17
+ const minimumTotalText = mapNullable(perCountable.minimum_total, (minimumTotal) => locale.translate(", minimum of {0}", formatCost(minimumTotal))) ?? "";
19
18
  return countableText + minimumTotalText;
20
19
  }) ?? "";
21
- const getTextForPermanentValue = (value, responsiveText, translate) => value === undefined
20
+ const getPermanentValueTranslation = (locale, responsiveTextSize, permanentValue) => permanentValue === undefined
22
21
  ? ""
23
- : responsive(responsiveText, (perm) => translate(", {0} of which are permanent", perm), (perm) => translate(" ({0} perm.)", perm), value);
24
- const getTextForNonModifiableOneTimeCost = (deps, value, env) => {
25
- const isMinimum = getMinimumText(value.is_minimum, deps.translate, env.responsiveText);
26
- const formatCostP = formatCost.bind(this, deps.translate, env.entity);
27
- const per = getTextForNonModifiableOneTimeCostPerCountable({ ...deps, formatCost: formatCostP }, value.per, env);
28
- const permanent = getTextForPermanentValue(value.permanent_value, env.responsiveText, deps.translate);
29
- const translation = deps.translateMap(value.translations);
30
- const note = mapNullableDefault(translation === undefined || translation.note === undefined
31
- ? undefined
32
- : getResponsiveTextOptional(translation.note, env.responsiveText), (noteIfPresent) => ` (${noteIfPresent})`, "");
33
- const cannotModify = getTextForNonModifiableSuffix(deps.translate, env.entity, ModifiableParameter.Cost, env.responsiveText);
34
- return (isMinimum + formatCostP(value.value) + per + permanent + note + cannotModify);
22
+ : responsive(responsiveTextSize, () => locale.translate(", {0} of which are permanent", permanentValue), () => locale.translate(" ({0} perm.)", permanentValue));
23
+ const getNonModifiableOneTimeCostTranslation = (locale, entity, responsiveTextSize, value) => {
24
+ const formatCostP = formatEnergyByEntity.bind(this, locale, entity);
25
+ const perCountable = getNonModifiableOneTimeCostPerCountableTranslation(formatCostP, locale, responsiveTextSize, value.per);
26
+ const permanentValue = getPermanentValueTranslation(locale, responsiveTextSize, value.permanent_value);
27
+ const costWrappedIfMinimum = wrapIfMinimum(locale, responsiveTextSize, value.is_minimum, formatCostP(value.value) + perCountable + permanentValue);
28
+ const withNote = appendNoteIfRequested("note", value.translations, locale.translateMap, responsiveTextSize, costWrappedIfMinimum);
29
+ const cannotModify = getNonModifiableSuffixTranslation(locale, entity, ModifiableParameter.Cost, responsiveTextSize);
30
+ return withNote + cannotModify;
35
31
  };
36
- const getTextForIndefiniteOneTimeCost = (deps, value, env) => (getResponsiveText(deps.translateMap(value.translations)?.description, env.responsiveText) ?? "") +
37
- getTextForNonModifiableSuffix(deps.translate, env.entity, ModifiableParameter.Cost, env.responsiveText);
38
- const getTextForSingleOneTimeCost = (deps, value, env) => {
32
+ const getIndefiniteOneTimeCostTranslation = (locale, entity, responsiveTextSize, value) => getResponsiveText(locale.translateMap(value.translations)?.description, responsiveTextSize) +
33
+ getNonModifiableSuffixTranslation(locale, entity, ModifiableParameter.Cost, responsiveTextSize);
34
+ const getSingleOneTimeCostTranslation = (getSkillModificationLevelById, locale, speed, entity, responsiveTextSize, value) => {
39
35
  switch (value.tag) {
40
36
  case "Modifiable":
41
- return getTextForModifiableOneTimeCost(deps, value.modifiable, env);
37
+ return getModifiableOneTimeCostTranslation(getSkillModificationLevelById, locale, responsiveTextSize, entity, speed, value.modifiable);
42
38
  case "NonModifiable":
43
- return getTextForNonModifiableOneTimeCost(deps, value.non_modifiable, env);
39
+ return getNonModifiableOneTimeCostTranslation(locale, entity, responsiveTextSize, value.non_modifiable);
44
40
  case "Indefinite":
45
- return getTextForIndefiniteOneTimeCost(deps, value.indefinite, env);
41
+ return getIndefiniteOneTimeCostTranslation(locale, entity, responsiveTextSize, value.indefinite);
46
42
  default:
47
43
  return assertExhaustive(value);
48
44
  }
49
45
  };
50
- const getTextForMultipleOneTimeCosts = (deps, value, type, env) => {
46
+ const getMultipleOneTimeCostsTranslation = (type, getSkillModificationLevelById, locale, speed, entity, responsiveTextSize, value) => {
51
47
  const modifiable = !value.every((part) => part.tag === "Modifiable")
52
- ? getTextForNonModifiableSuffix(deps.translate, env.entity, ModifiableParameter.Cost, env.responsiveText)
48
+ ? getNonModifiableSuffixTranslation(locale, entity, ModifiableParameter.Cost, responsiveTextSize)
53
49
  : "";
54
50
  return (value
55
- .map((part) => getTextForSingleOneTimeCost(deps, part, env))
51
+ .map((part) => getSingleOneTimeCostTranslation(getSkillModificationLevelById, locale, speed, entity, responsiveTextSize, part))
56
52
  .join((() => {
57
53
  switch (type) {
58
54
  case "conjunction":
59
- return responsive(env.responsiveText, () => deps.translate(" and "), () => deps.translate(" + "));
55
+ return responsive(responsiveTextSize, () => locale.translate(" and "), () => locale.translate(" + "));
60
56
  case "disjunction":
61
- return responsive(env.responsiveText, () => deps.translate(" or "), () => deps.translate(" / "));
57
+ return responsive(responsiveTextSize, () => locale.translate(" or "), () => locale.translate(" / "));
62
58
  default:
63
59
  return assertExhaustive(type);
64
60
  }
65
61
  })()) + modifiable);
66
62
  };
67
- const getTextForCostMap = (deps, value, env) => {
68
- const translation = deps.translateMap(value.translations);
63
+ const getCostMapTranslation = (locale, entity, responsiveTextSize, value) => {
64
+ const translation = locale.translateMap(value.translations);
69
65
  if (value.translations !== undefined && translation === undefined) {
70
66
  return MISSING_VALUE;
71
67
  }
72
68
  if (translation?.replacement !== undefined) {
73
69
  return translation.replacement;
74
70
  }
75
- const costs = value.options.map((option) => option.value).join("/");
76
71
  const labels = value.options
77
- .map((option) => deps.translateMap(option.translations)?.label ?? MISSING_VALUE)
72
+ .map((option) => locale.translateMap(option.translations)?.label ?? MISSING_VALUE)
78
73
  .join("/");
74
+ const costs = value.options.map((option) => option.value).join("/");
79
75
  const permanentCosts = value.options.every((option) => option.permanent_value !== undefined)
80
76
  ? value.options.map((option) => option.permanent_value).join("/")
81
77
  : undefined;
82
- const formatCostP = formatCost.bind(this, deps.translate, env.entity);
83
- const notModifiable = getTextForNonModifiableSuffix(deps.translate, env.entity, ModifiableParameter.Cost, env.responsiveText);
78
+ const formatCostP = formatEnergyByEntity.bind(this, locale, entity);
79
+ const notModifiable = getNonModifiableSuffixTranslation(locale, entity, ModifiableParameter.Cost, responsiveTextSize);
84
80
  return (formatCostP(costs) +
85
- deps.translate(" for ") +
81
+ locale.translate(" for ") +
86
82
  mapNullableDefault(translation?.list_prepend, (listPrepend) => `${listPrepend} `, "") +
87
83
  labels +
88
84
  (translation?.list_append ?? "") +
89
85
  (permanentCosts !== undefined
90
- ? deps.translate(", {0} of which are permanent", formatCostP(permanentCosts))
86
+ ? locale.translate(", {0} of which are permanent", formatCostP(permanentCosts))
91
87
  : "") +
92
88
  notModifiable);
93
89
  };
94
90
  /**
95
91
  * Returns the text for the cost of a one-time activatable skill.
96
92
  */
97
- export const getTextForOneTimeCost = (deps, value, env) => {
93
+ export const getOneTimeCostTranslation = (getSkillModificationLevelById, locale, speed, entity, responsiveTextSize, value) => {
98
94
  switch (value.tag) {
99
95
  case "Single":
100
- return getTextForSingleOneTimeCost(deps, value.single, env);
96
+ return getSingleOneTimeCostTranslation(getSkillModificationLevelById, locale, speed, entity, responsiveTextSize, value.single);
101
97
  case "Conjunction":
102
- return getTextForMultipleOneTimeCosts(deps, value.conjunction, "conjunction", env);
98
+ return getMultipleOneTimeCostsTranslation("conjunction", getSkillModificationLevelById, locale, speed, entity, responsiveTextSize, value.conjunction);
103
99
  case "Disjunction":
104
- return getTextForMultipleOneTimeCosts(deps, value.disjunction, "disjunction", env);
100
+ return getMultipleOneTimeCostsTranslation("disjunction", getSkillModificationLevelById, locale, speed, entity, responsiveTextSize, value.disjunction);
105
101
  case "Map":
106
- return getTextForCostMap(deps, value.map, env);
102
+ return getCostMapTranslation(locale, entity, responsiveTextSize, value.map);
107
103
  default:
108
104
  return assertExhaustive(value);
109
105
  }
110
106
  };
107
+ const getModifiableSustainedCostTranslation = (getSkillModificationLevelById, locale, speed, entity, responsiveTextSize, value) => mapNullable(getSkillModificationLevelById(value.initial_modification_level), (modificationLevel) => {
108
+ const cost = getModifiableBySpeed((config) => config.cost, (config) => config.cost, speed, modificationLevel);
109
+ const formatCostP = formatEnergyByEntity.bind(this, locale, entity);
110
+ const interval = formatTimeSpan(locale, responsiveTextSize, value.interval.unit, value.interval.value);
111
+ return responsive(responsiveTextSize, () => `${formatCostP(cost) + locale.translate(" (casting)")} + ${formatCostP(cost / 2) + locale.translate(" per {0}", interval)}`, () => `${formatCostP(cost)} + ${formatCostP(cost / 2) + locale.translate("/{0}", interval)}`);
112
+ }) ?? MISSING_VALUE;
113
+ const getNonModifiableSustainedCostTranslation = (locale, entity, responsiveTextSize, value) => {
114
+ const formatCostP = formatEnergyByEntity.bind(this, locale, entity);
115
+ const per = (() => {
116
+ if (value.per === undefined) {
117
+ return { countable: "", minimumTotal: "" };
118
+ }
119
+ const countable = responsive(responsiveTextSize, (entity) => locale.translate(" per {0}", entity), (entity) => locale.translate("/{0}", entity), getResponsiveText(locale.translateMap(value.per.translations)?.countable, responsiveTextSize));
120
+ const minimumTotal = value.per.minimum_total !== undefined
121
+ ? locale.translate(", minimum of {0}", formatCostP(value.per.minimum_total))
122
+ : "";
123
+ return { countable, minimumTotal };
124
+ })();
125
+ const interval = formatTimeSpan(locale, responsiveTextSize, value.interval.unit, value.interval.value);
126
+ const cost = responsive(responsiveTextSize, () => `${formatCostP(value.value) + locale.translate(" (casting)")} + ${(value.is_minimum === true
127
+ ? locale.translate("half of the activation cost")
128
+ : formatCostP(value.value / 2)) +
129
+ per.countable +
130
+ locale.translate(" per {0}", interval)}`, () => `${formatCostP(value.value)} + ${(value.is_minimum === true ? "50%" : formatCostP(value.value / 2)) +
131
+ per.countable +
132
+ locale.translate("/{0}", interval)}`) + per.minimumTotal;
133
+ const costWrappedIfMinimum = wrapIfMinimum(locale, responsiveTextSize, value.is_minimum, cost);
134
+ return (costWrappedIfMinimum +
135
+ getNonModifiableSuffixTranslation(locale, entity, ModifiableParameter.Cost, responsiveTextSize));
136
+ };
111
137
  /**
112
138
  * Returns the text for the cost of a sustained activatable skill.
113
139
  */
114
- export const getTextForSustainedCost = (deps, value, env) => {
140
+ export const getSustainedCostTranslation = (getSkillModificationLevelById, locale, speed, entity, responsiveTextSize, value) => {
115
141
  switch (value.tag) {
116
- case "Modifiable": {
117
- const modificationLevel = deps.getSkillModificationLevelById(value.modifiable.initial_modification_level);
118
- if (modificationLevel === undefined) {
119
- return MISSING_VALUE;
120
- }
121
- const cost = (() => {
122
- switch (env.speed) {
123
- case Speed.Fast:
124
- return modificationLevel.fast.cost;
125
- case Speed.Slow:
126
- return modificationLevel.slow.cost;
127
- default:
128
- return assertExhaustive(env.speed);
129
- }
130
- })();
131
- const formatCostP = formatCost.bind(this, deps.translate, env.entity);
132
- const interval = formatTimeSpan(deps.translate, env.responsiveText, value.modifiable.interval.unit, value.modifiable.interval.value);
133
- return responsive(env.responsiveText, () => `${formatCostP(cost) + deps.translate(" (casting)")} + ${formatCostP(cost / 2) + deps.translate(" per {0}", interval)}`, () => `${formatCostP(cost)} + ${formatCostP(cost / 2) + deps.translate("/{0}", interval)}`);
134
- }
135
- case "NonModifiable": {
136
- const isMinimum = getMinimumText(value.non_modifiable.is_minimum, deps.translate, env.responsiveText);
137
- const cost = value.non_modifiable.value;
138
- const formatCostP = formatCost.bind(this, deps.translate, env.entity);
139
- const per = (() => {
140
- if (value.non_modifiable.per === undefined) {
141
- return { countable: "", minimumTotal: "" };
142
- }
143
- const countable = responsive(env.responsiveText, (entity) => deps.translate(" per {0}", entity), (entity) => deps.translate("/{0}", entity), getResponsiveText(deps.translateMap(value.non_modifiable.per.translations)?.countable, env.responsiveText));
144
- const minimumTotal = value.non_modifiable.per.minimum_total !== undefined
145
- ? deps.translate(", minimum of {0}", formatCostP(value.non_modifiable.per.minimum_total))
146
- : "";
147
- return { countable, minimumTotal };
148
- })();
149
- const interval = formatTimeSpan(deps.translate, env.responsiveText, value.non_modifiable.interval.unit, value.non_modifiable.interval.value);
150
- return (isMinimum +
151
- responsive(env.responsiveText, () => `${formatCostP(cost) + deps.translate(" (casting)")} + ${(value.non_modifiable.is_minimum === true
152
- ? deps.translate("half of the activation cost")
153
- : formatCostP(cost / 2)) +
154
- per.countable +
155
- deps.translate(" per {0}", interval)}`, () => `${formatCostP(cost)} + ${(value.non_modifiable.is_minimum === true
156
- ? "50%"
157
- : formatCostP(cost / 2)) +
158
- per.countable +
159
- deps.translate("/{0}", interval)}`) +
160
- per.minimumTotal +
161
- getTextForNonModifiableSuffix(deps.translate, env.entity, ModifiableParameter.Cost, env.responsiveText));
162
- }
142
+ case "Modifiable":
143
+ return getModifiableSustainedCostTranslation(getSkillModificationLevelById, locale, speed, entity, responsiveTextSize, value.modifiable);
144
+ case "NonModifiable":
145
+ return getNonModifiableSustainedCostTranslation(locale, entity, responsiveTextSize, value.non_modifiable);
163
146
  default:
164
147
  return assertExhaustive(value);
165
148
  }
@@ -1,40 +1,21 @@
1
1
  import { DurationForOneTime, DurationForSustained } from "optolith-database-schema/types/_ActivatableSkillDuration";
2
2
  import { BlessingDuration } from "optolith-database-schema/types/Blessing";
3
3
  import { CantripDuration } from "optolith-database-schema/types/Cantrip";
4
- import { Translate, TranslateMap } from "../../../../helpers/translate.js";
4
+ import { LocaleEnvironment } from "../../../../helpers/locale.js";
5
5
  import { ResponsiveTextSize } from "../../responsiveText.js";
6
6
  /**
7
7
  * Returns the text for the duration of a one-time activatable skill.
8
8
  */
9
- export declare const getTextForDurationForOneTime: (deps: {
10
- translate: Translate;
11
- translateMap: TranslateMap;
12
- }, value: DurationForOneTime, env: {
13
- responsiveText: ResponsiveTextSize;
14
- }) => string;
9
+ export declare const getDurationForOneTimeTranslation: (locale: LocaleEnvironment, responsiveTextSize: ResponsiveTextSize, value: DurationForOneTime) => string;
15
10
  /**
16
11
  * Returns the text for the duration of a sustained activatable skill.
17
12
  */
18
- export declare const getTextForDurationForSustained: (deps: {
19
- translate: Translate;
20
- }, value: DurationForSustained | undefined, env: {
21
- responsiveText: ResponsiveTextSize;
22
- }) => string;
13
+ export declare const getDurationForSustainedTranslation: (locale: LocaleEnvironment, responsiveTextSize: ResponsiveTextSize, value: DurationForSustained | undefined) => string;
23
14
  /**
24
15
  * Returns the text for the duration of a cantrip.
25
16
  */
26
- export declare const getTextForCantripDuration: (deps: {
27
- translate: Translate;
28
- translateMap: TranslateMap;
29
- }, value: CantripDuration, env: {
30
- responsiveText: ResponsiveTextSize;
31
- }) => string;
17
+ export declare const getDurationTranslationForCantrip: (locale: LocaleEnvironment, responsiveTextSize: ResponsiveTextSize, value: CantripDuration) => string;
32
18
  /**
33
19
  * Returns the text for the duration of a blessing.
34
20
  */
35
- export declare const getTextForBlessingDuration: (deps: {
36
- translate: Translate;
37
- translateMap: TranslateMap;
38
- }, value: BlessingDuration, env: {
39
- responsiveText: ResponsiveTextSize;
40
- }) => string;
21
+ export declare const getDurationTranslationForBlessing: (locale: LocaleEnvironment, responsiveTextSize: ResponsiveTextSize, value: BlessingDuration) => string;
@@ -1,58 +1,43 @@
1
- import { mapNullableDefault } from "@optolith/helpers/nullable";
1
+ import { mapNullable } from "@optolith/helpers/nullable";
2
2
  import { assertExhaustive } from "@optolith/helpers/typeSafety";
3
3
  import { getResponsiveText, replaceTextIfRequested, responsive, } from "../../responsiveText.js";
4
- import { getTextForCheckResultBased } from "./checkResultBased.js";
5
- import { getTextForIsMaximum } from "./isMaximum.js";
6
- import { formatTimeSpan } from "./units.js";
7
- const getTextForImmediateDuration = (deps, value, env) => {
8
- const text = deps.translate("Immediate") +
9
- mapNullableDefault(value.maximum, (max) => {
10
- const maxText = formatTimeSpan(deps.translate, env.responsiveText, max.unit, max.value);
11
- return responsive(env.responsiveText, () => deps.translate(" (no more than {0})", maxText), () => deps.translate(" (max. {0})", maxText));
12
- }, "");
13
- return replaceTextIfRequested(value.translations, text, deps.translateMap, env.responsiveText);
4
+ import { formatTimeSpan } from "../../units/timeSpan.js";
5
+ import { getCheckResultBasedValueTranslation } from "./checkResultBased.js";
6
+ import { wrapAsMaximum, wrapIfMaximum } from "./isMinimumMaximum.js";
7
+ import { appendInParensIfNotEmpty } from "./parensIf.js";
8
+ const getImmediateDurationTranslation = (locale, responsiveTextSize, value) => {
9
+ const text = appendInParensIfNotEmpty(mapNullable(value.maximum, (max) => {
10
+ const maxText = formatTimeSpan(locale, responsiveTextSize, max.unit, max.value);
11
+ return responsive(responsiveTextSize, () => locale.translate("no more than {0}", maxText), () => locale.translate("max. {0}", maxText));
12
+ }), locale.translate("Immediate"));
13
+ return replaceTextIfRequested("replacement", value.translations, locale.translateMap, responsiveTextSize, text);
14
14
  };
15
- const getTextForPermanentDuration = (deps, value, env) => {
16
- const translation = deps.translateMap(value.translations);
17
- const text = deps.translate("Permanent");
18
- if (translation?.replacement !== undefined) {
19
- return getResponsiveText(translation.replacement, env.responsiveText).replace("$1", text);
20
- }
21
- else {
22
- return text;
23
- }
24
- };
25
- const getTextForFixedDuration = (deps, value, env) => {
26
- const isMaximum = getTextForIsMaximum(value.is_maximum, deps.translate, env.responsiveText);
27
- const unitValue = formatTimeSpan(deps.translate, env.responsiveText, value.unit, value.value);
28
- const text = isMaximum + unitValue;
29
- const translation = deps.translateMap(value.translations);
30
- if (translation?.replacement !== undefined) {
31
- return getResponsiveText(translation.replacement, env.responsiveText).replace("$1", text);
32
- }
33
- else {
34
- return text;
35
- }
15
+ const getPermanentDurationTranslation = (locale, responsiveTextSize, value) => replaceTextIfRequested("replacement", value.translations, locale.translateMap, responsiveTextSize, locale.translate("Permanent"));
16
+ const getFixedDurationTranslation = (locale, responsiveTextSize, value) => {
17
+ const duration = formatTimeSpan(locale, responsiveTextSize, value.unit, value.value);
18
+ const durationWrappedIfMaximum = wrapIfMaximum(locale, responsiveTextSize, value.is_maximum, duration);
19
+ return replaceTextIfRequested("replacement", value.translations, locale.translateMap, responsiveTextSize, durationWrappedIfMaximum);
36
20
  };
37
- const getTextForCheckResultBasedDuration = (deps, value, env) => {
38
- const isMaximum = getTextForIsMaximum(value.is_maximum, deps.translate, env.responsiveText);
39
- return formatTimeSpan(deps.translate, env.responsiveText, value.unit, isMaximum + getTextForCheckResultBased(value, deps.translate));
21
+ const getCheckResultBasedDurationTranslation = (locale, responsiveTextSize, value) => {
22
+ const duration = formatTimeSpan(locale, responsiveTextSize, value.unit, getCheckResultBasedValueTranslation(locale.translate, value));
23
+ return wrapIfMaximum(locale, responsiveTextSize, value.is_maximum, duration);
40
24
  };
25
+ const getIndefiniteDurationTranslation = (locale, responsiveTextSize, value) => getResponsiveText(locale.translateMap(value.translations)?.description, responsiveTextSize);
41
26
  /**
42
27
  * Returns the text for the duration of a one-time activatable skill.
43
28
  */
44
- export const getTextForDurationForOneTime = (deps, value, env) => {
29
+ export const getDurationForOneTimeTranslation = (locale, responsiveTextSize, value) => {
45
30
  switch (value.tag) {
46
31
  case "Immediate":
47
- return getTextForImmediateDuration(deps, value.immediate, env);
32
+ return getImmediateDurationTranslation(locale, responsiveTextSize, value.immediate);
48
33
  case "Permanent":
49
- return getTextForPermanentDuration(deps, value.permanent, env);
34
+ return getPermanentDurationTranslation(locale, responsiveTextSize, value.permanent);
50
35
  case "Fixed":
51
- return getTextForFixedDuration(deps, value.fixed, env);
36
+ return getFixedDurationTranslation(locale, responsiveTextSize, value.fixed);
52
37
  case "CheckResultBased":
53
- return getTextForCheckResultBasedDuration(deps, value.check_result_based, env);
38
+ return getCheckResultBasedDurationTranslation(locale, responsiveTextSize, value.check_result_based);
54
39
  case "Indefinite":
55
- return getResponsiveText(deps.translateMap(value.indefinite.translations)?.description, env.responsiveText);
40
+ return getIndefiniteDurationTranslation(locale, responsiveTextSize, value.indefinite);
56
41
  default:
57
42
  return assertExhaustive(value);
58
43
  }
@@ -60,25 +45,23 @@ export const getTextForDurationForOneTime = (deps, value, env) => {
60
45
  /**
61
46
  * Returns the text for the duration of a sustained activatable skill.
62
47
  */
63
- export const getTextForDurationForSustained = (deps, value, env) => value === undefined
64
- ? responsive(env.responsiveText, () => deps.translate("Sustained"), () => deps.translate("(S)"))
65
- : responsive(env.responsiveText, () => deps.translate("no more than "), () => deps.translate("max. ")) +
66
- formatTimeSpan(deps.translate, env.responsiveText, value.maximum.unit, value.maximum.value);
48
+ export const getDurationForSustainedTranslation = (locale, responsiveTextSize, value) => value === undefined
49
+ ? responsive(responsiveTextSize, () => locale.translate("Sustained"), () => locale.translate("(S)"))
50
+ : wrapAsMaximum(locale, responsiveTextSize, formatTimeSpan(locale, responsiveTextSize, value.maximum.unit, value.maximum.value));
51
+ const getDurationDuringLovemakingTranslation = (locale, responsiveTextSize, value) => formatTimeSpan(locale, responsiveTextSize, value.unit, value.value);
67
52
  /**
68
53
  * Returns the text for the duration of a cantrip.
69
54
  */
70
- export const getTextForCantripDuration = (deps, value, env) => {
55
+ export const getDurationTranslationForCantrip = (locale, responsiveTextSize, value) => {
71
56
  switch (value.tag) {
72
57
  case "Immediate":
73
- return getTextForImmediateDuration(deps, value.immediate, env);
58
+ return getImmediateDurationTranslation(locale, responsiveTextSize, value.immediate);
74
59
  case "Fixed":
75
- return getTextForFixedDuration(deps, value.fixed, env);
60
+ return getFixedDurationTranslation(locale, responsiveTextSize, value.fixed);
76
61
  case "Indefinite":
77
- return getResponsiveText(deps.translateMap(value.indefinite.translations)?.description, env.responsiveText);
78
- case "DuringLovemaking": {
79
- const { value: lovemakingValue, unit: lovemakingUnit } = value.during_lovemaking;
80
- return formatTimeSpan(deps.translate, env.responsiveText, lovemakingUnit, lovemakingValue);
81
- }
62
+ return getIndefiniteDurationTranslation(locale, responsiveTextSize, value.indefinite);
63
+ case "DuringLovemaking":
64
+ return getDurationDuringLovemakingTranslation(locale, responsiveTextSize, value.during_lovemaking);
82
65
  default:
83
66
  return assertExhaustive(value);
84
67
  }
@@ -86,14 +69,14 @@ export const getTextForCantripDuration = (deps, value, env) => {
86
69
  /**
87
70
  * Returns the text for the duration of a blessing.
88
71
  */
89
- export const getTextForBlessingDuration = (deps, value, env) => {
72
+ export const getDurationTranslationForBlessing = (locale, responsiveTextSize, value) => {
90
73
  switch (value.tag) {
91
74
  case "Immediate":
92
- return getTextForImmediateDuration(deps, value.immediate, env);
75
+ return getImmediateDurationTranslation(locale, responsiveTextSize, value.immediate);
93
76
  case "Fixed":
94
- return getTextForFixedDuration(deps, value.fixed, env);
77
+ return getFixedDurationTranslation(locale, responsiveTextSize, value.fixed);
95
78
  case "Indefinite":
96
- return getResponsiveText(deps.translateMap(value.indefinite.translations)?.description, env.responsiveText);
79
+ return getIndefiniteDurationTranslation(locale, responsiveTextSize, value.indefinite);
97
80
  default:
98
81
  return assertExhaustive(value);
99
82
  }
@@ -1,7 +1,7 @@
1
1
  import { Effect } from "optolith-database-schema/types/_ActivatableSkillEffect";
2
- import { Translate } from "../../../../helpers/translate.js";
3
- import { LibraryEntryContent } from "../../../../libraryEntry.js";
2
+ import { LocaleEnvironment } from "../../../../helpers/locale.js";
3
+ import { EntityDescriptionSection } from "../../../../index.js";
4
4
  /**
5
5
  * Gets the text for the effect of an activatable skill.
6
6
  */
7
- export declare const getTextForEffect: (effect: Effect, translate: Translate) => LibraryEntryContent[];
7
+ export declare const getTextForEffect: (locale: LocaleEnvironment, effect: Effect) => EntityDescriptionSection[];
@@ -1,14 +1,14 @@
1
1
  import { filterNonNullable } from "@optolith/helpers/array";
2
2
  import { mapNullable } from "@optolith/helpers/nullable";
3
3
  import { assertExhaustive } from "@optolith/helpers/typeSafety";
4
- const getContentPartsForQualityLevels = (source, getQualityLevelString, translate) => filterNonNullable([
4
+ const getContentPartsForQualityLevels = (getQualityLevelString, locale, source) => filterNonNullable([
5
5
  {
6
- label: translate("Effect"),
6
+ label: locale.translate("Effect"),
7
7
  value: source.text_before,
8
8
  },
9
9
  ...source.quality_levels.map((text, index) => ({
10
10
  value: text,
11
- label: translate("QL {0}", getQualityLevelString(index)),
11
+ label: locale.translate("QL {0}", getQualityLevelString(index)),
12
12
  })),
13
13
  mapNullable(source.text_after, (textAfter) => ({
14
14
  value: textAfter,
@@ -18,19 +18,19 @@ const getContentPartsForQualityLevels = (source, getQualityLevelString, translat
18
18
  /**
19
19
  * Gets the text for the effect of an activatable skill.
20
20
  */
21
- export const getTextForEffect = (effect, translate) => {
21
+ export const getTextForEffect = (locale, effect) => {
22
22
  switch (effect.tag) {
23
23
  case "Plain":
24
24
  return [
25
25
  {
26
- label: translate("Effect"),
26
+ label: locale.translate("Effect"),
27
27
  value: effect.plain.text,
28
28
  },
29
29
  ];
30
30
  case "ForEachQualityLevel":
31
- return getContentPartsForQualityLevels(effect.for_each_quality_level, (index) => index + 1, translate);
31
+ return getContentPartsForQualityLevels((index) => index + 1, locale, effect.for_each_quality_level);
32
32
  case "ForEachTwoQualityLevels":
33
- return getContentPartsForQualityLevels(effect.for_each_two_quality_levels, (index) => `${index * 2 + 1}–${index * 2 + 2}`, translate);
33
+ return getContentPartsForQualityLevels((index) => `${index * 2 + 1}–${index * 2 + 2}`, locale, effect.for_each_two_quality_levels);
34
34
  default:
35
35
  return assertExhaustive(effect);
36
36
  }
@@ -1,19 +1,12 @@
1
1
  import { FastOneTimePerformanceParameters, FastSustainedPerformanceParameters, SlowOneTimePerformanceParameters, SlowSustainedPerformanceParameters } from "optolith-database-schema/types/_ActivatableSkill";
2
2
  import { GetById } from "../../../../helpers/getTypes.js";
3
- import { Translate, TranslateMap } from "../../../../helpers/translate.js";
3
+ import { LocaleEnvironment } from "../../../../helpers/locale.js";
4
4
  import { ResponsiveTextSize } from "../../responsiveText.js";
5
5
  import { Entity } from "./entity.js";
6
6
  /**
7
7
  * Get the texts for all fast one-time performance parameters.
8
8
  */
9
- export declare const getTextForFastOneTimePerformanceParameters: (deps: {
10
- getSkillModificationLevelById: GetById.Static.SkillModificationLevel;
11
- translate: Translate;
12
- translateMap: TranslateMap;
13
- }, value: FastOneTimePerformanceParameters, env: {
14
- entity: Entity;
15
- responsiveText: ResponsiveTextSize;
16
- }) => {
9
+ export declare const getFastOneTimePerformanceParametersTranslations: (getSkillModificationLevelById: GetById.Static.SkillModificationLevel, locale: LocaleEnvironment, entity: Entity, responsiveTextSize: ResponsiveTextSize, value: FastOneTimePerformanceParameters) => {
17
10
  castingTime: string;
18
11
  cost: string;
19
12
  range: string;
@@ -22,14 +15,7 @@ export declare const getTextForFastOneTimePerformanceParameters: (deps: {
22
15
  /**
23
16
  * Get the texts for all fast sustained performance parameters.
24
17
  */
25
- export declare const getTextForFastSustainedPerformanceParameters: (deps: {
26
- getSkillModificationLevelById: GetById.Static.SkillModificationLevel;
27
- translate: Translate;
28
- translateMap: TranslateMap;
29
- }, value: FastSustainedPerformanceParameters, env: {
30
- entity: Entity;
31
- responsiveText: ResponsiveTextSize;
32
- }) => {
18
+ export declare const getFastSustainedPerformanceParametersTranslations: (getSkillModificationLevelById: GetById.Static.SkillModificationLevel, locale: LocaleEnvironment, entity: Entity, responsiveTextSize: ResponsiveTextSize, value: FastSustainedPerformanceParameters) => {
33
19
  castingTime: string;
34
20
  cost: string;
35
21
  range: string;
@@ -38,14 +24,7 @@ export declare const getTextForFastSustainedPerformanceParameters: (deps: {
38
24
  /**
39
25
  * Get the texts for all slow one-time performance parameters.
40
26
  */
41
- export declare const getTextForSlowOneTimePerformanceParameters: (deps: {
42
- getSkillModificationLevelById: GetById.Static.SkillModificationLevel;
43
- translate: Translate;
44
- translateMap: TranslateMap;
45
- }, value: SlowOneTimePerformanceParameters, env: {
46
- entity: Entity;
47
- responsiveText: ResponsiveTextSize;
48
- }) => {
27
+ export declare const getSlowOneTimePerformanceParametersTranslations: (getSkillModificationLevelById: GetById.Static.SkillModificationLevel, locale: LocaleEnvironment, entity: Entity, responsiveTextSize: ResponsiveTextSize, value: SlowOneTimePerformanceParameters) => {
49
28
  castingTime: string;
50
29
  cost: string;
51
30
  range: string;
@@ -54,14 +33,7 @@ export declare const getTextForSlowOneTimePerformanceParameters: (deps: {
54
33
  /**
55
34
  * Get the texts for all slow sustained performance parameters.
56
35
  */
57
- export declare const getTextForSlowSustainedPerformanceParameters: (deps: {
58
- getSkillModificationLevelById: GetById.Static.SkillModificationLevel;
59
- translate: Translate;
60
- translateMap: TranslateMap;
61
- }, value: SlowSustainedPerformanceParameters, env: {
62
- entity: Entity;
63
- responsiveText: ResponsiveTextSize;
64
- }) => {
36
+ export declare const getSlowSustainedPerformanceParametersTranslations: (getSkillModificationLevelById: GetById.Static.SkillModificationLevel, locale: LocaleEnvironment, entity: Entity, responsiveTextSize: ResponsiveTextSize, value: SlowSustainedPerformanceParameters) => {
65
37
  castingTime: string;
66
38
  cost: string;
67
39
  range: string;