@optolith/entity-descriptions 0.2.1 → 0.3.2

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 (191) hide show
  1. package/CHANGELOG.md +65 -0
  2. package/lib/creator.d.ts +32 -0
  3. package/lib/creator.js +72 -0
  4. package/lib/entities/activatable.d.ts +52 -0
  5. package/lib/entities/activatable.js +609 -0
  6. package/lib/entities/alternativeRule.d.ts +7 -0
  7. package/lib/entities/alternativeRule.js +21 -0
  8. package/lib/entities/attribute.d.ts +6 -0
  9. package/lib/entities/attribute.js +15 -0
  10. package/lib/entities/combatTechnique.d.ts +5 -7
  11. package/lib/entities/combatTechnique.js +34 -24
  12. package/lib/entities/condition.d.ts +12 -0
  13. package/lib/entities/condition.js +63 -0
  14. package/lib/entities/culture.d.ts +8 -0
  15. package/lib/entities/culture.js +309 -0
  16. package/lib/entities/curriculum.d.ts +11 -0
  17. package/lib/entities/curriculum.js +266 -0
  18. package/lib/entities/derivedCharacteristic.d.ts +9 -0
  19. package/lib/entities/derivedCharacteristic.js +91 -0
  20. package/lib/entities/disease.d.ts +9 -0
  21. package/lib/entities/disease.js +88 -0
  22. package/lib/entities/elixir.d.ts +10 -0
  23. package/lib/entities/elixir.js +76 -0
  24. package/lib/entities/equipment.d.ts +24 -0
  25. package/lib/entities/equipment.js +605 -0
  26. package/lib/entities/equipmentPackage.d.ts +8 -0
  27. package/lib/entities/equipmentPackage.js +300 -0
  28. package/lib/entities/experienceLevel.d.ts +3 -2
  29. package/lib/entities/experienceLevel.js +33 -28
  30. package/lib/entities/focusRule.d.ts +3 -4
  31. package/lib/entities/focusRule.js +13 -5
  32. package/lib/entities/influence.d.ts +11 -0
  33. package/lib/entities/influence.js +43 -0
  34. package/lib/entities/liturgicalChant.d.ts +13 -23
  35. package/lib/entities/liturgicalChant.js +171 -131
  36. package/lib/entities/optionalRule.d.ts +3 -2
  37. package/lib/entities/optionalRule.js +4 -3
  38. package/lib/entities/partial/activatableNameChunks.d.ts +58 -0
  39. package/lib/entities/partial/activatableNameChunks.js +356 -0
  40. package/lib/entities/partial/adventurePointsValue.d.ts +9 -0
  41. package/lib/entities/partial/adventurePointsValue.js +243 -0
  42. package/lib/entities/partial/animalTypes.d.ts +11 -0
  43. package/lib/entities/partial/animalTypes.js +13 -0
  44. package/lib/entities/partial/commonnessRatedAdvantagesAndDisadvantages.d.ts +16 -0
  45. package/lib/entities/partial/commonnessRatedAdvantagesAndDisadvantages.js +40 -0
  46. package/lib/entities/partial/dice.d.ts +10 -0
  47. package/lib/entities/partial/dice.js +13 -0
  48. package/lib/entities/partial/enhancements.d.ts +7 -0
  49. package/lib/entities/partial/enhancements.js +26 -0
  50. package/lib/entities/partial/herbary.d.ts +28 -0
  51. package/lib/entities/partial/herbary.js +65 -0
  52. package/lib/entities/partial/map.d.ts +49 -0
  53. package/lib/entities/partial/map.js +43 -0
  54. package/lib/entities/partial/mathOperation.d.ts +36 -0
  55. package/lib/entities/partial/mathOperation.js +107 -0
  56. package/lib/entities/partial/prerequisites/displayOption.d.ts +7 -0
  57. package/lib/entities/partial/prerequisites/displayOption.js +19 -0
  58. package/lib/entities/partial/prerequisites/index.d.ts +67 -0
  59. package/lib/entities/partial/prerequisites/index.js +189 -0
  60. package/lib/entities/partial/prerequisites/part.d.ts +26 -0
  61. package/lib/entities/partial/prerequisites/part.js +88 -0
  62. package/lib/entities/partial/prerequisites/prerequisiteGroups.d.ts +65 -0
  63. package/lib/entities/partial/prerequisites/prerequisiteGroups.js +278 -0
  64. package/lib/entities/partial/prerequisites/single/activatable.d.ts +18 -0
  65. package/lib/entities/partial/prerequisites/single/activatable.js +40 -0
  66. package/lib/entities/partial/prerequisites/single/animistPower.d.ts +8 -0
  67. package/lib/entities/partial/prerequisites/single/animistPower.js +23 -0
  68. package/lib/entities/partial/prerequisites/single/blessedTradition.d.ts +7 -0
  69. package/lib/entities/partial/prerequisites/single/blessedTradition.js +32 -0
  70. package/lib/entities/partial/prerequisites/single/commonSuggestedByRCP.d.ts +6 -0
  71. package/lib/entities/partial/prerequisites/single/commonSuggestedByRCP.js +19 -0
  72. package/lib/entities/partial/prerequisites/single/culture.d.ts +8 -0
  73. package/lib/entities/partial/prerequisites/single/culture.js +20 -0
  74. package/lib/entities/partial/prerequisites/single/enhancement.d.ts +8 -0
  75. package/lib/entities/partial/prerequisites/single/enhancement.js +41 -0
  76. package/lib/entities/partial/prerequisites/single/influence.d.ts +8 -0
  77. package/lib/entities/partial/prerequisites/single/influence.js +17 -0
  78. package/lib/entities/partial/prerequisites/single/magicalTradition.d.ts +7 -0
  79. package/lib/entities/partial/prerequisites/single/magicalTradition.js +27 -0
  80. package/lib/entities/partial/prerequisites/single/noOtherAncestorBloodAdvantage.d.ts +6 -0
  81. package/lib/entities/partial/prerequisites/single/noOtherAncestorBloodAdvantage.js +8 -0
  82. package/lib/entities/partial/prerequisites/single/pact.d.ts +8 -0
  83. package/lib/entities/partial/prerequisites/single/pact.js +30 -0
  84. package/lib/entities/partial/prerequisites/single/personalityTrait.d.ts +8 -0
  85. package/lib/entities/partial/prerequisites/single/personalityTrait.js +28 -0
  86. package/lib/entities/partial/prerequisites/single/primaryAttribute.d.ts +7 -0
  87. package/lib/entities/partial/prerequisites/single/primaryAttribute.js +15 -0
  88. package/lib/entities/partial/prerequisites/single/profession.d.ts +8 -0
  89. package/lib/entities/partial/prerequisites/single/profession.js +19 -0
  90. package/lib/entities/partial/prerequisites/single/publication.d.ts +8 -0
  91. package/lib/entities/partial/prerequisites/single/publication.js +19 -0
  92. package/lib/entities/partial/prerequisites/single/race.d.ts +8 -0
  93. package/lib/entities/partial/prerequisites/single/race.js +20 -0
  94. package/lib/entities/partial/prerequisites/single/rated.d.ts +8 -0
  95. package/lib/entities/partial/prerequisites/single/rated.js +41 -0
  96. package/lib/entities/partial/prerequisites/single/ratedMinimumNumber.d.ts +8 -0
  97. package/lib/entities/partial/prerequisites/single/ratedMinimumNumber.js +89 -0
  98. package/lib/entities/partial/prerequisites/single/ratedSum.d.ts +8 -0
  99. package/lib/entities/partial/prerequisites/single/ratedSum.js +21 -0
  100. package/lib/entities/partial/prerequisites/single/rule.d.ts +7 -0
  101. package/lib/entities/partial/prerequisites/single/rule.js +4 -0
  102. package/lib/entities/partial/prerequisites/single/sex.d.ts +7 -0
  103. package/lib/entities/partial/prerequisites/single/sex.js +19 -0
  104. package/lib/entities/partial/prerequisites/single/sexualCharacteristic.d.ts +7 -0
  105. package/lib/entities/partial/prerequisites/single/sexualCharacteristic.js +21 -0
  106. package/lib/entities/partial/prerequisites/single/socialStatus.d.ts +8 -0
  107. package/lib/entities/partial/prerequisites/single/socialStatus.js +21 -0
  108. package/lib/entities/partial/prerequisites/single/state.d.ts +8 -0
  109. package/lib/entities/partial/prerequisites/single/state.js +20 -0
  110. package/lib/entities/partial/prerequisites/single/text.d.ts +7 -0
  111. package/lib/entities/partial/prerequisites/single/text.js +9 -0
  112. package/lib/entities/partial/professions.d.ts +15 -0
  113. package/lib/entities/partial/professions.js +19 -0
  114. package/lib/entities/partial/rated/activatable/castingTime.d.ts +16 -7
  115. package/lib/entities/partial/rated/activatable/castingTime.js +35 -20
  116. package/lib/entities/partial/rated/activatable/checkResultBased.d.ts +18 -3
  117. package/lib/entities/partial/rated/activatable/checkResultBased.js +18 -10
  118. package/lib/entities/partial/rated/activatable/cost.d.ts +88 -8
  119. package/lib/entities/partial/rated/activatable/cost.js +183 -115
  120. package/lib/entities/partial/rated/activatable/duration.d.ts +36 -13
  121. package/lib/entities/partial/rated/activatable/duration.js +72 -61
  122. package/lib/entities/partial/rated/activatable/effect.d.ts +4 -4
  123. package/lib/entities/partial/rated/activatable/effect.js +32 -25
  124. package/lib/entities/partial/rated/activatable/index.d.ts +31 -27
  125. package/lib/entities/partial/rated/activatable/index.js +63 -28
  126. package/lib/entities/partial/rated/activatable/isMinimumMaximum.d.ts +5 -6
  127. package/lib/entities/partial/rated/activatable/isMinimumMaximum.js +8 -5
  128. package/lib/entities/partial/rated/activatable/nonModifiableSuffix.d.ts +2 -4
  129. package/lib/entities/partial/rated/activatable/nonModifiableSuffix.js +7 -42
  130. package/lib/entities/partial/rated/activatable/range.d.ts +22 -14
  131. package/lib/entities/partial/rated/activatable/range.js +54 -54
  132. package/lib/entities/partial/rated/activatable/speed.d.ts +11 -2
  133. package/lib/entities/partial/rated/activatable/speed.js +14 -1
  134. package/lib/entities/partial/rated/activatable/targetCategory.d.ts +4 -5
  135. package/lib/entities/partial/rated/activatable/targetCategory.js +19 -24
  136. package/lib/entities/partial/rated/improvementCost.d.ts +8 -4
  137. package/lib/entities/partial/rated/improvementCost.js +9 -4
  138. package/lib/entities/partial/rated/skillCheck.d.ts +20 -17
  139. package/lib/entities/partial/rated/skillCheck.js +56 -54
  140. package/lib/entities/partial/reader.d.ts +266 -0
  141. package/lib/entities/partial/reader.js +175 -0
  142. package/lib/entities/partial/responsiveText.d.ts +10 -5
  143. package/lib/entities/partial/responsiveText.js +19 -3
  144. package/lib/entities/partial/units/energy.d.ts +5 -8
  145. package/lib/entities/partial/units/energy.js +5 -23
  146. package/lib/entities/partial/units/length.d.ts +20 -2
  147. package/lib/entities/partial/units/length.js +24 -5
  148. package/lib/entities/partial/units/timeSpan.d.ts +25 -4
  149. package/lib/entities/partial/units/timeSpan.js +27 -15
  150. package/lib/entities/partial/unknown.d.ts +5 -1
  151. package/lib/entities/partial/unknown.js +5 -1
  152. package/lib/entities/personalityTrait.d.ts +7 -0
  153. package/lib/entities/personalityTrait.js +56 -0
  154. package/lib/entities/poison.d.ts +12 -0
  155. package/lib/entities/poison.js +368 -0
  156. package/lib/entities/profession.d.ts +12 -0
  157. package/lib/entities/profession.js +585 -0
  158. package/lib/entities/race.d.ts +9 -0
  159. package/lib/entities/race.js +146 -0
  160. package/lib/entities/sexPractice.d.ts +6 -0
  161. package/lib/entities/sexPractice.js +33 -0
  162. package/lib/entities/skill.d.ts +9 -9
  163. package/lib/entities/skill.js +124 -91
  164. package/lib/entities/spell.d.ts +86 -26
  165. package/lib/entities/spell.js +842 -147
  166. package/lib/entities/state.d.ts +6 -0
  167. package/lib/entities/state.js +17 -0
  168. package/lib/helpers/enums.d.ts +11 -0
  169. package/lib/helpers/enums.js +6 -0
  170. package/lib/helpers/getTypes.d.ts +12 -482
  171. package/lib/helpers/getTypes.js +1 -0
  172. package/lib/helpers/identifiers.d.ts +314 -0
  173. package/lib/helpers/identifiers.js +333 -0
  174. package/lib/helpers/locale.d.ts +21 -2
  175. package/lib/helpers/translate.d.ts +47 -5
  176. package/lib/helpers/translate.js +13 -6
  177. package/lib/index.d.ts +854 -21
  178. package/lib/index.js +182 -17
  179. package/lib/references/index.d.ts +6 -3
  180. package/lib/references/index.js +25 -33
  181. package/lib/references/page.d.ts +1 -1
  182. package/lib/references/page.js +14 -14
  183. package/lib/references/pageRange.d.ts +1 -5
  184. package/lib/references/pageRange.js +7 -16
  185. package/lib/tsconfig.tsbuildinfo +1 -0
  186. package/package.json +31 -10
  187. package/.prettierrc.yml +0 -1
  188. package/lib/entities/partial/rated/activatable/entity.d.ts +0 -11
  189. package/lib/entities/partial/rated/activatable/entity.js +0 -12
  190. package/lib/references/occurrence.d.ts +0 -4
  191. package/lib/references/occurrence.js +0 -3
