Skip to content

Commit

Permalink
Added level details to enemies
Browse files Browse the repository at this point in the history
  • Loading branch information
ofcoursenopewastaken committed Jul 27, 2024
1 parent c3e3ddd commit faa53d4
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 26 deletions.
66 changes: 55 additions & 11 deletions src/lib/logic/enemies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ import type { GHTrees } from "$lib/types"
type RawEnemyInHandbookTable = {
enemyId: string
enemyIndex: string
description: string
sortId: number
abilityList: { text: string; textFormat: string }[]
}

type RawEnemyHandbook = {
type RawHandbookTable = {
enemyData: { [enemyId: string]: RawEnemyInHandbookTable }
raceData: {
[id: string]: {
Expand All @@ -28,33 +29,53 @@ type RawEnemyHandbook = {
}
}

type EnemyDatabaseValue<T> = {
type RawDatabaseValue<T> = {
m_defined: boolean
m_value: T
}

type RawEnemyDatabase = {
type RawAttributes = {
[key: string]: RawDatabaseValue<unknown>
}

type RawDatabaseTable = {
enemies: {
Key: string
Value: {
level: number
enemyData: {
name: EnemyDatabaseValue<string>
description: EnemyDatabaseValue<string | undefined>
enemyTags: EnemyDatabaseValue<string[] | undefined>
name: RawDatabaseValue<string>
description: RawDatabaseValue<string | undefined>

lifePointReduce: RawDatabaseValue<number>

enemyTags: RawDatabaseValue<string[] | undefined>
attributes: RawAttributes
}
}[]
}[]
}

type ParsedAttributes = {
[key: string]: unknown
lifePointReduce: number | undefined
}

type ParsedEnemyLevels = { attributes: ParsedAttributes }[]

type ParsedEnemy = {
enemyId: string

name: string
description: string
tooltip: string

enemyTypes: string[]
code: string
sortId: number

abilities: { text: string; textFormat: string }[]
levels: ParsedEnemyLevels
}

type EnemiesTable = {
Expand All @@ -74,15 +95,15 @@ for (const region of SERVERS) {
`${GAMEDATA_PATH}/${langCode}/gamedata/excel/enemy_handbook_table.json`,
)
).toString(),
) as RawEnemyHandbook
) as RawHandbookTable

const rawTable = JSON.parse(
(
await fs.readFile(
`${GAMEDATA_PATH}/${langCode}/gamedata/levels/enemydata/enemy_database.json`,
)
).toString(),
) as RawEnemyDatabase
) as RawDatabaseTable

RaceData[region] = rawHandbook.raceData

Expand All @@ -101,16 +122,39 @@ for (const region of SERVERS) {
abilityList: [],
}

const levels: ParsedEnemyLevels = []

for (const rawLevel of rawEnemyData.Value) {
const attributes: ParsedAttributes = {
lifePointReduce: rawLevel.enemyData.lifePointReduce.m_defined
? rawLevel.enemyData.lifePointReduce.m_value
: undefined,
}

for (const [attrKey, attrVal] of Object.entries(rawLevel.enemyData.attributes)) {
if (attrVal.m_defined) {
attributes[attrKey] = attrVal.m_value
}
}

levels.push({
attributes: attributes,
})
}

Data[region][rawEnemyData.Key] = {
enemyId: rawEnemyData.Key,

name: rawEnemyData.Value[0].enemyData.name.m_value,
description: rawEnemyData.Value[0].enemyData.description.m_value || "",
enemyTypes: rawEnemyData.Value[0].enemyData.enemyTags.m_value || [],
description: rawHandbookEnemy.description || "",
tooltip: rawEnemyData.Value[0].enemyData.description.m_value || "",

enemyTypes: rawEnemyData.Value[0].enemyData.enemyTags.m_value || [],
code: rawHandbookEnemy.enemyIndex,
sortId: rawHandbookEnemy.sortId,

abilities: rawHandbookEnemy.abilityList,
levels: levels,
}
}
}
Expand All @@ -131,7 +175,7 @@ const rawTable = JSON.parse(
(
await fs.readFile(`${GAMEDATA_PATH}/zh_CN/gamedata/levels/enemydata/enemy_database.json`)
).toString(),
) as RawEnemyDatabase
) as RawDatabaseTable

