@optolith/entity-descriptions 0.11.1 → 0.12.0
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.
- package/CHANGELOG.md +21 -0
- package/lib/entities/activatable.js +11 -5
- package/lib/entities/elixir.js +9 -1
- package/lib/entities/influence.js +10 -1
- package/lib/entities/partial/activatableNameChunks.d.ts +2 -2
- package/lib/entities/partial/activatableNameChunks.js +18 -4
- package/lib/entities/partial/adventurePointsValue.js +19 -12
- package/lib/entities/partial/commonnessRatedAdvantagesAndDisadvantages.d.ts +1 -1
- package/lib/entities/partial/commonnessRatedAdvantagesAndDisadvantages.js +4 -4
- package/lib/entities/partial/enhancements.d.ts +1 -1
- package/lib/entities/partial/enhancements.js +13 -4
- package/lib/entities/partial/map.d.ts +1 -1
- package/lib/entities/partial/markdown.d.ts +5 -1
- package/lib/entities/partial/markdown.js +13 -1
- package/lib/entities/partial/prerequisites/displayOption.d.ts +2 -7
- package/lib/entities/partial/prerequisites/displayOption.js +1 -18
- package/lib/entities/partial/prerequisites/index.d.ts +26 -20
- package/lib/entities/partial/prerequisites/index.js +89 -65
- package/lib/entities/partial/prerequisites/part.d.ts +4 -4
- package/lib/entities/partial/prerequisites/part.js +23 -14
- package/lib/entities/partial/prerequisites/prerequisiteGroups.d.ts +16 -18
- package/lib/entities/partial/prerequisites/prerequisiteGroups.js +90 -82
- package/lib/entities/partial/prerequisites/single/activatable.d.ts +4 -5
- package/lib/entities/partial/prerequisites/single/activatable.js +21 -29
- package/lib/entities/partial/prerequisites/single/animistPower.d.ts +2 -3
- package/lib/entities/partial/prerequisites/single/animistPower.js +6 -9
- package/lib/entities/partial/prerequisites/single/anySpecialAbilityOfGroup.d.ts +1 -1
- package/lib/entities/partial/prerequisites/single/anySpecialAbilityOfGroup.js +4 -7
- package/lib/entities/partial/prerequisites/single/blessedTradition.d.ts +2 -2
- package/lib/entities/partial/prerequisites/single/blessedTradition.js +15 -17
- package/lib/entities/partial/prerequisites/single/commonSuggestedByRCP.d.ts +2 -2
- package/lib/entities/partial/prerequisites/single/commonSuggestedByRCP.js +9 -6
- package/lib/entities/partial/prerequisites/single/culture.d.ts +2 -3
- package/lib/entities/partial/prerequisites/single/culture.js +8 -15
- package/lib/entities/partial/prerequisites/single/enhancement.d.ts +1 -1
- package/lib/entities/partial/prerequisites/single/enhancement.js +1 -1
- package/lib/entities/partial/prerequisites/single/influence.d.ts +2 -3
- package/lib/entities/partial/prerequisites/single/influence.js +7 -10
- package/lib/entities/partial/prerequisites/single/magicalTradition.d.ts +2 -2
- package/lib/entities/partial/prerequisites/single/magicalTradition.js +10 -12
- package/lib/entities/partial/prerequisites/single/noOtherAncestorBloodAdvantage.d.ts +2 -2
- package/lib/entities/partial/prerequisites/single/noOtherAncestorBloodAdvantage.js +4 -3
- package/lib/entities/partial/prerequisites/single/pact.d.ts +2 -3
- package/lib/entities/partial/prerequisites/single/pact.js +17 -18
- package/lib/entities/partial/prerequisites/single/personalityTrait.d.ts +2 -3
- package/lib/entities/partial/prerequisites/single/personalityTrait.js +21 -22
- package/lib/entities/partial/prerequisites/single/primaryAttribute.d.ts +2 -2
- package/lib/entities/partial/prerequisites/single/primaryAttribute.js +6 -8
- package/lib/entities/partial/prerequisites/single/profession.d.ts +2 -3
- package/lib/entities/partial/prerequisites/single/profession.js +11 -14
- package/lib/entities/partial/prerequisites/single/publication.d.ts +2 -3
- package/lib/entities/partial/prerequisites/single/publication.js +7 -13
- package/lib/entities/partial/prerequisites/single/race.d.ts +2 -3
- package/lib/entities/partial/prerequisites/single/race.js +8 -15
- package/lib/entities/partial/prerequisites/single/rated.d.ts +2 -3
- package/lib/entities/partial/prerequisites/single/rated.js +7 -9
- package/lib/entities/partial/prerequisites/single/ratedMinimumNumber.d.ts +2 -3
- package/lib/entities/partial/prerequisites/single/ratedMinimumNumber.js +52 -53
- package/lib/entities/partial/prerequisites/single/ratedSum.d.ts +2 -3
- package/lib/entities/partial/prerequisites/single/ratedSum.js +15 -15
- package/lib/entities/partial/prerequisites/single/rule.d.ts +2 -2
- package/lib/entities/partial/prerequisites/single/rule.js +2 -1
- package/lib/entities/partial/prerequisites/single/sex.d.ts +2 -2
- package/lib/entities/partial/prerequisites/single/sex.js +7 -6
- package/lib/entities/partial/prerequisites/single/sexualCharacteristic.d.ts +2 -2
- package/lib/entities/partial/prerequisites/single/sexualCharacteristic.js +11 -8
- package/lib/entities/partial/prerequisites/single/socialStatus.d.ts +2 -3
- package/lib/entities/partial/prerequisites/single/socialStatus.js +9 -15
- package/lib/entities/partial/prerequisites/single/state.d.ts +2 -3
- package/lib/entities/partial/prerequisites/single/state.js +8 -15
- package/lib/entities/partial/prerequisites/single/text.d.ts +2 -2
- package/lib/entities/partial/prerequisites/single/text.js +4 -3
- package/lib/entities/partial/prerequisites/single/tinyActivatable.d.ts +1 -1
- package/lib/entities/partial/prerequisites/single/tinyActivatable.js +5 -8
- package/lib/entities/partial/rated/activatable/castingTime.d.ts +1 -1
- package/lib/entities/partial/rated/activatable/checkResultBased.d.ts +1 -1
- package/lib/entities/partial/rated/activatable/cost.d.ts +3 -3
- package/lib/entities/partial/rated/activatable/duration.d.ts +1 -1
- package/lib/entities/partial/rated/activatable/duration.js +1 -1
- package/lib/entities/partial/rated/activatable/effect.d.ts +1 -1
- package/lib/entities/partial/rated/activatable/index.d.ts +1 -1
- package/lib/entities/partial/rated/activatable/isMinimumMaximum.d.ts +1 -1
- package/lib/entities/partial/rated/activatable/nonModifiableSuffix.d.ts +1 -1
- package/lib/entities/partial/rated/activatable/nonModifiableSuffix.js +1 -1
- package/lib/entities/partial/rated/activatable/range.d.ts +1 -1
- package/lib/entities/partial/rated/activatable/targetCategory.d.ts +1 -1
- package/lib/entities/partial/rated/improvementCost.d.ts +1 -1
- package/lib/entities/partial/rated/skillCheck.d.ts +1 -1
- package/lib/entities/partial/reader.d.ts +2 -57
- package/lib/entities/partial/responsiveText.d.ts +1 -1
- package/lib/entities/partial/units/length.d.ts +1 -1
- package/lib/entities/partial/units/timeSpan.d.ts +3 -4
- package/lib/entities/personalityTrait.js +8 -1
- package/lib/entities/poison.js +5 -1
- package/lib/entities/profession.js +23 -18
- package/lib/entities/race.d.ts +1 -1
- package/lib/entities/race.js +16 -12
- package/lib/entities/spell.js +5 -2
- package/lib/env.d.ts +66 -0
- package/lib/env.js +1 -0
- package/lib/references/publicationOptions.d.ts +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
|
@@ -1,63 +1,87 @@
|
|
|
1
1
|
import { isNotEmpty } from "@elyukai/utils/array/nonEmpty";
|
|
2
2
|
import { on } from "@elyukai/utils/function";
|
|
3
3
|
import { mapNullable } from "@elyukai/utils/nullable";
|
|
4
|
+
import { Reader } from "@elyukai/utils/reader";
|
|
4
5
|
import { numAsc } from "@optolith/helpers/compare";
|
|
5
6
|
import { isNotNullish } from "@optolith/helpers/nullable";
|
|
6
7
|
import { romanize } from "@optolith/helpers/roman";
|
|
7
8
|
import { assertExhaustive } from "@optolith/helpers/typeSafety";
|
|
8
9
|
import { renderActivatableNameComponents, renderActivatableNameComponentsCombinedIfPossible, } from "../activatableNameChunks.js";
|
|
10
|
+
import { localeJoinR, translateR } from "../reader.js";
|
|
9
11
|
import { MISSING_VALUE } from "../unknown.js";
|
|
10
12
|
import { printDisplayOption } from "./displayOption.js";
|
|
11
13
|
import { hasPartValueObject, joinPrerequisiteParts } from "./part.js";
|
|
12
14
|
import { printAdvantageDisadvantagePrerequisiteGroup, printAnimistPowerPrerequisiteGroup, printArcaneTraditionPrerequisiteGroup, printDerivedCharacteristicPrerequisiteGroup, printEnhancementPrerequisiteGroup, printGeneralPrerequisiteGroup, printGeodeRitualPrerequisiteGroup, printInfluencePrerequisiteGroup, printLanguagePrerequisiteGroup, printLiturgyPrerequisiteGroup, printPersonalityTraitPrerequisiteGroup, printProfessionPrerequisiteGroup, printPublicationPrerequisiteGroup, printSpellworkPrerequisiteGroup, } from "./prerequisiteGroups.js";
|
|
13
|
-
const printPrerequisiteGroup = (
|
|
14
|
-
value: translateMap(group.translations)?.text ?? MISSING_VALUE,
|
|
15
|
+
const printPrerequisiteGroup = (group) => Reader.asks(env => ({
|
|
16
|
+
value: env.translateMap(group.translations)?.text ?? MISSING_VALUE,
|
|
15
17
|
sentenceType: undefined,
|
|
16
18
|
isMeta: false,
|
|
17
|
-
});
|
|
18
|
-
const printPrerequisitesDisjunction = (getPrerequisiteTranslation,
|
|
19
|
+
}));
|
|
20
|
+
const printPrerequisitesDisjunction = (getPrerequisiteTranslation, disjunction) => {
|
|
19
21
|
if (disjunction.display_option !== undefined) {
|
|
20
|
-
return printDisplayOption(
|
|
22
|
+
return printDisplayOption(disjunction.display_option);
|
|
21
23
|
}
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
? renderActivatableNameComponentsCombinedIfPossible(
|
|
34
|
-
:
|
|
24
|
+
const disjunctionList = disjunction.list;
|
|
25
|
+
return Reader.traverse(disjunctionList, getPrerequisiteTranslation)
|
|
26
|
+
.map(list => list.filter(isNotNullish))
|
|
27
|
+
.thenW(([first, ...other]) => {
|
|
28
|
+
if (first === undefined) {
|
|
29
|
+
return Reader.of(undefined);
|
|
30
|
+
}
|
|
31
|
+
if (disjunctionList.length < 2 ||
|
|
32
|
+
(isNotEmpty(disjunctionList) &&
|
|
33
|
+
disjunctionList.slice(1).every(part => part.kind === disjunctionList[0].kind))) {
|
|
34
|
+
return (hasPartValueObject(first) && other.every(hasPartValueObject)
|
|
35
|
+
? Reader.asks((env) => renderActivatableNameComponentsCombinedIfPossible(env.translate, env.translateMap, [first.value, ...other.map(part => part.value)], true, list => env.localeJoin(list.toSorted(env.localeCompare), "disjunction")))
|
|
36
|
+
: Reader.traverse([first, ...other], part => Reader.asks((env) => typeof part.value === "string"
|
|
35
37
|
? part.value
|
|
36
|
-
: renderActivatableNameComponents(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
: renderActivatableNameComponents(env.translateMap, part.value, true))).thenW(list => localeJoinR(list, "disjunction"))).map(value => ({
|
|
39
|
+
label: first.label,
|
|
40
|
+
value,
|
|
41
|
+
sentenceType: undefined,
|
|
42
|
+
isMeta: false,
|
|
43
|
+
}));
|
|
44
|
+
}
|
|
45
|
+
return Reader.traverse([first, ...other], part => Reader.asks((env) => (part.label ?? "") +
|
|
43
46
|
(typeof part.value === "string"
|
|
44
47
|
? part.value
|
|
45
|
-
: renderActivatableNameComponents(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
: renderActivatableNameComponents(env.translateMap, part.value, true))))
|
|
49
|
+
.thenW(list => localeJoinR(list, "disjunction"))
|
|
50
|
+
.map(value => ({
|
|
51
|
+
value,
|
|
52
|
+
sentenceType: undefined,
|
|
53
|
+
isMeta: false,
|
|
54
|
+
}));
|
|
55
|
+
});
|
|
49
56
|
};
|
|
50
57
|
/**
|
|
51
58
|
* Print prerequisites element as a string.
|
|
52
59
|
*/
|
|
53
|
-
const printPrerequisitesElement = (printPrerequisite,
|
|
60
|
+
const printPrerequisitesElement = (printPrerequisite, element) => {
|
|
54
61
|
switch (element.kind) {
|
|
55
62
|
case "Single":
|
|
56
63
|
return printPrerequisite(element.Single);
|
|
57
64
|
case "Disjunction":
|
|
58
|
-
return printPrerequisitesDisjunction(printPrerequisite,
|
|
65
|
+
return printPrerequisitesDisjunction(printPrerequisite, element.Disjunction);
|
|
59
66
|
case "Group":
|
|
60
|
-
return printPrerequisiteGroup(
|
|
67
|
+
return printPrerequisiteGroup(element.Group);
|
|
68
|
+
default:
|
|
69
|
+
return assertExhaustive(element);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Print plain prerequisites as a string.
|
|
74
|
+
*/
|
|
75
|
+
const printPlainPrerequisites = (printPrerequisite, prerequisites) => Reader.traverse(prerequisites, element => printPrerequisitesElement(printPrerequisite, element).map(nullablePart => mapNullable(nullablePart, part => ({
|
|
76
|
+
type: element.kind === "Single" ? element.Single.kind : element.kind,
|
|
77
|
+
part,
|
|
78
|
+
})))).thenW(list => joinPrerequisiteParts(list.filter(isNotNullish)));
|
|
79
|
+
const printPrerequisiteDiff = (printPrerequisite, map, element) => {
|
|
80
|
+
switch (element.kind) {
|
|
81
|
+
case "Add":
|
|
82
|
+
return printPrerequisite(element.Add).map(part => map(element.Add, part));
|
|
83
|
+
case "Remove":
|
|
84
|
+
return printPrerequisite(element.Remove).map(part => map(element.Remove, part === undefined ? undefined : { ...part, isRemoved: true }));
|
|
61
85
|
default:
|
|
62
86
|
return assertExhaustive(element);
|
|
63
87
|
}
|
|
@@ -65,20 +89,18 @@ const printPrerequisitesElement = (printPrerequisite, locale, element) => {
|
|
|
65
89
|
/**
|
|
66
90
|
* Print plain prerequisites as a string.
|
|
67
91
|
*/
|
|
68
|
-
const
|
|
69
|
-
.map(element => mapNullable(printPrerequisitesElement(printPrerequisite, locale, element), part => ({
|
|
92
|
+
const printPlainDiffPrerequisites = (printPrerequisite, prerequisites) => Reader.traverse(prerequisites, diffElement => printPrerequisiteDiff(element => printPrerequisitesElement(printPrerequisite, element), (element, nullablePart) => mapNullable(nullablePart, part => ({
|
|
70
93
|
type: element.kind === "Single" ? element.Single.kind : element.kind,
|
|
71
94
|
part,
|
|
72
|
-
})))
|
|
73
|
-
.filter(isNotNullish));
|
|
95
|
+
})), diffElement)).thenW(list => joinPrerequisiteParts(list.filter(isNotNullish)));
|
|
74
96
|
/**
|
|
75
97
|
* Print prerequisite for level as a string.
|
|
76
98
|
*/
|
|
77
|
-
const printPrerequisiteForLevel = (printPrerequisite,
|
|
99
|
+
const printPrerequisiteForLevel = (printPrerequisite, value) => printPrerequisitesElement(printPrerequisite, value.prerequisite);
|
|
78
100
|
/**
|
|
79
101
|
* Print prerequisites for levels as a string.
|
|
80
102
|
*/
|
|
81
|
-
const printPrerequisitesForLevels = (printPrerequisite,
|
|
103
|
+
const printPrerequisitesForLevels = (printPrerequisite, value, printPreviousLevelPrerequisites, trailingText) => {
|
|
82
104
|
const previousLevelPrerequisites = printPreviousLevelPrerequisites === undefined
|
|
83
105
|
? []
|
|
84
106
|
: Array.from({ length: printPreviousLevelPrerequisites.levels - 1 }, (_, i) => ({
|
|
@@ -102,21 +124,19 @@ const printPrerequisitesForLevels = (printPrerequisite, locale, value, printPrev
|
|
|
102
124
|
...(hasBasePrerequisites
|
|
103
125
|
? []
|
|
104
126
|
: [
|
|
105
|
-
|
|
127
|
+
translateR("Level {$level}", {
|
|
106
128
|
level: romanize(1),
|
|
107
|
-
})
|
|
129
|
+
}).then(levelLabel => translateR("none").map(levelValue => `${levelLabel}: ${levelValue}`)),
|
|
108
130
|
]),
|
|
109
131
|
...sortedByLevel.map(([levelNumber, prerequisites]) => {
|
|
110
|
-
const prerequisitesString =
|
|
111
|
-
|
|
112
|
-
.map(element => mapNullable(printPrerequisiteForLevel(printPrerequisite, locale, element), part => ({
|
|
132
|
+
const prerequisitesString = Reader.sequence([
|
|
133
|
+
Reader.traverse(prerequisites, element => printPrerequisiteForLevel(printPrerequisite, element).map(nullablePart => mapNullable(nullablePart, part => ({
|
|
113
134
|
type: element.prerequisite.kind === "Single"
|
|
114
135
|
? element.prerequisite.Single.kind
|
|
115
136
|
: element.prerequisite.kind,
|
|
116
137
|
part,
|
|
117
|
-
})))
|
|
118
|
-
|
|
119
|
-
...(levelNumber === 1 && trailingText !== undefined
|
|
138
|
+
})))).map(list => list.filter(isNotNullish)),
|
|
139
|
+
Reader.of(levelNumber === 1 && trailingText !== undefined
|
|
120
140
|
? [
|
|
121
141
|
{
|
|
122
142
|
type: "trailing",
|
|
@@ -124,32 +144,32 @@ const printPrerequisitesForLevels = (printPrerequisite, locale, value, printPrev
|
|
|
124
144
|
},
|
|
125
145
|
]
|
|
126
146
|
: []),
|
|
127
|
-
]);
|
|
147
|
+
]).then(list => joinPrerequisiteParts(list.flat()));
|
|
128
148
|
return hasOnlyBasePrerequisites
|
|
129
149
|
? prerequisitesString
|
|
130
|
-
:
|
|
150
|
+
: prerequisitesString.then(string => translateR("Level {$level}", {
|
|
131
151
|
level: romanize(levelNumber),
|
|
132
|
-
})}: ${
|
|
152
|
+
}).map(levelLabel => `${levelLabel}: ${string}`));
|
|
133
153
|
}),
|
|
134
154
|
];
|
|
135
|
-
return printedParts.join("; ");
|
|
155
|
+
return Reader.sequence(printedParts).map(parts => parts.join("; "));
|
|
136
156
|
};
|
|
137
157
|
/**
|
|
138
158
|
* Print derived characteristic prerequisites as a string.
|
|
139
159
|
*/
|
|
140
|
-
export const printDerivedCharacteristicPrerequisites = (
|
|
160
|
+
export const printDerivedCharacteristicPrerequisites = (value) => printPlainPrerequisites(printDerivedCharacteristicPrerequisiteGroup, value);
|
|
141
161
|
/**
|
|
142
162
|
* Print publication prerequisites as a string.
|
|
143
163
|
*/
|
|
144
|
-
export const printPublicationPrerequisites = (
|
|
164
|
+
export const printPublicationPrerequisites = (value) => printPlainPrerequisites(printPublicationPrerequisiteGroup, value);
|
|
145
165
|
/**
|
|
146
166
|
* Print plain general prerequisites as a string.
|
|
147
167
|
*/
|
|
148
|
-
export const printPlainGeneralPrerequisites = (
|
|
168
|
+
export const printPlainGeneralPrerequisites = (value) => printPlainPrerequisites(printGeneralPrerequisiteGroup, value);
|
|
149
169
|
/**
|
|
150
170
|
* Print general prerequisites as a string.
|
|
151
171
|
*/
|
|
152
|
-
export const printGeneralPrerequisites = (
|
|
172
|
+
export const printGeneralPrerequisites = (value, printPreviousLevelPrerequisites, trailingText) => printPrerequisitesForLevels(printGeneralPrerequisiteGroup, value, printPreviousLevelPrerequisites === undefined
|
|
153
173
|
? undefined
|
|
154
174
|
: {
|
|
155
175
|
levels: printPreviousLevelPrerequisites.levels,
|
|
@@ -165,44 +185,48 @@ export const printGeneralPrerequisites = (getInstanceById, getResolvedSelectOpti
|
|
|
165
185
|
/**
|
|
166
186
|
* Print profession prerequisites as a string.
|
|
167
187
|
*/
|
|
168
|
-
export const printProfessionPrerequisites = (
|
|
188
|
+
export const printProfessionPrerequisites = (value) => printPlainPrerequisites(printProfessionPrerequisiteGroup, value);
|
|
189
|
+
/**
|
|
190
|
+
* Print profession prerequisites as a string.
|
|
191
|
+
*/
|
|
192
|
+
export const printProfessionVariantPrerequisites = (value) => printPlainDiffPrerequisites(printProfessionPrerequisiteGroup, value);
|
|
169
193
|
/**
|
|
170
194
|
* Print advantage disadvantage prerequisites as a string.
|
|
171
195
|
*/
|
|
172
|
-
export const printAdvantageDisadvantagePrerequisites = (
|
|
196
|
+
export const printAdvantageDisadvantagePrerequisites = (value, name, type) => printPrerequisitesForLevels(prerequisite => printAdvantageDisadvantagePrerequisiteGroup(prerequisite, name, type), value);
|
|
173
197
|
/**
|
|
174
198
|
* Print arcane tradition prerequisites as a string.
|
|
175
199
|
*/
|
|
176
|
-
export const printArcaneTraditionPrerequisites = (
|
|
200
|
+
export const printArcaneTraditionPrerequisites = (value) => printPlainPrerequisites(printArcaneTraditionPrerequisiteGroup, value);
|
|
177
201
|
/**
|
|
178
202
|
* Print personality trait prerequisites as a string.
|
|
179
203
|
*/
|
|
180
|
-
export const printPersonalityTraitPrerequisites = (
|
|
204
|
+
export const printPersonalityTraitPrerequisites = (value) => printPlainPrerequisites(printPersonalityTraitPrerequisiteGroup, value);
|
|
181
205
|
/**
|
|
182
206
|
* Print spellwork prerequisites as a string.
|
|
183
207
|
*/
|
|
184
|
-
export const printSpellworkPrerequisites = (
|
|
208
|
+
export const printSpellworkPrerequisites = (value) => printPlainPrerequisites(printSpellworkPrerequisiteGroup, value);
|
|
185
209
|
/**
|
|
186
210
|
* Print liturgy prerequisites as a string.
|
|
187
211
|
*/
|
|
188
|
-
export const printLiturgyPrerequisites = (
|
|
212
|
+
export const printLiturgyPrerequisites = (value) => printPlainPrerequisites(printLiturgyPrerequisiteGroup, value);
|
|
189
213
|
/**
|
|
190
214
|
* Print influence prerequisites as a string.
|
|
191
215
|
*/
|
|
192
|
-
export const printInfluencePrerequisites = (
|
|
216
|
+
export const printInfluencePrerequisites = (value) => printPlainPrerequisites(printInfluencePrerequisiteGroup, value);
|
|
193
217
|
/**
|
|
194
218
|
* Print language prerequisites as a string.
|
|
195
219
|
*/
|
|
196
|
-
export const printLanguagePrerequisites = (
|
|
220
|
+
export const printLanguagePrerequisites = (value) => printPrerequisitesForLevels(printLanguagePrerequisiteGroup, value);
|
|
197
221
|
/**
|
|
198
222
|
* Print animist power prerequisites as a string.
|
|
199
223
|
*/
|
|
200
|
-
export const printAnimistPowerPrerequisites = (
|
|
224
|
+
export const printAnimistPowerPrerequisites = (value) => printPlainPrerequisites(printAnimistPowerPrerequisiteGroup, value);
|
|
201
225
|
/**
|
|
202
226
|
* Print geode ritual prerequisites as a string.
|
|
203
227
|
*/
|
|
204
|
-
export const printGeodeRitualPrerequisites = (
|
|
228
|
+
export const printGeodeRitualPrerequisites = (value) => printPlainPrerequisites(printGeodeRitualPrerequisiteGroup, value);
|
|
205
229
|
/**
|
|
206
230
|
* Print enhancement prerequisites as a string.
|
|
207
231
|
*/
|
|
208
|
-
export const printEnhancementPrerequisites = (
|
|
232
|
+
export const printEnhancementPrerequisites = (value) => printPlainPrerequisites(printEnhancementPrerequisiteGroup, value);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { SentenceType } from "@optolith/database-schema/gen";
|
|
2
|
-
import type {
|
|
3
|
-
import type { Translate, TranslateMap } from "../../../helpers/translate.js";
|
|
2
|
+
import type { StdReader } from "../../../env.js";
|
|
4
3
|
import { type ActivatableNameComponents } from "../activatableNameChunks.js";
|
|
5
4
|
/**
|
|
6
5
|
* A part of the total list of prerequisites.
|
|
@@ -10,6 +9,7 @@ export type PrerequisitePart = {
|
|
|
10
9
|
value: string | ActivatableNameComponents;
|
|
11
10
|
sentenceType: SentenceType | undefined;
|
|
12
11
|
isMeta: boolean;
|
|
12
|
+
isRemoved?: true;
|
|
13
13
|
};
|
|
14
14
|
/**
|
|
15
15
|
* Type guard for prerequisite parts with a value object.
|
|
@@ -20,7 +20,7 @@ export declare const hasPartValueObject: (part: PrerequisitePart) => part is Pre
|
|
|
20
20
|
/**
|
|
21
21
|
* Join prerequisite parts using their configuration.
|
|
22
22
|
*/
|
|
23
|
-
export declare const joinPrerequisiteParts: (
|
|
23
|
+
export declare const joinPrerequisiteParts: (parts: {
|
|
24
24
|
type: string;
|
|
25
25
|
part: PrerequisitePart;
|
|
26
|
-
}[]) => string
|
|
26
|
+
}[]) => StdReader<string, "t" | "tm" | "lc">;
|
|
@@ -2,10 +2,12 @@ import { groupBy } from "@elyukai/utils/array/groups";
|
|
|
2
2
|
import { deepEqual, equal } from "@elyukai/utils/equality";
|
|
3
3
|
import { on } from "@elyukai/utils/function";
|
|
4
4
|
import { compareNumber, reduceCompare } from "@elyukai/utils/ordering";
|
|
5
|
+
import { Reader } from "@elyukai/utils/reader";
|
|
5
6
|
import { assertExhaustive } from "@optolith/helpers/typeSafety";
|
|
6
7
|
import { fromUniformCase } from "tsondb/schema/gen";
|
|
7
8
|
import { renderActivatableNameComponents, renderActivatableNameComponentsCombinedIfPossible, } from "../activatableNameChunks.js";
|
|
8
9
|
import { attributedInstance } from "../markdown.js";
|
|
10
|
+
import { translateR } from "../reader.js";
|
|
9
11
|
/**
|
|
10
12
|
* Type guard for prerequisite parts with a value object.
|
|
11
13
|
*/
|
|
@@ -13,18 +15,19 @@ export const hasPartValueObject = (part) => typeof part.value !== "string";
|
|
|
13
15
|
const countFurtherToCombined = (part, remainingParts) => {
|
|
14
16
|
const indexHasDifferentBaseValues = remainingParts.findIndex(remaining => !(part.label === remaining.label &&
|
|
15
17
|
deepEqual(part.value.id, remaining.value.id) &&
|
|
16
|
-
part.value.level === remaining.value.level
|
|
18
|
+
part.value.level === remaining.value.level &&
|
|
19
|
+
part.isRemoved === remaining.isRemoved));
|
|
17
20
|
return indexHasDifferentBaseValues === -1
|
|
18
21
|
? // if -1 is returned, all remaining parts have the same base values, so we can combine with all of them
|
|
19
22
|
remainingParts.length
|
|
20
23
|
: indexHasDifferentBaseValues;
|
|
21
24
|
};
|
|
22
25
|
const wrapActivatableInAttributedString = (text, id) => attributedInstance(text, id.kind, fromUniformCase(id), { context: '"prerequisite"' });
|
|
23
|
-
const joinAdjacentParts = (translateMap, localeCompare, part, remainingParts) => {
|
|
26
|
+
const joinAdjacentParts = (translate, translateMap, localeCompare, part, remainingParts) => {
|
|
24
27
|
const valuesWithSameBase = remainingParts.slice(0, countFurtherToCombined(part, remainingParts));
|
|
25
28
|
if (valuesWithSameBase.length > 0) {
|
|
26
29
|
return [
|
|
27
|
-
|
|
30
|
+
renderActivatableNameComponentsCombinedIfPossible(translate, translateMap, [part.value, ...valuesWithSameBase.map(p => p.value)], true, list => list.toSorted(localeCompare).join(", ")),
|
|
28
31
|
valuesWithSameBase.length,
|
|
29
32
|
];
|
|
30
33
|
}
|
|
@@ -53,43 +56,49 @@ const activatableKindToGroup = (kind) => kind === "Advantage" ? "Advantage" : ki
|
|
|
53
56
|
const activatableGroupOrder = ["Advantage", "Disadvantage", "SpecialAbility"];
|
|
54
57
|
const sortByActivatableGroup = on(group => activatableGroupOrder.indexOf(group), compareNumber);
|
|
55
58
|
const sortByActivatableGroupAndName = (localeCompare) => reduceCompare(on(item => item[0], sortByActivatableGroup), on(item => item[1], localeCompare));
|
|
56
|
-
const appendPrerequisitePartGroup = (previous,
|
|
59
|
+
const appendPrerequisitePartGroup = (previous, parts, isLast) => {
|
|
57
60
|
if (parts.length === 0) {
|
|
58
|
-
return previous;
|
|
61
|
+
return Reader.of(previous);
|
|
59
62
|
}
|
|
60
|
-
|
|
61
|
-
|
|
63
|
+
const wrapInNoPrerequisite = (text) => parts[0]?.isRemoved === true
|
|
64
|
+
? translateR("no prerequisite {$prerequisite}", { prerequisite: text })
|
|
65
|
+
: Reader.of(text);
|
|
66
|
+
if (parts.every(hasPartValueObject)) {
|
|
67
|
+
return Reader.asks(({ translate, translateMap, localeCompare }) => appendBySentenceType(previous, wrapInNoPrerequisite(parts
|
|
62
68
|
.toSorted(on(part => fromUniformCase(part.value.id), localeCompare))
|
|
63
69
|
.reduce((acc, current, i, arr) => {
|
|
64
70
|
if (acc[1] > 0) {
|
|
65
71
|
return [acc[0], acc[1] - 1];
|
|
66
72
|
}
|
|
67
|
-
const [rendered, furtherIncluded] = joinAdjacentParts(translateMap, localeCompare, current, arr.slice(i + 1));
|
|
73
|
+
const [rendered, furtherIncluded] = joinAdjacentParts(translate, translateMap, localeCompare, current, arr.slice(i + 1));
|
|
68
74
|
return [
|
|
69
75
|
[
|
|
70
76
|
...acc[0],
|
|
71
|
-
[
|
|
77
|
+
[
|
|
78
|
+
activatableKindToGroup(current.value.id.kind),
|
|
79
|
+
(current.label ?? "") + rendered,
|
|
80
|
+
],
|
|
72
81
|
],
|
|
73
82
|
furtherIncluded,
|
|
74
83
|
];
|
|
75
84
|
}, [[], 0])[0]
|
|
76
85
|
.toSorted(sortByActivatableGroupAndName(localeCompare))
|
|
77
86
|
.map(grouped => grouped[1])
|
|
78
|
-
.join(", "), undefined, isLast);
|
|
87
|
+
.join(", ")).run({ translate }), undefined, isLast));
|
|
79
88
|
}
|
|
80
89
|
else {
|
|
81
|
-
return parts.reduce((acc, current, i, arr) => appendBySentenceType(acc, (current.label ?? "") +
|
|
90
|
+
return Reader.asks(({ translate, translateMap }) => parts.reduce((acc, current, i, arr) => appendBySentenceType(acc, wrapInNoPrerequisite((current.label ?? "") +
|
|
82
91
|
(typeof current.value === "string"
|
|
83
92
|
? current.value
|
|
84
|
-
: wrapActivatableInAttributedString(renderActivatableNameComponents(translateMap, current.value, true), current.value.id)), current.sentenceType, isLast && i === arr.length - 1), previous);
|
|
93
|
+
: wrapActivatableInAttributedString(renderActivatableNameComponents(translateMap, current.value, true), current.value.id))).run({ translate }), current.sentenceType, isLast && i === arr.length - 1), previous));
|
|
85
94
|
}
|
|
86
95
|
};
|
|
87
96
|
/**
|
|
88
97
|
* Join prerequisite parts using their configuration.
|
|
89
98
|
*/
|
|
90
|
-
export const joinPrerequisiteParts = (
|
|
99
|
+
export const joinPrerequisiteParts = (parts) => groupBy(parts, on(part => part.type, equal))
|
|
91
100
|
.map(group => ({
|
|
92
101
|
type: group[0].type,
|
|
93
102
|
parts: group.map(groupItem => groupItem.part),
|
|
94
103
|
}))
|
|
95
|
-
.reduce((
|
|
104
|
+
.reduce((accR, partGroup, i, arr) => accR.thenW(acc => appendPrerequisitePartGroup(acc, partGroup.parts, i === arr.length - 1)), parts.every(({ part }) => part.isMeta) ? translateR("none") : Reader.of(""));
|
|
@@ -1,65 +1,63 @@
|
|
|
1
1
|
import type { ActivatableIdentifier, AdvantageDisadvantagePrerequisiteGroup, AnimistPowerPrerequisiteGroup, ArcaneTraditionPrerequisiteGroup, DerivedCharacteristicPrerequisiteGroup, EnhancementPrerequisiteGroup, GeneralPrerequisiteGroup, GeodeRitualPrerequisiteGroup, InfluencePrerequisiteGroup, LanguagePrerequisiteGroup, LiturgyPrerequisiteGroup, PersonalityTraitPrerequisiteGroup, PreconditionGroup, ProfessionPrerequisiteGroup, PublicationPrerequisiteGroup, RatedIdentifier, SpellworkPrerequisiteGroup } from "@optolith/database-schema/gen";
|
|
2
|
-
import type {
|
|
3
|
-
import type { LocaleEnvironment } from "../../../helpers/locale.js";
|
|
2
|
+
import type { StdReader } from "../../../env.js";
|
|
4
3
|
import type { PrerequisitePart } from "./part.js";
|
|
5
|
-
import { type GetResolvedSelectOptionById } from "./single/activatable.js";
|
|
6
4
|
/**
|
|
7
5
|
* Print the translation of a derived characteristic prerequisite group.
|
|
8
6
|
*/
|
|
9
|
-
export declare const printDerivedCharacteristicPrerequisiteGroup: (
|
|
7
|
+
export declare const printDerivedCharacteristicPrerequisiteGroup: (prerequisite: DerivedCharacteristicPrerequisiteGroup) => StdReader<PrerequisitePart | undefined, "t" | "tm">;
|
|
10
8
|
/**
|
|
11
9
|
* Print the translation of a publication prerequisite group.
|
|
12
10
|
*/
|
|
13
|
-
export declare const printPublicationPrerequisiteGroup: (
|
|
11
|
+
export declare const printPublicationPrerequisiteGroup: (prerequisite: PublicationPrerequisiteGroup) => StdReader<PrerequisitePart | undefined, "t" | "tm" | "ibi", "Publication">;
|
|
14
12
|
/**
|
|
15
13
|
* Print the translation of a general prerequisite group.
|
|
16
14
|
*/
|
|
17
|
-
export declare const printGeneralPrerequisiteGroup: (
|
|
15
|
+
export declare const printGeneralPrerequisiteGroup: (prerequisite: GeneralPrerequisiteGroup) => StdReader<PrerequisitePart | undefined, "t" | "tm" | "lj" | "lc" | "rso" | "ibi", "Race" | "Culture" | "PactCategory" | "PactDomain" | "SocialStatus" | "State" | ActivatableIdentifier["kind"] | RatedIdentifier["kind"] | "Property" | "Aspect" | "Enhancement" | "PersonalityTrait" | "Blessing" | "Cantrip">;
|
|
18
16
|
/**
|
|
19
17
|
* Print the translation of a profession prerequisite group.
|
|
20
18
|
*/
|
|
21
|
-
export declare const printProfessionPrerequisiteGroup: (
|
|
19
|
+
export declare const printProfessionPrerequisiteGroup: (prerequisite: ProfessionPrerequisiteGroup) => StdReader<PrerequisitePart | undefined, "t" | "tm" | "rso" | "ibi", "Race" | "Culture" | ActivatableIdentifier["kind"] | RatedIdentifier["kind"] | "Aspect">;
|
|
22
20
|
/**
|
|
23
21
|
* Print the translation of an advantage/disadvantage prerequisite group.
|
|
24
22
|
*/
|
|
25
|
-
export declare const printAdvantageDisadvantagePrerequisiteGroup: (
|
|
23
|
+
export declare const printAdvantageDisadvantagePrerequisiteGroup: (prerequisite: AdvantageDisadvantagePrerequisiteGroup, name: string, type: "Advantage" | "Disadvantage") => StdReader<PrerequisitePart | undefined, "t" | "tm" | "lj" | "lc" | "rso" | "ibi", "Race" | "Culture" | "PactCategory" | "PactDomain" | "SocialStatus" | "State" | ActivatableIdentifier["kind"] | RatedIdentifier["kind"] | "Property" | "Aspect" | "Enhancement" | "PersonalityTrait" | "Blessing" | "Cantrip">;
|
|
26
24
|
/**
|
|
27
25
|
* Print the translation of an arcane tradition prerequisite group.
|
|
28
26
|
*/
|
|
29
|
-
export declare const printArcaneTraditionPrerequisiteGroup: (
|
|
27
|
+
export declare const printArcaneTraditionPrerequisiteGroup: (prerequisite: ArcaneTraditionPrerequisiteGroup) => StdReader<PrerequisitePart | undefined, "t" | "tm" | "ibi", "Culture">;
|
|
30
28
|
/**
|
|
31
29
|
* Print the translation of a personality trait prerequisite group.
|
|
32
30
|
*/
|
|
33
|
-
export declare const printPersonalityTraitPrerequisiteGroup: (
|
|
31
|
+
export declare const printPersonalityTraitPrerequisiteGroup: (prerequisite: PersonalityTraitPrerequisiteGroup) => StdReader<PrerequisitePart | undefined, "t" | "tm" | "ibi", "Race" | "Culture" | "PersonalityTrait">;
|
|
34
32
|
/**
|
|
35
33
|
* Print the translation of a spellwork prerequisite group.
|
|
36
34
|
*/
|
|
37
|
-
export declare const printSpellworkPrerequisiteGroup: (
|
|
35
|
+
export declare const printSpellworkPrerequisiteGroup: (prerequisite: SpellworkPrerequisiteGroup) => StdReader<PrerequisitePart | undefined, "t" | "tm" | "ibi", RatedIdentifier["kind"]>;
|
|
38
36
|
/**
|
|
39
37
|
* Print the translation of a liturgy prerequisite group.
|
|
40
38
|
*/
|
|
41
|
-
export declare const printLiturgyPrerequisiteGroup: (
|
|
39
|
+
export declare const printLiturgyPrerequisiteGroup: (prerequisite: LiturgyPrerequisiteGroup) => StdReader<PrerequisitePart | undefined, never>;
|
|
42
40
|
/**
|
|
43
41
|
* Print the translation of an influence prerequisite group.
|
|
44
42
|
*/
|
|
45
|
-
export declare const printInfluencePrerequisiteGroup: (
|
|
43
|
+
export declare const printInfluencePrerequisiteGroup: (prerequisite: InfluencePrerequisiteGroup) => StdReader<PrerequisitePart | undefined, "t" | "tm" | "rso" | "ibi" | "acibp", "Influence" | "Race" | ActivatableIdentifier["kind"] | "Aspect", never, "ProfessionVersion">;
|
|
46
44
|
/**
|
|
47
45
|
* Print the translation of a language prerequisite group.
|
|
48
46
|
*/
|
|
49
|
-
export declare const printLanguagePrerequisiteGroup: (
|
|
47
|
+
export declare const printLanguagePrerequisiteGroup: (prerequisite: LanguagePrerequisiteGroup) => StdReader<PrerequisitePart | undefined, "t" | "tm" | "rso" | "ibi", "Race" | ActivatableIdentifier["kind"] | "Aspect">;
|
|
50
48
|
/**
|
|
51
49
|
* Print the translation of an animist power prerequisite group.
|
|
52
50
|
*/
|
|
53
|
-
export declare const printAnimistPowerPrerequisiteGroup: (
|
|
51
|
+
export declare const printAnimistPowerPrerequisiteGroup: (prerequisite: AnimistPowerPrerequisiteGroup) => StdReader<PrerequisitePart | undefined, "tm" | "ibi", "AnimistPower">;
|
|
54
52
|
/**
|
|
55
53
|
* Print the translation of a geode ritual prerequisite group.
|
|
56
54
|
*/
|
|
57
|
-
export declare const printGeodeRitualPrerequisiteGroup: (
|
|
55
|
+
export declare const printGeodeRitualPrerequisiteGroup: (prerequisite: GeodeRitualPrerequisiteGroup) => StdReader<PrerequisitePart | undefined, "t" | "tm" | "rso" | "ibi", ActivatableIdentifier["kind"] | "Aspect" | "Influence">;
|
|
58
56
|
/**
|
|
59
57
|
* Print the translation of an enhancement prerequisite group.
|
|
60
58
|
*/
|
|
61
|
-
export declare const printEnhancementPrerequisiteGroup: (
|
|
59
|
+
export declare const printEnhancementPrerequisiteGroup: (prerequisite: EnhancementPrerequisiteGroup) => StdReader<PrerequisitePart | undefined, "t" | "tm" | "ibi", RatedIdentifier["kind"] | "Enhancement">;
|
|
62
60
|
/**
|
|
63
61
|
* Print the translation of a precondition group.
|
|
64
62
|
*/
|
|
65
|
-
export declare const printPreconditionGroup: (
|
|
63
|
+
export declare const printPreconditionGroup: (prerequisite: PreconditionGroup) => StdReader<PrerequisitePart | undefined, "t" | "tm" | "ibi", "Publication">;
|