@@ -1,8 +1,7 @@
1
- import { TargetCategory } from "optolith-database-schema/types/_ActivatableSkillTargetCategory";
2
- import { GetById } from "../../../../helpers/getTypes.js";
3
- import { LocaleEnvironment } from "../../../../helpers/locale.js";
4
- import { EntityDescriptionSection } from "../../../../index.js";
1
+ import type { AffectedTargetCategories } from "optolith-database-schema/gen";
2
+ import { type RawDefinitionListEntityDescriptionSectionItem } from "../../../../index.js";
3
+ import { type StdReader } from "../../reader.js";
5
4
  /**
6
5
  * Get the text for the target category.
7
6
  */
8
- export declare const getTargetCategoryTranslation: (getTargetCategoryById: GetById.Static.TargetCategory, locale: LocaleEnvironment, values: TargetCategory) => EntityDescriptionSection;
7
+ export declare const renderTargetCategory: (values: AffectedTargetCategories) => StdReader<RawDefinitionListEntityDescriptionSectionItem, "t" | "tm" | "ibi", "TargetCategory">;
@@ -1,28 +1,26 @@
1
+ import { Reader } from "@elyukai/utils/reader";
1
2
  import { mapNullable } from "@optolith/helpers/nullable";
2
3
  import { assertExhaustive } from "@optolith/helpers/typeSafety";
