Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 45 additions & 10 deletions src/cache/activatableSelectOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
ImprovementCost,
Poison,
PrerequisiteForLevel,
Property_ID,
RequirableSelectOptionIdentifier,
Ritual_ID,
SelectOptionCategory,
SelectOptions,
SelectOptionsAdventurePointsValue,
Expand All @@ -28,9 +30,10 @@
SkillSelectOptionCategoryPrerequisite,
SpecificFromSkillSelectOptionCategoryCategory,
SpecificTargetCategory,
Spell_ID,
TargetCategory,
TradeSecretAdventurePointsValue,
} from "../../gen/types.js"

Check failure on line 36 in src/cache/activatableSelectOptions.ts

View workflow job for this annotation

GitHub Actions / test (24)

Cannot find module '../../gen/types.js' or its corresponding type declarations.

Check failure on line 36 in src/cache/activatableSelectOptions.ts

View workflow job for this annotation

GitHub Actions / test (23)

Cannot find module '../../gen/types.js' or its corresponding type declarations.
import type { TSONDBTypes } from "../main.js"
import type { IdMap } from "./index.ts"
import type { CacheBuilder } from "./internal.ts"
Expand Down Expand Up @@ -67,17 +70,19 @@
): TradeSecretAdventurePointsValue | undefined =>
apValue === undefined ? undefined : Case("Fixed", apValue)

const matchesSpecificSkillishIdList = (
id: string,
config: SpecificFromSkillSelectOptionCategoryCategory<string>,
const matchesSpecificSkillishIdList = <Ref>(
config: SpecificFromSkillSelectOptionCategoryCategory<Ref>,
matches: (required: Ref) => boolean,
): boolean => {
const isInList = config.list.some(matches)

switch (config.operation.kind) {
case "Intersection":
return config.list.includes(id)
return isInList
case "Difference":
return !config.list.includes(id)
return !isInList
default:
return assertExhaustive(config.operation)

Check failure on line 85 in src/cache/activatableSelectOptions.ts

View workflow job for this annotation

GitHub Actions / test (24)

Argument of type 'any' is not assignable to parameter of type 'never'.

Check failure on line 85 in src/cache/activatableSelectOptions.ts

View workflow job for this annotation

GitHub Actions / test (23)

Argument of type 'any' is not assignable to parameter of type 'never'.
}
}

Expand Down Expand Up @@ -116,7 +121,7 @@
),
}
default:
return assertExhaustive(p)

Check failure on line 124 in src/cache/activatableSelectOptions.ts

View workflow job for this annotation

GitHub Actions / test (24)

Argument of type 'SkillSelectOptionCategoryPrerequisite' is not assignable to parameter of type 'never'.

Check failure on line 124 in src/cache/activatableSelectOptions.ts

View workflow job for this annotation

GitHub Actions / test (23)

Argument of type 'SkillSelectOptionCategoryPrerequisite' is not assignable to parameter of type 'never'.
}
})
}
Expand All @@ -132,7 +137,7 @@
}

return (
bindingCost.Fixed.map.find(mapping => equalsSkillishIdGroup(mapping.id, id))?.bindingCost ??

Check failure on line 140 in src/cache/activatableSelectOptions.ts

View workflow job for this annotation

GitHub Actions / test (24)

Parameter 'mapping' implicitly has an 'any' type.

Check failure on line 140 in src/cache/activatableSelectOptions.ts

View workflow job for this annotation

GitHub Actions / test (23)

Parameter 'mapping' implicitly has an 'any' type.
bindingCost.Fixed.default
)
}
Expand All @@ -159,7 +164,7 @@
b.kind === "RangedCombatTechnique" && a.RangedCombatTechnique === b.RangedCombatTechnique
)
default:
return assertExhaustive(a)

Check failure on line 167 in src/cache/activatableSelectOptions.ts

View workflow job for this annotation

GitHub Actions / test (24)

Argument of type 'any' is not assignable to parameter of type 'never'.

Check failure on line 167 in src/cache/activatableSelectOptions.ts

View workflow job for this annotation

GitHub Actions / test (23)

Argument of type 'any' is not assignable to parameter of type 'never'.
}
}

Expand Down Expand Up @@ -188,7 +193,7 @@
case "D":
return 4
default:
assertExhaustive(ic)

Check failure on line 196 in src/cache/activatableSelectOptions.ts

View workflow job for this annotation

GitHub Actions / test (24)

