Skip to content

Commit

Permalink
refactor: outsource entity description generation to @optolith/entity…
Browse files Browse the repository at this point in the history
…-descriptions
  • Loading branch information
elyukai committed Oct 7, 2024
1 parent 928498b commit 938da65
Show file tree
Hide file tree
Showing 48 changed files with 372 additions and 3,545 deletions.
29 changes: 29 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"license": "MPL-2.0",
"main": ".webpack/main.cjs",
"dependencies": {
"@optolith/entity-descriptions": "^0.2.1",
"@reduxjs/toolkit": "^2.2.7",
"adm-zip": "^0.5.16",
"debug": "^4.3.7",
Expand Down
28 changes: 19 additions & 9 deletions src/main_window/inlineLibrary/entities/InlineLibraryBlessing.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { FC } from "react"
import { LibraryEntry } from "../../../shared/components/libraryEntry/LibraryEntry.tsx"
import { getBlessingLibraryEntry } from "../../../shared/domain/rated/liturgicalChant.ts"
import { getBlessingEntityDescription } from "@optolith/entity-descriptions/entities/liturgicalChant"
import { FC, useCallback } from "react"
import {
LibraryEntry,
PartialEntityDescriptionCreator,
} from "../../../shared/components/libraryEntry/LibraryEntry.tsx"
import { useAppSelector } from "../../hooks/redux.ts"
import { SelectGetById } from "../../selectors/basicCapabilitySelectors.ts"

Expand All @@ -15,11 +18,18 @@ export const InlineLibraryBlessing: FC<Props> = ({ id }) => {
const getTargetCategoryById = useAppSelector(SelectGetById.Static.TargetCategory)
const entry = useAppSelector(SelectGetById.Static.Blessing)(id)

return (
<LibraryEntry
createLibraryEntry={getBlessingLibraryEntry(entry, {
getTargetCategoryById,
})}
/>
const createEntityDescription: PartialEntityDescriptionCreator = useCallback(
(defaultDatabaseAccessors, locale) =>
getBlessingEntityDescription(
{
...defaultDatabaseAccessors,
getTargetCategoryById,
},
locale,
entry,
),
[entry, getTargetCategoryById],
)

return <LibraryEntry createEntityDescription={createEntityDescription} />
}
34 changes: 22 additions & 12 deletions src/main_window/inlineLibrary/entities/InlineLibraryCantrip.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { FC } from "react"
import { LibraryEntry } from "../../../shared/components/libraryEntry/LibraryEntry.tsx"
import { getCantripLibraryEntry } from "../../../shared/domain/rated/spell.ts"
import { getCantripEntityDescription } from "@optolith/entity-descriptions/entities/spell"
import { FC, useCallback } from "react"
import {
LibraryEntry,
PartialEntityDescriptionCreator,
} from "../../../shared/components/libraryEntry/LibraryEntry.tsx"
import { useAppSelector } from "../../hooks/redux.ts"
import { SelectGetById } from "../../selectors/basicCapabilitySelectors.ts"

Expand All @@ -18,14 +21,21 @@ export const InlineLibraryCantrip: FC<Props> = ({ id }) => {
const getMagicalTraditionById = useAppSelector(SelectGetById.Static.MagicalTradition)
const entry = useAppSelector(SelectGetById.Static.Cantrip)(id)

return (
<LibraryEntry
createLibraryEntry={getCantripLibraryEntry(entry, {
getTargetCategoryById,
getPropertyById,
getMagicalTraditionById,
getCurriculumById,
})}
/>
const createEntityDescription: PartialEntityDescriptionCreator = useCallback(
(defaultDatabaseAccessors, locale) =>
getCantripEntityDescription(
{
...defaultDatabaseAccessors,
getTargetCategoryById,
getPropertyById,
getCurriculumById,
getMagicalTraditionById,
},
locale,
entry,
),
[entry, getCurriculumById, getMagicalTraditionById, getPropertyById, getTargetCategoryById],
)

return <LibraryEntry createEntityDescription={createEntityDescription} />
}
51 changes: 37 additions & 14 deletions src/main_window/inlineLibrary/entities/InlineLibraryCeremony.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { FC } from "react"
import { LibraryEntry } from "../../../shared/components/libraryEntry/LibraryEntry.tsx"
import { getCeremonyLibraryEntry } from "../../../shared/domain/rated/liturgicalChant.ts"
import { getCeremonyEntityDescription } from "@optolith/entity-descriptions/entities/liturgicalChant"
import { FC, useCallback } from "react"
import {
LibraryEntry,
PartialEntityDescriptionCreator,
} from "../../../shared/components/libraryEntry/LibraryEntry.tsx"
import { DerivedCharacteristicIdentifier } from "../../../shared/domain/identifier.ts"
import { useAppSelector } from "../../hooks/redux.ts"
import { SelectGetById } from "../../selectors/basicCapabilitySelectors.ts"

Expand All @@ -14,22 +18,41 @@ type Props = {
export const InlineLibraryCeremony: FC<Props> = ({ id }) => {
const getAttributeById = useAppSelector(SelectGetById.Static.Attribute)
const getDerivedCharacteristicById = useAppSelector(SelectGetById.Static.DerivedCharacteristic)
const spirit = getDerivedCharacteristicById(DerivedCharacteristicIdentifier.Spirit)
const toughness = getDerivedCharacteristicById(DerivedCharacteristicIdentifier.Toughness)
const getSkillModificationLevelById = useAppSelector(SelectGetById.Static.SkillModificationLevel)
const getTargetCategoryById = useAppSelector(SelectGetById.Static.TargetCategory)
const getBlessedTraditionById = useAppSelector(SelectGetById.Static.BlessedTradition)
const getAspectById = useAppSelector(SelectGetById.Static.Aspect)
const entry = useAppSelector(SelectGetById.Static.Ceremony)(id)

return (
<LibraryEntry
createLibraryEntry={getCeremonyLibraryEntry(entry, {
getAttributeById,
getDerivedCharacteristicById,
getSkillModificationLevelById,
getTargetCategoryById,
getBlessedTraditionById,
getAspectById,
})}
/>
const createEntityDescription: PartialEntityDescriptionCreator = useCallback(
(defaultDatabaseAccessors, locale) =>
getCeremonyEntityDescription(
{
...defaultDatabaseAccessors,
getAttributeById,
getSpirit: () => spirit,
getToughness: () => toughness,
getSkillModificationLevelById,
getTargetCategoryById,
getBlessedTraditionById,
getAspectById,
},
locale,
entry,
),
[
entry,
getAspectById,
getAttributeById,
getBlessedTraditionById,
getSkillModificationLevelById,
getTargetCategoryById,
spirit,
toughness,
],
)

return <LibraryEntry createEntityDescription={createEntityDescription} />
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { FC } from "react"
import { LibraryEntry } from "../../../shared/components/libraryEntry/LibraryEntry.tsx"
import { getCloseCombatTechniqueLibraryEntry } from "../../../shared/domain/rated/combatTechnique.ts"
import { getCloseCombatTechniqueEntityDescription } from "@optolith/entity-descriptions/entities/combatTechnique"
import { FC, useCallback } from "react"
import {
LibraryEntry,
PartialEntityDescriptionCreator,
} from "../../../shared/components/libraryEntry/LibraryEntry.tsx"
import { useAppSelector } from "../../hooks/redux.ts"
import { SelectGetById } from "../../selectors/basicCapabilitySelectors.ts"

Expand All @@ -15,11 +18,18 @@ export const InlineLibraryCloseCombatTechnique: FC<Props> = ({ id }) => {
const getAttributeById = useAppSelector(SelectGetById.Static.Attribute)
const entry = useAppSelector(SelectGetById.Static.CloseCombatTechnique)(id)

return (
<LibraryEntry
createLibraryEntry={getCloseCombatTechniqueLibraryEntry(entry, {
getAttributeById,
})}
/>
const createEntityDescription: PartialEntityDescriptionCreator = useCallback(
(defaultDatabaseAccessors, locale) =>
getCloseCombatTechniqueEntityDescription(
{
...defaultDatabaseAccessors,
getAttributeById,
},
locale,
entry,
),
[entry, getAttributeById],
)

return <LibraryEntry createEntityDescription={createEntityDescription} />
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { FC } from "react"
import { LibraryEntry } from "../../../shared/components/libraryEntry/LibraryEntry.tsx"
import { getExperienceLevelLibraryEntry } from "../../../shared/domain/experienceLevel.ts"
import { getExperienceLevelEntityDescription } from "@optolith/entity-descriptions/entities/experienceLevel"
import { FC, useCallback } from "react"
import {
LibraryEntry,
PartialEntityDescriptionCreator,
} from "../../../shared/components/libraryEntry/LibraryEntry.tsx"
import { useAppSelector } from "../../hooks/redux.ts"
import { selectStaticExperienceLevels } from "../../slices/databaseSlice.ts"

Expand All @@ -14,5 +17,11 @@ type Props = {
export const InlineLibraryExperienceLevel: FC<Props> = ({ id }) => {
const entry = useAppSelector(selectStaticExperienceLevels)[id]

return <LibraryEntry createLibraryEntry={getExperienceLevelLibraryEntry(entry)} />
const createEntityDescription: PartialEntityDescriptionCreator = useCallback(
(defaultDatabaseAccessors, locale) =>
getExperienceLevelEntityDescription(defaultDatabaseAccessors, locale, entry),
[entry],
)

return <LibraryEntry createEntityDescription={createEntityDescription} />
}
24 changes: 20 additions & 4 deletions src/main_window/inlineLibrary/entities/InlineLibraryFocusRule.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { FC } from "react"
import { LibraryEntry } from "../../../shared/components/libraryEntry/LibraryEntry.tsx"
import { getFocusRuleLibraryEntry } from "../../../shared/domain/rules/focusRule.ts"
import { getFocusRuleEntityDescription } from "@optolith/entity-descriptions/entities/focusRule"
import { FC, useCallback } from "react"
import {
LibraryEntry,
PartialEntityDescriptionCreator,
} from "../../../shared/components/libraryEntry/LibraryEntry.tsx"
import { useAppSelector } from "../../hooks/redux.ts"
import { SelectGetById } from "../../selectors/basicCapabilitySelectors.ts"
import { selectStaticFocusRules } from "../../slices/databaseSlice.ts"
Expand All @@ -16,5 +19,18 @@ export const InlineLibraryFocusRule: FC<Props> = ({ id }) => {
const entry = useAppSelector(selectStaticFocusRules)[id]
const getSubjectById = useAppSelector(SelectGetById.Static.Subject)

return <LibraryEntry createLibraryEntry={getFocusRuleLibraryEntry(entry, { getSubjectById })} />
const createEntityDescription: PartialEntityDescriptionCreator = useCallback(
(defaultDatabaseAccessors, locale) =>
getFocusRuleEntityDescription(
{
...defaultDatabaseAccessors,
getSubjectById,
},
locale,
entry,
),
[entry, getSubjectById],
)

return <LibraryEntry createEntityDescription={createEntityDescription} />
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { FC } from "react"
import { LibraryEntry } from "../../../shared/components/libraryEntry/LibraryEntry.tsx"
import { getLiturgicalChantLibraryEntry } from "../../../shared/domain/rated/liturgicalChant.ts"
import { getLiturgicalChantEntityDescription } from "@optolith/entity-descriptions/entities/liturgicalChant"
import { FC, useCallback } from "react"
import {
LibraryEntry,
PartialEntityDescriptionCreator,
} from "../../../shared/components/libraryEntry/LibraryEntry.tsx"
import { DerivedCharacteristicIdentifier } from "../../../shared/domain/identifier.ts"
import { useAppSelector } from "../../hooks/redux.ts"
import { SelectGetById } from "../../selectors/basicCapabilitySelectors.ts"

Expand All @@ -14,22 +18,41 @@ type Props = {
export const InlineLibraryLiturgicalChant: FC<Props> = ({ id }) => {
const getAttributeById = useAppSelector(SelectGetById.Static.Attribute)
const getDerivedCharacteristicById = useAppSelector(SelectGetById.Static.DerivedCharacteristic)
const spirit = getDerivedCharacteristicById(DerivedCharacteristicIdentifier.Spirit)
const toughness = getDerivedCharacteristicById(DerivedCharacteristicIdentifier.Toughness)
const getSkillModificationLevelById = useAppSelector(SelectGetById.Static.SkillModificationLevel)
const getTargetCategoryById = useAppSelector(SelectGetById.Static.TargetCategory)
const getBlessedTraditionById = useAppSelector(SelectGetById.Static.BlessedTradition)
const getAspectById = useAppSelector(SelectGetById.Static.Aspect)
const entry = useAppSelector(SelectGetById.Static.LiturgicalChant)(id)

return (
<LibraryEntry
createLibraryEntry={getLiturgicalChantLibraryEntry(entry, {
getAttributeById,
getDerivedCharacteristicById,
getSkillModificationLevelById,
getTargetCategoryById,
getBlessedTraditionById,
getAspectById,
})}
/>
const createEntityDescription: PartialEntityDescriptionCreator = useCallback(
(defaultDatabaseAccessors, locale) =>
getLiturgicalChantEntityDescription(
{
...defaultDatabaseAccessors,
getAttributeById,
getSpirit: () => spirit,
getToughness: () => toughness,
getSkillModificationLevelById,
getTargetCategoryById,
getBlessedTraditionById,
getAspectById,
},
locale,
entry,
),
[
entry,
getAspectById,
getAttributeById,
getBlessedTraditionById,
getSkillModificationLevelById,
getTargetCategoryById,
spirit,
toughness,
],
)

return <LibraryEntry createEntityDescription={createEntityDescription} />
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { FC } from "react"
import { LibraryEntry } from "../../../shared/components/libraryEntry/LibraryEntry.tsx"
import { getOptionalRuleLibraryEntry } from "../../../shared/domain/rules/optionalRule.ts"
import { getOptionalRuleEntityDescription } from "@optolith/entity-descriptions/entities/optionalRule"
import { FC, useCallback } from "react"
import {
LibraryEntry,
PartialEntityDescriptionCreator,
} from "../../../shared/components/libraryEntry/LibraryEntry.tsx"
import { useAppSelector } from "../../hooks/redux.ts"
import { selectStaticOptionalRules } from "../../slices/databaseSlice.ts"

Expand All @@ -14,5 +17,11 @@ type Props = {
export const InlineLibraryOptionalRule: FC<Props> = ({ id }) => {
const entry = useAppSelector(selectStaticOptionalRules)[id]

return <LibraryEntry createLibraryEntry={getOptionalRuleLibraryEntry(entry)} />
const createEntityDescription: PartialEntityDescriptionCreator = useCallback(
(defaultDatabaseAccessors, locale) =>
getOptionalRuleEntityDescription(defaultDatabaseAccessors, locale, entry),
[entry],
)

return <LibraryEntry createEntityDescription={createEntityDescription} />
}
Loading

0 comments on commit 938da65

Please sign in to comment.