4
+ import { getInstanceByIdFnR, translateMapR, translateR, } from "../../reader.js";
3
5
  import { MISSING_VALUE } from "../../unknown.js";
4
6
  import { appendInParensIfNotEmpty } from "./parensIf.js";
5
- const getSelfTranslation = (locale) => locale.translate("Self");
6
- const getZoneTranslation = (locale) => locale.translate("Zone");
7
- const getLiturgicalChantsAndCeremoniesTranslation = (locale) => locale.translate("Liturgical Chants and Ceremonies");
8
- const getCantripsTranslation = (locale) => locale.translate("Cantrips");
9
- const getPredefinedTranslation = (getTargetCategoryById, locale, value) => {
10
- const numericId = value.id.target_category;
11
- const specificTargetCategory = getTargetCategoryById(numericId);
12
- return (mapNullable(locale.translateMap(specificTargetCategory?.translations), (translation) => translation.name) ?? MISSING_VALUE);
13
- };
14
- const getTargetCategoryTranslationByType = (getTargetCategoryById, locale, id) => {
15
- switch (id.tag) {
7
+ const renderPredefined = (targetCategoryId) => getInstanceByIdFnR()
8
+ .thenW(getInstanceById => mapNullable(getInstanceById("TargetCategory", targetCategoryId), targetCategory => translateMapR(targetCategory.translations).map(translation => translation?.name)) ?? Reader.of(undefined))
9
+ .map(translation => translation ?? MISSING_VALUE);
10
+ const getTargetCategoryTranslationByType = (id) => {
11
+ switch (id.kind) {
16
12
  case "Self":
17
- return getSelfTranslation(locale);
13
+ return translateR("Self");
18
14
  case "Zone":
19
- return getZoneTranslation(locale);
15
+ return translateR("Zone");
20
16
  case "LiturgicalChantsAndCeremonies":
21
- return getLiturgicalChantsAndCeremoniesTranslation(locale);
17
+ return translateR("Liturgical Chants and Ceremonies");
18
+ case "Spellworks":
19
+ return translateR("Spellworks");
22
20
  case "Cantrips":
23
- return getCantripsTranslation(locale);
21
+ return translateR("Cantrips");
24
22
  case "Predefined":
25
- return getPredefinedTranslation(getTargetCategoryById, locale, id.predefined);
23
+ return renderPredefined(id.Predefined);
26
24
  default:
27
25
  return assertExhaustive(id);
28
26
  }
@@ -30,11 +28,8 @@ const getTargetCategoryTranslationByType = (getTargetCategoryById, locale, id) =
30
28
  /**
31
29
  * Get the text for the target category.
32
30
  */
33
- export const getTargetCategoryTranslation = (getTargetCategoryById, locale, values) => ({
34
- label: locale.translate("Target Category"),
35
- value: values.length === 0
36
- ? locale.translate("all")
37
- : values
38
- .map(({ id, translations }) => appendInParensIfNotEmpty(locale.translateMap(translations)?.note, getTargetCategoryTranslationByType(getTargetCategoryById, locale, id)))
39
- .join(", "),
40
- });
31
+ export const renderTargetCategory = (values) => translateR("Target Category").thenW(label => (values.length === 0
32
+ ? translateR("all")
33
+ : Reader.sequence(values.map(({ id, translations }) => getTargetCategoryTranslationByType(id).then(text => translateMapR(translations)
34
+ .map(translation => translation?.note)
35
+ .map(note => appendInParensIfNotEmpty(note, text)) ?? text))).map(texts => texts.join(", "))).map(value => ({ label, value })));
@@ -1,7 +1,11 @@
1
- import { ImprovementCost as RawImprovementCost } from "optolith-database-schema/types/_ImprovementCost";
2
- import { Translate } from "../../../helpers/translate.js";
3
- import { EntityDescriptionSection } from "../../../index.js";
1
+ import type { ImprovementCost } from "optolith-database-schema/gen";
2
+ import { type RawDefinitionListEntityDescriptionSectionItem } from "../../../index.js";
3
+ import { type StdReader } from "../reader.js";
4
+ /**
5
+ * Renders an improvement cost value as a string.
6
+ */
7
+ export declare const renderImprovementCostValue: (improvementCost: ImprovementCost) => string;
4
8
  /**
5
9
  * Returns the improvement cost as an inline library property.
6
10
  */
7
- export declare const createImprovementCost: (translate: Translate, improvementCost: RawImprovementCost) => EntityDescriptionSection;
11
+ export declare const renderImprovementCost: (improvementCost: ImprovementCost) => StdReader<RawDefinitionListEntityDescriptionSectionItem, "t">;
@@ -1,7 +1,12 @@
1
+ import { translateR } from "../reader.js";
2
+ /**
3
+ * Renders an improvement cost value as a string.
4
+ */
5
+ export const renderImprovementCostValue = (improvementCost) => improvementCost.kind;
1
6
  /**
2
7
  * Returns the improvement cost as an inline library property.
3
8
  */
4
- export const createImprovementCost = (translate, improvementCost) => ({
5
- label: translate("Improvement Cost"),
6
- value: improvementCost,
7
- });
9
+ export const renderImprovementCost = (improvementCost) => translateR("Improvement Cost").map(label => ({
10
+ label,
11
+ value: renderImprovementCostValue(improvementCost),
12
+ }));
@@ -1,19 +1,22 @@
1
- import { SkillCheck, SkillCheckPenalty } from "optolith-database-schema/types/_SkillCheck";
2
- import { DerivedCharacteristic } from "optolith-database-schema/types/DerivedCharacteristic";
3
- import { GetById } from "../../../helpers/getTypes.js";
4
- import { Translate, TranslateMap } from "../../../helpers/translate.js";
5
- import { EntityDescriptionSection } from "../../../index.js";
6
- import { ResponsiveTextSize } from "../responsiveText.js";
1
+ import type { SkillCheckPenalty as GeneralSkillCheckPenalty, MagicalRuneCombatTechniqueCheckPenalty, SkillCheck } from "optolith-database-schema/gen";
2
+ import { type IdMap } from "../../../index.js";
3
+ import { type StdReader } from "../reader.js";
7
4
  /**
8
- * Returns the skill check as an inline library property.
5
+ * Renders a skill check.
9
6
  */
10
- export declare const getTextForCheck: (deps: {
11
- translate: Translate;
12
- translateMap: TranslateMap;
13
- getAttributeById: GetById.Static.Attribute;
14
- }, check: SkillCheck, checkPenalty?: {
15
- value: SkillCheckPenalty | undefined;
16
- responsiveText: ResponsiveTextSize;
17
- getSpirit: () => DerivedCharacteristic | undefined;
18
- getToughness: () => DerivedCharacteristic | undefined;
19
- }) => EntityDescriptionSection;
7
+ export declare const renderSkillCheck: (check: SkillCheck) => StdReader<{
8
+ label: string;
9
+ value: string;
10
+ }, "t" | "tm" | "ibi", "Attribute">;
11
+ type SkillCheckPenalty = GeneralSkillCheckPenalty | {
12
+ kind: "CombatTechnique";
13
+ CombatTechnique: MagicalRuneCombatTechniqueCheckPenalty;
14
+ };
15
+ /**
16
+ * Renders a skill check with a possible penalty.
17
+ */
18
+ export declare const renderSkillCheckWithPenalty: (check: SkillCheck, checkPenalty: SkillCheckPenalty | undefined, idMap: IdMap) => StdReader<{
19
+ label: string;
20
+ value: string;
21
+ }, "t" | "tm" | "rts" | "ibi", "Attribute" | "DerivedCharacteristic">;
22
+ export {};
@@ -1,58 +1,60 @@
1
+ import { Reader } from "@elyukai/utils/reader";
1
2
  import { assertExhaustive } from "@optolith/helpers/typeSafety";
2
- import { responsive } from "../responsiveText.js";
3
+ import { getInstanceByIdFnR, responsiveR, responsiveThenR, responsiveTranslateR, translateMapR, translateR, } from "../reader.js";
4
+ import { MISSING_VALUE } from "../unknown.js";
3
5
  /**
4
- * Returns the skill check as an inline library property.
6
+ * Renders a skill check.
5
7
  */
6
- export const getTextForCheck = (deps, check, checkPenalty) => ({
7
- label: deps.translate("Check"),
8
+ export const renderSkillCheck = (check) => Reader.asks(({ translate, translateMap, getInstanceById }) => ({
9
+ label: translate("Check"),
8
10
  value: check
9
- .map(({ id: { attribute: id } }) => deps.translateMap(deps.getAttributeById(id)?.translations)
10
- ?.abbreviation ?? "??")
11
- .join("/") +
12
- (() => {
13
- if (checkPenalty?.value === undefined) {
14
- return "";
15
- }
16
- const { responsiveText } = checkPenalty;
17
- const getDerivedCharacteristicTranslation = (getDerivedCharacteristic) => deps.translateMap(getDerivedCharacteristic()?.translations);
18
- const getSpiritTranslation = () => getDerivedCharacteristicTranslation(checkPenalty.getSpirit);
19
- const getToughnessTranslation = () => getDerivedCharacteristicTranslation(checkPenalty.getToughness);
20
- const penalty = (() => {
21
- switch (checkPenalty.value) {
22
- case "Spirit": {
23
- const translation = getSpiritTranslation();
24
- return translation === undefined
25
- ? ""
26
- : responsive(responsiveText, () => translation.name, () => translation.abbreviation);
27
- }
28
- case "HalfOfSpirit": {
29
- const translation = getSpiritTranslation();
30
- return translation === undefined
31
- ? ""
32
- : responsive(responsiveText, () => `${translation.name}/2`, () => `${translation.abbreviation}/2`);
33
- }
34
- case "Toughness": {
35
- const translation = getToughnessTranslation();
36
- return translation === undefined
37
- ? ""
38
- : responsive(responsiveText, () => `${translation.name}/2`, () => `${translation.abbreviation}/2`);
39
- }
40
- case "HigherOfSpiritAndToughness": {
41
- const spiritTranslation = getSpiritTranslation();
42
- const toughnessTranslation = getToughnessTranslation();
43
- return spiritTranslation === undefined ||
44
- toughnessTranslation === undefined
45
- ? ""
46
- : responsive(responsiveText, () => deps.translate("{0} or {1}, depending on which value is higher", spiritTranslation.abbreviation, toughnessTranslation.abbreviation), () => `${spiritTranslation.abbreviation}/${toughnessTranslation.abbreviation}`);
47
- }
48
- case "SummoningDifficulty":
49
- return responsive(responsiveText, () => deps.translate("Invocation Difficulty"), () => deps.translate("ID"));
50
- case "CreationDifficulty":
51
- return responsive(responsiveText, () => deps.translate("Creation Difficulty"), () => deps.translate("CD"));
52
- default:
53
- return assertExhaustive(checkPenalty.value);
54
- }
55
- })();
56
- return responsive(responsiveText, () => deps.translate(" (modified by {0})", penalty), () => deps.translate(" (− {0})", penalty));
57
- })(),
58
- });
11
+ .map(id => translateMap(getInstanceById("Attribute", id)?.translations)
12
+ ?.abbreviation ?? MISSING_VALUE)
13
+ .join("/"),
14
+ }));
15
+ const renderSkillCheckPenalty = (idMap, penalty) => {
16
+ const getDerivedCharacteristicTranslation = (id) => getInstanceByIdFnR()
17
+ .map(getInstanceById => getInstanceById("DerivedCharacteristic", id))
18
+ .thenW(dc => dc === undefined
19
+ ? Reader.of(undefined)
20
+ : translateMapR(dc.translations).thenW(translation => translation === undefined
21
+ ? Reader.of(undefined)
22
+ : responsiveR(() => translation.name, () => translation.abbreviation)))
23
+ .map(translation => translation ?? MISSING_VALUE);
24
+ const getSpiritTranslation = () => getDerivedCharacteristicTranslation(idMap.DerivedCharacteristic.Spirit);
25
+ const getToughnessTranslation = () => getDerivedCharacteristicTranslation(idMap.DerivedCharacteristic.Toughness);
26
+ switch (penalty.kind) {
27
+ case "Spirit":
28
+ return getSpiritTranslation();
29
+ case "HalfOfSpirit":
30
+ return getSpiritTranslation().map(translation => `${translation}/2`);
31
+ case "Toughness":
32
+ return getToughnessTranslation();
33
+ case "HigherOfSpiritAndToughness":
34
+ return getSpiritTranslation().thenW(spirit => getToughnessTranslation().thenW(toughness => responsiveThenR(() => translateR("{$first} or {$second}, depending on which value is higher", {
35
+ first: spirit,
36
+ second: toughness,
37
+ }), () => Reader.of(`${spirit}/${toughness}`))));
38
+ case "SummoningDifficulty":
39
+ return responsiveTranslateR("Invocation Difficulty", "ID");
40
+ case "CreationDifficulty":
41
+ return responsiveTranslateR("Creation Difficulty", "CD");
42
+ case "Object":
43
+ return translateR("Object");
44
+ case "CombatTechnique":
45
+ return responsiveTranslateR("Combat Technique", "CT");
46
+ default:
47
+ return assertExhaustive(penalty);
48
+ }
49
+ };
50
+ /**
51
+ * Renders a skill check with a possible penalty.
52
+ */
53
+ export const renderSkillCheckWithPenalty = (check, checkPenalty, idMap) => checkPenalty === undefined
54
+ ? renderSkillCheck(check)
55
+ : renderSkillCheck(check).thenW(checkText => renderSkillCheckPenalty(idMap, checkPenalty)
56
+ .then(penaltyText => responsiveTranslateR(" (modified by {$modifier})", " (−{$modifier})", { modifier: penaltyText }))
57
+ .map(penaltyText => ({
58
+ ...checkText,
59
+ value: checkText.value + penaltyText,
60
+ })));
@@ -0,0 +1,266 @@
1
+ import { Reader } from "@elyukai/utils/reader";
2
+ import type { ChildEntityMap, EntityMap, FastSkillModificationLevelConfig, ResponsiveText, ResponsiveTextOptional, SkillModificationLevel, SlowSkillModificationLevelConfig } from "optolith-database-schema/gen";
3
+ import type { IdArgsVariant } from "tsondb/schema/gen";
4
+ import type { GetAllChildInstancesForParent, GetAllInstances, GetInstanceById } from "../../helpers/getTypes.js";
5
+ import type { LocaleCompare, LocaleJoin, LocaleJoinType } from "../../helpers/locale.js";
6
+ import type { Format, LocaleMap, Translate, TranslateMap, TranslationKeyMatchingParamsOfKey, TranslationKeysWithoutParams, TranslationParamsInArray, Translations } from "../../helpers/translate.js";
7
+ import type { GetResolvedSelectOptionById } from "./prerequisites/single/activatable.js";
8
+ import type { ModifiableParameter } from "./rated/activatable/nonModifiableSuffix.js";
9
+ import { Speed } from "./rated/activatable/speed.js";
10
+ import { ResponsiveTextSize } from "./responsiveText.js";
11
+ import { type EnergyUnit } from "./units/energy.js";
12
+ /**
13
+ * The standard set of environment properties for readers in this project.
14
+ */
15
+ export type EnvMap<E extends keyof EntityMap = never, AE extends keyof EntityMap = never, CE extends keyof ChildEntityMap = never> = {
16
+ format: Format;
17
+ translate: Translate;
18
+ translateMap: TranslateMap;
19
+ localeJoin: LocaleJoin;
20
+ localeCompare: LocaleCompare;
21
+ responsiveTextSize: ResponsiveTextSize;
22
+ speed: Speed;
23
+ energyUnit: EnergyUnit;
24
+ nonModifiableSuffix?: (param: ModifiableParameter) => TranslationKeysWithoutParams;
25
+ getInstanceById: GetInstanceById<E>;
26
+ getAllInstances: GetAllInstances<AE>;
27
+ getChildInstancesForInstanceId: GetAllChildInstancesForParent<CE>;
28
+ getResolvedSelectOptionById: GetResolvedSelectOptionById;
29
+ };
30
+ /**
31
+ * Shortcuts for selecting keys of the shared environment map type.
32
+ */
33
+ export type EnvMapAbbr = {
34
+ f: "format";
35
+ t: "translate";
36
+ tm: "translateMap";
37
+ lj: "localeJoin";
38
+ lc: "localeCompare";
39
+ rts: "responsiveTextSize";
40
+ s: "speed";
41
+ eu: "energyUnit";
42
+ nms: "nonModifiableSuffix";
43
+ ibi: "getInstanceById";
44
+ ai: "getAllInstances";
45
+ acibp: "getChildInstancesForInstanceId";
46
+ rso: "getResolvedSelectOptionById";
47
+ };
48
+ /**
49
+ * The standard set of environment properties for readers in this project.
50
+ *
51
+ * The keys are abbreviated to keep type annotations short.
52
+ */
53
+ export type StdEnv<K extends keyof EnvMapAbbr = keyof EnvMapAbbr, E extends keyof EntityMap = never, AE extends keyof EntityMap = never, CE extends keyof ChildEntityMap = never> = Pick<EnvMap<E, AE, CE>, EnvMapAbbr[K]>;
54
+ /**
55
+ * Shortcut for a reader with common environment properties.
56
+ *
57
+ * The keys are abbreviated to keep return type annotations short.
58
+ */
59
+ export type StdReader<T, K extends keyof EnvMapAbbr, E extends keyof EntityMap = never, AE extends keyof EntityMap = never, CE extends keyof ChildEntityMap = never> = Reader<StdEnv<K, E, AE, CE>, T>;
60
+ /**
61
+ * Treats the text as a translation string and applies supplied arguments.
62
+ */
63
+ export declare const formatR: (text: string, args?: Record<string, unknown> | undefined) => Reader<{
64
+ format: Format;
65
+ }, string>;
66
+ /**
67
+ * Creates a value from a translation key.
68
+ */
69
+ export declare const translateR: <K extends keyof Translations>(key: K, ...rest: TranslationParamsInArray<K>) => Reader<{
70
+ translate: Translate;
71
+ }, string>;
72
+ /**
73
+ * Returns the `translate` function from the context.
74
+ */
75
+ export declare const translateFnR: Reader<{
76
+ translate: Translate;
77
+ }, Translate>;
78
+ /**
79
+ * Takes the appropriate translation from a locale map.
80
+ */
81
+ export declare const translateMapR: <T>(map: LocaleMap<T> | undefined) => Reader<{
82
+ translateMap: TranslateMap;
83
+ }, T | undefined>;
84
+ /**
85
+ * Returns the `translateMap` function from the context.
86
+ */
87
+ export declare const translateMapFnR: Reader<{
88
+ translateMap: TranslateMap;
89
+ }, TranslateMap>;
90
+ /**
91
+ * Retrieves the translation for the current locale from the given value’s `translations` property.
92
+ * @returns `undefined` if the value does not exist or does not have a translation for the current locale, otherwise the translation.
93
+ */
94
+ export declare const translationR: <T>(value: {
95
+ translations?: LocaleMap<T>;
96
+ } | undefined) => Reader<{
97
+ translateMap: TranslateMap;
98
+ }, T | undefined>;
99
+ /**
100
+ * Retrieves a specific property of the specified entry.
101
+ */
102
+ export declare const mapTranslationR: <E extends keyof EntityMap & { [K in keyof EntityMap]: EntityMap[K] extends {
103
+ translations: LocaleMap<object>;
104
+ } ? K : never; }[keyof EntityMap], R>(...args: [...IdArgsVariant<EntityMap, E>, fn: (translation: EntityMap[E] extends {
105
+ translations: LocaleMap<infer T>;
106
+ } ? T | undefined : never) => R]) => Reader<{
107
+ translateMap: TranslateMap;
108
+ getInstanceById: GetInstanceById<E>;
109
+ }, R | undefined>;
110
+ /**
111
+ * Retrieves the `name` property of the specified entry.
112
+ */
113
+ export declare const nameR: <E extends { [K in keyof EntityMap]: EntityMap[K] extends {
114
+ translations: LocaleMap<{
115
+ name: string;
116
+ }>;
117
+ } ? K : never; }[keyof EntityMap]>(...args: IdArgsVariant<EntityMap, E>) => Reader<{
118
+ translateMap: TranslateMap;
119
+ getInstanceById: GetInstanceById<E>;
120
+ }, string | undefined>;
121
+ /**
122
+ * Retrieves the `name` property of the specified entry.
123
+ *
124
+ * Returns {@link MISSING_VALUE} if there is no name for the entry in the locale. This can happen if the entry itself does not exist, or it does not have a translation for the current locale.
125
+ */
126
+ export declare const strictNameR: <E extends { [K in keyof EntityMap]: EntityMap[K] extends {
127
+ translations: LocaleMap<{
128
+ name: string;
129
+ }>;
130
+ } ? K : never; }[keyof EntityMap]>(...args: IdArgsVariant<EntityMap, E>) => Reader<{
131
+ translateMap: TranslateMap;
132
+ getInstanceById: GetInstanceById<E>;
133
+ }, string>;
134
+ /**
135
+ * Joins a list of strings according to the locale’s rules for the given type.
136
+ */
137
+ export declare const localeJoinR: (arr: string[], type: LocaleJoinType) => Reader<{
138
+ localeJoin: LocaleJoin;
139
+ }, string>;
140
+ /**
141
+ * Returns a function to retrieve an instance from the database by its entity name and ID.
142
+ */
143
+ export declare const getInstanceByIdFnR: <E extends keyof EntityMap = never>() => Reader<{
144
+ getInstanceById: GetInstanceById<E>;
145
+ }, GetInstanceById<E>>;
146
+ /**
147
+ * Retrieves an instance from the database by its entity name and ID.
148
+ */
149
+ export declare const getInstanceByIdR: <E extends keyof EntityMap>(...args: IdArgsVariant<EntityMap, E>) => Reader<{
150
+ getInstanceById: GetInstanceById<E>;
151
+ }, EntityMap[E] | undefined>;
152
+ /**
153
+ * Retrieves all instances of an entity from the database by their entity name.
154
+ */
155
+ export declare const getAllInstancesR: <E extends keyof EntityMap>(entityName: E) => Reader<{
156
+ getAllInstances: GetAllInstances<E>;
157
+ }, {
158
+ id: string;
159
+ content: EntityMap[E];
160
+ }[]>;
161
+ /**
162
+ * Retrieves all child instances of an entity from the database by their child entity name and their parent’s identifier.
163
+ */
164
+ export declare const getChildInstancesForInstanceIdR: <CE extends keyof ChildEntityMap>(entityName: CE, parentId: ChildEntityMap[CE][2]) => Reader<{
165
+ getChildInstancesForInstanceId: GetAllChildInstancesForParent<CE>;
166
+ }, {
167
+ id: string;
168
+ content: ChildEntityMap[CE][0];
169
+ }[]>;
170
+ /**
171
+ * Joins a list of strings according to the locale’s rules for the given type.
172
+ */
173
+ export declare const responsiveLocaleJoinR: (arr: string[], type: LocaleJoinType) => Reader<{
174
+ localeJoin: LocaleJoin;
175
+ responsiveTextSize: ResponsiveTextSize;
176
+ }, string>;
177
+ /**
178
+ * Compares two strings according to the locale’s sorting rules.
179
+ */
180
+ export declare const localeCompareR: Reader<{
181
+ localeCompare: LocaleCompare;
182
+ }, LocaleCompare>;
183
+ /**
184
+ * Sorts an array of strings according to the locale’s sorting rules.
185
+ */
186
+ export declare const localeSortR: <T extends string>(arr: T[]) => Reader<{
187
+ localeCompare: LocaleCompare;
188
+ }, T[]>;
189
+ /**
190
+ * Creates a responsive value from two functions that return the value for the full and compressed version, respectively.
191
+ */
192
+ export declare const responsiveR: <T>(full: () => T, compressed: () => T) => Reader<{
193
+ responsiveTextSize: ResponsiveTextSize;
194
+ }, T>;
195
+ /**
196
+ * Creates a responsive value from two functions that return the value for the full and compressed version, respectively.
197
+ */
198
+ export declare const responsiveThenR: <T, RF extends object, RC extends object>(full: () => Reader<RF, T>, compressed: () => Reader<RC, T>) => Reader<{
199
+ responsiveTextSize: ResponsiveTextSize;
200
+ } & RF & RC, T>;
201
+ /**
202
+ * Creates a responsive value from a translation key that has a full and a compressed version.
203
+ */
204
+ export declare const responsiveTranslateR: <K extends keyof Translations, K2 extends TranslationKeyMatchingParamsOfKey<K>>(fullKey: K, compressedKey: K2, ...rest: TranslationParamsInArray<K> & TranslationParamsInArray<K2>) => Reader<{
205
+ translate: Translate;
206
+ responsiveTextSize: ResponsiveTextSize;
207
+ }, string>;
208
+ /**
209
+ * Creates a responsive value from a responsive text.
210
+ */
211
+ export declare const responsiveTextR: (responsiveText: ResponsiveText) => Reader<{
212
+ responsiveTextSize: ResponsiveTextSize;
213
+ }, string>;
214
+ /**
215
+ * Creates a responsive value from a responsive text with an optional compressed variant.
216
+ */
217
+ export declare const responsiveTextOptionalR: (responsiveText: ResponsiveTextOptional) => Reader<{
218
+ responsiveTextSize: ResponsiveTextSize;
219
+ }, string | undefined>;
220
+ /**
221
+ * Formats the given energy cost value with the appropriate unit.
222
+ */
223
+ export declare const formatEnergyR: (value: string | number) => Reader<{
224
+ translate: Translate;
225
+ energyUnit: EnergyUnit;
226
+ }, string>;
227
+ /**
228
+ * Formats the given energy cost value with the appropriate unit based on the entity type.
229
+ */
230
+ export declare const formatEnergyFnR: Reader<{
231
+ translate: Translate;
232
+ energyUnit: EnergyUnit;
233
+ }, (value: string | number) => string>;
234
+ type SpeedMap = {
235
+ [Speed.Fast]: FastSkillModificationLevelConfig;
236
+ [Speed.Slow]: SlowSkillModificationLevelConfig;
237
+ };
238
+ /**
239
+ * Returns a common value for a skill modification level depending on the speed.
240
+ */
241
+ export declare const modifiableBySpeedR: <Fast extends object, Slow extends { [K_ in keyof Fast]: unknown; }, K extends keyof Fast>(key: K, level: {
242
+ fast: Fast;
243
+ slow: Slow;
244
+ }) => Reader<{
245
+ speed: Speed;
246
+ }, (Fast | Slow)[K]>;
247
+ /**
248
+ * Returns a common value for a skill modification level depending on the speed.
249
+ */
250
+ export declare const modifiableBySpeedOptionalR: <Fast extends object, Slow extends { [K_ in keyof Fast]: unknown; }, K extends keyof Fast>(key: K, level: {
251
+ fast?: Fast;
252
+ slow?: Slow;
253
+ }) => Reader<{
254
+ speed: Speed;
255
+ }, (Fast | Slow)[K] | undefined>;
256
+ /**
257
+ * Returns a common value for a skill modification level depending on the speed.
258
+ */
259
+ export declare const modifyBySpeedR: Reader<{
260
+ speed: Speed;
261
+ }, <S extends Speed, K extends keyof SpeedMap[S]>(key: K, level: SkillModificationLevel) => SpeedMap[S][K]>;
262
+ /**
263
+ * Returns the default values wrapped in a reader if the value is nullish, otherwise applies the given function to the value and returns the result.
264
+ */
265
+ export declare const mapNullableR: <T, U, R>(defaultValue: U, fn: (value: NonNullable<T>) => Reader<U, R>) => (value: T) => Reader<U, R> | Reader<unknown, U>;
266
+ export {};