@optolith/entity-descriptions 0.4.7 → 0.4.10
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 +22 -0
- package/lib/entities/activatable.d.ts +8 -3
- package/lib/entities/activatable.js +187 -15
- package/lib/entities/curriculum.js +14 -21
- package/lib/entities/derivedCharacteristic.js +5 -7
- package/lib/entities/equipmentPackage.js +2 -1
- package/lib/entities/liturgicalChant.js +7 -3
- package/lib/entities/partial/commonnessRatedAdvantagesAndDisadvantages.js +8 -12
- package/lib/entities/partial/herbary.js +5 -8
- package/lib/entities/partial/markdown.d.ts +55 -0
- package/lib/entities/partial/markdown.js +59 -0
- package/lib/entities/partial/prerequisites/index.d.ts +1 -1
- package/lib/entities/partial/prerequisites/index.js +26 -13
- package/lib/entities/partial/prerequisites/part.js +8 -3
- package/lib/entities/partial/prerequisites/single/culture.js +2 -1
- package/lib/entities/partial/prerequisites/single/personalityTrait.js +2 -1
- package/lib/entities/partial/prerequisites/single/profession.js +4 -1
- package/lib/entities/partial/prerequisites/single/race.js +2 -1
- package/lib/entities/partial/prerequisites/single/rated.js +2 -27
- package/lib/entities/partial/prerequisites/single/ratedMinimumNumber.js +2 -1
- package/lib/entities/partial/prerequisites/single/ratedSum.js +2 -1
- package/lib/entities/partial/prerequisites/single/state.js +2 -1
- package/lib/entities/partial/reader.d.ts +33 -0
- package/lib/entities/partial/reader.js +13 -0
- package/lib/entities/partial/unknown.d.ts +1 -1
- package/lib/entities/partial/unknown.js +1 -1
- package/lib/entities/personalityTrait.js +9 -2
- package/lib/entities/profession.js +25 -25
- package/lib/entities/race.js +4 -6
- package/lib/entities/spell.js +13 -25
- package/lib/index.d.ts +53 -53
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Some helpers to create Markdown content.
|
|
3
|
+
*/
|
|
4
|
+
import type { EntityMap } from "optolith-database-schema/gen";
|
|
5
|
+
import { type IdArgsVariant } from "tsondb/schema/gen";
|
|
6
|
+
import type { GetInstanceById } from "../../helpers/getTypes.js";
|
|
7
|
+
import type { LocaleMap, TranslateMap } from "../../helpers/translate.js";
|
|
8
|
+
/**
|
|
9
|
+
* Creates an attributed string in Markdown format.
|
|
10
|
+
*/
|
|
11
|
+
export declare const attributedString: (text: string, rawAttributes: Partial<Record<string, string>>) => string;
|
|
12
|
+
/**
|
|
13
|
+
* Display an instance of an entity in Markdown format.
|
|
14
|
+
*/
|
|
15
|
+
export declare const attributedInstance: (name: string, entity: string, id?: string, other?: Record<string, string>) => string;
|
|
16
|
+
/**
|
|
17
|
+
* Renders the name of an instance in an attributed string.
|
|
18
|
+
*/
|
|
19
|
+
export declare const attributedName: <E extends { [K in keyof EntityMap]: EntityMap[K] extends {
|
|
20
|
+
translations: LocaleMap<{
|
|
21
|
+
name: string;
|
|
22
|
+
}>;
|
|
23
|
+
} ? K : never; }[keyof EntityMap]>(translateMap: TranslateMap, getInstanceById: GetInstanceById<E>, context: string, ...args: IdArgsVariant<EntityMap, E>) => string | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Renders the name of an instance according to a custom function.
|
|
26
|
+
*/
|
|
27
|
+
export declare const customName: <E extends { [K in keyof EntityMap]: EntityMap[K] extends {
|
|
28
|
+
translations: LocaleMap<object>;
|
|
29
|
+
} ? K : never; }[keyof EntityMap]>(translateMap: TranslateMap, getInstanceById: GetInstanceById<E>, fn: (translation: EntityMap[E]["translations"][string]) => string, ...args: IdArgsVariant<EntityMap, E>) => string | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Renders the name of an instance according to a custom function in an attributed string.
|
|
32
|
+
*/
|
|
33
|
+
export declare const attributedCustomName: <E extends { [K in keyof EntityMap]: EntityMap[K] extends {
|
|
34
|
+
translations: LocaleMap<object>;
|
|
35
|
+
} ? K : never; }[keyof EntityMap]>(translateMap: TranslateMap, getInstanceById: GetInstanceById<E>, context: string, fn: (translation: EntityMap[E]["translations"][string]) => string, ...args: IdArgsVariant<EntityMap, E>) => string | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Renders the name of an instance in an attributed string.
|
|
38
|
+
*/
|
|
39
|
+
export declare const attributedNameFromInstance: (translateMap: TranslateMap, instance: {
|
|
40
|
+
translations: LocaleMap<{
|
|
41
|
+
name: string;
|
|
42
|
+
}>;
|
|
43
|
+
} | undefined, context: string, ...args: IdArgsVariant<EntityMap, keyof EntityMap>) => string | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Renders the name of an instance in an attributed string.
|
|
46
|
+
*/
|
|
47
|
+
export declare const attributedNameFromTranslation: (translation: {
|
|
48
|
+
name: string;
|
|
49
|
+
} | undefined, context: string, ...args: IdArgsVariant<EntityMap, keyof EntityMap>) => string | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* Renders the name of an instance in an attributed string.
|
|
52
|
+
*/
|
|
53
|
+
export declare const attributedNameFromSafeTranslation: (translation: {
|
|
54
|
+
name: string;
|
|
55
|
+
}, context: string, ...args: IdArgsVariant<EntityMap, keyof EntityMap>) => string;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Some helpers to create Markdown content.
|
|
3
|
+
*/
|
|
4
|
+
import { mapNullable } from "@elyukai/utils/nullable";
|
|
5
|
+
import { normalizedIdArgs } from "tsondb/schema/gen";
|
|
6
|
+
/**
|
|
7
|
+
* Creates an attributed string in Markdown format.
|
|
8
|
+
*/
|
|
9
|
+
export const attributedString = (text, rawAttributes) => `^[${text}](${Object.entries(rawAttributes)
|
|
10
|
+
.filter((pair) => pair[1] !== undefined)
|
|
11
|
+
.map(([key, value]) => `${key}: ${value}`)
|
|
12
|
+
.join(", ")})`;
|
|
13
|
+
/**
|
|
14
|
+
* Display an instance of an entity in Markdown format.
|
|
15
|
+
*/
|
|
16
|
+
export const attributedInstance = (name, entity, id, other) => attributedString(name, {
|
|
17
|
+
...other,
|
|
18
|
+
entity: `"${entity}"`,
|
|
19
|
+
instance: id === undefined ? undefined : `"${id}"`,
|
|
20
|
+
});
|
|
21
|
+
/**
|
|
22
|
+
* Renders the name of an instance in an attributed string.
|
|
23
|
+
*/
|
|
24
|
+
export const attributedName = (translateMap, getInstanceById, context, ...args) => {
|
|
25
|
+
const id = normalizedIdArgs(args);
|
|
26
|
+
return mapNullable(translateMap(getInstanceById(...args)?.translations)?.name, name => attributedInstance(name, id.entityName, id.id, { context: `"${context}"` }));
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Renders the name of an instance according to a custom function.
|
|
30
|
+
*/
|
|
31
|
+
export const customName = (translateMap, getInstanceById, fn, ...args) => mapNullable(translateMap(getInstanceById(...args)?.translations), translation => fn(translation));
|
|
32
|
+
/**
|
|
33
|
+
* Renders the name of an instance according to a custom function in an attributed string.
|
|
34
|
+
*/
|
|
35
|
+
export const attributedCustomName = (translateMap, getInstanceById, context, fn, ...args) => {
|
|
36
|
+
const id = normalizedIdArgs(args);
|
|
37
|
+
return mapNullable(translateMap(getInstanceById(...args)?.translations), translation => attributedInstance(fn(translation), id.entityName, id.id, { context: `"${context}"` }));
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Renders the name of an instance in an attributed string.
|
|
41
|
+
*/
|
|
42
|
+
export const attributedNameFromInstance = (translateMap, instance, context, ...args) => {
|
|
43
|
+
const id = normalizedIdArgs(args);
|
|
44
|
+
return mapNullable(translateMap(instance?.translations)?.name, name => attributedInstance(name, id.entityName, id.id, { context: `"${context}"` }));
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Renders the name of an instance in an attributed string.
|
|
48
|
+
*/
|
|
49
|
+
export const attributedNameFromTranslation = (translation, context, ...args) => {
|
|
50
|
+
const id = normalizedIdArgs(args);
|
|
51
|
+
return mapNullable(translation?.name, name => attributedInstance(name, id.entityName, id.id, { context: `"${context}"` }));
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Renders the name of an instance in an attributed string.
|
|
55
|
+
*/
|
|
56
|
+
export const attributedNameFromSafeTranslation = (translation, context, ...args) => {
|
|
57
|
+
const id = normalizedIdArgs(args);
|
|
58
|
+
return attributedInstance(translation.name, id.entityName, id.id, { context: `"${context}"` });
|
|
59
|
+
};
|
|
@@ -20,7 +20,7 @@ export declare const printPlainGeneralPrerequisites: (getInstanceById: GetInstan
|
|
|
20
20
|
export declare const printGeneralPrerequisites: (getInstanceById: GetInstanceById<"Race" | "Culture" | "PactCategory" | "PactDomain" | "SocialStatus" | "State" | ActivatableIdentifier["kind"] | RatedIdentifier["kind"] | "Property" | "Aspect" | "Enhancement">, getResolvedSelectOptionById: GetResolvedSelectOptionById, locale: LocaleEnvironment, value: GeneralPrerequisites, printPreviousLevelPrerequisites?: {
|
|
21
21
|
id: SpecialAbilityIdentifier;
|
|
22
22
|
levels: number;
|
|
23
|
-
}) => string;
|
|
23
|
+
}, trailingText?: string) => string;
|
|
24
24
|
/**
|
|
25
25
|
* Print profession prerequisites as a string.
|
|
26
26
|
*/
|
|
@@ -78,17 +78,20 @@ const printPrerequisiteForLevel = (printPrerequisite, locale, value) => printPre
|
|
|
78
78
|
/**
|
|
79
79
|
* Print prerequisites for levels as a string.
|
|
80
80
|
*/
|
|
81
|
-
const printPrerequisitesForLevels = (printPrerequisite, locale, value, printPreviousLevelPrerequisites) => {
|
|
81
|
+
const printPrerequisitesForLevels = (printPrerequisite, locale, value, printPreviousLevelPrerequisites, trailingText) => {
|
|
82
82
|
const previousLevelPrerequisites = printPreviousLevelPrerequisites === undefined
|
|
83
83
|
? []
|
|
84
84
|
: Array.from({ length: printPreviousLevelPrerequisites.levels - 1 }, (_, i) => ({
|
|
85
85
|
level: i + 2,
|
|
86
86
|
prerequisite: {
|
|
87
87
|
kind: "Single",
|
|
88
|
-
Single: printPreviousLevelPrerequisites.
|
|
88
|
+
Single: printPreviousLevelPrerequisites.createPrerequisite(i + 1),
|
|
89
89
|
},
|
|
90
90
|
}));
|
|
91
91
|
const groupedByLevel = Map.groupBy([...value, ...previousLevelPrerequisites], prerequisite => prerequisite.level);
|
|
92
|
+
if (trailingText !== undefined && !groupedByLevel.has(1)) {
|
|
93
|
+
groupedByLevel.set(1, []);
|
|
94
|
+
}
|
|
92
95
|
const hasBasePrerequisites = groupedByLevel.has(1);
|
|
93
96
|
const sortedByLevel = groupedByLevel
|
|
94
97
|
.entries()
|
|
@@ -104,14 +107,24 @@ const printPrerequisitesForLevels = (printPrerequisite, locale, value, printPrev
|
|
|
104
107
|
})}: ${locale.translate("none")}`,
|
|
105
108
|
]),
|
|
106
109
|
...sortedByLevel.map(([levelNumber, prerequisites]) => {
|
|
107
|
-
const prerequisitesString = joinPrerequisiteParts(locale.translate, locale.translateMap, locale.compare,
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
110
|
+
const prerequisitesString = joinPrerequisiteParts(locale.translate, locale.translateMap, locale.compare, [
|
|
111
|
+
...prerequisites
|
|
112
|
+
.map(element => mapNullable(printPrerequisiteForLevel(printPrerequisite, locale, element), part => ({
|
|
113
|
+
type: element.prerequisite.kind === "Single"
|
|
114
|
+
? element.prerequisite.Single.kind
|
|
115
|
+
: element.prerequisite.kind,
|
|
116
|
+
part,
|
|
117
|
+
})))
|
|
118
|
+
.filter(isNotNullish),
|
|
119
|
+
...(levelNumber === 1 && trailingText !== undefined
|
|
120
|
+
? [
|
|
121
|
+
{
|
|
122
|
+
type: "trailing",
|
|
123
|
+
part: { value: trailingText, sentenceType: undefined, isMeta: false },
|
|
124
|
+
},
|
|
125
|
+
]
|
|
126
|
+
: []),
|
|
127
|
+
]);
|
|
115
128
|
return hasOnlyBasePrerequisites
|
|
116
129
|
? prerequisitesString
|
|
117
130
|
: `${locale.translate("Level {$level}", {
|
|
@@ -136,11 +149,11 @@ export const printPlainGeneralPrerequisites = (getInstanceById, getResolvedSelec
|
|
|
136
149
|
/**
|
|
137
150
|
* Print general prerequisites as a string.
|
|
138
151
|
*/
|
|
139
|
-
export const printGeneralPrerequisites = (getInstanceById, getResolvedSelectOptionById, locale, value, printPreviousLevelPrerequisites) => printPrerequisitesForLevels(prerequisite => printGeneralPrerequisiteGroup(getInstanceById, getResolvedSelectOptionById, locale, prerequisite), locale, value, printPreviousLevelPrerequisites === undefined
|
|
152
|
+
export const printGeneralPrerequisites = (getInstanceById, getResolvedSelectOptionById, locale, value, printPreviousLevelPrerequisites, trailingText) => printPrerequisitesForLevels(prerequisite => printGeneralPrerequisiteGroup(getInstanceById, getResolvedSelectOptionById, locale, prerequisite), locale, value, printPreviousLevelPrerequisites === undefined
|
|
140
153
|
? undefined
|
|
141
154
|
: {
|
|
142
155
|
levels: printPreviousLevelPrerequisites.levels,
|
|
143
|
-
|
|
156
|
+
createPrerequisite: (level) => ({
|
|
144
157
|
kind: "Activatable",
|
|
145
158
|
Activatable: {
|
|
146
159
|
id: printPreviousLevelPrerequisites.id,
|
|
@@ -148,7 +161,7 @@ export const printGeneralPrerequisites = (getInstanceById, getResolvedSelectOpti
|
|
|
148
161
|
level,
|
|
149
162
|
},
|
|
150
163
|
}),
|
|
151
|
-
});
|
|
164
|
+
}, trailingText);
|
|
152
165
|
/**
|
|
153
166
|
* Print profession prerequisites as a string.
|
|
154
167
|
*/
|
|
@@ -5,6 +5,7 @@ import { compareNumber, reduceCompare } from "@elyukai/utils/ordering";
|
|
|
5
5
|
import { assertExhaustive } from "@optolith/helpers/typeSafety";
|
|
6
6
|
import { fromUniformCase } from "tsondb/schema/gen";
|
|
7
7
|
import { renderActivatableNameComponents, renderActivatableNameComponentsCombinedIfPossible, } from "../activatableNameChunks.js";
|
|
8
|
+
import { attributedInstance } from "../markdown.js";
|
|
8
9
|
/**
|
|
9
10
|
* Type guard for prerequisite parts with a value object.
|
|
10
11
|
*/
|
|
@@ -18,15 +19,19 @@ const countFurtherToCombined = (part, remainingParts) => {
|
|
|
18
19
|
remainingParts.length
|
|
19
20
|
: indexHasDifferentBaseValues;
|
|
20
21
|
};
|
|
22
|
+
const wrapActivatableInAttributedString = (text, id) => attributedInstance(text, id.kind, fromUniformCase(id), { context: '"prerequisite"' });
|
|
21
23
|
const joinAdjacentParts = (translateMap, localeCompare, part, remainingParts) => {
|
|
22
24
|
const valuesWithSameBase = remainingParts.slice(0, countFurtherToCombined(part, remainingParts));
|
|
23
25
|
if (valuesWithSameBase.length > 0) {
|
|
24
26
|
return [
|
|
25
|
-
renderActivatableNameComponentsCombinedIfPossible(translateMap, [part.value, ...valuesWithSameBase.map(p => p.value)], true, list => list.toSorted(localeCompare).join(", ")),
|
|
27
|
+
wrapActivatableInAttributedString(renderActivatableNameComponentsCombinedIfPossible(translateMap, [part.value, ...valuesWithSameBase.map(p => p.value)], true, list => list.toSorted(localeCompare).join(", ")), part.value.id),
|
|
26
28
|
valuesWithSameBase.length,
|
|
27
29
|
];
|
|
28
30
|
}
|
|
29
|
-
return [
|
|
31
|
+
return [
|
|
32
|
+
wrapActivatableInAttributedString(renderActivatableNameComponents(translateMap, part.value, true), part.value.id),
|
|
33
|
+
0,
|
|
34
|
+
];
|
|
30
35
|
};
|
|
31
36
|
const appendBySentenceType = (previouslyRendered, currentRendered, sentenceType, isLast) => {
|
|
32
37
|
switch (sentenceType?.kind) {
|
|
@@ -76,7 +81,7 @@ const appendPrerequisitePartGroup = (previous, translateMap, localeCompare, part
|
|
|
76
81
|
return parts.reduce((acc, current, i, arr) => appendBySentenceType(acc, (current.label ?? "") +
|
|
77
82
|
(typeof current.value === "string"
|
|
78
83
|
? current.value
|
|
79
|
-
: renderActivatableNameComponents(translateMap, current.value, true)), current.sentenceType, isLast && i === arr.length - 1), previous);
|
|
84
|
+
: wrapActivatableInAttributedString(renderActivatableNameComponents(translateMap, current.value, true), current.value.id)), current.sentenceType, isLast && i === arr.length - 1), previous);
|
|
80
85
|
}
|
|
81
86
|
};
|
|
82
87
|
/**
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { attributedNameFromSafeTranslation } from "../../markdown.js";
|
|
1
2
|
import { printDisplayOption } from "../displayOption.js";
|
|
2
3
|
/**
|
|
3
4
|
* Get the translation of a culture prerequisite.
|
|
@@ -13,7 +14,7 @@ export const printCulturePrerequisite = (getInstanceById, locale, prerequisite)
|
|
|
13
14
|
}
|
|
14
15
|
return {
|
|
15
16
|
label: `${locale.translate("Culture")} `,
|
|
16
|
-
value: cultureTranslation.
|
|
17
|
+
value: attributedNameFromSafeTranslation(cultureTranslation, "prerequisite", "Culture", prerequisite.id),
|
|
17
18
|
sentenceType: undefined,
|
|
18
19
|
isMeta: false,
|
|
19
20
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { attributedNameFromSafeTranslation } from "../../markdown.js";
|
|
1
2
|
import { printDisplayOption } from "../displayOption.js";
|
|
2
3
|
/**
|
|
3
4
|
* Get the translation of a personality trait prerequisite.
|
|
@@ -11,7 +12,7 @@ export const printPersonalityTraitPrerequisite = (getInstanceById, locale, prere
|
|
|
11
12
|
if (personalityTrait === undefined || personalityTraitTranslation === undefined) {
|
|
12
13
|
return undefined;
|
|
13
14
|
}
|
|
14
|
-
const name = `${personalityTraitTranslation.
|
|
15
|
+
const name = `${attributedNameFromSafeTranslation(personalityTraitTranslation, "prerequisite", "PersonalityTrait", prerequisite.id)} (${locale.translate("Level {$level}", {
|
|
15
16
|
level: personalityTrait.level,
|
|
16
17
|
})})`;
|
|
17
18
|
return {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { attributedInstance } from "../../markdown.js";
|
|
1
2
|
import { getProfessionName } from "../../professions.js";
|
|
2
3
|
import { printDisplayOption } from "../displayOption.js";
|
|
3
4
|
/**
|
|
@@ -12,7 +13,9 @@ export const printProfessionPrerequisite = (getChildInstancesForInstanceId, loca
|
|
|
12
13
|
return undefined;
|
|
13
14
|
}
|
|
14
15
|
return {
|
|
15
|
-
value: professionName,
|
|
16
|
+
value: attributedInstance(professionName, "Profession", prerequisite.id, {
|
|
17
|
+
context: '"prerequisite"',
|
|
18
|
+
}),
|
|
16
19
|
sentenceType: undefined,
|
|
17
20
|
isMeta: false,
|
|
18
21
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { attributedNameFromSafeTranslation } from "../../markdown.js";
|
|
1
2
|
import { printDisplayOption } from "../displayOption.js";
|
|
2
3
|
/**
|
|
3
4
|
* Get the translation of a race prerequisite.
|
|
@@ -13,7 +14,7 @@ export const printRacePrerequisite = (getInstanceById, locale, prerequisite) =>
|
|
|
13
14
|
}
|
|
14
15
|
return {
|
|
15
16
|
label: `${locale.translate("Race")} `,
|
|
16
|
-
value: raceTranslation.
|
|
17
|
+
value: attributedNameFromSafeTranslation(raceTranslation, "prerequisite", "Race", prerequisite.id),
|
|
17
18
|
sentenceType: undefined,
|
|
18
19
|
isMeta: false,
|
|
19
20
|
};
|
|
@@ -1,31 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { attributedName } from "../../markdown.js";
|
|
2
2
|
import { MISSING_VALUE } from "../../unknown.js";
|
|
3
3
|
import { printDisplayOption } from "../displayOption.js";
|
|
4
|
-
const printRatedName = (getInstanceById, translateMap, id) => {
|
|
5
|
-
switch (id.kind) {
|
|
6
|
-
case "Attribute":
|
|
7
|
-
return (translateMap(getInstanceById("Attribute", id.Attribute)?.translations)?.abbreviation ??
|
|
8
|
-
MISSING_VALUE);
|
|
9
|
-
case "Skill":
|
|
10
|
-
return translateMap(getInstanceById("Skill", id.Skill)?.translations)?.name ?? MISSING_VALUE;
|
|
11
|
-
case "CloseCombatTechnique":
|
|
12
|
-
return (translateMap(getInstanceById("CloseCombatTechnique", id.CloseCombatTechnique)?.translations)
|
|
13
|
-
?.name ?? MISSING_VALUE);
|
|
14
|
-
case "RangedCombatTechnique":
|
|
15
|
-
return (translateMap(getInstanceById("RangedCombatTechnique", id.RangedCombatTechnique)?.translations)?.name ?? MISSING_VALUE);
|
|
16
|
-
case "Spell":
|
|
17
|
-
return translateMap(getInstanceById("Spell", id.Spell)?.translations)?.name ?? MISSING_VALUE;
|
|
18
|
-
case "Ritual":
|
|
19
|
-
return translateMap(getInstanceById("Ritual", id.Ritual)?.translations)?.name ?? MISSING_VALUE;
|
|
20
|
-
case "LiturgicalChant":
|
|
21
|
-
return (translateMap(getInstanceById("LiturgicalChant", id.LiturgicalChant)?.translations)?.name ??
|
|
22
|
-
MISSING_VALUE);
|
|
23
|
-
case "Ceremony":
|
|
24
|
-
return (translateMap(getInstanceById("Ceremony", id.Ceremony)?.translations)?.name ?? MISSING_VALUE);
|
|
25
|
-
default:
|
|
26
|
-
return assertExhaustive(id);
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
4
|
/**
|
|
30
5
|
* Get the translation of a blessed tradition prerequisite.
|
|
31
6
|
*/
|
|
@@ -34,7 +9,7 @@ export const printRatedPrerequisite = (getInstanceById, locale, prerequisite) =>
|
|
|
34
9
|
return printDisplayOption(locale.translateMap, prerequisite.display_option);
|
|
35
10
|
}
|
|
36
11
|
return {
|
|
37
|
-
value: `${
|
|
12
|
+
value: `${attributedName(locale.translateMap, getInstanceById, "prerequisite", prerequisite.id) ?? MISSING_VALUE} ${prerequisite.value.toFixed()}`,
|
|
38
13
|
sentenceType: undefined,
|
|
39
14
|
isMeta: false,
|
|
40
15
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isNotNullish } from "@optolith/helpers/nullable";
|
|
2
2
|
import { assertExhaustive } from "@optolith/helpers/typeSafety";
|
|
3
|
+
import { attributedName } from "../../markdown.js";
|
|
3
4
|
import { MISSING_VALUE } from "../../unknown.js";
|
|
4
5
|
import { printDisplayOption } from "../displayOption.js";
|
|
5
6
|
const printNumberOfTheFollowingSkills = (locale, number) => locale.translate(".input {$count :number} {{{$count} of the following skills}}", {
|
|
@@ -36,7 +37,7 @@ export const printRatedMinimumNumberPrerequisite = (getInstanceById, locale, pre
|
|
|
36
37
|
switch (prerequisite.targets.kind) {
|
|
37
38
|
case "Skills": {
|
|
38
39
|
const skills = prerequisite.targets.Skills.targets
|
|
39
|
-
.map(id => locale.translateMap
|
|
40
|
+
.map(id => attributedName(locale.translateMap, getInstanceById, "prerequisite", "Skill", id))
|
|
40
41
|
.filter(isNotNullish);
|
|
41
42
|
return {
|
|
42
43
|
value: locale.translate(".input {$minRating :number} {{{$count} on at least SR {$minRating}: {$list}}}", // zwei der folgenden Talente mindestens FW 10:
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isNotNullish } from "@optolith/helpers/nullable";
|
|
2
|
+
import { attributedName } from "../../markdown.js";
|
|
2
3
|
import { printDisplayOption } from "../displayOption.js";
|
|
3
4
|
/**
|
|
4
5
|
* Get the translation of a rated sum prerequisite.
|
|
@@ -8,7 +9,7 @@ export const printRatedSumPrerequisite = (getInstanceById, locale, prerequisite)
|
|
|
8
9
|
return printDisplayOption(locale.translateMap, prerequisite.display_option);
|
|
9
10
|
}
|
|
10
11
|
const skills = prerequisite.targets
|
|
11
|
-
.map(skillId => locale.translateMap
|
|
12
|
+
.map(skillId => attributedName(locale.translateMap, getInstanceById, "prerequisite", "Skill", skillId))
|
|
12
13
|
.filter(isNotNullish);
|
|
13
14
|
return {
|
|
14
15
|
value: locale.translate("the SR for {$skill} combined must add up to at least {$minRating}", {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { attributedNameFromSafeTranslation } from "../../markdown.js";
|
|
1
2
|
import { printDisplayOption } from "../displayOption.js";
|
|
2
3
|
/**
|
|
3
4
|
* Get the translation of a state prerequisite.
|
|
@@ -13,7 +14,7 @@ export const printStatePrerequisite = (getInstanceById, locale, prerequisite) =>
|
|
|
13
14
|
}
|
|
14
15
|
return {
|
|
15
16
|
label: `${locale.translate("State")} `,
|
|
16
|
-
value:
|
|
17
|
+
value: attributedNameFromSafeTranslation(stateTranslation, "prerequisite", "State", prerequisite.id),
|
|
17
18
|
sentenceType: undefined,
|
|
18
19
|
isMeta: false,
|
|
19
20
|
};
|
|
@@ -133,6 +133,39 @@ export declare const strictNameR: <E extends { [K in keyof EntityMap]: EntityMap
|
|
|
133
133
|
translateMap: TranslateMap;
|
|
134
134
|
getInstanceById: GetInstanceById<E>;
|
|
135
135
|
}, string>;
|
|
136
|
+
/**
|
|
137
|
+
* Retrieves the `name` property of the specified entry in an attributed string.
|
|
138
|
+
*/
|
|
139
|
+
export declare const attributedNameR: <E extends { [K in keyof EntityMap]: EntityMap[K] extends {
|
|
140
|
+
translations: LocaleMap<{
|
|
141
|
+
name: string;
|
|
142
|
+
}>;
|
|
143
|
+
} ? K : never; }[keyof EntityMap]>(context: string, ...args: IdArgsVariant<EntityMap, E>) => Reader<{
|
|
144
|
+
translateMap: TranslateMap;
|
|
145
|
+
getInstanceById: GetInstanceById<E>;
|
|
146
|
+
}, string | undefined>;
|
|
147
|
+
/**
|
|
148
|
+
* Applies a function to the translation of the specified entry and renders it in an attributed string.
|
|
149
|
+
*/
|
|
150
|
+
export declare const attributedCustomNameR: <E extends { [K in keyof EntityMap]: EntityMap[K] extends {
|
|
151
|
+
translations: LocaleMap<{
|
|
152
|
+
name: string;
|
|
153
|
+
}>;
|
|
154
|
+
} ? K : never; }[keyof EntityMap]>(context: string, fn: (translation: EntityMap[E]["translations"][string]) => string, ...args: IdArgsVariant<EntityMap, E>) => Reader<{
|
|
155
|
+
translateMap: TranslateMap;
|
|
156
|
+
getInstanceById: GetInstanceById<E>;
|
|
157
|
+
}, string | undefined>;
|
|
158
|
+
/**
|
|
159
|
+
* Applies a function to the translation of the specified entry.
|
|
160
|
+
*/
|
|
161
|
+
export declare const customNameR: <E extends { [K in keyof EntityMap]: EntityMap[K] extends {
|
|
162
|
+
translations: LocaleMap<{
|
|
163
|
+
name: string;
|
|
164
|
+
}>;
|
|
165
|
+
} ? K : never; }[keyof EntityMap]>(fn: (translation: EntityMap[E]["translations"][string]) => string, ...args: IdArgsVariant<EntityMap, E>) => Reader<{
|
|
166
|
+
translateMap: TranslateMap;
|
|
167
|
+
getInstanceById: GetInstanceById<E>;
|
|
168
|
+
}, string | undefined>;
|
|
136
169
|
/**
|
|
137
170
|
* Joins a list of strings according to the locale’s rules for the given type.
|
|
138
171
|
*/
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isNotNullish } from "@elyukai/utils/nullable";
|
|
2
2
|
import { Reader } from "@elyukai/utils/reader";
|
|
3
3
|
import { assertExhaustive } from "@elyukai/utils/typeSafety";
|
|
4
|
+
import { attributedCustomName, attributedName, customName } from "./markdown.js";
|
|
4
5
|
import { Speed } from "./rated/activatable/speed.js";
|
|
5
6
|
import { responsive, ResponsiveTextSize } from "./responsiveText.js";
|
|
6
7
|
import { formatEnergy } from "./units/energy.js";
|
|
@@ -50,6 +51,18 @@ export const nameR = (...args) => Reader.asks(env => env.translateMap(env.getIns
|
|
|
50
51
|
* 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.
|
|
51
52
|
*/
|
|
52
53
|
export const strictNameR = (...args) => nameR(...args).map(name => name ?? MISSING_VALUE);
|
|
54
|
+
/**
|
|
55
|
+
* Retrieves the `name` property of the specified entry in an attributed string.
|
|
56
|
+
*/
|
|
57
|
+
export const attributedNameR = (context, ...args) => Reader.asks(env => attributedName(env.translateMap, env.getInstanceById, context, ...args));
|
|
58
|
+
/**
|
|
59
|
+
* Applies a function to the translation of the specified entry and renders it in an attributed string.
|
|
60
|
+
*/
|
|
61
|
+
export const attributedCustomNameR = (context, fn, ...args) => Reader.asks(env => attributedCustomName(env.translateMap, env.getInstanceById, context, fn, ...args));
|
|
62
|
+
/**
|
|
63
|
+
* Applies a function to the translation of the specified entry.
|
|
64
|
+
*/
|
|
65
|
+
export const customNameR = (fn, ...args) => Reader.asks(env => customName(env.translateMap, env.getInstanceById, fn, ...args));
|
|
53
66
|
/**
|
|
54
67
|
* Joins a list of strings according to the locale’s rules for the given type.
|
|
55
68
|
*/
|
|
@@ -5,4 +5,4 @@ export declare const MISSING_VALUE = "###MISSING###";
|
|
|
5
5
|
/**
|
|
6
6
|
* String to display when a translation that should be present produces an error.
|
|
7
7
|
*/
|
|
8
|
-
export declare const UNHANDLED_VALUE = "###
|
|
8
|
+
export declare const UNHANDLED_VALUE = "###UNHANDLEDERROR###";
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { on } from "@elyukai/utils/function";
|
|
2
|
+
import { mapNullable } from "@elyukai/utils/nullable";
|
|
2
3
|
import { compareNullish } from "@elyukai/utils/ordering";
|
|
3
4
|
import { romanize } from "@elyukai/utils/roman";
|
|
4
5
|
import { numAsc } from "@optolith/helpers/compare";
|
|
5
6
|
import { createEntityDescriptionCreator } from "../creator.js";
|
|
7
|
+
import { attributedNameFromInstance } from "./partial/markdown.js";
|
|
6
8
|
import { printPersonalityTraitPrerequisites } from "./partial/prerequisites/index.js";
|
|
7
9
|
import { MISSING_VALUE } from "./partial/unknown.js";
|
|
8
10
|
/**
|
|
@@ -31,13 +33,18 @@ export const getPersonalityTraitEntityDescription = createEntityDescriptionCreat
|
|
|
31
33
|
? undefined
|
|
32
34
|
: {
|
|
33
35
|
label: translate("Can be combined with"),
|
|
34
|
-
value: Map.groupBy(entry.combination_options.map(optionId => getInstanceById("PersonalityTrait", optionId)
|
|
36
|
+
value: Map.groupBy(entry.combination_options.map(optionId => mapNullable(getInstanceById("PersonalityTrait", optionId), pt => ({
|
|
37
|
+
id: optionId,
|
|
38
|
+
content: pt,
|
|
39
|
+
}))), option => option?.content.level ?? null)
|
|
35
40
|
.entries()
|
|
36
41
|
.toArray()
|
|
37
42
|
.toSorted(on(group => group[0], compareNullish(numAsc)))
|
|
38
43
|
.map(([level, options]) => level === null
|
|
39
44
|
? MISSING_VALUE
|
|
40
|
-
: `${translate("Level {$level}", { level: romanize(level) })} ${localeJoin(options.map(option =>
|
|
45
|
+
: `${translate("Level {$level}", { level: romanize(level) })} ${localeJoin(options.map(option => (option &&
|
|
46
|
+
attributedNameFromInstance(translateMap, option.content, "prerequisite", "PersonalityTrait", option.id)) ??
|
|
47
|
+
MISSING_VALUE), "disjunction")}`)
|
|
41
48
|
.join(", "),
|
|
42
49
|
},
|
|
43
50
|
entry.prerequisites === undefined
|