@optolith/entity-descriptions 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +65 -0
- package/lib/creator.d.ts +32 -0
- package/lib/creator.js +72 -0
- package/lib/entities/activatable.d.ts +52 -0
- package/lib/entities/activatable.js +609 -0
- package/lib/entities/alternativeRule.d.ts +7 -0
- package/lib/entities/alternativeRule.js +21 -0
- package/lib/entities/attribute.d.ts +6 -0
- package/lib/entities/attribute.js +15 -0
- package/lib/entities/combatTechnique.d.ts +5 -7
- package/lib/entities/combatTechnique.js +34 -24
- package/lib/entities/condition.d.ts +12 -0
- package/lib/entities/condition.js +63 -0
- package/lib/entities/culture.d.ts +8 -0
- package/lib/entities/culture.js +309 -0
- package/lib/entities/curriculum.d.ts +11 -0
- package/lib/entities/curriculum.js +266 -0
- package/lib/entities/derivedCharacteristic.d.ts +9 -0
- package/lib/entities/derivedCharacteristic.js +91 -0
- package/lib/entities/disease.d.ts +9 -0
- package/lib/entities/disease.js +88 -0
- package/lib/entities/elixir.d.ts +10 -0
- package/lib/entities/elixir.js +76 -0
- package/lib/entities/equipment.d.ts +24 -0
- package/lib/entities/equipment.js +613 -0
- package/lib/entities/equipmentPackage.d.ts +8 -0
- package/lib/entities/equipmentPackage.js +301 -0
- package/lib/entities/experienceLevel.d.ts +3 -2
- package/lib/entities/experienceLevel.js +33 -28
- package/lib/entities/focusRule.d.ts +3 -4
- package/lib/entities/focusRule.js +13 -5
- package/lib/entities/influence.d.ts +7 -0
- package/lib/entities/influence.js +35 -0
- package/lib/entities/liturgicalChant.d.ts +10 -23
- package/lib/entities/liturgicalChant.js +169 -131
- package/lib/entities/optionalRule.d.ts +3 -2
- package/lib/entities/optionalRule.js +4 -3
- package/lib/entities/partial/activatableNameChunks.d.ts +58 -0
- package/lib/entities/partial/activatableNameChunks.js +356 -0
- package/lib/entities/partial/adventurePointsValue.d.ts +9 -0
- package/lib/entities/partial/adventurePointsValue.js +243 -0
- package/lib/entities/partial/animalTypes.d.ts +11 -0
- package/lib/entities/partial/animalTypes.js +13 -0
- package/lib/entities/partial/commonnessRatedAdvantagesAndDisadvantages.d.ts +16 -0
- package/lib/entities/partial/commonnessRatedAdvantagesAndDisadvantages.js +40 -0
- package/lib/entities/partial/dice.d.ts +10 -0
- package/lib/entities/partial/dice.js +13 -0
- package/lib/entities/partial/herbary.d.ts +28 -0
- package/lib/entities/partial/herbary.js +65 -0
- package/lib/entities/partial/map.d.ts +49 -0
- package/lib/entities/partial/map.js +43 -0
- package/lib/entities/partial/mathOperation.d.ts +36 -0
- package/lib/entities/partial/mathOperation.js +107 -0
- package/lib/entities/partial/prerequisites/displayOption.d.ts +7 -0
- package/lib/entities/partial/prerequisites/displayOption.js +19 -0
- package/lib/entities/partial/prerequisites/index.d.ts +67 -0
- package/lib/entities/partial/prerequisites/index.js +189 -0
- package/lib/entities/partial/prerequisites/part.d.ts +26 -0
- package/lib/entities/partial/prerequisites/part.js +88 -0
- package/lib/entities/partial/prerequisites/prerequisiteGroups.d.ts +65 -0
- package/lib/entities/partial/prerequisites/prerequisiteGroups.js +269 -0
- package/lib/entities/partial/prerequisites/single/activatable.d.ts +18 -0
- package/lib/entities/partial/prerequisites/single/activatable.js +40 -0
- package/lib/entities/partial/prerequisites/single/animistPower.d.ts +8 -0
- package/lib/entities/partial/prerequisites/single/animistPower.js +23 -0
- package/lib/entities/partial/prerequisites/single/blessedTradition.d.ts +7 -0
- package/lib/entities/partial/prerequisites/single/blessedTradition.js +32 -0
- package/lib/entities/partial/prerequisites/single/commonSuggestedByRCP.d.ts +6 -0
- package/lib/entities/partial/prerequisites/single/commonSuggestedByRCP.js +19 -0
- package/lib/entities/partial/prerequisites/single/culture.d.ts +8 -0
- package/lib/entities/partial/prerequisites/single/culture.js +20 -0
- package/lib/entities/partial/prerequisites/single/enhancement.d.ts +8 -0
- package/lib/entities/partial/prerequisites/single/enhancement.js +41 -0
- package/lib/entities/partial/prerequisites/single/influence.d.ts +8 -0
- package/lib/entities/partial/prerequisites/single/influence.js +17 -0
- package/lib/entities/partial/prerequisites/single/magicalTradition.d.ts +7 -0
- package/lib/entities/partial/prerequisites/single/magicalTradition.js +27 -0
- package/lib/entities/partial/prerequisites/single/noOtherAncestorBloodAdvantage.d.ts +6 -0
- package/lib/entities/partial/prerequisites/single/noOtherAncestorBloodAdvantage.js +8 -0
- package/lib/entities/partial/prerequisites/single/pact.d.ts +8 -0
- package/lib/entities/partial/prerequisites/single/pact.js +30 -0
- package/lib/entities/partial/prerequisites/single/personalityTrait.d.ts +8 -0
- package/lib/entities/partial/prerequisites/single/personalityTrait.js +28 -0
- package/lib/entities/partial/prerequisites/single/primaryAttribute.d.ts +7 -0
- package/lib/entities/partial/prerequisites/single/primaryAttribute.js +15 -0
- package/lib/entities/partial/prerequisites/single/publication.d.ts +8 -0
- package/lib/entities/partial/prerequisites/single/publication.js +19 -0
- package/lib/entities/partial/prerequisites/single/race.d.ts +8 -0
- package/lib/entities/partial/prerequisites/single/race.js +20 -0
- package/lib/entities/partial/prerequisites/single/rated.d.ts +8 -0
- package/lib/entities/partial/prerequisites/single/rated.js +41 -0
- package/lib/entities/partial/prerequisites/single/ratedMinimumNumber.d.ts +8 -0
- package/lib/entities/partial/prerequisites/single/ratedMinimumNumber.js +89 -0
- package/lib/entities/partial/prerequisites/single/ratedSum.d.ts +8 -0
- package/lib/entities/partial/prerequisites/single/ratedSum.js +21 -0
- package/lib/entities/partial/prerequisites/single/rule.d.ts +7 -0
- package/lib/entities/partial/prerequisites/single/rule.js +4 -0
- package/lib/entities/partial/prerequisites/single/sex.d.ts +7 -0
- package/lib/entities/partial/prerequisites/single/sex.js +19 -0
- package/lib/entities/partial/prerequisites/single/sexualCharacteristic.d.ts +7 -0
- package/lib/entities/partial/prerequisites/single/sexualCharacteristic.js +21 -0
- package/lib/entities/partial/prerequisites/single/socialStatus.d.ts +8 -0
- package/lib/entities/partial/prerequisites/single/socialStatus.js +21 -0
- package/lib/entities/partial/prerequisites/single/state.d.ts +8 -0
- package/lib/entities/partial/prerequisites/single/state.js +20 -0
- package/lib/entities/partial/prerequisites/single/text.d.ts +7 -0
- package/lib/entities/partial/prerequisites/single/text.js +9 -0
- package/lib/entities/partial/professions.d.ts +15 -0
- package/lib/entities/partial/professions.js +19 -0
- package/lib/entities/partial/rated/activatable/castingTime.d.ts +16 -7
- package/lib/entities/partial/rated/activatable/castingTime.js +35 -20
- package/lib/entities/partial/rated/activatable/checkResultBased.d.ts +18 -3
- package/lib/entities/partial/rated/activatable/checkResultBased.js +18 -10
- package/lib/entities/partial/rated/activatable/cost.d.ts +88 -8
- package/lib/entities/partial/rated/activatable/cost.js +183 -115
- package/lib/entities/partial/rated/activatable/duration.d.ts +36 -13
- package/lib/entities/partial/rated/activatable/duration.js +72 -61
- package/lib/entities/partial/rated/activatable/effect.d.ts +4 -4
- package/lib/entities/partial/rated/activatable/effect.js +32 -25
- package/lib/entities/partial/rated/activatable/index.d.ts +31 -27
- package/lib/entities/partial/rated/activatable/index.js +63 -28
- package/lib/entities/partial/rated/activatable/isMinimumMaximum.d.ts +5 -6
- package/lib/entities/partial/rated/activatable/isMinimumMaximum.js +8 -5
- package/lib/entities/partial/rated/activatable/nonModifiableSuffix.d.ts +2 -4
- package/lib/entities/partial/rated/activatable/nonModifiableSuffix.js +7 -42
- package/lib/entities/partial/rated/activatable/range.d.ts +22 -14
- package/lib/entities/partial/rated/activatable/range.js +54 -54
- package/lib/entities/partial/rated/activatable/speed.d.ts +11 -2
- package/lib/entities/partial/rated/activatable/speed.js +14 -1
- package/lib/entities/partial/rated/activatable/targetCategory.d.ts +4 -5
- package/lib/entities/partial/rated/activatable/targetCategory.js +19 -24
- package/lib/entities/partial/rated/improvementCost.d.ts +16 -4
- package/lib/entities/partial/rated/improvementCost.js +63 -4
- package/lib/entities/partial/rated/skillCheck.d.ts +20 -17
- package/lib/entities/partial/rated/skillCheck.js +56 -54
- package/lib/entities/partial/reader.d.ts +266 -0
- package/lib/entities/partial/reader.js +175 -0
- package/lib/entities/partial/responsiveText.d.ts +10 -5
- package/lib/entities/partial/responsiveText.js +19 -3
- package/lib/entities/partial/units/energy.d.ts +5 -8
- package/lib/entities/partial/units/energy.js +5 -23
- package/lib/entities/partial/units/length.d.ts +20 -2
- package/lib/entities/partial/units/length.js +24 -5
- package/lib/entities/partial/units/timeSpan.d.ts +25 -4
- package/lib/entities/partial/units/timeSpan.js +27 -15
- package/lib/entities/partial/unknown.d.ts +5 -1
- package/lib/entities/partial/unknown.js +5 -1
- package/lib/entities/personalityTrait.d.ts +7 -0
- package/lib/entities/personalityTrait.js +56 -0
- package/lib/entities/poison.d.ts +12 -0
- package/lib/entities/poison.js +356 -0
- package/lib/entities/profession.d.ts +12 -0
- package/lib/entities/profession.js +585 -0
- package/lib/entities/race.d.ts +9 -0
- package/lib/entities/race.js +146 -0
- package/lib/entities/sexPractice.d.ts +6 -0
- package/lib/entities/sexPractice.js +33 -0
- package/lib/entities/skill.d.ts +9 -9
- package/lib/entities/skill.js +124 -91
- package/lib/entities/spell.d.ts +83 -26
- package/lib/entities/spell.js +835 -147
- package/lib/entities/state.d.ts +6 -0
- package/lib/entities/state.js +17 -0
- package/lib/helpers/enums.d.ts +11 -0
- package/lib/helpers/enums.js +6 -0
- package/lib/helpers/getTypes.d.ts +12 -482
- package/lib/helpers/getTypes.js +1 -0
- package/lib/helpers/identifiers.d.ts +314 -0
- package/lib/helpers/identifiers.js +333 -0
- package/lib/helpers/locale.d.ts +21 -2
- package/lib/helpers/translate.d.ts +47 -5
- package/lib/helpers/translate.js +13 -6
- package/lib/index.d.ts +848 -21
- package/lib/index.js +182 -17
- package/lib/references/index.d.ts +6 -3
- package/lib/references/index.js +25 -33
- package/lib/references/page.d.ts +1 -1
- package/lib/references/page.js +14 -14
- package/lib/references/pageRange.d.ts +1 -5
- package/lib/references/pageRange.js +7 -16
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/package.json +30 -10
- package/.prettierrc.yml +0 -1
- package/lib/entities/partial/rated/activatable/entity.d.ts +0 -11
- package/lib/entities/partial/rated/activatable/entity.js +0 -12
- package/lib/references/occurrence.d.ts +0 -4
- package/lib/references/occurrence.js +0 -3
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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
|
|
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
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
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
|
|
13
|
+
return translateR("Self");
|
|
18
14
|
case "Zone":
|
|
19
|
-
return
|
|
15
|
+
return translateR("Zone");
|
|
20
16
|
case "LiturgicalChantsAndCeremonies":
|
|
21
|
-
return
|
|
17
|
+
return translateR("Liturgical Chants and Ceremonies");
|
|
18
|
+
case "Spellworks":
|
|
19
|
+
return translateR("Spellworks");
|
|
22
20
|
case "Cantrips":
|
|
23
|
-
return
|
|
21
|
+
return translateR("Cantrips");
|
|
24
22
|
case "Predefined":
|
|
25
|
-
return
|
|
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
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { type RangeBounds } from "@elyukai/utils/range";
|
|
2
|
+
import type { ImprovementCost } from "optolith-database-schema/gen";
|
|
3
|
+
import { type RawDefinitionListEntityDescriptionSectionItem } from "../../../index.js";
|
|
4
|
+
import { type StdReader } from "../reader.js";
|
|
5
|
+
/**
|
|
6
|
+
* Renders an improvement cost value as a string.
|
|
7
|
+
*/
|
|
8
|
+
export declare const renderImprovementCostValue: (improvementCost: ImprovementCost) => string;
|
|
4
9
|
/**
|
|
5
10
|
* Returns the improvement cost as an inline library property.
|
|
6
11
|
*/
|
|
7
|
-
export declare const
|
|
12
|
+
export declare const renderImprovementCost: (improvementCost: ImprovementCost) => StdReader<RawDefinitionListEntityDescriptionSectionItem, "t">;
|
|
13
|
+
/**
|
|
14
|
+
* Calculates the adventure points for an improvement cost.
|
|
15
|
+
* @throws {RangeError} if the rating range is invalid (max < min).
|
|
16
|
+
*/
|
|
17
|
+
export declare const calculateAdventurePointsFromImprovementCost: (improvementCost: ImprovementCost | ImprovementCost["kind"] | {
|
|
18
|
+
kind: "E";
|
|
19
|
+
} | "E", rating?: number | RangeBounds) => number;
|
|
@@ -1,7 +1,66 @@
|
|
|
1
|
+
import { rangeSize } from "@elyukai/utils/range";
|
|
2
|
+
import { assertExhaustive } from "@elyukai/utils/typeSafety";
|
|
3
|
+
import { translateR } from "../reader.js";
|
|
4
|
+
/**
|
|
5
|
+
* Renders an improvement cost value as a string.
|
|
6
|
+
*/
|
|
7
|
+
export const renderImprovementCostValue = (improvementCost) => improvementCost.kind;
|
|
1
8
|
/**
|
|
2
9
|
* Returns the improvement cost as an inline library property.
|
|
3
10
|
*/
|
|
4
|
-
export const
|
|
5
|
-
label
|
|
6
|
-
value: improvementCost,
|
|
7
|
-
});
|
|
11
|
+
export const renderImprovementCost = (improvementCost) => translateR("Improvement Cost").map(label => ({
|
|
12
|
+
label,
|
|
13
|
+
value: renderImprovementCostValue(improvementCost),
|
|
14
|
+
}));
|
|
15
|
+
/**
|
|
16
|
+
* Calculates the adventure points for an improvement cost.
|
|
17
|
+
* @throws {RangeError} if the rating range is invalid (max < min).
|
|
18
|
+
*/
|
|
19
|
+
export const calculateAdventurePointsFromImprovementCost = (improvementCost, rating = 1) => {
|
|
20
|
+
const normalized = typeof improvementCost === "string" ? improvementCost : improvementCost.kind;
|
|
21
|
+
const base = (() => {
|
|
22
|
+
switch (normalized) {
|
|
23
|
+
case "A":
|
|
24
|
+
return 1;
|
|
25
|
+
case "B":
|
|
26
|
+
return 2;
|
|
27
|
+
case "C":
|
|
28
|
+
return 3;
|
|
29
|
+
case "D":
|
|
30
|
+
return 4;
|
|
31
|
+
case "E":
|
|
32
|
+
return 15;
|
|
33
|
+
default:
|
|
34
|
+
return assertExhaustive(normalized);
|
|
35
|
+
}
|
|
36
|
+
})();
|
|
37
|
+
const lastRatingOfSameValue = (() => {
|
|
38
|
+
switch (normalized) {
|
|
39
|
+
case "A":
|
|
40
|
+
case "B":
|
|
41
|
+
case "C":
|
|
42
|
+
case "D":
|
|
43
|
+
return 12;
|
|
44
|
+
case "E":
|
|
45
|
+
return 14;
|
|
46
|
+
default:
|
|
47
|
+
return assertExhaustive(normalized);
|
|
48
|
+
}
|
|
49
|
+
})();
|
|
50
|
+
if (typeof rating === "number") {
|
|
51
|
+
return (base *
|
|
52
|
+
(rating < lastRatingOfSameValue ? 1 : rating - lastRatingOfSameValue + 1));
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
const [min, max] = rating;
|
|
56
|
+
if (max < min) {
|
|
57
|
+
throw new RangeError(`Invalid rating range: ${min} - ${max}`);
|
|
58
|
+
}
|
|
59
|
+
const size = rangeSize(rating);
|
|
60
|
+
const constantRangeSize = Math.min(size, lastRatingOfSameValue - min + 1);
|
|
61
|
+
const variableRangeSize = size - constantRangeSize;
|
|
62
|
+
const constantCost = base * constantRangeSize;
|
|
63
|
+
const variableCost = base * (((variableRangeSize + 1) * (variableRangeSize + 2)) / 2 - 1);
|
|
64
|
+
return constantCost + variableCost;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
@@ -1,19 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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
|
-
*
|
|
5
|
+
* Renders a skill check.
|
|
9
6
|
*/
|
|
10
|
-
export declare const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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 {
|
|
3
|
+
import { getInstanceByIdFnR, responsiveR, responsiveThenR, responsiveTranslateR, translateMapR, translateR, } from "../reader.js";
|
|
4
|
+
import { MISSING_VALUE } from "../unknown.js";
|
|
3
5
|
/**
|
|
4
|
-
*
|
|
6
|
+
* Renders a skill check.
|
|
5
7
|
*/
|
|
6
|
-
export const
|
|
7
|
-
label:
|
|
8
|
+
export const renderSkillCheck = (check) => Reader.asks(({ translate, translateMap, getInstanceById }) => ({
|
|
9
|
+
label: translate("Check"),
|
|
8
10
|
value: check
|
|
9
|
-
.map(
|
|
10
|
-
?.abbreviation ??
|
|
11
|
-
.join("/")
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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 {};
|