@@ -6,25 +6,31 @@ import FormattedLink from "../../components/FormattedLink"
66import Guides from "../../components/Guides"
77import Icon , { SmallIcon } from "../../components/Icon"
88import Main from "../../components/Main"
9- import { CostTemplates , getCharacters , getCostTemplates , getMaterials , getWeapons } from "../../utils/data-cache"
10- import { Cost , CostTemplate , Material , SmallChar , SmallWeapon } from "../../utils/types"
11- import { clean , createSmallChar , createSmallWeapon , getCostsFromTemplate , getGuidesFor , getIconPath , getLinkToGuide , getStarColor , isInCosts , joinMulti , urlify } from "../../utils/utils"
9+ import { MaterialCost } from "../../components/Material"
10+ import { Specialty , SpecialtyItem } from "../../components/Specialty"
11+ import { getCharacters , getCostTemplates , getMaterials , getWeapons } from "../../utils/data-cache"
12+ import { Material , SmallChar , SmallMaterial , SmallWeapon } from "../../utils/types"
13+ import { clean , createSmallChar , createSmallMaterial , createSmallWeapon , getGuidesFor , getIconPath , getLinkToGuide , getStarColor , isInCosts , joinMulti , urlify } from "../../utils/utils"
14+ import styles from "../style.module.css"
15+
1216
1317interface Props {
1418 mat : Material ,
1519 guides ?: string [ ] [ ] ,
20+ specialty : SpecialtyItem | null ,
1621 usedBy : {
1722 charTalents : SmallChar [ ]
1823 charAscension : SmallChar [ ]
1924 weaponAscension : SmallWeapon [ ]
25+ food : SmallMaterial [ ]
2026 }
2127}
2228
23- export default function MaterialWebpage ( { mat, location, guides, usedBy } : Props & { location : string } ) {
29+ export default function MaterialWebpage ( { mat, location, guides, specialty , usedBy } : Props & { location : string } ) {
2430 const color = getStarColor ( mat . stars ?? 1 )
2531 const usedByDesc = [ ]
2632
27- const { charTalents, charAscension, weaponAscension } = usedBy
33+ const { charTalents, charAscension, weaponAscension, food } = usedBy
2834
2935 const overlap = charTalents . filter ( x => charAscension . some ( y => x . name == y . name ) )
3036 const uniqueTalents = charTalents . filter ( x => ! charAscension . some ( y => x . name == y . name ) )
@@ -101,6 +107,27 @@ export default function MaterialWebpage({ mat, location, guides, usedBy }: Props
101107 { mat . sources . map ( s => < div key = { s } > { s } </ div > ) }
102108 </ > }
103109
110+ { mat . recipe && < >
111+ < h3 className = "text-lg font-bold pt-1" id = "recipe" > Recipe:</ h3 >
112+ < table className = { `table-auto ${ styles . table } mb-2 sm:text-sm md:text-base text-xs` } >
113+ < thead >
114+ < tr className = "divide-x divide-gray-200 dark:divide-gray-500" >
115+ < th > Items</ th >
116+ </ tr >
117+ </ thead >
118+ < tbody className = "divide-y divide-gray-200 dark:divide-gray-500" >
119+ { mat . recipe . map ( ( { name, count } ) => < tr className = "pr-1 divide-x divide-gray-200 dark:divide-gray-500" key = { name } >
120+ < td > < MaterialCost name = { name } count = { count } /> </ td >
121+ </ tr > ) }
122+ </ tbody >
123+ </ table >
124+ </ > }
125+
126+ { specialty && < >
127+ < h3 className = "text-lg font-bold pt-1" id = "specialty" > Specialty:</ h3 >
128+ < Specialty specialty = { specialty } location = { location } />
129+ </ > }
130+
104131 { overlap . length > 0 && < >
105132 < h3 className = "text-lg font-bold pt-1" id = "chartalents" > Used by character ascensions and talents:</ h3 >
106133 < div className = "flex flex-wrap justify-start text-center mt-2" >
@@ -129,6 +156,13 @@ export default function MaterialWebpage({ mat, location, guides, usedBy }: Props
129156 </ div >
130157 </ > }
131158
159+ { food . length > 0 && < >
160+ < h3 className = "text-lg font-bold pt-1" id = "food" > Used by food:</ h3 >
161+ < div className = "flex flex-wrap justify-start text-center mt-2" >
162+ { food . map ( c => < SmallIcon key = { c . name } thing = { c } location = { location } /> ) }
163+ </ div >
164+ </ > }
165+
132166 { mat . longDesc && < >
133167 < h3 className = "text-lg font-bold pt-1" id = "longdesc" > Description:</ h3 >
134168 < blockquote className = "pl-5 mb-2 border-l-2" >
@@ -140,6 +174,7 @@ export default function MaterialWebpage({ mat, location, guides, usedBy }: Props
140174 )
141175}
142176
177+
143178export async function getStaticProps ( context : GetStaticPropsContext ) : Promise < GetStaticPropsResult < Props > > {
144179 const matName = context . params ?. material
145180 const data = await getMaterials ( )
@@ -154,13 +189,13 @@ export async function getStaticProps(context: GetStaticPropsContext): Promise<Ge
154189
155190 const guides = ( await getGuidesFor ( "material" , mat . name ) ) ?. map ( ( { guide, page } ) => [ page . name , getLinkToGuide ( guide , page ) ] )
156191
157- const char = await getCharacters ( )
192+ const chars = await getCharacters ( )
158193 const costTemplates = await getCostTemplates ( )
159194 const charAscension : SmallChar [ ] = [ ]
160195 const charTalents : SmallChar [ ] = [ ]
161196
162- if ( char && costTemplates ) {
163- for ( const c of Object . values ( char ) ) {
197+ if ( chars && costTemplates ) {
198+ for ( const c of Object . values ( chars ) ) {
164199 if ( c . ascensionCosts && isInCosts ( c . ascensionCosts , costTemplates , mat . name ) )
165200 charAscension . push ( createSmallChar ( c ) )
166201
@@ -184,14 +219,46 @@ export async function getStaticProps(context: GetStaticPropsContext): Promise<Ge
184219 }
185220 }
186221
222+ const food : SmallMaterial [ ] = [ ]
223+ for ( const material of Object . values ( data ?? { } ) ) {
224+ if ( material . recipe && material . recipe . some ( x => x . name == mat . name ) )
225+ food . push ( createSmallMaterial ( material ) )
226+ }
227+
228+ let specialty : SpecialtyItem | null = null
229+ if ( mat . specialty && chars && data ) {
230+ const char = Object . values ( chars ) . find ( c => c . name == mat . specialty ?. char )
231+ const recipe = Object . values ( data ) . find ( m => m . name == mat . specialty ?. recipe )
232+ if ( char && recipe )
233+ specialty = {
234+ special : createSmallMaterial ( mat ) ,
235+ char : createSmallChar ( char ) ,
236+ recipe : createSmallMaterial ( recipe )
237+ }
238+ } else if ( chars && data ) {
239+ const special = Object . values ( data ) . find ( m => mat . name == m . specialty ?. recipe )
240+ if ( special ) {
241+ const char = Object . values ( chars ) . find ( c => c . name == special . specialty ?. char )
242+
243+ if ( char )
244+ specialty = {
245+ special : createSmallMaterial ( special ) ,
246+ char : createSmallChar ( char ) ,
247+ recipe : createSmallMaterial ( mat )
248+ }
249+ }
250+ }
251+
187252 return {
188253 props : {
189254 mat,
190255 guides,
256+ specialty,
191257 usedBy : {
192258 charAscension,
193259 charTalents,
194- weaponAscension : weaponAscension . sort ( ( a , b ) => ( a . stars && b . stars && b . stars - a . stars ) || ( a . weapon && b . weapon && a . weapon . localeCompare ( b . weapon ) ) || a . name . localeCompare ( b . name ) )
260+ weaponAscension : weaponAscension . sort ( ( a , b ) => ( a . stars && b . stars && b . stars - a . stars ) || ( a . weapon && b . weapon && a . weapon . localeCompare ( b . weapon ) ) || a . name . localeCompare ( b . name ) ) ,
261+ food
195262 }
196263 } ,
197264 revalidate : 60 * 60 * 2
0 commit comments