@optolith/entity-descriptions 0.2.1 → 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 +58 -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
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { isNotEmpty } from "@elyukai/utils/array/nonEmpty";
|
|
2
|
+
import { mapNullable } from "@elyukai/utils/nullable";
|
|
3
|
+
import { Reader } from "@elyukai/utils/reader";
|
|
4
|
+
import { ensureNonEmpty } from "@optolith/helpers/array";
|
|
5
|
+
import { parensIf } from "./rated/activatable/parensIf.js";
|
|
6
|
+
import { MISSING_VALUE } from "./unknown.js";
|
|
7
|
+
const renderCommonnessRatedAdvantageOrDisadvantageName = (translateMap, getInstanceById, entity, item) => {
|
|
8
|
+
const instance = getInstanceById(entity, item.id);
|
|
9
|
+
const instanceTranslation = translateMap(instance?.translations);
|
|
10
|
+
const customTranslation = translateMap(item.translations);
|
|
11
|
+
const name = instanceTranslation?.name_in_library ?? instanceTranslation?.name;
|
|
12
|
+
return name !== undefined &&
|
|
13
|
+
customTranslation?.options !== undefined &&
|
|
14
|
+
name.endsWith(")")
|
|
15
|
+
? `${name.slice(0, -1)}; ${customTranslation.options})`
|
|
16
|
+
: (name ?? MISSING_VALUE) + parensIf(customTranslation?.options);
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Render the names of either commonness-rated advantages or commonness-rated disadvantages.
|
|
20
|
+
*/
|
|
21
|
+
export const renderCommonnessRatedAdvantagesOrDisadvantages = (entity, items) => Reader.asks(({ translate, translateMap, getInstanceById, localeCompare }) => items === undefined || !isNotEmpty(items)
|
|
22
|
+
? translate("none")
|
|
23
|
+
: items
|
|
24
|
+
.map(item => renderCommonnessRatedAdvantageOrDisadvantageName(translateMap, getInstanceById, entity, item))
|
|
25
|
+
.toSorted(localeCompare)
|
|
26
|
+
.join(", "));
|
|
27
|
+
/**
|
|
28
|
+
* Render the names of commonness-rated advantages and disadvantages together.
|
|
29
|
+
*/
|
|
30
|
+
export const renderCommonnessRatedAdvantagesAndDisadvantages = (advantages, disadvantages) => Reader.asks(({ translate, translateMap, getInstanceById, localeCompare }) => mapNullable(ensureNonEmpty([
|
|
31
|
+
["Advantage", advantages],
|
|
32
|
+
["Disadvantage", disadvantages],
|
|
33
|
+
].flatMap(([entity, items]) => items?.map(item => renderCommonnessRatedAdvantageOrDisadvantageName(translateMap, getInstanceById, entity, item)) ?? [])), renderedItems => renderedItems.toSorted(localeCompare).join(", ")) ?? translate("none"));
|
|
34
|
+
/**
|
|
35
|
+
* Render a value with a possible translation, falling back to explicity rendering the value if no translation is available.
|
|
36
|
+
*/
|
|
37
|
+
export const renderValueWithPossibleTranslation = (label, value, renderValue, valueTranslation) => Reader.asks(({ translate }) => ({
|
|
38
|
+
label: translate(label),
|
|
39
|
+
value: valueTranslation ?? renderValue(value),
|
|
40
|
+
}));
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Dice } from "optolith-database-schema/gen";
|
|
2
|
+
import type { Translate } from "../../helpers/translate.js";
|
|
3
|
+
/**
|
|
4
|
+
* Renders a dice expression like "2D6" into a localized string.
|
|
5
|
+
*/
|
|
6
|
+
export declare const renderDice: (translate: Translate, dice: Dice) => string;
|
|
7
|
+
/**
|
|
8
|
+
* Renders a dice expression with an additional flat modifier, like "2D6+3" or "2D6-1".
|
|
9
|
+
*/
|
|
10
|
+
export declare const renderDiceAndFlat: (translate: Translate, dice: Dice, flat: number | undefined) => string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { additionFormatter, subtractionFormatter } from "./mathOperation.js";
|
|
2
|
+
/**
|
|
3
|
+
* Renders a dice expression like "2D6" into a localized string.
|
|
4
|
+
*/
|
|
5
|
+
export const renderDice = (translate, dice) => translate("{$count}D{$sides}", { count: dice.number, sides: dice.sides });
|
|
6
|
+
/**
|
|
7
|
+
* Renders a dice expression with an additional flat modifier, like "2D6+3" or "2D6-1".
|
|
8
|
+
*/
|
|
9
|
+
export const renderDiceAndFlat = (translate, dice, flat) => flat === undefined || flat === 0
|
|
10
|
+
? renderDice(translate, dice)
|
|
11
|
+
: flat > 0
|
|
12
|
+
? additionFormatter(renderDice(translate, dice), flat)
|
|
13
|
+
: subtractionFormatter(renderDice(translate, dice), flat);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { AlternativeName, LaboratoryLevel, Resistance } from "optolith-database-schema/gen";
|
|
2
|
+
import type { GetInstanceById } from "../../helpers/getTypes.js";
|
|
3
|
+
import type { LocaleMap, Translate, TranslateMap } from "../../helpers/translate.js";
|
|
4
|
+
import type { IdMap } from "../../index.js";
|
|
5
|
+
/**
|
|
6
|
+
* Renders a laboratory level into a localized string.
|
|
7
|
+
*/
|
|
8
|
+
export declare const renderLaboratoryLevel: (translate: Translate, level: LaboratoryLevel) => string;
|
|
9
|
+
/**
|
|
10
|
+
* Renders a resistance into a localized string.
|
|
11
|
+
*/
|
|
12
|
+
export declare const renderResistance: (translate: Translate, translateMap: TranslateMap, getInstanceById: GetInstanceById<"DerivedCharacteristic">, idMap: IdMap, resistance: Resistance) => string;
|
|
13
|
+
/**
|
|
14
|
+
* Renders a chance value into a localized string.
|
|
15
|
+
*/
|
|
16
|
+
export declare const renderChance: (translate: Translate, translateMap: TranslateMap, item: {
|
|
17
|
+
chance?: number;
|
|
18
|
+
translations?: LocaleMap<{
|
|
19
|
+
chance?: string;
|
|
20
|
+
}>;
|
|
21
|
+
}, includePercentage?: boolean) => string | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Renders a list of alternative names into a localized string, or returns undefined if there are no alternative names.
|
|
24
|
+
*/
|
|
25
|
+
export declare const renderAlternativeNames: (translate: Translate, alternativeNames: AlternativeName[] | undefined) => {
|
|
26
|
+
label: string;
|
|
27
|
+
value: string;
|
|
28
|
+
} | undefined;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { isNotEmpty } from "@elyukai/utils/array/nonEmpty";
|
|
2
|
+
import { assertExhaustive } from "@elyukai/utils/typeSafety";
|
|
3
|
+
import { renderDice } from "./dice.js";
|
|
4
|
+
import { parensIf } from "./rated/activatable/parensIf.js";
|
|
5
|
+
import { MISSING_VALUE } from "./unknown.js";
|
|
6
|
+
/**
|
|
7
|
+
* Renders a laboratory level into a localized string.
|
|
8
|
+
*/
|
|
9
|
+
export const renderLaboratoryLevel = (translate, level) => {
|
|
10
|
+
switch (level.kind) {
|
|
11
|
+
case "ArchaicLaboratory":
|
|
12
|
+
return translate("Archaic laboratory");
|
|
13
|
+
case "WitchKitchen":
|
|
14
|
+
return translate("Witch kitchen");
|
|
15
|
+
case "AlchemistsLaboratory":
|
|
16
|
+
return translate("Alchemist’s laboratory");
|
|
17
|
+
default:
|
|
18
|
+
return assertExhaustive(level);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Renders a resistance into a localized string.
|
|
23
|
+
*/
|
|
24
|
+
export const renderResistance = (translate, translateMap, getInstanceById, idMap, resistance) => {
|
|
25
|
+
switch (resistance.kind) {
|
|
26
|
+
case "Spirit":
|
|
27
|
+
return (translateMap(getInstanceById("DerivedCharacteristic", idMap.DerivedCharacteristic.Spirit)?.translations)?.name ?? MISSING_VALUE);
|
|
28
|
+
case "Toughness":
|
|
29
|
+
return (translateMap(getInstanceById("DerivedCharacteristic", idMap.DerivedCharacteristic.Toughness)?.translations)?.name ?? MISSING_VALUE);
|
|
30
|
+
case "LowerOfSpiritAndToughness": {
|
|
31
|
+
const spiritTranslation = translateMap(getInstanceById("DerivedCharacteristic", idMap.DerivedCharacteristic.Spirit)?.translations)?.name ?? MISSING_VALUE;
|
|
32
|
+
const toughnessTranslation = translateMap(getInstanceById("DerivedCharacteristic", idMap.DerivedCharacteristic.Toughness)?.translations)?.name ?? MISSING_VALUE;
|
|
33
|
+
return translate("{$first} or {$second}, depending on which value is lower", {
|
|
34
|
+
first: spiritTranslation,
|
|
35
|
+
second: toughnessTranslation,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
default:
|
|
39
|
+
return assertExhaustive(resistance);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Renders a chance value into a localized string.
|
|
44
|
+
*/
|
|
45
|
+
export const renderChance = (translate, translateMap, item, includePercentage = false) => translateMap(item.translations)?.chance ??
|
|
46
|
+
(item.chance === undefined
|
|
47
|
+
? undefined
|
|
48
|
+
: translate("{$valueRange} on {$dice}", {
|
|
49
|
+
valueRange: item.chance === 5 ? 1 : `1–${item.chance / 5}`,
|
|
50
|
+
dice: renderDice(translate, { number: 1, sides: 20 }),
|
|
51
|
+
}) +
|
|
52
|
+
(includePercentage
|
|
53
|
+
? `, ${translate(".input {$value :number} {{{$value}%}}", { value: item.chance })}`
|
|
54
|
+
: ""));
|
|
55
|
+
/**
|
|
56
|
+
* Renders a list of alternative names into a localized string, or returns undefined if there are no alternative names.
|
|
57
|
+
*/
|
|
58
|
+
export const renderAlternativeNames = (translate, alternativeNames) => alternativeNames === undefined || !isNotEmpty(alternativeNames)
|
|
59
|
+
? undefined
|
|
60
|
+
: {
|
|
61
|
+
label: translate(".input {$hiddenCount :number} {{Alternative Names}}", { hiddenCount: alternativeNames.length }),
|
|
62
|
+
value: alternativeNames
|
|
63
|
+
.map(name => name.name + parensIf(name.region))
|
|
64
|
+
.join(", "),
|
|
65
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { ResponsiveTextOptional } from "optolith-database-schema/gen";
|
|
2
|
+
import type { LocaleMap, Translate, TranslateMap } from "../../helpers/translate.js";
|
|
3
|
+
import { type StdReader } from "./reader.js";
|
|
4
|
+
/**
|
|
5
|
+
* Renders a map of options to a string.
|
|
6
|
+
*/
|
|
7
|
+
export declare const renderMap: <M extends {
|
|
8
|
+
options: MO[];
|
|
9
|
+
translations?: LocaleMap<MT>;
|
|
10
|
+
}, MOT = M extends {
|
|
11
|
+
options: {
|
|
12
|
+
translations?: LocaleMap<infer MOT_>;
|
|
13
|
+
}[];
|
|
14
|
+
} ? MOT_ : never, MT = M extends {
|
|
15
|
+
translations?: LocaleMap<infer MT_>;
|
|
16
|
+
} ? MT_ : never, MO extends {
|
|
17
|
+
translations?: LocaleMap<MOT>;
|
|
18
|
+
} = M extends {
|
|
19
|
+
options: (infer MO_ & {
|
|
20
|
+
translations?: LocaleMap<MOT>;
|
|
21
|
+
})[];
|
|
22
|
+
} ? MO_ : never>(translate: Translate, translateMap: TranslateMap, map: M, getValue: (option: MO) => string | number, surroundValues: ((values: string) => string) | undefined, getLabel: (optionTranslation: MOT) => string, getListPrefix: (translation: MT) => string | undefined, getListSuffix: (translation: MT) => string | undefined, getReplacement: (translation: MT) => string | undefined, ...moreToAppend: ({
|
|
23
|
+
surround: (values: string) => string;
|
|
24
|
+
getAdditionalValue: (option: MO, optionTranslation: MOT) => string | number;
|
|
25
|
+
} | undefined)[]) => string;
|
|
26
|
+
/**
|
|
27
|
+
* Renders a map of options to a string.
|
|
28
|
+
*/
|
|
29
|
+
export declare const renderResponsiveMap: <M extends {
|
|
30
|
+
options: MO[];
|
|
31
|
+
translations?: LocaleMap<{
|
|
32
|
+
list_prepend?: ResponsiveTextOptional;
|
|
33
|
+
listPrefix?: ResponsiveTextOptional;
|
|
34
|
+
list_append?: ResponsiveTextOptional;
|
|
35
|
+
listSuffix?: ResponsiveTextOptional;
|
|
36
|
+
replacement?: ResponsiveTextOptional;
|
|
37
|
+
}>;
|
|
38
|
+
}, MO extends {
|
|
39
|
+
translations?: LocaleMap<{
|
|
40
|
+
label: ResponsiveTextOptional;
|
|
41
|
+
}>;
|
|
42
|
+
} = M extends {
|
|
43
|
+
options: (infer MO_)[];
|
|
44
|
+
} ? MO_ : never>(map: M, getValue: (option: MO) => string | number, surroundValues: ((values: string) => string) | undefined, ...moreToAppend: ({
|
|
45
|
+
surround: (values: string) => string;
|
|
46
|
+
getAdditionalValue: (option: MO, optionTranslation: {
|
|
47
|
+
label: ResponsiveTextOptional;
|
|
48
|
+
}) => string | number;
|
|
49
|
+
} | undefined)[]) => StdReader<string, "t" | "tm" | "rts">;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { mapNullableDefault } from "@elyukai/utils/nullable";
|
|
2
|
+
import { Reader } from "@elyukai/utils/reader";
|
|
3
|
+
import { isNotNullish, mapNullable } from "@optolith/helpers/nullable";
|
|
4
|
+
import { getResponsiveTextOptional } from "./responsiveText.js";
|
|
5
|
+
import { MISSING_VALUE } from "./unknown.js";
|
|
6
|
+
/**
|
|
7
|
+
* Renders a map of options to a string.
|
|
8
|
+
*/
|
|
9
|
+
export const renderMap = (translate, translateMap, map, getValue, surroundValues = values => values, getLabel, getListPrefix, getListSuffix, getReplacement, ...moreToAppend) => {
|
|
10
|
+
const translation = translateMap(map.translations);
|
|
11
|
+
if (translation === undefined) {
|
|
12
|
+
return MISSING_VALUE;
|
|
13
|
+
}
|
|
14
|
+
const replacement = getReplacement(translation);
|
|
15
|
+
if (replacement !== undefined) {
|
|
16
|
+
return replacement;
|
|
17
|
+
}
|
|
18
|
+
return `${surroundValues(map.options.map(option => getValue(option)).join("/"))} ${translate("for")} ${mapNullableDefault(getListPrefix(translation), listPrefix => `${listPrefix} `, "")}${map.options
|
|
19
|
+
.map(option => {
|
|
20
|
+
const optionTranslation = translateMap(option.translations);
|
|
21
|
+
if (optionTranslation === undefined) {
|
|
22
|
+
return MISSING_VALUE;
|
|
23
|
+
}
|
|
24
|
+
return getLabel(optionTranslation);
|
|
25
|
+
})
|
|
26
|
+
.join("/")}${mapNullableDefault(getListSuffix(translation), listSuffix => ` ${listSuffix}`, "")}${moreToAppend
|
|
27
|
+
.filter(isNotNullish)
|
|
28
|
+
.map(({ surround, getAdditionalValue }) => surround(map.options
|
|
29
|
+
.map(option => {
|
|
30
|
+
const optionTranslation = translateMap(option.translations);
|
|
31
|
+
if (optionTranslation === undefined) {
|
|
32
|
+
return MISSING_VALUE;
|
|
33
|
+
}
|
|
34
|
+
return getAdditionalValue(option, optionTranslation);
|
|
35
|
+
})
|
|
36
|
+
.join("/")))
|
|
37
|
+
.join("")}`;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Renders a map of options to a string.
|
|
41
|
+
*/
|
|
42
|
+
export const renderResponsiveMap = (map, getValue, surroundValues, ...moreToAppend) => Reader.asks(({ translate, translateMap, responsiveTextSize }) => renderMap(translate, translateMap, map, getValue, surroundValues, translation => getResponsiveTextOptional(translation.label, responsiveTextSize) ??
|
|
43
|
+
translation.label.full, translation => mapNullable(translation.listPrefix ?? translation.list_prepend, text => getResponsiveTextOptional(text, responsiveTextSize)), translation => mapNullable(translation.listSuffix ?? translation.list_append, text => getResponsiveTextOptional(text, responsiveTextSize)), translation => mapNullable(translation.replacement, text => getResponsiveTextOptional(text, responsiveTextSize)), ...moreToAppend));
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { MathOperation } from "optolith-database-schema/gen";
|
|
2
|
+
type UnaryFormatter = (value: string | number) => string;
|
|
3
|
+
type BinaryFormatter = (left: string | number, right: string | number) => string;
|
|
4
|
+
/**
|
|
5
|
+
* Typographic formatter for addition.
|
|
6
|
+
*/
|
|
7
|
+
export declare const additionFormatter: BinaryFormatter;
|
|
8
|
+
/**
|
|
9
|
+
* Typographic formatter for subtraction.
|
|
10
|
+
*/
|
|
11
|
+
export declare const subtractionFormatter: BinaryFormatter;
|
|
12
|
+
/**
|
|
13
|
+
* Typographic formatter for multiplication.
|
|
14
|
+
*/
|
|
15
|
+
export declare const multiplicationFormatter: BinaryFormatter;
|
|
16
|
+
/**
|
|
17
|
+
* Typographic formatter for division.
|
|
18
|
+
*/
|
|
19
|
+
export declare const divisionFormatter: BinaryFormatter;
|
|
20
|
+
/**
|
|
21
|
+
* Typographic formatter for exponentiation. Uses Markdown syntax.
|
|
22
|
+
*/
|
|
23
|
+
export declare const exponentiationFormatter: BinaryFormatter;
|
|
24
|
+
/**
|
|
25
|
+
* Typographic formatter for grouping (parentheses).
|
|
26
|
+
*/
|
|
27
|
+
export declare const groupFormatter: UnaryFormatter;
|
|
28
|
+
/**
|
|
29
|
+
* Render a math operation as a string, using the provided function to render the values.
|
|
30
|
+
*/
|
|
31
|
+
export declare const renderMathOperation: <T>(operation: MathOperation<T>, renderValue: (value: T) => string) => string;
|
|
32
|
+
/**
|
|
33
|
+
* Evaluate a math operation, using the provided function to evaluate the values.
|
|
34
|
+
*/
|
|
35
|
+
export declare const evaluateMathOperation: <T>(operation: MathOperation<T>, evaluateValue: (value: T) => number) => number;
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { assertExhaustive } from "@optolith/helpers/typeSafety";
|
|
2
|
+
/**
|
|
3
|
+
* Typographic formatter for addition.
|
|
4
|
+
*/
|
|
5
|
+
export const additionFormatter = (left, right) =>
|
|
6
|
+
// eslint-disable-next-line no-irregular-whitespace
|
|
7
|
+
`${left} + ${right}`;
|
|
8
|
+
/**
|
|
9
|
+
* Typographic formatter for subtraction.
|
|
10
|
+
*/
|
|
11
|
+
export const subtractionFormatter = (left, right) =>
|
|
12
|
+
// eslint-disable-next-line no-irregular-whitespace
|
|
13
|
+
`${left} − ${right}`;
|
|
14
|
+
/**
|
|
15
|
+
* Typographic formatter for multiplication.
|
|
16
|
+
*/
|
|
17
|
+
export const multiplicationFormatter = (left, right) =>
|
|
18
|
+
// eslint-disable-next-line no-irregular-whitespace
|
|
19
|
+
`${left} × ${right}`;
|
|
20
|
+
/**
|
|
21
|
+
* Typographic formatter for division.
|
|
22
|
+
*/
|
|
23
|
+
export const divisionFormatter = (left, right) =>
|
|
24
|
+
// eslint-disable-next-line no-irregular-whitespace
|
|
25
|
+
`${left} / ${right}`;
|
|
26
|
+
/**
|
|
27
|
+
* Typographic formatter for exponentiation. Uses Markdown syntax.
|
|
28
|
+
*/
|
|
29
|
+
export const exponentiationFormatter = (left, right) => `${left}^${right}^`;
|
|
30
|
+
/**
|
|
31
|
+
* Typographic formatter for grouping (parentheses).
|
|
32
|
+
*/
|
|
33
|
+
export const groupFormatter = value => `(${value})`;
|
|
34
|
+
/**
|
|
35
|
+
* Render a math operation as a string, using the provided function to render the values.
|
|
36
|
+
*/
|
|
37
|
+
export const renderMathOperation = (operation, renderValue) => {
|
|
38
|
+
const renderWithParenthesis = (op, addParenthesisTo = []) => {
|
|
39
|
+
const rendered = renderMathOperation(op, renderValue);
|
|
40
|
+
return addParenthesisTo.includes(op.kind)
|
|
41
|
+
? groupFormatter(rendered)
|
|
42
|
+
: rendered;
|
|
43
|
+
};
|
|
44
|
+
const renderBinary = ([left, right], options) => options.formatter(renderWithParenthesis(left, options.addParenthesisTo), renderWithParenthesis(right, options.addParenthesisToRight ?? options.addParenthesisTo));
|
|
45
|
+
switch (operation.kind) {
|
|
46
|
+
case "Value":
|
|
47
|
+
return renderValue(operation.Value);
|
|
48
|
+
case "Addition":
|
|
49
|
+
return renderBinary(operation.Addition, { formatter: additionFormatter });
|
|
50
|
+
case "Subtraction":
|
|
51
|
+
return renderBinary(operation.Subtraction, {
|
|
52
|
+
formatter: subtractionFormatter,
|
|
53
|
+
addParenthesisToRight: ["Addition", "Subtraction"],
|
|
54
|
+
});
|
|
55
|
+
case "Multiplication":
|
|
56
|
+
return renderBinary(operation.Multiplication, {
|
|
57
|
+
formatter: multiplicationFormatter,
|
|
58
|
+
addParenthesisTo: ["Addition", "Subtraction"],
|
|
59
|
+
});
|
|
60
|
+
case "Division":
|
|
61
|
+
return renderBinary(operation.Division, {
|
|
62
|
+
formatter: divisionFormatter,
|
|
63
|
+
addParenthesisTo: ["Addition", "Subtraction"],
|
|
64
|
+
});
|
|
65
|
+
case "Exponentiation":
|
|
66
|
+
return renderBinary(operation.Exponentiation, {
|
|
67
|
+
formatter: exponentiationFormatter,
|
|
68
|
+
});
|
|
69
|
+
default:
|
|
70
|
+
return assertExhaustive(operation);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Evaluate a math operation, using the provided function to evaluate the values.
|
|
75
|
+
*/
|
|
76
|
+
export const evaluateMathOperation = (operation, evaluateValue) => {
|
|
77
|
+
switch (operation.kind) {
|
|
78
|
+
case "Value":
|
|
79
|
+
return evaluateValue(operation.Value);
|
|
80
|
+
case "Addition": {
|
|
81
|
+
const [left, right] = operation.Addition;
|
|
82
|
+
return (evaluateMathOperation(left, evaluateValue) +
|
|
83
|
+
evaluateMathOperation(right, evaluateValue));
|
|
84
|
+
}
|
|
85
|
+
case "Subtraction": {
|
|
86
|
+
const [left, right] = operation.Subtraction;
|
|
87
|
+
return (evaluateMathOperation(left, evaluateValue) -
|
|
88
|
+
evaluateMathOperation(right, evaluateValue));
|
|
89
|
+
}
|
|
90
|
+
case "Multiplication": {
|
|
91
|
+
const [left, right] = operation.Multiplication;
|
|
92
|
+
return (evaluateMathOperation(left, evaluateValue) *
|
|
93
|
+
evaluateMathOperation(right, evaluateValue));
|
|
94
|
+
}
|
|
95
|
+
case "Division": {
|
|
96
|
+
const [left, right] = operation.Division;
|
|
97
|
+
return (evaluateMathOperation(left, evaluateValue) /
|
|
98
|
+
evaluateMathOperation(right, evaluateValue));
|
|
99
|
+
}
|
|
100
|
+
case "Exponentiation": {
|
|
101
|
+
const [left, right] = operation.Exponentiation;
|
|
102
|
+
return Math.pow(evaluateMathOperation(left, evaluateValue), evaluateMathOperation(right, evaluateValue));
|
|
103
|
+
}
|
|
104
|
+
default:
|
|
105
|
+
return assertExhaustive(operation);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DisplayOption } from "optolith-database-schema/gen";
|
|
2
|
+
import type { TranslateMap } from "../../../helpers/translate.js";
|
|
3
|
+
import { PrerequisitePart } from "./part.js";
|
|
4
|
+
/**
|
|
5
|
+
* Get the translation of a display option.
|
|
6
|
+
*/
|
|
7
|
+
export declare const printDisplayOption: (translateMap: TranslateMap, displayOption: DisplayOption) => PrerequisitePart | undefined;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { assertExhaustive } from "@optolith/helpers/typeSafety";
|
|
2
|
+
import { MISSING_VALUE } from "../unknown.js";
|
|
3
|
+
/**
|
|
4
|
+
* Get the translation of a display option.
|
|
5
|
+
*/
|
|
6
|
+
export const printDisplayOption = (translateMap, displayOption) => {
|
|
7
|
+
switch (displayOption.kind) {
|
|
8
|
+
case "Hide":
|
|
9
|
+
return undefined;
|
|
10
|
+
case "ReplaceWith":
|
|
11
|
+
return {
|
|
12
|
+
value: translateMap(displayOption.ReplaceWith.translations)?.replacement ?? MISSING_VALUE,
|
|
13
|
+
sentenceType: displayOption.ReplaceWith.sentence_type,
|
|
14
|
+
isMeta: false,
|
|
15
|
+
};
|
|
16
|
+
default:
|
|
17
|
+
return assertExhaustive(displayOption);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { AdvantageDisadvantagePrerequisites, AnimistPowerPrerequisites, ArcaneTraditionPrerequisites, DerivedCharacteristicPrerequisites, EnhancementPrerequisites, GeneralPrerequisites, GeodeRitualPrerequisites, InfluencePrerequisites, LanguagePrerequisites, LiturgyPrerequisites, PersonalityTraitPrerequisites, PlainGeneralPrerequisites, ProfessionPrerequisites, PublicationPrerequisites, SpecialAbilityIdentifier, SpellworkPrerequisites, type ActivatableIdentifier, type RatedIdentifier } from "optolith-database-schema/gen";
|
|
2
|
+
import type { GetInstanceById } from "../../../helpers/getTypes.js";
|
|
3
|
+
import { LocaleEnvironment } from "../../../helpers/locale.js";
|
|
4
|
+
import { GetResolvedSelectOptionById } from "./single/activatable.js";
|
|
5
|
+
/**
|
|
6
|
+
* Print derived characteristic prerequisites as a string.
|
|
7
|
+
*/
|
|
8
|
+
export declare const printDerivedCharacteristicPrerequisites: (locale: LocaleEnvironment, value: DerivedCharacteristicPrerequisites) => string;
|
|
9
|
+
/**
|
|
10
|
+
* Print publication prerequisites as a string.
|
|
11
|
+
*/
|
|
12
|
+
export declare const printPublicationPrerequisites: (getInstanceById: GetInstanceById<"Publication">, locale: LocaleEnvironment, value: PublicationPrerequisites) => string;
|
|
13
|
+
/**
|
|
14
|
+
* Print plain general prerequisites as a string.
|
|
15
|
+
*/
|
|
16
|
+
export declare const printPlainGeneralPrerequisites: (getInstanceById: GetInstanceById<"Race" | "Culture" | "PactCategory" | "PactDomain" | "SocialStatus" | "State" | ActivatableIdentifier["kind"] | RatedIdentifier["kind"] | "Property" | "Aspect" | "Enhancement">, getResolvedSelectOptionById: GetResolvedSelectOptionById, locale: LocaleEnvironment, value: PlainGeneralPrerequisites) => string;
|
|
17
|
+
/**
|
|
18
|
+
* Print general prerequisites as a string.
|
|
19
|
+
*/
|
|
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
|
+
id: SpecialAbilityIdentifier;
|
|
22
|
+
levels: number;
|
|
23
|
+
}) => string;
|
|
24
|
+
/**
|
|
25
|
+
* Print profession prerequisites as a string.
|
|
26
|
+
*/
|
|
27
|
+
export declare const printProfessionPrerequisites: (getInstanceById: GetInstanceById<"Race" | "Culture" | ActivatableIdentifier["kind"] | RatedIdentifier["kind"] | "Aspect">, getResolvedSelectOptionById: GetResolvedSelectOptionById, locale: Pick<LocaleEnvironment, "translate" | "translateMap" | "compare" | "join">, value: ProfessionPrerequisites) => string;
|
|
28
|
+
/**
|
|
29
|
+
* Print advantage disadvantage prerequisites as a string.
|
|
30
|
+
*/
|
|
31
|
+
export declare const printAdvantageDisadvantagePrerequisites: (getInstanceById: GetInstanceById<"Race" | "Culture" | "PactCategory" | "PactDomain" | "SocialStatus" | "State" | ActivatableIdentifier["kind"] | RatedIdentifier["kind"] | "Property" | "Aspect" | "Enhancement">, getResolvedSelectOptionById: GetResolvedSelectOptionById, locale: LocaleEnvironment, value: AdvantageDisadvantagePrerequisites, name: string, type: "Advantage" | "Disadvantage") => string;
|
|
32
|
+
/**
|
|
33
|
+
* Print arcane tradition prerequisites as a string.
|
|
34
|
+
*/
|
|
35
|
+
export declare const printArcaneTraditionPrerequisites: (getInstanceById: GetInstanceById<"Culture">, locale: LocaleEnvironment, value: ArcaneTraditionPrerequisites) => string;
|
|
36
|
+
/**
|
|
37
|
+
* Print personality trait prerequisites as a string.
|
|
38
|
+
*/
|
|
39
|
+
export declare const printPersonalityTraitPrerequisites: (getInstanceById: GetInstanceById<"Race" | "Culture" | "PersonalityTrait">, locale: LocaleEnvironment, value: PersonalityTraitPrerequisites) => string;
|
|
40
|
+
/**
|
|
41
|
+
* Print spellwork prerequisites as a string.
|
|
42
|
+
*/
|
|
43
|
+
export declare const printSpellworkPrerequisites: (getInstanceById: GetInstanceById<RatedIdentifier["kind"]>, locale: LocaleEnvironment, value: SpellworkPrerequisites) => string;
|
|
44
|
+
/**
|
|
45
|
+
* Print liturgy prerequisites as a string.
|
|
46
|
+
*/
|
|
47
|
+
export declare const printLiturgyPrerequisites: (locale: LocaleEnvironment, value: LiturgyPrerequisites) => string;
|
|
48
|
+
/**
|
|
49
|
+
* Print influence prerequisites as a string.
|
|
50
|
+
*/
|
|
51
|
+
export declare const printInfluencePrerequisites: (getInstanceById: GetInstanceById<"Influence">, locale: LocaleEnvironment, value: InfluencePrerequisites) => string;
|
|
52
|
+
/**
|
|
53
|
+
* Print language prerequisites as a string.
|
|
54
|
+
*/
|
|
55
|
+
export declare const printLanguagePrerequisites: (getInstanceById: GetInstanceById<"Race" | ActivatableIdentifier["kind"] | "Aspect">, getResolvedSelectOptionById: GetResolvedSelectOptionById, locale: LocaleEnvironment, value: LanguagePrerequisites) => string;
|
|
56
|
+
/**
|
|
57
|
+
* Print animist power prerequisites as a string.
|
|
58
|
+
*/
|
|
59
|
+
export declare const printAnimistPowerPrerequisites: (getInstanceById: GetInstanceById<"AnimistPower">, locale: LocaleEnvironment, value: AnimistPowerPrerequisites) => string;
|
|
60
|
+
/**
|
|
61
|
+
* Print geode ritual prerequisites as a string.
|
|
62
|
+
*/
|
|
63
|
+
export declare const printGeodeRitualPrerequisites: (getInstanceById: GetInstanceById<"Influence">, locale: LocaleEnvironment, value: GeodeRitualPrerequisites) => string;
|
|
64
|
+
/**
|
|
65
|
+
* Print enhancement prerequisites as a string.
|
|
66
|
+
*/
|
|
67
|
+
export declare const printEnhancementPrerequisites: (getInstanceById: GetInstanceById<RatedIdentifier["kind"] | "Enhancement">, locale: LocaleEnvironment, value: EnhancementPrerequisites) => string;
|