Argument of type 'ImprovementCost' is not assignable to parameter of type 'never'.

Check failure on line 196 in src/cache/activatableSelectOptions.ts

View workflow job for this annotation

GitHub Actions / test (23)

Argument of type 'ImprovementCost' is not assignable to parameter of type 'never'.
}
})() *
(config.DerivedFromImprovementCost.multiplier ?? 1) +
Expand All @@ -196,11 +201,11 @@
)
case "Fixed":
return (
config.Fixed.map.find(mapping => equalsSkillishIdGroup(mapping.id, id))?.ap_value ??

Check failure on line 204 in src/cache/activatableSelectOptions.ts

View workflow job for this annotation

GitHub Actions / test (24)

Parameter 'mapping' implicitly has an 'any' type.

Check failure on line 204 in src/cache/activatableSelectOptions.ts

View workflow job for this annotation

GitHub Actions / test (23)

Parameter 'mapping' implicitly has an 'any' type.
config.Fixed.default
)
default:
return assertExhaustive(config)

Check failure on line 208 in src/cache/activatableSelectOptions.ts

View workflow job for this annotation

GitHub Actions / test (24)

Argument of type 'any' is not assignable to parameter of type 'never'.

Check failure on line 208 in src/cache/activatableSelectOptions.ts

View workflow job for this annotation

GitHub Actions / test (23)

Argument of type 'any' is not assignable to parameter of type 'never'.
}
}

Expand Down Expand Up @@ -233,22 +238,43 @@
const { specific } = category
return specific === undefined
? undefined
: ({ id }) => matchesSpecificSkillishIdList(id, specific)
: ({ id }) => matchesSpecificSkillishIdList(specific, required => required === id)
}

const getSpellworkFilter = <E extends "Spell" | "Ritual">(
category: GenericSkillsSelectOptionCategoryCategory<
Case<"Single", Spell_ID | Ritual_ID> | Case<"Property", Property_ID>
>,
): ((instance: { id: string; content: Entity<TSONDBTypes, E> }) => boolean) | undefined => {
const { specific } = category
return specific === undefined
? undefined
: ({ id, content: { property } }) =>
matchesSpecificSkillishIdList(specific, required => {
switch (required.kind) {

Check failure on line 254 in src/cache/activatableSelectOptions.ts

View workflow job for this annotation

GitHub Actions / test (24)

'required' is of type 'unknown'.

Check failure on line 254 in src/cache/activatableSelectOptions.ts

View workflow job for this annotation

GitHub Actions / test (23)

'required' is of type 'unknown'.
case "Single":
return required.Single === id

Check failure on line 256 in src/cache/activatableSelectOptions.ts

View workflow job for this annotation

GitHub Actions / test (24)

'required' is of type 'unknown'.

Check failure on line 256 in src/cache/activatableSelectOptions.ts

View workflow job for this annotation

GitHub Actions / test (23)

'required' is of type 'unknown'.
case "Property":
return property === required.Property
default:
return assertExhaustive(required)
}
})
}

