@@ -4,18 +4,22 @@ import Head from "next/head"
44import ReactMarkdown from "react-markdown"
55import FormattedLink from "../../components/FormattedLink"
66import Guides from "../../components/Guides"
7- import Icon from "../../components/Icon"
7+ import Icon , { CharIcon , IconName } from "../../components/Icon"
88import Main from "../../components/Main"
9- import { getMaterials } from "../../utils/data-cache"
10- import { Material } from "../../utils/types"
11- import { getGuidesFor , getLinkToGuide , getStarColor , urlify } from "../../utils/utils"
9+ import { CostTemplates , getCharacters , getCostTemplates , getMaterials } from "../../utils/data-cache"
10+ import { Cost , CostTemplate , Material , SmallChar } from "../../utils/types"
11+ import { createSmallChar , getCostsFromTemplate , getGuidesFor , getLinkToGuide , getStarColor , urlify } from "../../utils/utils"
1212
1313interface Props {
1414 mat : Material ,
15- guides ?: string [ ] [ ]
15+ guides ?: string [ ] [ ] ,
16+ usedBy : {
17+ charTalents : SmallChar [ ]
18+ charAscension : SmallChar [ ]
19+ }
1620}
1721
18- export default function CharacterWebpage ( { mat, location, guides } : Props & { location : string } ) {
22+ export default function CharacterWebpage ( { mat, location, guides, usedBy } : Props & { location : string } ) {
1923 const color = getStarColor ( mat . stars ?? 1 )
2024
2125 return (
@@ -74,6 +78,20 @@ export default function CharacterWebpage({ mat, location, guides }: Props & { lo
7478 { mat . sources . map ( s => < div key = { s } > { s } </ div > ) }
7579 </ > }
7680
81+ { usedBy . charTalents . length > 0 && < >
82+ < h3 className = "text-lg font-bold pt-1" id = "chartalents" > Used by character talents:</ h3 >
83+ < div className = "flex flex-wrap justify-start text-center mt-2" >
84+ { usedBy . charTalents . map ( c => < CharIcon key = { c . name } char = { c } location = { location } /> ) }
85+ </ div >
86+ </ > }
87+
88+ { usedBy . charAscension . length > 0 && < >
89+ < h3 className = "text-lg font-bold pt-1" id = "charascension" > Used by character ascensions:</ h3 >
90+ < div className = "flex flex-wrap justify-start text-center mt-2" >
91+ { usedBy . charAscension . map ( c => < CharIcon key = { c . name } char = { c } location = { location } /> ) }
92+ </ div >
93+ </ > }
94+
7795 { mat . longDesc && < >
7896 < h3 className = "text-lg font-bold pt-1" id = "longdesc" > Description:</ h3 >
7997 < blockquote className = "pl-5 mb-2 border-l-2" >
@@ -86,6 +104,16 @@ export default function CharacterWebpage({ mat, location, guides }: Props & { lo
86104}
87105
88106
107+ function isInCosts ( template : CostTemplate | Cost [ ] , costTemplates : CostTemplates , name : string ) : boolean {
108+ const costs = Array . isArray ( template ) ? template : getCostsFromTemplate ( template , costTemplates )
109+
110+ for ( const c of costs )
111+ if ( c . items . some ( i => i . name == name ) )
112+ return true
113+
114+ return false
115+ }
116+
89117export async function getStaticProps ( context : GetStaticPropsContext ) : Promise < GetStaticPropsResult < Props > > {
90118 const matName = context . params ?. material
91119 const data = await getMaterials ( )
@@ -100,10 +128,33 @@ export async function getStaticProps(context: GetStaticPropsContext): Promise<Ge
100128
101129 const guides = ( await getGuidesFor ( "material" , mat . name ) ) ?. map ( ( { guide, page } ) => [ page . name , getLinkToGuide ( guide , page ) ] )
102130
131+ const char = await getCharacters ( )
132+ const costTemplates = await getCostTemplates ( )
133+ const charAscension : SmallChar [ ] = [ ]
134+ const charTalents : SmallChar [ ] = [ ]
135+
136+ if ( char && costTemplates ) {
137+ for ( const c of Object . values ( char ) ) {
138+ if ( c . ascensionCosts && isInCosts ( c . ascensionCosts , costTemplates , mat . name ) )
139+ charAscension . push ( createSmallChar ( c ) )
140+
141+ if ( c . skills ) {
142+ const talents = c . skills . flatMap ( s => [ ...( s . talents ?? [ ] ) , s . ult ] )
143+
144+ if ( talents . some ( x => x ?. costs && isInCosts ( x . costs , costTemplates , mat . name ) ) )
145+ charTalents . push ( createSmallChar ( c ) )
146+ }
147+ }
148+ }
149+
103150 return {
104151 props : {
105152 mat,
106- guides
153+ guides,
154+ usedBy : {
155+ charAscension,
156+ charTalents
157+ }
107158 } ,
108159 revalidate : 60 * 60
109160 }
0 commit comments