Skip to content

Commit

Permalink
refactor data to use smaller endpoints and add all remaining api mirrors
Browse files Browse the repository at this point in the history
  • Loading branch information
atomicptr committed Dec 26, 2024
1 parent ba6d3a6 commit 9744883
Show file tree
Hide file tree
Showing 44 changed files with 333 additions and 286 deletions.
19 changes: 9 additions & 10 deletions src/lib/build/validate.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import { BuildFlags, type Build } from "./Build";
import { talentEmpty } from "./talents";
import { armourMaxLevel, weaponMaxLevel } from "$lib/data/static-data";
import type { ArmourType, Data } from "$lib/data/phalanx-types";
import type { ArmourType } from "$lib/data/phalanx-types";
import { phalanxWeapons } from "$lib/data/phalanx-weapons";
import { phalanxArmours } from "$lib/data/phalanx-armours";
import { phalanxPerks } from "$lib/data/phalanx-perks";
import { phalanxLanternCores } from "$lib/data/phalanx-lantern-cores";

export const validate = (build: Build, data: Data): Build => {
export const validate = (build: Build): Build => {
const newBuild = structuredClone(build);

const armours = data.armours;
const lanternCores = data.lantern_cores;
const perks = data.perks;

const levelIsInRange = (level: number, maxLevel: number) => level >= 1 && level <= maxLevel;
const weaponExists = (id: number) => (id === 0 ? true : id in phalanxWeapons);
const armourExists = (id: number) => (id === 0 ? true : id in armours);
const armourIs = (id: number, type: ArmourType) => (id === 0 ? true : armours[id].type === type);
const lanternCoreExists = (id: number) => (id === 0 ? true : id in lanternCores);
const perkExists = (id: number) => (id === 0 ? true : id in perks);
const armourExists = (id: number) => (id === 0 ? true : id in phalanxArmours);
const armourIs = (id: number, type: ArmourType) => (id === 0 ? true : phalanxArmours[id].type === type);
const lanternCoreExists = (id: number) => (id === 0 ? true : id in phalanxLanternCores);
const perkExists = (id: number) => (id === 0 ? true : id in phalanxPerks);
const hasInvalidCell = (cells: number[]) => !cells.some(perkExists);

// weapon 1
Expand Down
7 changes: 4 additions & 3 deletions src/lib/components/ArmourPerks.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<script lang="ts">
import type { BuildArmourPiece } from "$lib/build/Build";
import { armourStatsForLevel, getCellPerks, mergePerks, sortPerkSetByName } from "$lib/data/levels";
import { phalanxData } from "$lib/data/phalanx-data";
import { phalanxArmours } from "$lib/data/phalanx-armours";
import { phalanxPerks } from "$lib/data/phalanx-perks";
import { type Perk } from "$lib/data/phalanx-types";
import { perkIcon } from "$lib/data/static-data";
import { translatableString } from "$lib/utils/translatable-string";
Expand All @@ -14,9 +15,9 @@ interface Props {
}
const { selected }: Props = $props();
const armour = $derived(selected.id !== 0 ? phalanxData.armours[selected.id] : null);
const armour = $derived(selected.id !== 0 ? phalanxArmours[selected.id] : null);
const perks = $derived(armourStatsForLevel(armour, selected.level) ?? {});
const perkSet = $derived(sortPerkSetByName(phalanxData.perks, mergePerks(perks, getCellPerks(selected.cells))));
const perkSet = $derived(sortPerkSetByName(phalanxPerks, mergePerks(perks, getCellPerks(selected.cells))));
</script>

{#if Object.keys(perkSet).length > 0}
Expand Down
5 changes: 2 additions & 3 deletions src/lib/components/ArmourPicker.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<script lang="ts">
import { page } from "$app/stores";
import type { BuildArmourPiece } from "$lib/build/Build";
import { itemIconSize } from "$lib/constants";
import { phalanxData } from "$lib/data/phalanx-data";
import { phalanxArmours } from "$lib/data/phalanx-armours";
import type { ArmourType } from "$lib/data/phalanx-types";
import { t } from "$lib/i18n.svelte";
import { translatableString } from "$lib/utils/translatable-string";
Expand All @@ -20,7 +19,7 @@ interface ArmourPiecePickerProps {
}
const { type, selected, onArmourPieceClick, onCellClick }: ArmourPiecePickerProps = $props();
const armour = $derived(selected.id !== 0 ? phalanxData.armours[selected.id] : null);
const armour = $derived(selected.id !== 0 ? phalanxArmours[selected.id] : null);
const icon = $derived(armour?.icon ?? `/icons/${type}.png`);
const disabled = $derived(onArmourPieceClick === undefined);
</script>
Expand Down
18 changes: 9 additions & 9 deletions src/lib/components/BuildStats.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import type { Build } from "$lib/build/Build";
import { phalanxData } from "$lib/data/phalanx-data";
import { phalanxArmours } from "$lib/data/phalanx-armours";
import type { Element } from "$lib/data/phalanx-types";
import { elementResistanceLevel, oppositeElement, powerLevel, resistanceLevel } from "$lib/data/static-data";
import { t } from "$lib/i18n.svelte";
Expand Down Expand Up @@ -34,17 +34,17 @@ type ElementalResistanceMap = {
const elementalResistances = $derived(
[
build.head.id in phalanxData.armours
? [phalanxData.armours[build.head.id].element, elementResistanceLevel(build.head.level)]
build.head.id in phalanxArmours
? [phalanxArmours[build.head.id].element, elementResistanceLevel(build.head.level)]
: null,
build.torso.id in phalanxData.armours
? [phalanxData.armours[build.torso.id].element, elementResistanceLevel(build.torso.level)]
build.torso.id in phalanxArmours
? [phalanxArmours[build.torso.id].element, elementResistanceLevel(build.torso.level)]
: null,
build.arms.id in phalanxData.armours
? [phalanxData.armours[build.arms.id].element, elementResistanceLevel(build.arms.level)]
build.arms.id in phalanxArmours
? [phalanxArmours[build.arms.id].element, elementResistanceLevel(build.arms.level)]
: null,
build.legs.id in phalanxData.armours
? [phalanxData.armours[build.legs.id].element, elementResistanceLevel(build.legs.level)]
build.legs.id in phalanxArmours
? [phalanxArmours[build.legs.id].element, elementResistanceLevel(build.legs.level)]
: null,
]
.filter((elem) => elem !== null)
Expand Down
16 changes: 7 additions & 9 deletions src/lib/components/BuildTitle.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import { page } from "$app/stores";
import { deserialize, empty } from "$lib/build/Build";
import { phalanxData } from "$lib/data/phalanx-data";
import { phalanxArmours } from "$lib/data/phalanx-armours";
import { phalanxLanternCores } from "$lib/data/phalanx-lantern-cores";
import { phalanxWeapons } from "$lib/data/phalanx-weapons";
import { t } from "$lib/i18n.svelte";
import { translatableString } from "$lib/utils/translatable-string";
Expand Down Expand Up @@ -50,13 +50,11 @@ const iconPath = $derived(
const metaDescription = $derived(
"⚔️ " +
[
build.head.id !== 0 ? translatableString(phalanxData.armours[build.head.id].name) : null,
build.torso.id !== 0 ? translatableString(phalanxData.armours[build.torso.id].name) : null,
build.arms.id !== 0 ? translatableString(phalanxData.armours[build.arms.id].name) : null,
build.legs.id !== 0 ? translatableString(phalanxData.armours[build.legs.id].name) : null,
build.lanternCore.id !== 0
? translatableString(phalanxData.lantern_cores[build.lanternCore.id].name)
: null,
build.head.id !== 0 ? translatableString(phalanxArmours[build.head.id].name) : null,
build.torso.id !== 0 ? translatableString(phalanxArmours[build.torso.id].name) : null,
build.arms.id !== 0 ? translatableString(phalanxArmours[build.arms.id].name) : null,
build.legs.id !== 0 ? translatableString(phalanxArmours[build.legs.id].name) : null,
build.lanternCore.id !== 0 ? translatableString(phalanxLanternCores[build.lanternCore.id].name) : null,
]
.filter((p) => !!p)
.join(", "),
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/CellPicker.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { phalanxData } from "$lib/data/phalanx-data";
import { phalanxPerks } from "$lib/data/phalanx-perks";
import type { ArmourType } from "$lib/data/phalanx-types";
import { perkIcon } from "$lib/data/static-data";
import { translatableString } from "$lib/utils/translatable-string";
Expand All @@ -13,7 +13,7 @@ interface CellPickerProps {
}
const { type, selected, index, onClick }: CellPickerProps = $props();
const perk = $derived(selected !== 0 ? phalanxData.perks[selected] : null);
const perk = $derived(selected !== 0 ? phalanxPerks[selected] : null);
const disabled = $derived(onClick === undefined);
</script>

Expand Down
5 changes: 2 additions & 3 deletions src/lib/components/FinderItemFilter.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<script lang="ts">
import { page } from "$app/stores";
import { armourTypeValues, type Armour, type ArmourType } from "$lib/data/phalanx-types";
import { translatableString } from "$lib/utils/translatable-string";
import { match } from "ts-pattern";
Expand All @@ -12,7 +11,7 @@ import { filterItemCompare } from "$lib/build/filters";
import type { WhitelistedItems } from "$lib/finder/finder.svelte";
import { searchInTranslatableStrings } from "$lib/utils/search";
import { t } from "$lib/i18n.svelte";
import { phalanxData } from "$lib/data/phalanx-data";
import { phalanxArmours } from "$lib/data/phalanx-armours";
interface Props {
heads: number[];
Expand All @@ -29,7 +28,7 @@ const filtersCount = $derived(heads.length + torsos.length + arms.length + legs.
let filtersSearch = $state("");
let filtersOpen = $state(false);
const armours = Object.values<Armour>(phalanxData.armours);
const armours = Object.values<Armour>(phalanxArmours);
const armoursByType = Object.groupBy(armours, (item) => item.type);
const collectionByType = (type: ArmourType) =>
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/LanternCorePicker.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import type { BuildLanternCore } from "$lib/build/Build";
import { itemIconSize } from "$lib/constants";
import { phalanxData } from "$lib/data/phalanx-data";
import { phalanxLanternCores } from "$lib/data/phalanx-lantern-cores";
import { t } from "$lib/i18n.svelte";
import { translatableString } from "$lib/utils/translatable-string";
import LanternCoreStats from "./LanternCoreStats.svelte";
Expand All @@ -13,7 +13,7 @@ interface LanternCorePickerProps {
}
const { selected, onClick }: LanternCorePickerProps = $props();
const lanternCore = $derived(selected.id !== 0 ? phalanxData.lantern_cores[selected.id] : null);
const lanternCore = $derived(selected.id !== 0 ? phalanxLanternCores[selected.id] : null);
const icon = $derived(lanternCore?.icon ?? "/icon.png");
const disabled = $derived(onClick === undefined);
</script>
Expand Down
5 changes: 2 additions & 3 deletions src/lib/components/LanternCoreStats.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<script lang="ts">
import { page } from "$app/stores";
import type { BuildLanternCore } from "$lib/build/Build";
import { phalanxData } from "$lib/data/phalanx-data";
import { phalanxLanternCores } from "$lib/data/phalanx-lantern-cores";
import { t } from "$lib/i18n.svelte";
import { translatableString } from "$lib/utils/translatable-string";
import LazyImage from "./LazyImage.svelte";
Expand All @@ -12,7 +11,7 @@ interface Props {
}
const { selected }: Props = $props();
const lanternCore = $derived(selected.id !== 0 ? phalanxData.lantern_cores[selected.id] : null);
const lanternCore = $derived(selected.id !== 0 ? phalanxLanternCores[selected.id] : null);
</script>

{#if lanternCore?.passive}
Expand Down
38 changes: 20 additions & 18 deletions src/lib/components/MiniBuild.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<script lang="ts">
import { empty, serialize, type Build } from "$lib/build/Build";
import { armourStatsForLevel, getCellPerks, mergePerksArray, sortPerkSetByName } from "$lib/data/levels";
import { phalanxData } from "$lib/data/phalanx-data";
import { phalanxArmours } from "$lib/data/phalanx-armours";
import { phalanxLanternCores } from "$lib/data/phalanx-lantern-cores";
import { phalanxPerks } from "$lib/data/phalanx-perks";
import { phalanxWeapons } from "$lib/data/phalanx-weapons";
import { translatableString } from "$lib/utils/translatable-string";
import LazyImage from "./LazyImage.svelte";
Expand All @@ -19,22 +21,22 @@ const buildId = $derived(serialize(build));
// same as in PerkList
const perkSet = $derived(
sortPerkSetByName(
phalanxData.perks,
phalanxPerks,
mergePerksArray([
phalanxData.armours[build.head.id]
? (armourStatsForLevel(phalanxData.armours[build.head.id], build.head.level) ?? {})
phalanxArmours[build.head.id]
? (armourStatsForLevel(phalanxArmours[build.head.id], build.head.level) ?? {})
: {},
getCellPerks(build.head.cells),
phalanxData.armours[build.torso.id]
? (armourStatsForLevel(phalanxData.armours[build.torso.id], build.torso.level) ?? {})
phalanxArmours[build.torso.id]
? (armourStatsForLevel(phalanxArmours[build.torso.id], build.torso.level) ?? {})
: {},
getCellPerks(build.torso.cells),
phalanxData.armours[build.arms.id]
? (armourStatsForLevel(phalanxData.armours[build.arms.id], build.arms.level) ?? {})
phalanxArmours[build.arms.id]
? (armourStatsForLevel(phalanxArmours[build.arms.id], build.arms.level) ?? {})
: {},
getCellPerks(build.arms.cells),
phalanxData.armours[build.legs.id]
? (armourStatsForLevel(phalanxData.armours[build.legs.id], build.legs.level) ?? {})
phalanxArmours[build.legs.id]
? (armourStatsForLevel(phalanxArmours[build.legs.id], build.legs.level) ?? {})
: {},
getCellPerks(build.legs.cells),
]),
Expand Down Expand Up @@ -64,29 +66,29 @@ const imgClasses = "w-12 h-12";
<LazyImage class={imgClasses} src={phalanxWeapons[build.weapon2.id]?.icon ?? `/icons/${phalanxWeapons[build.weapon2.id].type}.png`} alt={translatableString(phalanxWeapons[build.weapon2.id].name)} />
{/if}
{#if build.head.id !== 0}
<LazyImage class={imgClasses} src={phalanxData.armours[build.head.id]?.icon ?? `/icons/${phalanxData.armours[build.head.id].type}.png`} alt={translatableString(phalanxData.armours[build.head.id].name)} />
<LazyImage class={imgClasses} src={phalanxArmours[build.head.id]?.icon ?? `/icons/${phalanxArmours[build.head.id].type}.png`} alt={translatableString(phalanxArmours[build.head.id].name)} />
{/if}
{#if build.torso.id !== 0}
<LazyImage class={imgClasses} src={phalanxData.armours[build.torso.id]?.icon ?? `/icons/${phalanxData.armours[build.torso.id].type}.png`} alt={translatableString(phalanxData.armours[build.torso.id].name)} />
<LazyImage class={imgClasses} src={phalanxArmours[build.torso.id]?.icon ?? `/icons/${phalanxArmours[build.torso.id].type}.png`} alt={translatableString(phalanxArmours[build.torso.id].name)} />
{/if}
{#if build.arms.id !== 0}
<LazyImage class={imgClasses} src={phalanxData.armours[build.arms.id]?.icon ?? `/icons/${phalanxData.armours[build.arms.id].type}.png`} alt={translatableString(phalanxData.armours[build.arms.id].name)} />
<LazyImage class={imgClasses} src={phalanxArmours[build.arms.id]?.icon ?? `/icons/${phalanxArmours[build.arms.id].type}.png`} alt={translatableString(phalanxArmours[build.arms.id].name)} />
{/if}
{#if build.legs.id !== 0}
<LazyImage class={imgClasses} src={phalanxData.armours[build.legs.id]?.icon ?? `/icons/${phalanxData.armours[build.legs.id].type}.png`} alt={translatableString(phalanxData.armours[build.legs.id].name)} />
<LazyImage class={imgClasses} src={phalanxArmours[build.legs.id]?.icon ?? `/icons/${phalanxArmours[build.legs.id].type}.png`} alt={translatableString(phalanxArmours[build.legs.id].name)} />
{/if}
{#if build.lanternCore.id !== 0}
<LazyImage class={imgClasses} src={phalanxData.lantern_cores[build.lanternCore.id].icon ?? `/icons/lantern.png`} alt={translatableString(phalanxData.lantern_cores[build.lanternCore.id].name)} />
<LazyImage class={imgClasses} src={phalanxLanternCores[build.lanternCore.id].icon ?? `/icons/lantern.png`} alt={translatableString(phalanxLanternCores[build.lanternCore.id].name)} />
{/if}
</div>
<div class="flex flex-row flex-wrap gap-2 justify-center">
{#each Object.entries(perkSet) as [perkId, amount]}
<div
class="badge"
class:badge-primary={amount >= phalanxData.perks[perkId].threshold}
class:badge-primary={amount >= phalanxPerks[perkId].threshold}
>
{translatableString(phalanxData.perks[perkId].name)}
{amount}/{phalanxData.perks[perkId].threshold}
{translatableString(phalanxPerks[perkId].name)}
{amount}/{phalanxPerks[perkId].threshold}
</div>
{/each}
</div>
Expand Down
5 changes: 2 additions & 3 deletions src/lib/components/PerkItem.svelte
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<script lang="ts">
import { page } from "$app/stores";
import { type Perk } from "$lib/data/phalanx-types";
import { translatableString } from "$lib/utils/translatable-string";
import type { Snippet } from "svelte";
import PerkTooltip from "./PerkTooltip.svelte";
import { phalanxData } from "$lib/data/phalanx-data";
import { phalanxPerks } from "$lib/data/phalanx-perks";
interface Props {
perkId: string;
Expand All @@ -21,5 +20,5 @@ const { perkId, amount, item }: Props = $props();
{/snippet}

<PerkTooltip {perkId}>
{@render (item ?? genericItem)(phalanxData.perks[perkId], amount)}
{@render (item ?? genericItem)(phalanxPerks[perkId], amount)}
</PerkTooltip>
22 changes: 11 additions & 11 deletions src/lib/components/PerkList.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script lang="ts">
import { page } from "$app/stores";
import type { Build } from "$lib/build/Build";
import { armourStatsForLevel, getCellPerks, mergePerksArray, sortPerkSetByName } from "$lib/data/levels";
import { phalanxData } from "$lib/data/phalanx-data";
import { phalanxArmours } from "$lib/data/phalanx-armours";
import { phalanxPerks } from "$lib/data/phalanx-perks";
import { type Perk } from "$lib/data/phalanx-types";
import { perkIcon } from "$lib/data/static-data";
import { t } from "$lib/i18n.svelte";
Expand All @@ -20,22 +20,22 @@ const { build }: PerkListProps = $props();
const perkSet = $derived(
sortPerkSetByName(
phalanxData.perks,
phalanxPerks,
mergePerksArray([
phalanxData.armours[build.head.id]
? (armourStatsForLevel(phalanxData.armours[build.head.id], build.head.level) ?? {})
phalanxArmours[build.head.id]
? (armourStatsForLevel(phalanxArmours[build.head.id], build.head.level) ?? {})
: {},
getCellPerks(build.head.cells),
phalanxData.armours[build.torso.id]
? (armourStatsForLevel(phalanxData.armours[build.torso.id], build.torso.level) ?? {})
phalanxArmours[build.torso.id]
? (armourStatsForLevel(phalanxArmours[build.torso.id], build.torso.level) ?? {})
: {},
getCellPerks(build.torso.cells),
phalanxData.armours[build.arms.id]
? (armourStatsForLevel(phalanxData.armours[build.arms.id], build.arms.level) ?? {})
phalanxArmours[build.arms.id]
? (armourStatsForLevel(phalanxArmours[build.arms.id], build.arms.level) ?? {})
: {},
getCellPerks(build.arms.cells),
phalanxData.armours[build.legs.id]
? (armourStatsForLevel(phalanxData.armours[build.legs.id], build.legs.level) ?? {})
phalanxArmours[build.legs.id]
? (armourStatsForLevel(phalanxArmours[build.legs.id], build.legs.level) ?? {})
: {},
getCellPerks(build.legs.cells),
]),
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/PerkSelect.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { phalanxData } from "$lib/data/phalanx-data";
import { phalanxPerks } from "$lib/data/phalanx-perks";
import type { Perk } from "$lib/data/phalanx-types";
import { perkIcon } from "$lib/data/static-data";
import { t } from "$lib/i18n.svelte";
Expand All @@ -20,7 +20,7 @@ interface Props {
let search = $state("");
const { perks, disabledPerks, onSelect, onClear }: Props = $props();
const perkGroups = Object.groupBy(Object.values(phalanxData.perks) as Perk[], (perk) => perk.type);
const perkGroups = Object.groupBy(Object.values(phalanxPerks) as Perk[], (perk) => perk.type);
const getPerksByCategoryName = (category: string) => perkGroups[category as keyof typeof perkGroups] as Perk[];
Expand Down
Loading

0 comments on commit 9744883

Please sign in to comment.