Skip to content

Commit db17118

Browse files
committed
Update material page
1 parent 8222726 commit db17118

File tree

4 files changed

+63
-52
lines changed

4 files changed

+63
-52
lines changed

pages/api/sitemap.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ export default async function api(req: NextApiRequest, res: NextApiResponse) {
3131
for (const material of Object.values((await getMaterials()) ?? {}))
3232
urls.push(`${config.appUri}/materials/${urlify(material.name, false)}`)
3333

34-
urls.push(`${config.appUri}/materials`)
35-
for (const material of Object.values((await getMaterials()) ?? {}))
36-
urls.push(`${config.appUri}/materials/${urlify(material.name, false)}`)
37-
3834
urls.push(`${config.appUri}/weapons`)
3935
for (const weapon of Object.values((await getWeapons()) ?? {}))
4036
urls.push(`${config.appUri}/weapons/${urlify(weapon.name, false)}`)

pages/characters/[char].tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { FullAscensionCosts } from "../../components/Tables"
1313
import YouTube from "../../components/YouTube"
1414
import { CharacterCurves, CostTemplates, getCharacterCurves, getCharacters, getCostTemplates } from "../../utils/data-cache"
1515
import { Character, CharacterFull, Constellation, CostTemplate, CurveEnum, Meta, Passive, Skill, Skills, TalentTable, TalentValue } from "../../utils/types"
16-
import { clean, elements, ElementType, getCharStatsAt, getCostsFromTemplate, getGuidesFor, getIconPath, getLinkToGuide, getStarColor, image, isFullCharacter, isValueTable, joinMulti, stat, urlify, weapons } from "../../utils/utils"
16+
import { elements, ElementType, getCharStatsAt, getCostsFromTemplate, getGuidesFor, getIconPath, getLinkToGuide, getStarColor, isFullCharacter, isValueTable, joinMulti, stat, urlify, weapons } from "../../utils/utils"
1717
import styles from "../style.module.css"
1818

1919
interface Props {

pages/materials/[material].tsx

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Icon, { SmallIcon } from "../../components/Icon"
88
import Main from "../../components/Main"
99
import { CostTemplates, getCharacters, getCostTemplates, getMaterials, getWeapons } from "../../utils/data-cache"
1010
import { Cost, CostTemplate, Material, SmallChar, SmallWeapon } from "../../utils/types"
11-
import { clean, createSmallChar, createSmallWeapon, getCostsFromTemplate, getGuidesFor, getIconPath, getLinkToGuide, getStarColor, joinMulti, urlify } from "../../utils/utils"
11+
import { clean, createSmallChar, createSmallWeapon, getCostsFromTemplate, getGuidesFor, getIconPath, getLinkToGuide, getStarColor, isInCosts, joinMulti, urlify } from "../../utils/utils"
1212

1313
interface Props {
1414
mat: Material,
@@ -24,15 +24,23 @@ export default function MaterialWebpage({ mat, location, guides, usedBy }: Props
2424
const color = getStarColor(mat.stars ?? 1)
2525
const usedByDesc = []
2626

27-
if (usedBy.charTalents.length > 0 && usedBy.charAscension.length > 0)
28-
usedByDesc.push(`Used by ${joinMulti([...usedBy.charTalents, ...usedBy.charAscension].map(x => x.name).filter((v, i, a) => a.indexOf(v) == i))} character talents/ascensions.`)
29-
else if (usedBy.charTalents.length > 0)
30-
usedByDesc.push(`Used by ${joinMulti(usedBy.charTalents.map(x => x.name))} character talents.`)
31-
else if (usedBy.charAscension.length > 0)
32-
usedByDesc.push(`Used by ${joinMulti(usedBy.charAscension.map(x => x.name))} character ascensions.`)
27+
const { charTalents, charAscension, weaponAscension } = usedBy
3328

34-
if (usedBy.weaponAscension.length > 0)
35-
usedByDesc.push(`Used by ${joinMulti(usedBy.weaponAscension.map(x => x.name))} weapon ascensions.`)
29+
const overlap = charTalents.filter(x => charAscension.some(y => x.name == y.name))
30+
const uniqueTalents = charTalents.filter(x => !charAscension.some(y => x.name == y.name))
31+
const uniqueAscension = charAscension.filter(x => !charTalents.some(y => x.name == y.name))
32+
33+
if (overlap.length > 0)
34+
usedByDesc.push(`Used by ${joinMulti(overlap.map(x => x.name).filter((v, i, a) => a.indexOf(v) == i))} character talents and ascensions.`)
35+
36+
if (uniqueTalents.length > 0)
37+
usedByDesc.push(`Used by ${joinMulti(uniqueTalents.map(x => x.name))} character talents.`)
38+
39+
if (uniqueAscension.length > 0)
40+
usedByDesc.push(`Used by ${joinMulti(uniqueAscension.map(x => x.name))} character ascensions.`)
41+
42+
if (weaponAscension.length > 0)
43+
usedByDesc.push(`Used by ${joinMulti(weaponAscension.map(x => x.name))} weapon ascensions.`)
3644

3745
const desc = `${mat.name} is a ${mat.stars ? `${mat.stars} star ` : ""}${mat.type}. \n${usedByDesc.join("\n")}\n${mat.desc ? clean(mat.desc ?? "") : ""}`.trim()
3846
return (
@@ -93,24 +101,31 @@ export default function MaterialWebpage({ mat, location, guides, usedBy }: Props
93101
{mat.sources.map(s => <div key={s}>{s}</div>)}
94102
</>}
95103

96-
{usedBy.charTalents.length > 0 && <>
104+
{overlap.length > 0 && <>
105+
<h3 className="text-lg font-bold pt-1" id="chartalents">Used by character ascensions and talents:</h3>
106+
<div className="flex flex-wrap justify-start text-center mt-2">
107+
{overlap.map(c => <SmallIcon key={c.name} thing={c} location={location} />)}
108+
</div>
109+
</>}
110+
111+
{uniqueTalents.length > 0 && <>
97112
<h3 className="text-lg font-bold pt-1" id="chartalents">Used by character talents:</h3>
98113
<div className="flex flex-wrap justify-start text-center mt-2">
99-
{usedBy.charTalents.map(c => <SmallIcon key={c.name} thing={c} location={location} />)}
114+
{uniqueTalents.map(c => <SmallIcon key={c.name} thing={c} location={location} />)}
100115
</div>
101116
</>}
102117

103-
{usedBy.charAscension.length > 0 && <>
118+
{uniqueAscension.length > 0 && <>
104119
<h3 className="text-lg font-bold pt-1" id="charascension">Used by character ascensions:</h3>
105120
<div className="flex flex-wrap justify-start text-center mt-2">
106-
{usedBy.charAscension.map(c => <SmallIcon key={c.name} thing={c} location={location} />)}
121+
{uniqueAscension.map(c => <SmallIcon key={c.name} thing={c} location={location} />)}
107122
</div>
108123
</>}
109124

110-
{usedBy.weaponAscension.length > 0 && <>
125+
{weaponAscension.length > 0 && <>
111126
<h3 className="text-lg font-bold pt-1" id="weaponascension">Used by weapon ascensions:</h3>
112127
<div className="flex flex-wrap justify-start text-center mt-2">
113-
{usedBy.weaponAscension.map(c => <SmallIcon key={c.name} thing={c} location={location} />)}
128+
{weaponAscension.map(c => <SmallIcon key={c.name} thing={c} location={location} />)}
114129
</div>
115130
</>}
116131

@@ -125,17 +140,6 @@ export default function MaterialWebpage({ mat, location, guides, usedBy }: Props
125140
)
126141
}
127142

128-
129-
function isInCosts(template: CostTemplate | Cost[], costTemplates: CostTemplates, name: string): boolean {
130-
const costs = Array.isArray(template) ? template : getCostsFromTemplate(template, costTemplates)
131-
132-
for (const c of costs)
133-
if (c.items.some(i => i.name == name))
134-
return true
135-
136-
return false
137-
}
138-
139143
export async function getStaticProps(context: GetStaticPropsContext): Promise<GetStaticPropsResult<Props>> {
140144
const matName = context.params?.material
141145
const data = await getMaterials()

utils/utils.ts

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Catalyst from "../public/img/weapon_types/Catalyst.png"
1010
import Claymore from "../public/img/weapon_types/Claymore.png"
1111
import Polearm from "../public/img/weapon_types/Polearm.png"
1212
import Sword from "../public/img/weapon_types/Sword.png"
13-
import { getGuides } from "./data-cache"
13+
import { CostTemplates, getGuides } from "./data-cache"
1414
import { Artifact, Character, CharacterFull, Cost, CostTemplate, CurveEnum, Enemy, Guide, GuidePage, SmallArtifact, SmallChar, SmallEnemy, SmallWeapon, TalentTable, TalentValue, Weapon, WeaponCurveName, WeaponType } from "./types"
1515

1616
export const elements = {
@@ -105,7 +105,18 @@ export function stat(name: string, value: number): string {
105105
}
106106
}
107107

108-
export function image(type: string, name: string, ext="png"): string {
108+
export function isInCosts(template: CostTemplate | Cost[], costTemplates: CostTemplates, name: string): boolean {
109+
const costs = Array.isArray(template) ? template : getCostsFromTemplate(template, costTemplates)
110+
111+
for (const c of costs)
112+
if (c.items.some(i => i.name == name))
113+
return true
114+
115+
return false
116+
}
117+
118+
119+
export function image(type: string, name: string, ext = "png"): string {
109120
return `/img/${type}/${name.replace(/[:\-,'"]/g, "").replace(/ +/g, "_")}.${ext}`
110121
}
111122

@@ -120,18 +131,18 @@ export function getCostsFromTemplate(costTemplate: CostTemplate, costTemplates:
120131
mora: c.mora,
121132
items: c.items.map(i => ({
122133
count: i.count,
123-
name: i.name.replace(/<(.*?)>/g, (_, x) => costTemplate.mapping[x])
134+
name: i.name.replace(/<(.*?)>/g, (_, x) => costTemplate.mapping[x])
124135
}))
125136
}))
126137
}
127138

128139
export async function getGuidesFor(type: "enemy" | "character" | "material" | "weapon" | "artifact", name: string): Promise<{ guide: Guide, page: GuidePage }[]> {
129140
return (await getGuides())?.flatMap(guide => guide.pages
130-
.filter(page => page.links?.[type]?.includes(name))
131-
.map(page => ({
132-
guide, page
133-
}))
134-
) ?? []
141+
.filter(page => page.links?.[type]?.includes(name))
142+
.map(page => ({
143+
guide, page
144+
}))
145+
) ?? []
135146
}
136147

137148
export function isValueTable(talent: TalentTable | TalentValue): talent is TalentTable {
@@ -201,7 +212,7 @@ export function createSmallEnemy(enemy: Enemy): SmallEnemy {
201212
export function joinMulti(input: string[]): string {
202213
if (input.length <= 1) return input[0]
203214

204-
const last = input[input.length-1]
215+
const last = input[input.length - 1]
205216
return `${input.slice(0, -1).join(", ")} and ${last}`
206217
}
207218

@@ -210,7 +221,7 @@ export async function send(api: string, object: unknown) {
210221
body: JSON.stringify(object),
211222
headers: { "Content-Type": "application/json" },
212223
method: "POST"
213-
})
224+
})
214225
}
215226

216227
const minutes_per_resin = 8
@@ -220,13 +231,13 @@ export function parseDuration(time: string): number {
220231

221232
for (const time of times) {
222233
const name = time[3].toLowerCase(), amount = parseInt(time[2])
223-
if (name.startsWith("mo")) duration += amount * 30 * 24 * 60 * 60 * 1000
224-
else if (name.startsWith("w")) duration += amount * 7 * 24 * 60 * 60 * 1000
225-
else if (name.startsWith("d")) duration += amount * 24 * 60 * 60 * 1000
226-
else if (name.startsWith("h")) duration += amount * 60 * 60 * 1000
227-
else if (name.startsWith("m")) duration += amount * 60 * 1000
228-
else if (name.startsWith("s")) duration += amount * 1000
229-
else if (name.startsWith("r")) duration += amount * minutes_per_resin * 60 * 1000
234+
if (name.startsWith("mo")) duration += amount * 30 * 24 * 60 * 60 * 1000
235+
else if (name.startsWith("w")) duration += amount * 7 * 24 * 60 * 60 * 1000
236+
else if (name.startsWith("d")) duration += amount * 24 * 60 * 60 * 1000
237+
else if (name.startsWith("h")) duration += amount * 60 * 60 * 1000
238+
else if (name.startsWith("m")) duration += amount * 60 * 1000
239+
else if (name.startsWith("s")) duration += amount * 1000
240+
else if (name.startsWith("r")) duration += amount * minutes_per_resin * 60 * 1000
230241
}
231242

232243
return duration
@@ -239,25 +250,25 @@ export function timeLeft(diff: number, full = false, short = true): string {
239250
const result = [], originalTime = diff / 1000
240251

241252
diff /= 1000 // convert to s
242-
if (diff >= 24*60*60) {
253+
if (diff >= 24 * 60 * 60) {
243254
const days = Math.floor(diff / 24 / 60 / 60)
244255
result.push(days + (short ? "d" : (days == 1 ? " day" : " days")))
245256
diff -= days * 24 * 60 * 60
246257
}
247258

248-
if (diff >= 60*60) {
259+
if (diff >= 60 * 60) {
249260
const hours = Math.floor(diff / 60 / 60)
250261
result.push(hours + (short ? "h" : (hours == 1 ? " hour" : " hours")))
251262
diff -= hours * 60 * 60
252263
}
253264

254-
if (diff >= 60 && (originalTime < 24*60*60 || full)) {
265+
if (diff >= 60 && (originalTime < 24 * 60 * 60 || full)) {
255266
const minutes = Math.floor(diff / 60)
256267
result.push(minutes + (short ? "m" : (minutes == 1 ? " minute" : " minutes")))
257268
diff -= minutes * 60
258269
}
259270

260-
if (diff > 0 && (originalTime < 60*60 || full)) {
271+
if (diff > 0 && (originalTime < 60 * 60 || full)) {
261272
const seconds = Math.floor(diff)
262273
result.push(seconds + (short ? "s" : (seconds == 1 ? " second" : " seconds")))
263274
}

0 commit comments

Comments
 (0)