export const AvailableIcons = Object.values(rawTable.enemies)
.filter((v) => {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/[region]/depot/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</svelte:head>

<main
class="max-w-2xl m-auto pt-6 pb-6 grid grid-cols-3 md:grid-cols-4 lg:grid-cols-6 xl:grid-cols-7"
class="max-w-2xl m-auto p-3 grid grid-cols-4 md:grid-cols-5 lg:grid-cols-6 xl:grid-cols-7"
>
{#each itemTable as [itemId, item] (itemId)}
{@const url = data.availableIcons.includes(item.iconId)
Expand Down
10 changes: 6 additions & 4 deletions src/routes/[region]/depot/[itemId]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
<title>{data.name}</title>
</svelte:head>

<div class="max-w-xl min-h-dvh m-auto pt-6 pb-6 flex place-items-center">
<main class="w-full h-fit flex flex-row place-items-center">
<div class="w-[30%] h-fit pr-4">
<div class="max-w-3xl min-h-dvh m-auto p-3 flex place-items-center">
<main
class="w-full h-fit flex flex-col gap-3 sm:flex-row place-items-center"
>
<div class="sm:w-[30%] h-fit pr-4">
<ItemIcon url={data.iconUrl} name={data.name} />
</div>

<div class="w-[70%] h-fit">
<div class="sm:w-[70%] h-fit">
<p class="text-2xl font-bold">
{data.name}
</p>
Expand Down
2 changes: 1 addition & 1 deletion src/routes/[region]/enemies/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</svelte:head>

<main
class="max-w-3xl m-auto pt-6 pb-6 grid grid-cols-3 md:grid-cols-4 lg:grid-cols-6 xl:grid-cols-7"
class="max-w-3xl m-auto p-3 grid grid-cols-4 md:grid-cols-5 lg:grid-cols-6 xl:grid-cols-7"
>
{#each displayedEnemies as enemy (enemy.enemyId)}
{@const url = data.availableIcons.includes(enemy.enemyId)
Expand Down
8 changes: 6 additions & 2 deletions src/routes/[region]/enemies/[enemyId]/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ export async function load({ params }) {
return {
name: enemyData.name,
description: enemyData.description,
iconUrl: iconUrl,
tooltip: enemyData.tooltip,

abilities: enemyData.abilities,
types: enemyData.enemyTypes,
levels: enemyData.levels,

iconUrl: iconUrl,
types: types,
}
}

Expand Down
39 changes: 32 additions & 7 deletions src/routes/[region]/enemies/[enemyId]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,42 @@
</svelte:head>

{#snippet richtext(text)}
<Richtext {text} data={props.richtextTable} />
<Richtext {text} data={props.richtextTable} />
{/snippet}

<main class="max-w-3xl m-auto p-3">
<!-- Display only on sm and DOWN -->
<div class="block sm:hidden max-w-sm m-auto mb-4">
<ItemIcon url={props.iconUrl} name={props.name} />
</div>

<div class="flex mb-4">
<!-- Display only on sm and UP -->
<div class="mr-2 hidden sm:block max-w-[30%]">
<ItemIcon url={props.iconUrl} name={props.name} />
</div>

<div>
<p class="font-bold text-2xl">{props.name}</p>
<p class="font-bold text-lg text-slate-400">
{props.types.join(" ")}
</p>
</div>
</div>

<div class="bg-black/40 p-2 mb-4">
{@render richtext(props.description)}
</div>
{@render richtext(props.description)}

<div class="italic mt-3">
{@render richtext(props.tooltip)}
</div>
</div>

<div class="bg-black/40 p-2">
{#each props.abilities as ability, idx}
<!-- have top padding only for the titles -->
{@const shouldPush = idx !== 0 && ability.textFormat === "TITLE"}

{#if ability.textFormat === "TITLE"}
<p
class="font-bold text-lg text-red-500 {shouldPush
Expand All @@ -57,4 +61,25 @@
{/if}
{/each}
</div>

<!-- this is horrible -->
{#each props.levels as level, idx}
<div class="mt-4">
<details class="group border border-gray-400 bg-black/40">
<summary class="p-2 group-open:border-b border-gray-400">{`Level ${idx}`}</summary>
<div class="p-2">
<table class="border w-full">
<tbody>
{#each Object.entries(level.attributes) as [attrKey, attrVal]}
<tr class="border">
<th class="border p-1 font-normal">{attrKey}</th>
<th class="border p-1 font-normal">{attrVal}</th>
</tr>
{/each}
</tbody>
</table>
</div>
</details>
</div>
{/each}
</main>

0 comments on commit faa53d4

Please sign in to comment.