@optolith/entity-descriptions 0.0.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.
Files changed (62) hide show
  1. package/.prettierrc.yml +1 -0
  2. package/AUTHORS +1 -0
  3. package/CHANGELOG.md +5 -0
  4. package/LICENSE +373 -0
  5. package/README.md +1 -0
  6. package/lib/entities/combatTechnique.d.ts +15 -0
  7. package/lib/entities/combatTechnique.js +59 -0
  8. package/lib/entities/experienceLevel.d.ts +5 -0
  9. package/lib/entities/experienceLevel.js +44 -0
  10. package/lib/entities/liturgicalChant.d.ts +35 -0
  11. package/lib/entities/liturgicalChant.js +244 -0
  12. package/lib/entities/partial/rated/activatable/castingTime.d.ts +25 -0
  13. package/lib/entities/partial/rated/activatable/castingTime.js +50 -0
  14. package/lib/entities/partial/rated/activatable/checkResultBased.d.ts +7 -0
  15. package/lib/entities/partial/rated/activatable/checkResultBased.js +28 -0
  16. package/lib/entities/partial/rated/activatable/cost.d.ts +30 -0
  17. package/lib/entities/partial/rated/activatable/cost.js +166 -0
  18. package/lib/entities/partial/rated/activatable/duration.d.ts +40 -0
  19. package/lib/entities/partial/rated/activatable/duration.js +100 -0
  20. package/lib/entities/partial/rated/activatable/effect.d.ts +7 -0
  21. package/lib/entities/partial/rated/activatable/effect.js +37 -0
  22. package/lib/entities/partial/rated/activatable/entity.d.ts +11 -0
  23. package/lib/entities/partial/rated/activatable/entity.js +12 -0
  24. package/lib/entities/partial/rated/activatable/index.d.ts +69 -0
  25. package/lib/entities/partial/rated/activatable/index.js +59 -0
  26. package/lib/entities/partial/rated/activatable/isMaximum.d.ts +6 -0
  27. package/lib/entities/partial/rated/activatable/isMaximum.js +10 -0
  28. package/lib/entities/partial/rated/activatable/modifiableParameter.d.ts +8 -0
  29. package/lib/entities/partial/rated/activatable/modifiableParameter.js +9 -0
  30. package/lib/entities/partial/rated/activatable/nonModifiable.d.ts +9 -0
  31. package/lib/entities/partial/rated/activatable/nonModifiable.js +75 -0
  32. package/lib/entities/partial/rated/activatable/parensIf.d.ts +10 -0
  33. package/lib/entities/partial/rated/activatable/parensIf.js +10 -0
  34. package/lib/entities/partial/rated/activatable/range.d.ts +36 -0
  35. package/lib/entities/partial/rated/activatable/range.js +122 -0
  36. package/lib/entities/partial/rated/activatable/speed.d.ts +12 -0
  37. package/lib/entities/partial/rated/activatable/speed.js +22 -0
  38. package/lib/entities/partial/rated/activatable/targetCategory.d.ts +12 -0
  39. package/lib/entities/partial/rated/activatable/targetCategory.js +36 -0
  40. package/lib/entities/partial/rated/activatable/units.d.ts +13 -0
  41. package/lib/entities/partial/rated/activatable/units.js +53 -0
  42. package/lib/entities/partial/rated/improvementCost.d.ts +7 -0
  43. package/lib/entities/partial/rated/improvementCost.js +7 -0
  44. package/lib/entities/partial/rated/skillCheck.d.ts +19 -0
  45. package/lib/entities/partial/rated/skillCheck.js +58 -0
  46. package/lib/entities/partial/responsiveText.d.ts +31 -0
  47. package/lib/entities/partial/responsiveText.js +49 -0
  48. package/lib/entities/partial/unknown.d.ts +4 -0
  49. package/lib/entities/partial/unknown.js +4 -0
  50. package/lib/entities/skill.d.ts +13 -0
  51. package/lib/entities/skill.js +109 -0
  52. package/lib/entities/spell.d.ts +38 -0
  53. package/lib/entities/spell.js +274 -0
  54. package/lib/helpers/getTypes.d.ts +482 -0
  55. package/lib/helpers/getTypes.js +1 -0
  56. package/lib/helpers/translate.d.ts +14 -0
  57. package/lib/helpers/translate.js +8 -0
  58. package/lib/index.d.ts +1 -0
  59. package/lib/index.js +1 -0
  60. package/lib/libraryEntry.d.ts +52 -0
  61. package/lib/libraryEntry.js +17 -0
  62. package/package.json +34 -0
