@optolith/entity-descriptions 0.2.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +605 -0
- package/lib/entities/equipmentPackage.d.ts +8 -0
- package/lib/entities/equipmentPackage.js +300 -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 +11 -0
- package/lib/entities/influence.js +43 -0
- package/lib/entities/liturgicalChant.d.ts +13 -23
- package/lib/entities/liturgicalChant.js +171 -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/enhancements.d.ts +7 -0
- package/lib/entities/partial/enhancements.js +26 -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 +278 -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/profession.d.ts +8 -0
- package/lib/entities/partial/prerequisites/single/profession.js +19 -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 +8 -4
- package/lib/entities/partial/rated/improvementCost.js +9 -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 +368 -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 +86 -26
- package/lib/entities/spell.js +842 -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 +854 -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 +31 -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,175 @@
|
|
|
1
|
+
import { isNotNullish } from "@elyukai/utils/nullable";
|
|
2
|
+
import { Reader } from "@elyukai/utils/reader";
|
|
3
|
+
import { assertExhaustive } from "@elyukai/utils/typeSafety";
|
|
4
|
+
import { Speed } from "./rated/activatable/speed.js";
|
|
5
|
+
import { responsive, ResponsiveTextSize } from "./responsiveText.js";
|
|
6
|
+
import { formatEnergy } from "./units/energy.js";
|
|
7
|
+
import { MISSING_VALUE } from "./unknown.js";
|
|
8
|
+
// Specialized constructors for common contexts
|
|
9
|
+
/**
|
|
10
|
+
* Treats the text as a translation string and applies supplied arguments.
|
|
11
|
+
*/
|
|
12
|
+
export const formatR = (text, args) => Reader.asks(env => env.format(text, args));
|
|
13
|
+
/**
|
|
14
|
+
* Creates a value from a translation key.
|
|
15
|
+
*/
|
|
16
|
+
export const translateR = (key, ...rest) => Reader.asks(env => env.translate(key, ...rest));
|
|
17
|
+
/**
|
|
18
|
+
* Returns the `translate` function from the context.
|
|
19
|
+
*/
|
|
20
|
+
export const translateFnR = Reader.asks(env => env.translate);
|
|
21
|
+
/**
|
|
22
|
+
* Takes the appropriate translation from a locale map.
|
|
23
|
+
*/
|
|
24
|
+
export const translateMapR = (map) => Reader.asks(env => env.translateMap(map));
|
|
25
|
+
/**
|
|
26
|
+
* Returns the `translateMap` function from the context.
|
|
27
|
+
*/
|
|
28
|
+
export const translateMapFnR = Reader.asks(env => env.translateMap);
|
|
29
|
+
/**
|
|
30
|
+
* Retrieves the translation for the current locale from the given value’s `translations` property.
|
|
31
|
+
* @returns `undefined` if the value does not exist or does not have a translation for the current locale, otherwise the translation.
|
|
32
|
+
*/
|
|
33
|
+
export const translationR = (value) => Reader.asks(env => env.translateMap(value?.translations));
|
|
34
|
+
/**
|
|
35
|
+
* Retrieves a specific property of the specified entry.
|
|
36
|
+
*/
|
|
37
|
+
export const mapTranslationR = (...args) => Reader.asks(env => {
|
|
38
|
+
const idArgs = args.length === 3 ? [args[0], args[1]] : [args[0]];
|
|
39
|
+
const fn = args.length === 3 ? args[2] : args[1];
|
|
40
|
+
const translation = env.translateMap(env.getInstanceById(...idArgs)?.translations);
|
|
41
|
+
return fn(translation);
|
|
42
|
+
});
|
|
43
|
+
/**
|
|
44
|
+
* Retrieves the `name` property of the specified entry.
|
|
45
|
+
*/
|
|
46
|
+
export const nameR = (...args) => Reader.asks(env => env.translateMap(env.getInstanceById(...args)?.translations)?.name);
|
|
47
|
+
/**
|
|
48
|
+
* Retrieves the `name` property of the specified entry.
|
|
49
|
+
*
|
|
50
|
+
* 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
|
+
export const strictNameR = (...args) => nameR(...args).map(name => name ?? MISSING_VALUE);
|
|
53
|
+
/**
|
|
54
|
+
* Joins a list of strings according to the locale’s rules for the given type.
|
|
55
|
+
*/
|
|
56
|
+
export const localeJoinR = (arr, type) => Reader.asks(env => env.localeJoin(arr, type));
|
|
57
|
+
/**
|
|
58
|
+
* Returns a function to retrieve an instance from the database by its entity name and ID.
|
|
59
|
+
*/
|
|
60
|
+
export const getInstanceByIdFnR = () => Reader.asks(env => env.getInstanceById);
|
|
61
|
+
/**
|
|
62
|
+
* Retrieves an instance from the database by its entity name and ID.
|
|
63
|
+
*/
|
|
64
|
+
export const getInstanceByIdR = (...args) => Reader.asks(env => env.getInstanceById(...args));
|
|
65
|
+
/**
|
|
66
|
+
* Retrieves all instances of an entity from the database by their entity name.
|
|
67
|
+
*/
|
|
68
|
+
export const getAllInstancesR = (entityName) => Reader.asks(env => env.getAllInstances(entityName));
|
|
69
|
+
/**
|
|
70
|
+
* Retrieves all child instances of an entity from the database by their child entity name and their parent’s identifier.
|
|
71
|
+
*/
|
|
72
|
+
export const getChildInstancesForInstanceIdR = (entityName, parentId) => Reader.asks(env => env.getChildInstancesForInstanceId(entityName, parentId));
|
|
73
|
+
/**
|
|
74
|
+
* Joins a list of strings according to the locale’s rules for the given type.
|
|
75
|
+
*/
|
|
76
|
+
export const responsiveLocaleJoinR = (arr, type) => Reader.asks(({ localeJoin, responsiveTextSize }) => responsive(responsiveTextSize, () => localeJoin(arr, type), () => {
|
|
77
|
+
switch (type) {
|
|
78
|
+
case "conjunction":
|
|
79
|
+
return " + ";
|
|
80
|
+
case "disjunction":
|
|
81
|
+
return " / ";
|
|
82
|
+
case "unit":
|
|
83
|
+
return " ";
|
|
84
|
+
default:
|
|
85
|
+
return assertExhaustive(type);
|
|
86
|
+
}
|
|
87
|
+
}));
|
|
88
|
+
/**
|
|
89
|
+
* Compares two strings according to the locale’s sorting rules.
|
|
90
|
+
*/
|
|
91
|
+
export const localeCompareR = Reader.asks(env => env.localeCompare);
|
|
92
|
+
/**
|
|
93
|
+
* Sorts an array of strings according to the locale’s sorting rules.
|
|
94
|
+
*/
|
|
95
|
+
export const localeSortR = (arr) => Reader.asks(({ localeCompare }) => arr.toSorted(localeCompare));
|
|
96
|
+
/**
|
|
97
|
+
* Creates a responsive value from two functions that return the value for the full and compressed version, respectively.
|
|
98
|
+
*/
|
|
99
|
+
export const responsiveR = (full, compressed) => Reader.asks(({ responsiveTextSize }) => responsive(responsiveTextSize, full, compressed));
|
|
100
|
+
/**
|
|
101
|
+
* Creates a responsive value from two functions that return the value for the full and compressed version, respectively.
|
|
102
|
+
*/
|
|
103
|
+
export const responsiveThenR = (full, compressed) => Reader.asks(env => {
|
|
104
|
+
switch (env.responsiveTextSize) {
|
|
105
|
+
case ResponsiveTextSize.Full:
|
|
106
|
+
return full().run(env);
|
|
107
|
+
case ResponsiveTextSize.Compressed:
|
|
108
|
+
return compressed().run(env);
|
|
109
|
+
default:
|
|
110
|
+
return assertExhaustive(env.responsiveTextSize);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
/**
|
|
114
|
+
* Creates a responsive value from a translation key that has a full and a compressed version.
|
|
115
|
+
*/
|
|
116
|
+
export const responsiveTranslateR = (fullKey, compressedKey, ...rest) => Reader.asks(({ translate, responsiveTextSize }) => responsive(responsiveTextSize, () => translate(fullKey, ...rest), () => translate(compressedKey, ...rest)));
|
|
117
|
+
/**
|
|
118
|
+
* Creates a responsive value from a responsive text.
|
|
119
|
+
*/
|
|
120
|
+
export const responsiveTextR = (responsiveText) => Reader.asks(({ responsiveTextSize }) => responsive(responsiveTextSize, () => responsiveText.full, () => responsiveText.compressed));
|
|
121
|
+
/**
|
|
122
|
+
* Creates a responsive value from a responsive text with an optional compressed variant.
|
|
123
|
+
*/
|
|
124
|
+
export const responsiveTextOptionalR = (responsiveText) => Reader.asks(({ responsiveTextSize }) => responsive(responsiveTextSize, () => responsiveText.full, () => responsiveText.compressed));
|
|
125
|
+
/**
|
|
126
|
+
* Formats the given energy cost value with the appropriate unit.
|
|
127
|
+
*/
|
|
128
|
+
export const formatEnergyR = (value) => Reader.asks(({ translate, energyUnit }) => formatEnergy(translate, energyUnit, value));
|
|
129
|
+
/**
|
|
130
|
+
* Formats the given energy cost value with the appropriate unit based on the entity type.
|
|
131
|
+
*/
|
|
132
|
+
export const formatEnergyFnR = Reader.asks(({ translate, energyUnit }) => value => formatEnergy(translate, energyUnit, value));
|
|
133
|
+
/**
|
|
134
|
+
* Returns a common value for a skill modification level depending on the speed.
|
|
135
|
+
*/
|
|
136
|
+
export const modifiableBySpeedR = (key, level) => Reader.asks(({ speed }) => {
|
|
137
|
+
switch (speed) {
|
|
138
|
+
case Speed.Fast:
|
|
139
|
+
return level.fast[key];
|
|
140
|
+
case Speed.Slow:
|
|
141
|
+
return level.slow[key];
|
|
142
|
+
default:
|
|
143
|
+
return assertExhaustive(speed);
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
/**
|
|
147
|
+
* Returns a common value for a skill modification level depending on the speed.
|
|
148
|
+
*/
|
|
149
|
+
export const modifiableBySpeedOptionalR = (key, level) => Reader.asks(({ speed }) => {
|
|
150
|
+
switch (speed) {
|
|
151
|
+
case Speed.Fast:
|
|
152
|
+
return level.fast?.[key];
|
|
153
|
+
case Speed.Slow:
|
|
154
|
+
return level.slow?.[key];
|
|
155
|
+
default:
|
|
156
|
+
return assertExhaustive(speed);
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
/**
|
|
160
|
+
* Returns a common value for a skill modification level depending on the speed.
|
|
161
|
+
*/
|
|
162
|
+
export const modifyBySpeedR = Reader.asks(({ speed }) => (key, level) => {
|
|
163
|
+
switch (speed) {
|
|
164
|
+
case Speed.Fast:
|
|
165
|
+
return level.fast[key];
|
|
166
|
+
case Speed.Slow:
|
|
167
|
+
return level.slow[key];
|
|
168
|
+
default:
|
|
169
|
+
return assertExhaustive(speed);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
/**
|
|
173
|
+
* 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.
|
|
174
|
+
*/
|
|
175
|
+
export const mapNullableR = (defaultValue, fn) => (value) => isNotNullish(value) ? fn(value) : Reader.of(defaultValue);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ResponsiveText, ResponsiveTextOptional, ResponsiveTextReplace } from "optolith-database-schema/
|
|
3
|
-
import {
|
|
1
|
+
import { Reader } from "@elyukai/utils/reader";
|
|
2
|
+
import type { ResponsiveText, ResponsiveTextOptional, ResponsiveTextReplace } from "optolith-database-schema/gen";
|
|
3
|
+
import { type LocaleMap } from "../../helpers/translate.js";
|
|
4
|
+
import { type StdEnv } from "./reader.js";
|
|
4
5
|
/**
|
|
5
6
|
* Whether the entry is displayed in a normal or compressed setting. Normal/full
|
|
6
7
|
* usually means a full library entry display, whether compressed usually means
|
|
@@ -26,9 +27,13 @@ export declare const getResponsiveTextOptional: (value: ResponsiveTextOptional |
|
|
|
26
27
|
* Replaces a text with a given value if a replacement is requested, otherwise
|
|
27
28
|
* just return the given value.
|
|
28
29
|
*/
|
|
29
|
-
export declare const
|
|
30
|
+
export declare const replaceTextIfNeeded: (translations: LocaleMap<{
|
|
31
|
+
replacement?: ResponsiveTextReplace;
|
|
32
|
+
}> | undefined, valueToReplace: string) => Reader<StdEnv<"rts" | "tm">, string>;
|
|
30
33
|
/**
|
|
31
34
|
* Appends a note to a given value if a note is requested, otherwise just return
|
|
32
35
|
* the given value.
|
|
33
36
|
*/
|
|
34
|
-
export declare const
|
|
37
|
+
export declare const appendNoteIfNeeded: (translations: LocaleMap<{
|
|
38
|
+
note?: ResponsiveTextOptional;
|
|
39
|
+
}> | undefined, valueToAppendTo: string) => Reader<StdEnv<"rts" | "tm">, string>;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { identity } from "@elyukai/utils/function";
|
|
2
|
+
import { Reader } from "@elyukai/utils/reader";
|
|
2
3
|
import { assertExhaustive } from "@optolith/helpers/typeSafety";
|
|
3
4
|
import { appendInParensIfNotEmpty } from "./rated/activatable/parensIf.js";
|
|
5
|
+
import { responsiveTextOptionalR, responsiveTextR, translateMapR, } from "./reader.js";
|
|
4
6
|
import { MISSING_VALUE } from "./unknown.js";
|
|
5
7
|
/**
|
|
6
8
|
* Whether the entry is displayed in a normal or compressed setting. Normal/full
|
|
@@ -47,9 +49,23 @@ export const getResponsiveTextOptional = (value, size) => {
|
|
|
47
49
|
* Replaces a text with a given value if a replacement is requested, otherwise
|
|
48
50
|
* just return the given value.
|
|
49
51
|
*/
|
|
50
|
-
export const
|
|
52
|
+
export const replaceTextIfNeeded = (translations, valueToReplace) => translateMapR(translations)
|
|
53
|
+
.with(identity)
|
|
54
|
+
.then(translation => {
|
|
55
|
+
if (translation?.replacement === undefined) {
|
|
56
|
+
return Reader.of(valueToReplace);
|
|
57
|
+
}
|
|
58
|
+
return responsiveTextR(translation.replacement).map(note => note.replace("$1", valueToReplace));
|
|
59
|
+
});
|
|
51
60
|
/**
|
|
52
61
|
* Appends a note to a given value if a note is requested, otherwise just return
|
|
53
62
|
* the given value.
|
|
54
63
|
*/
|
|
55
|
-
export const
|
|
64
|
+
export const appendNoteIfNeeded = (translations, valueToAppendTo) => translateMapR(translations)
|
|
65
|
+
.with(identity)
|
|
66
|
+
.then(translation => {
|
|
67
|
+
if (translation?.note === undefined) {
|
|
68
|
+
return Reader.of(valueToAppendTo);
|
|
69
|
+
}
|
|
70
|
+
return responsiveTextOptionalR(translation.note).map(note => appendInParensIfNotEmpty(note, valueToAppendTo));
|
|
71
|
+
});
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Entity } from "../rated/activatable/entity.js";
|
|
3
|
-
type EnergyUnit = "ArcaneEnergy" | "KarmaPoints";
|
|
1
|
+
import type { Translate } from "../../../helpers/translate.js";
|
|
4
2
|
/**
|
|
5
|
-
*
|
|
3
|
+
* The unit of an energy cost.
|
|
6
4
|
*/
|
|
7
|
-
export
|
|
5
|
+
export type EnergyUnit = "LifePoints" | "ArcaneEnergy" | "KarmaPoints";
|
|
8
6
|
/**
|
|
9
|
-
* Returns the text for an energy unit
|
|
7
|
+
* Returns the text for an energy unit.
|
|
10
8
|
*/
|
|
11
|
-
export declare const
|
|
12
|
-
export {};
|
|
9
|
+
export declare const formatEnergy: (translate: Translate, unit: EnergyUnit, value: number | string) => string;
|
|
@@ -1,30 +1,12 @@
|
|
|
1
|
-
import { assertExhaustive } from "@optolith/helpers/typeSafety";
|
|
2
|
-
import { Entity } from "../rated/activatable/entity.js";
|
|
3
1
|
const lengthUnitTranslationKeys = {
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
LifePoints: "{$value} LP",
|
|
3
|
+
ArcaneEnergy: "{$value} AE",
|
|
4
|
+
KarmaPoints: "{$value} KP",
|
|
6
5
|
};
|
|
7
6
|
/**
|
|
8
7
|
* Returns the text for an energy unit.
|
|
9
8
|
*/
|
|
10
|
-
export const formatEnergy = (
|
|
9
|
+
export const formatEnergy = (translate, unit, value) => {
|
|
11
10
|
const key = lengthUnitTranslationKeys[unit];
|
|
12
|
-
return
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Returns the text for an energy unit that is based on the entity type.
|
|
16
|
-
*/
|
|
17
|
-
export const formatEnergyByEntity = (locale, entity, value) => {
|
|
18
|
-
switch (entity) {
|
|
19
|
-
case Entity.Cantrip:
|
|
20
|
-
case Entity.Spell:
|
|
21
|
-
case Entity.Ritual:
|
|
22
|
-
return formatEnergy(locale, "ArcaneEnergy", value);
|
|
23
|
-
case Entity.Blessing:
|
|
24
|
-
case Entity.LiturgicalChant:
|
|
25
|
-
case Entity.Ceremony:
|
|
26
|
-
return formatEnergy(locale, "KarmaPoints", value);
|
|
27
|
-
default:
|
|
28
|
-
return assertExhaustive(entity);
|
|
29
|
-
}
|
|
11
|
+
return translate(key, { value });
|
|
30
12
|
};
|
|
@@ -1,8 +1,26 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Translate } from "../../../helpers/translate.js";
|
|
2
|
+
import type { StdReader } from "../reader.js";
|
|
2
3
|
import { ResponsiveTextSize } from "../responsiveText.js";
|
|
3
4
|
type LengthUnit = "Steps" | "Miles";
|
|
4
5
|
/**
|
|
5
6
|
* Returns the text for a length unit.
|
|
6
7
|
*/
|
|
7
|
-
export declare const formatLength: (
|
|
8
|
+
export declare const formatLength: (translate: Translate, responsiveTextSize: ResponsiveTextSize, unit: LengthUnit | {
|
|
9
|
+
kind: LengthUnit;
|
|
10
|
+
}, value: number | string) => string;
|
|
11
|
+
/**
|
|
12
|
+
* Returns the text for a length unit.
|
|
13
|
+
*/
|
|
14
|
+
export declare const formatLengthR: (unit: LengthUnit | {
|
|
15
|
+
kind: LengthUnit;
|
|
16
|
+
}, value: number | string) => StdReader<string, "t" | "rts">;
|
|
17
|
+
/**
|
|
18
|
+
* Returns the text for a length unit.
|
|
19
|
+
*/
|
|
20
|
+
export declare const formatCombinedLengthR: (object: {
|
|
21
|
+
unit: LengthUnit | {
|
|
22
|
+
kind: LengthUnit;
|
|
23
|
+
};
|
|
24
|
+
value: number | string;
|
|
25
|
+
}) => StdReader<string, "t" | "rts">;
|
|
8
26
|
export {};
|
|
@@ -1,12 +1,31 @@
|
|
|
1
|
+
import { Reader } from "@elyukai/utils/reader";
|
|
1
2
|
import { responsive } from "../responsiveText.js";
|
|
2
3
|
const lengthUnitTranslationKeys = {
|
|
3
|
-
Steps: [
|
|
4
|
-
|
|
4
|
+
Steps: [
|
|
5
|
+
".input {$value :number} {{{$value} yards}}",
|
|
6
|
+
"{$value} yards",
|
|
7
|
+
"{$value} yd",
|
|
8
|
+
],
|
|
9
|
+
Miles: [
|
|
10
|
+
".input {$value :number} {{{$value} miles}}",
|
|
11
|
+
"{$value} miles",
|
|
12
|
+
"{$value} mi.",
|
|
13
|
+
],
|
|
5
14
|
};
|
|
6
15
|
/**
|
|
7
16
|
* Returns the text for a length unit.
|
|
8
17
|
*/
|
|
9
|
-
export const formatLength = (
|
|
10
|
-
const [fullKey, compressedKey] = lengthUnitTranslationKeys[unit];
|
|
11
|
-
return responsive(responsiveTextSize, () =>
|
|
18
|
+
export const formatLength = (translate, responsiveTextSize, unit, value) => {
|
|
19
|
+
const [fullNumberKey, fullKey, compressedKey] = lengthUnitTranslationKeys[typeof unit === "string" ? unit : unit.kind];
|
|
20
|
+
return responsive(responsiveTextSize, () => translate(typeof value === "number" ? fullNumberKey : fullKey, {
|
|
21
|
+
value,
|
|
22
|
+
}), () => translate(compressedKey, { value }));
|
|
12
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
* Returns the text for a length unit.
|
|
26
|
+
*/
|
|
27
|
+
export const formatLengthR = (unit, value) => Reader.asks(env => formatLength(env.translate, env.responsiveTextSize, unit, value));
|
|
28
|
+
/**
|
|
29
|
+
* Returns the text for a length unit.
|
|
30
|
+
*/
|
|
31
|
+
export const formatCombinedLengthR = (object) => Reader.asks(env => formatLength(env.translate, env.responsiveTextSize, object.unit, object.value));
|
|
@@ -1,8 +1,29 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Reader } from "@elyukai/utils/reader";
|
|
2
|
+
import type { Translate } from "../../../helpers/translate.js";
|
|
3
|
+
import type { StdEnv } from "../reader.js";
|
|
2
4
|
import { ResponsiveTextSize } from "../responsiveText.js";
|
|
3
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Possible units to use for time spans.
|
|
7
|
+
*/
|
|
8
|
+
export type TimeSpanUnit = "Seconds" | "Minutes" | "Hours" | "Days" | "Weeks" | "Months" | "Years" | "Centuries" | "Actions" | "CombatRounds" | "SeductionActions" | "Rounds";
|
|
9
|
+
/**
|
|
10
|
+
* Returns the text for a time span unit.
|
|
11
|
+
*/
|
|
12
|
+
export declare const formatTimeSpan: (translate: Translate, responsiveTextSize: ResponsiveTextSize, unit: {
|
|
13
|
+
kind: TimeSpanUnit;
|
|
14
|
+
} | TimeSpanUnit, value: number | string) => string;
|
|
15
|
+
/**
|
|
16
|
+
* Returns the text for a time span unit.
|
|
17
|
+
*/
|
|
18
|
+
export declare const formatTimeSpanR: (unit: {
|
|
19
|
+
kind: TimeSpanUnit;
|
|
20
|
+
} | TimeSpanUnit, value: number | string) => Reader<StdEnv<"t" | "rts">, string>;
|
|
4
21
|
/**
|
|
5
22
|
* Returns the text for a time span unit.
|
|
6
23
|
*/
|
|
7
|
-
export declare const
|
|
8
|
-
|
|
24
|
+
export declare const formatCombinedTimeSpanR: (object: {
|
|
25
|
+
unit: {
|
|
26
|
+
kind: TimeSpanUnit;
|
|
27
|
+
};
|
|
28
|
+
value: number | string;
|
|
29
|
+
}) => Reader<StdEnv<"t" | "rts">, string>;
|
|
@@ -1,22 +1,34 @@
|
|
|
1
|
+
import { Reader } from "@elyukai/utils/reader";
|
|
1
2
|
import { responsive } from "../responsiveText.js";
|
|
3
|
+
// prettier-ignore
|
|
2
4
|
const timeSpanUnitTranslationKeys = {
|
|
3
|
-
Seconds: ["{
|
|
4
|
-
Minutes: ["{
|
|
5
|
-
Hours: ["{
|
|
6
|
-
Days: ["{
|
|
7
|
-
Weeks: ["{
|
|
8
|
-
Months: ["{
|
|
9
|
-
Years: ["{
|
|
10
|
-
Centuries: ["{
|
|
11
|
-
Actions: ["{
|
|
12
|
-
CombatRounds: ["{
|
|
13
|
-
SeductionActions: ["{
|
|
14
|
-
Rounds: ["{
|
|
5
|
+
Seconds: [".input {$value :number} {{{$value} seconds}}", "{$value} seconds", "{$value} s"],
|
|
6
|
+
Minutes: [".input {$value :number} {{{$value} minutes}}", "{$value} minutes", "{$value} min"],
|
|
7
|
+
Hours: [".input {$value :number} {{{$value} hours}}", "{$value} hours", "{$value} h"],
|
|
8
|
+
Days: [".input {$value :number} {{{$value} days}}", "{$value} days", "{$value} d"],
|
|
9
|
+
Weeks: [".input {$value :number} {{{$value} weeks}}", "{$value} weeks", ".input {$value :number} {{{$value} wks.}}"],
|
|
10
|
+
Months: [".input {$value :number} {{{$value} months}}", "{$value} months", ".input {$value :number} {{{$value} mos.}}"],
|
|
11
|
+
Years: [".input {$value :number} {{{$value} years}}", "{$value} years", ".input {$value :number} {{{$value} yrs.}}"],
|
|
12
|
+
Centuries: [".input {$value :number} {{{$value} centuries}}", "{$value} centuries", "{$value} cent."],
|
|
13
|
+
Actions: [".input {$value :number} {{{$value} actions}}", "{$value} actions", "{$value} act"],
|
|
14
|
+
CombatRounds: [".input {$value :number} {{{$value} combat rounds}}", "{$value} combat rounds", "{$value} CR"],
|
|
15
|
+
SeductionActions: [".input {$value :number} {{{$value} seduction actions}}", "{$value} seduction actions", "{$value} SA"],
|
|
16
|
+
Rounds: [".input {$value :number} {{{$value} rounds}}", "{$value} rounds", "{$value} rnds"],
|
|
15
17
|
};
|
|
16
18
|
/**
|
|
17
19
|
* Returns the text for a time span unit.
|
|
18
20
|
*/
|
|
19
|
-
export const formatTimeSpan = (
|
|
20
|
-
const [fullKey, compressedKey] = timeSpanUnitTranslationKeys[unit];
|
|
21
|
-
return responsive(responsiveTextSize, () =>
|
|
21
|
+
export const formatTimeSpan = (translate, responsiveTextSize, unit, value) => {
|
|
22
|
+
const [fullNumberKey, fullKey, compressedKey] = timeSpanUnitTranslationKeys[typeof unit === "string" ? unit : unit.kind];
|
|
23
|
+
return responsive(responsiveTextSize, () => translate(typeof value === "number" ? fullNumberKey : fullKey, {
|
|
24
|
+
value,
|
|
25
|
+
}), () => translate(compressedKey, { value }));
|
|
22
26
|
};
|
|
27
|
+
/**
|
|
28
|
+
* Returns the text for a time span unit.
|
|
29
|
+
*/
|
|
30
|
+
export const formatTimeSpanR = (unit, value) => Reader.asks(({ translate, responsiveTextSize }) => formatTimeSpan(translate, responsiveTextSize, unit, value));
|
|
31
|
+
/**
|
|
32
|
+
* Returns the text for a time span unit.
|
|
33
|
+
*/
|
|
34
|
+
export const formatCombinedTimeSpanR = (object) => formatTimeSpanR(object.unit, object.value);
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* String to display when a translation that should be present is missing.
|
|
3
3
|
*/
|
|
4
|
-
export declare const MISSING_VALUE = "
|
|
4
|
+
export declare const MISSING_VALUE = "###MISSING###";
|
|
5
|
+
/**
|
|
6
|
+
* String to display when a translation that should be present produces an error.
|
|
7
|
+
*/
|
|
8
|
+
export declare const UNHANDLED_VALUE = "###UNHANDLED_ERROR###";
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* String to display when a translation that should be present is missing.
|
|
3
3
|
*/
|
|
4
|
-
export const MISSING_VALUE = "
|
|
4
|
+
export const MISSING_VALUE = "###MISSING###";
|
|
5
|
+
/**
|
|
6
|
+
* String to display when a translation that should be present produces an error.
|
|
7
|
+
*/
|
|
8
|
+
export const UNHANDLED_VALUE = "###UNHANDLED_ERROR###";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { GetInstanceById } from "../helpers/getTypes.js";
|
|
2
|
+
/**
|
|
3
|
+
* Get a JSON representation of the rules text for a .
|
|
4
|
+
*/
|
|
5
|
+
export declare const getPersonalityTraitEntityDescription: import("../creator.js").EntityDescriptionCreator<"PersonalityTrait", {
|
|
6
|
+
getInstanceById: GetInstanceById<"Publication" | "Race" | "Culture" | "PersonalityTrait">;
|
|
7
|
+
}, import("../index.js").EntityDescription>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { on } from "@elyukai/utils/function";
|
|
2
|
+
import { compareNullish } from "@elyukai/utils/ordering";
|
|
3
|
+
import { romanize } from "@elyukai/utils/roman";
|
|
4
|
+
import { numAsc } from "@optolith/helpers/compare";
|
|
5
|
+
import { createEntityDescriptionCreator } from "../creator.js";
|
|
6
|
+
import { printPersonalityTraitPrerequisites } from "./partial/prerequisites/index.js";
|
|
7
|
+
import { MISSING_VALUE } from "./partial/unknown.js";
|
|
8
|
+
/**
|
|
9
|
+
* Get a JSON representation of the rules text for a .
|
|
10
|
+
*/
|
|
11
|
+
export const getPersonalityTraitEntityDescription = createEntityDescriptionCreator(({ getInstanceById }, locale, { content: entry }) => {
|
|
12
|
+
const { translate, translateMap, join: localeJoin } = locale;
|
|
13
|
+
const translation = translateMap(entry.translations);
|
|
14
|
+
if (translation === undefined) {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
title: `${translation.name} (${translate("Level {$level}", {
|
|
19
|
+
level: romanize(entry.level),
|
|
20
|
+
})})`,
|
|
21
|
+
className: "personality-trait",
|
|
22
|
+
body: [
|
|
23
|
+
{
|
|
24
|
+
type: "definitionList",
|
|
25
|
+
items: [
|
|
26
|
+
...(translation.effects.map(effect => ({
|
|
27
|
+
label: effect.label,
|
|
28
|
+
value: effect.text,
|
|
29
|
+
})) ?? []),
|
|
30
|
+
entry.combination_options === undefined
|
|
31
|
+
? undefined
|
|
32
|
+
: {
|
|
33
|
+
label: translate("Can be combined with"),
|
|
34
|
+
value: Map.groupBy(entry.combination_options.map(optionId => getInstanceById("PersonalityTrait", optionId)), option => option?.level ?? null)
|
|
35
|
+
.entries()
|
|
36
|
+
.toArray()
|
|
37
|
+
.toSorted(on(group => group[0], compareNullish(numAsc)))
|
|
38
|
+
.map(([level, options]) => level === null
|
|
39
|
+
? MISSING_VALUE
|
|
40
|
+
: `${translate("Level {$level}", { level: romanize(level) })} ${localeJoin(options.map(option => translateMap(option?.translations)?.name ??
|
|
41
|
+
MISSING_VALUE), "disjunction")}`)
|
|
42
|
+
.join(", "),
|
|
43
|
+
},
|
|
44
|
+
entry.prerequisites === undefined
|
|
45
|
+
? undefined
|
|
46
|
+
: {
|
|
47
|
+
label: translate("Prerequisites"),
|
|
48
|
+
value: printPersonalityTraitPrerequisites(getInstanceById, locale, entry.prerequisites),
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
errata: translation.errata,
|
|
54
|
+
references: entry.src,
|
|
55
|
+
};
|
|
56
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ActivatableIdentifier, RatedIdentifier } from "optolith-database-schema/gen";
|
|
2
|
+
import type { GetInstanceById } from "../helpers/getTypes.js";
|
|
3
|
+
import type { IdMap } from "../index.js";
|
|
4
|
+
import type { GetResolvedSelectOptionById } from "./partial/prerequisites/single/activatable.js";
|
|
5
|
+
/**
|
|
6
|
+
* Get a JSON representation of the rules text for a poison.
|
|
7
|
+
*/
|
|
8
|
+
export declare const getPoisonEntityDescription: import("../creator.js").EntityDescriptionCreator<"Poison", {
|
|
9
|
+
getInstanceById: GetInstanceById<"Publication" | "DerivedCharacteristic" | "Disease" | ActivatableIdentifier["kind"] | RatedIdentifier["kind"] | "Race" | "Culture" | "State" | "Enhancement" | "PactCategory" | "PactDomain" | "SocialStatus" | "Aspect" | "Property">;
|
|
10
|
+
getResolvedSelectOptionById: GetResolvedSelectOptionById;
|
|
11
|
+
idMap: IdMap;
|
|
12
|
+
}, import("../index.js").EntityDescription>;
|