const getDerivedSkillishSelectOptions = <E extends SkillishEntityName>(
const getDerivedSkillishSelectOptions = <E extends SkillishEntityName, ID>(
database: TSONDB<TSONDBTypes>,
entryId: ActivatableIdentifier,
entity: E,
category: GenericSkillsSelectOptionCategoryCategory<string> & {
category: GenericSkillsSelectOptionCategoryCategory<ID> & {
skill_applications?: SkillApplicationOrUse[] | undefined
skill_uses?: SkillApplicationOrUse[] | undefined
},
options: {
bindingCost?: SelectOptionsBindingCostValue<SkillishIdentifier | CombatTechniqueIdentifier>
ap_value?: SelectOptionsAdventurePointsValue<SkillishIdentifier | CombatTechniqueIdentifier>
},
filter = getDefaultSkillishFilter<E>(category),
filter: ((instance: { id: string; content: Entity<TSONDBTypes, E> }) => boolean) | undefined,
) => {
const { prerequisites } = category
const { bindingCost, ap_value } = options
Expand Down Expand Up @@ -928,7 +954,10 @@

const matchesIdRequirement =
category.Skills.specific === undefined ||
matchesSpecificSkillishIdList(id, category.Skills.specific)
matchesSpecificSkillishIdList(
category.Skills.specific,
required => required === id,
)

return matchesGroupRequirement && matchesIdRequirement
},
Expand All @@ -940,6 +969,7 @@
"Spell",
category.Spells,
selectOptionCategory.Skills,
getSpellworkFilter(category.Spells),
)
case "Rituals":
return getDerivedSkillishSelectOptions(
Expand All @@ -948,6 +978,7 @@
"Ritual",
category.Rituals,
selectOptionCategory.Skills,
getSpellworkFilter(category.Rituals),
)
case "LiturgicalChants":
return getDerivedSkillishSelectOptions(
Expand All @@ -956,6 +987,7 @@
"LiturgicalChant",
category.LiturgicalChants,
selectOptionCategory.Skills,
getDefaultSkillishFilter(category.LiturgicalChants),
)
case "Ceremonies":
return getDerivedSkillishSelectOptions(
Expand All @@ -964,6 +996,7 @@
"Ceremony",
category.Ceremonies,
selectOptionCategory.Skills,
getDefaultSkillishFilter(category.Ceremonies),
)
default:
return assertExhaustive(category)
Expand All @@ -980,6 +1013,7 @@
"CloseCombatTechnique",
category.CloseCombatTechniques,
selectOptionCategory.CombatTechniques,
getDefaultSkillishFilter(category.CloseCombatTechniques),
)
case "RangedCombatTechniques":
return getDerivedSkillishSelectOptions(
Expand All @@ -988,6 +1022,7 @@
"RangedCombatTechnique",
category.RangedCombatTechniques,
selectOptionCategory.CombatTechniques,
getDefaultSkillishFilter(category.RangedCombatTechniques),
)
default:
return assertExhaustive(category)
Expand Down
23 changes: 21 additions & 2 deletions src/types/_ActivatableSelectOptionCategory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
SkillIdentifier,
SpellIdentifier,
TargetCategoryIdentifier,
PropertyIdentifier,
} from "./_Identifier.js"
import {
ActivatableIdentifier,
Expand Down Expand Up @@ -211,16 +212,34 @@ const SkillsSelectOptionCategory = DB.TypeAlias(import.meta.url, {
}),
})

const SpellFilter = DB.Enum(import.meta.url, {
name: "SpellFilter",
values: () => ({
Single: DB.EnumCase({ type: SpellIdentifier() }),
Property: DB.EnumCase({ type: PropertyIdentifier() }),
}),
})

const RitualFilter = DB.Enum(import.meta.url, {
name: "RitualFilter",
values: () => ({
Single: DB.EnumCase({ type: RitualIdentifier() }),
Property: DB.EnumCase({ type: PropertyIdentifier() }),
}),
})

Comment on lines +215 to +230

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ich würde Identifier vielleicht eher Single oder so nennen, da ja auch die Property ein Identifier ist.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ist umgesetzt.

const SkillsSelectOptionCategoryCategory = DB.Enum(import.meta.url, {
name: "SkillsSelectOptionCategoryCategory",
values: () => ({
Skills: DB.EnumCase({ type: DB.IncludeIdentifier(SkillSelectOptionCategoryCategory) }),
Spells: DB.EnumCase({
type: DB.GenIncludeIdentifier(GenericSkillsSelectOptionCategoryCategory, [SpellIdentifier()]),
type: DB.GenIncludeIdentifier(GenericSkillsSelectOptionCategoryCategory, [
DB.IncludeIdentifierType(SpellFilter),
]),
}),
Rituals: DB.EnumCase({
type: DB.GenIncludeIdentifier(GenericSkillsSelectOptionCategoryCategory, [
RitualIdentifier(),
DB.IncludeIdentifierType(RitualFilter),
]),
}),
LiturgicalChants: DB.EnumCase({
Expand Down
18 changes: 18 additions & 0 deletions src/types/prerequisites/single/PropertyPrerequisite.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as DB from "tsondb/schema/dsl"
import { PropertyIdentifier } from "../../_Identifier.js"
import { DisplayOption } from "../DisplayOption.js"

export const PropertyPrerequisite = DB.TypeAlias(import.meta.url, {
name: "PropertyPrerequisite",
comment: "Requires a specific property or one of a specific set of properties.",
type: () =>
DB.Object({
id: DB.Required({
comment: "The property�s identifier.",
type: PropertyIdentifier(),
}),
display_option: DB.Optional({
type: DB.IncludeIdentifier(DisplayOption),
}),
}),
})
Comment on lines +5 to +18

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ich schätze mal, dass hier die Einrückung nicht passt und er deswegen meckert.