@@ -0,0 +1,274 @@
1
+ import { isNotNullish, mapNullable } from "@optolith/helpers/nullable";
2
+ import { assertExhaustive } from "@optolith/helpers/typeSafety";
3
+ import { createLibraryEntryCreator, } from "../libraryEntry.js";
4
+ import { getTextForCantripDuration } from "./partial/rated/activatable/duration.js";
5
+ import { getTextForEffect } from "./partial/rated/activatable/effect.js";
6
+ import { Entity } from "./partial/rated/activatable/entity.js";
7
+ import { getTextForFastOneTimePerformanceParameters, getTextForFastSustainedPerformanceParameters, getTextForSlowOneTimePerformanceParameters, getTextForSlowSustainedPerformanceParameters, } from "./partial/rated/activatable/index.js";
8
+ import { parensIf } from "./partial/rated/activatable/parensIf.js";
9
+ import { getTextForCantripRange } from "./partial/rated/activatable/range.js";
10
+ import { getTextForTargetCategory } from "./partial/rated/activatable/targetCategory.js";
11
+ import { createImprovementCost } from "./partial/rated/improvementCost.js";
12
+ import { getTextForCheck } from "./partial/rated/skillCheck.js";
13
+ import { ResponsiveTextSize } from "./partial/responsiveText.js";
14
+ const getTextForProperty = (deps, value) => {
15
+ const text = (() => {
16
+ const staticEntry = deps.getPropertyById(value.id.property);
17
+ const staticEntryTranslation = deps.translateMap(staticEntry?.translations);
18
+ if (staticEntryTranslation === undefined) {
19
+ return "";
20
+ }
21
+ return staticEntryTranslation.name;
22
+ })();
23
+ return {
24
+ label: deps.translate("Property"),
25
+ value: text,
26
+ };
27
+ };
28
+ const getTextForTraditions = (deps, value) => {
29
+ const text = (() => {
30
+ switch (value.tag) {
31
+ case "General":
32
+ return deps.translate("General");
33
+ case "Specific":
34
+ return value.specific
35
+ .map((trad) => deps.translateMap(deps.getMagicalTraditionById(trad.magical_tradition)?.translations))
36
+ .filter(isNotNullish)
37
+ .map((trad) => trad.name_for_arcane_spellworks ?? trad.name)
38
+ .sort(deps.localeCompare)
39
+ .join(", ");
40
+ default:
41
+ return assertExhaustive(value);
42
+ }
43
+ })();
44
+ return {
45
+ label: deps.translate("Traditions"),
46
+ value: text,
47
+ };
48
+ };
49
+ const getTraditionNameForArcaneSpellworksById = (ref, getMagicalTraditionById, translateMap) => {
50
+ const translation = translateMap(getMagicalTraditionById(ref.id.magical_tradition)?.translations);
51
+ return translation?.name_for_arcane_spellworks ?? translation?.name;
52
+ };
53
+ /**
54
+ * Get a JSON representation of the rules text for a cantrip.
55
+ */
56
+ export const getCantripLibraryEntry = createLibraryEntryCreator((entry, { getTargetCategoryById, getPropertyById, getMagicalTraditionById, getCurriculumById, }) => ({ translate, translateMap, localeCompare }) => {
57
+ const translation = translateMap(entry.translations);
58
+ if (translation === undefined) {
59
+ return undefined;
60
+ }
61
+ const range = getTextForCantripRange({ translate }, entry.parameters.range, {
62
+ responsiveText: ResponsiveTextSize.Full,
63
+ });
64
+ const duration = getTextForCantripDuration({ translate, translateMap }, entry.parameters.duration, {
65
+ responsiveText: ResponsiveTextSize.Full,
66
+ });
67
+ return {
68
+ title: translation.name,
69
+ className: "cantrip",
70
+ content: [
71
+ {
72
+ label: translate("Effect"),
73
+ value: translation.effect,
74
+ },
75
+ {
76
+ label: translate("Range"),
77
+ value: range !== translation.range
78
+ ? `***${range}*** (${translation.range})`
79
+ : range,
80
+ },
81
+ {
82
+ label: translate("Duration"),
83
+ value: duration !== translation.duration
84
+ ? `***${duration}*** (${translation.duration})`
85
+ : duration,
86
+ },
87
+ getTextForTargetCategory({ translate, translateMap, getTargetCategoryById }, entry.target),
88
+ getTextForProperty({ translate, translateMap, getPropertyById }, entry.property),
89
+ mapNullable(entry.note, (note) => ({
90
+ label: translate("Note"),
91
+ value: (() => {
92
+ switch (note.tag) {
93
+ case "Common":
94
+ return note.common.list
95
+ .map((academyOrTradition) => {
96
+ switch (academyOrTradition.tag) {
97
+ case "Academy":
98
+ return translateMap(getCurriculumById(academyOrTradition.academy.id.curriculum)?.translations)?.name;
99
+ case "Tradition": {
100
+ return mapNullable(getTraditionNameForArcaneSpellworksById(academyOrTradition.tradition, getMagicalTraditionById, translateMap), (name) => name +
101
+ parensIf(translateMap(academyOrTradition.tradition.translations)?.note));
102
+ }
103
+ default:
104
+ return assertExhaustive(academyOrTradition);
105
+ }
106
+ })
107
+ .filter(isNotNullish)
108
+ .sort(localeCompare)
109
+ .join(", ");
110
+ case "Exclusive":
111
+ return note.exclusive.traditions
112
+ .map((tradition) => getTraditionNameForArcaneSpellworksById(tradition, getMagicalTraditionById, translateMap))
113
+ .filter(isNotNullish)
114
+ .sort(localeCompare)
115
+ .join(", ");
116
+ default:
117
+ return assertExhaustive(note);
118
+ }
119
+ })(),
120
+ })),
121
+ ],
122
+ src: entry.src,
123
+ };
124
+ });
125
+ /**
126
+ * Get a JSON representation of the rules text for a skill.
127
+ */
128
+ export const getSpellLibraryEntry = createLibraryEntryCreator((entry, { getAttributeById, getSpirit, getToughness, getSkillModificationLevelById, getTargetCategoryById, getPropertyById, getMagicalTraditionById, }) => ({ translate, translateMap, localeCompare }) => {
129
+ const translation = translateMap(entry.translations);
130
+ if (translation === undefined) {
131
+ return undefined;
132
+ }
133
+ const { castingTime, cost, range, duration } = (() => {
134
+ switch (entry.parameters.tag) {
135
+ case "OneTime":
136
+ return getTextForFastOneTimePerformanceParameters({
137
+ getSkillModificationLevelById,
138
+ translate,
139
+ translateMap,
140
+ }, entry.parameters.one_time, {
141
+ entity: Entity.Spell,
142
+ responsiveText: ResponsiveTextSize.Full,
143
+ });
144
+ case "Sustained":
145
+ return getTextForFastSustainedPerformanceParameters({
146
+ getSkillModificationLevelById,
147
+ translate,
148
+ translateMap,
149
+ }, entry.parameters.sustained, {
150
+ entity: Entity.Spell,
151
+ responsiveText: ResponsiveTextSize.Full,
152
+ });
153
+ default:
154
+ return assertExhaustive(entry.parameters);
155
+ }
156
+ })();
157
+ return {
158
+ title: translation.name,
159
+ className: "spell",
160
+ content: [
161
+ getTextForCheck({ translate, translateMap, getAttributeById }, entry.check, {
162
+ value: entry.check_penalty,
163
+ responsiveText: ResponsiveTextSize.Full,
164
+ getSpirit,
165
+ getToughness,
166
+ }),
167
+ ...getTextForEffect(translation.effect, translate),
168
+ {
169
+ label: translate("Casting Time"),
170
+ value: castingTime !== translation.casting_time.full
171
+ ? `***${castingTime}*** (${translation.casting_time.full})`
172
+ : castingTime,
173
+ },
174
+ {
175
+ label: translate("AE Cost"),
176
+ value: cost !== translation.cost.full
177
+ ? `***${cost}*** (${translation.cost.full})`
178
+ : cost,
179
+ },
180
+ {
181
+ label: translate("Range"),
182
+ value: range !== translation.range.full
183
+ ? `***${range}*** (${translation.range.full})`
184
+ : range,
185
+ },
186
+ {
187
+ label: translate("Duration"),
188
+ value: duration !== translation.duration.full
189
+ ? `***${duration}*** (${translation.duration.full})`
190
+ : duration,
191
+ },
192
+ getTextForTargetCategory({ translate, translateMap, getTargetCategoryById }, entry.target),
193
+ getTextForProperty({ translate, translateMap, getPropertyById }, entry.property),
194
+ getTextForTraditions({ translate, translateMap, localeCompare, getMagicalTraditionById }, entry.traditions),
195
+ createImprovementCost(translate, entry.improvement_cost),
196
+ ],
197
+ src: entry.src,
198
+ };
199
+ });
200
+ /**
201
+ * Get a JSON representation of the rules text for a ritual.
202
+ */
203
+ export const getRitualLibraryEntry = createLibraryEntryCreator((entry, { getAttributeById, getSpirit, getToughness, getSkillModificationLevelById, getTargetCategoryById, getPropertyById, getMagicalTraditionById, }) => ({ translate, translateMap, localeCompare }) => {
204
+ const translation = translateMap(entry.translations);
205
+ if (translation === undefined) {
206
+ return undefined;
207
+ }
208
+ const { castingTime, cost, range, duration } = (() => {
209
+ switch (entry.parameters.tag) {
210
+ case "OneTime":
211
+ return getTextForSlowOneTimePerformanceParameters({
212
+ getSkillModificationLevelById,
213
+ translate,
214
+ translateMap,
215
+ }, entry.parameters.one_time, {
216
+ entity: Entity.Ritual,
217
+ responsiveText: ResponsiveTextSize.Full,
218
+ });
219
+ case "Sustained":
220
+ return getTextForSlowSustainedPerformanceParameters({
221
+ getSkillModificationLevelById,
222
+ translate,
223
+ translateMap,
224
+ }, entry.parameters.sustained, {
225
+ entity: Entity.Ritual,
226
+ responsiveText: ResponsiveTextSize.Full,
227
+ });
228
+ default:
229
+ return assertExhaustive(entry.parameters);
230
+ }
231
+ })();
232
+ return {
233
+ title: translation.name,
234
+ className: "ritual",
235
+ content: [
236
+ getTextForCheck({ translate, translateMap, getAttributeById }, entry.check, {
237
+ value: entry.check_penalty,
238
+ responsiveText: ResponsiveTextSize.Full,
239
+ getSpirit,
240
+ getToughness,
241
+ }),
242
+ ...getTextForEffect(translation.effect, translate),
243
+ {
244
+ label: translate("Ritual Time"),
245
+ value: castingTime !== translation.casting_time.full
246
+ ? `***${castingTime}*** (${translation.casting_time.full})`
247
+ : castingTime,
248
+ },
249
+ {
250
+ label: translate("AE Cost"),
251
+ value: cost !== translation.cost.full
252
+ ? `***${cost}*** (${translation.cost.full})`
253
+ : cost,
254
+ },
255
+ {
256
+ label: translate("Range"),
257
+ value: range !== translation.range.full
258
+ ? `***${range}*** (${translation.range.full})`
259
+ : range,
260
+ },
261
+ {
262
+ label: translate("Duration"),
263
+ value: duration !== translation.duration.full
264
+ ? `***${duration}*** (${translation.duration.full})`
265
+ : duration,
266
+ },
267
+ getTextForTargetCategory({ translate, translateMap, getTargetCategoryById }, entry.target),
268
+ getTextForProperty({ translate, translateMap, getPropertyById }, entry.property),
269
+ getTextForTraditions({ translate, translateMap, localeCompare, getMagicalTraditionById }, entry.traditions),
270
+ createImprovementCost(translate, entry.improvement_cost),
271
+ ],
272
+ src: entry.src,
273
+ };
274
+ });