Skip to content

Commit

Permalink
charm splits fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverGrack committed Feb 20, 2024
1 parent 984296b commit 9458d59
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 37 deletions.
15 changes: 11 additions & 4 deletions src/app/run/[id]/_run_splits.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import { Checkbox } from '@/components/ui/checkbox';
import { Table, TableBody, TableCell, TableRow } from '@/components/ui/table';
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';
import { cn } from '@/lib/utils';
import Image from 'next/image';
import { forwardRef, memo, useCallback, useEffect, useId, useMemo, useRef, type ReactNode } from 'react';
import { assertNever } from '~/lib/utils/utils';
import {
RecordingSplitGroups,
recordingSplitGroups,
type RecordingSplit,
type RecordingSplitGroup,
} from '~/lib/viz/recording-files/recording-splits';
Expand All @@ -28,7 +27,15 @@ const RunSplitRow = memo(
) {
let icon: ReactNode | undefined = undefined;
if (split.imageUrl) {
icon = <Image src={split.imageUrl} className="mr-2 h-6 w-6" width={84} height={96} alt="" />;
// icon = <Image src={split.imageUrl} className="mr-2 h-6 w-6" width={84} height={96} alt="" />;
icon = (
<div
className="mr-2 h-7 w-7 bg-contain bg-center bg-no-repeat"
style={{
backgroundImage: `url(${split.imageUrl})`,
}}
/>
);
}

function handleClick() {
Expand Down Expand Up @@ -124,7 +131,7 @@ export function RunSplits({ useViewOptionsStore }: Props) {
<>
<div>
<div className="flex flex-wrap gap-2 p-4">
{RecordingSplitGroups.map((group) => {
{recordingSplitGroups.map((group) => {
const checked = visibleSplitGroups.includes(group.name);
return (
<div className="flex flex-row gap-2" key={group.name}>
Expand Down
7 changes: 2 additions & 5 deletions src/app/run/[id]/_viewOptionsStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ import { create } from 'zustand';
import { combine } from 'zustand/middleware';
import { playerDataFields } from '~/lib/viz/player-data/player-data';
import { type CombinedRecording } from '~/lib/viz/recording-files/recording';
import {
RecordingSplitGroup,
RecordingSplitGroups as recordingSplitGroups,
} from '~/lib/viz/recording-files/recording-splits';
import { RecordingSplitGroup, recordingSplitGroups } from '~/lib/viz/recording-files/recording-splits';
import { type AggregatedRunData, type AggregationVariable } from '~/lib/viz/recording-files/run-aggregation-store';

export type RoomVisibility = 'all' | 'visited' | 'visited-animated';
Expand Down Expand Up @@ -42,7 +39,7 @@ function createViewOptionsStore() {
extraChartsFollowAnimation: true,
mainCardTab: 'overview' as MainCardTab,

visibleSplitGroups: recordingSplitGroups.map((it) => it.name),
visibleSplitGroups: recordingSplitGroups.filter((it) => it.defaultShown).map((it) => it.name),
},
(set, get) => {
function handleAnyAnimationVisiblityChanged() {
Expand Down
3 changes: 2 additions & 1 deletion src/lib/viz/charms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ type GetCharmId<T> = T extends `gotCharm_${infer N}` ? N : never;
type CharmPlayerDataId = GetCharmId<keyof FrameEndEvent>;

function defaultHasCharm(charmId: CharmPlayerDataId): (frameEndEvent: FrameEndEvent) => boolean {
return (frameEndEvent) => frameEndEvent[`gotCharm_${charmId}`] === true;
const key = `gotCharm_${charmId}` as const;
return (frameEndEvent) => !!frameEndEvent[key];
}

function defaultSpriteName(charmId: CharmPlayerDataId): string {
Expand Down
4 changes: 3 additions & 1 deletion src/lib/viz/player-data/enemies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const playerDataNameToDefeatedName: Record<
lurien: { dreamer: 'Lurien', achievementSprite: 'Achievement_icon__0000_watcher' },
hegemol: { dreamer: 'Herrah', achievementSprite: 'Achievement_icon__0002_beast' },
monomon: { dreamer: 'Monomon', achievementSprite: 'Achievement_icon__0001_teacher' },
zote: { enemy: 'Zote' },
zote: undefined, // covered below { enemy: 'Zote' },
falseKnight: undefined,
falseKnightDream: undefined,
mawlek: undefined,
Expand Down Expand Up @@ -85,6 +85,8 @@ const isBossOverrides: Partial<Record<EnemyName, boolean>> = {
Worm: false, // Goam
BigCentipede: false, // Garpede
AbyssTendril: false, // Void Tendrils
LazyFlyer: false, // Aluba
BindingSeal: false,
};

export function isEnemyBoss(enemy: EnemyInfo): boolean {
Expand Down
36 changes: 10 additions & 26 deletions src/lib/viz/recording-files/recording-splits.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
import { assertNever } from '~/lib/utils/utils';
import { charms, virtualCharms } from '../charms';
import { virtualCharms } from '../charms';
import { enemiesJournalLang } from '../generated/lang-enemies-journal.generated';
import { enemies, isEnemyBoss, playerDataNameToDefeatedName, type EnemyInfo } from '../player-data/enemies';
import {
getCharmIdFromGotCharmField,
getEnemyNameFromDefeatedField,
getEnemyNameFromKilledField,
isPlayerDataDefeatedField,
isPlayerDataGotCharmField,
isPlayerDataKilledField,
playerDataFields,
} from '../player-data/player-data';
import { type CombinedRecording } from './recording';

export const RecordingSplitGroups = [
export const recordingSplitGroups = [
{
name: 'boss',
displayName: 'Bosses',
defaultShown: true,
},
{
name: 'dreamer',
displayName: 'Dreamers',
defaultShown: true,
},
{
name: 'charmCollection',
displayName: 'Charm pick ups',
defaultShown: false,
},
] as const;

export type RecordingSplitGroup = (typeof RecordingSplitGroups)[number]['name'];
export type RecordingSplitGroup = (typeof recordingSplitGroups)[number]['name'];

export interface RecordingSplit {
msIntoGame: number;
Expand Down Expand Up @@ -131,37 +132,20 @@ export function createRecordingSplits(recording: CombinedRecording): RecordingSp
}
});
}
} else if (isPlayerDataGotCharmField(field)) {
const charmId = getCharmIdFromGotCharmField(field);
const charm = charms.byId[charmId];
const charmName = charm?.name ?? `Charm ${charmId}`;

recording.allPlayerDataEventsOfField(field).forEach((event) => {
if (event.value && !event.previousPlayerDataEventOfField?.value) {
splits.push({
msIntoGame: event.msIntoGame,
title: `Got ${charmName}`,
tooltip: `Got ${charmName}`,
imageUrl: charm ? `/ingame-sprites/charms/${charm.spriteName}.png` : undefined,
group: 'charmCollection',
debugInfo: undefined,
});
}
});
}
}

for (const frameEndEvent of recording.frameEndEvents) {
for (const virtualCharm of virtualCharms) {
for (const virtualCharm of virtualCharms) {
for (const frameEndEvent of recording.frameEndEvents) {
if (
virtualCharm.hasCharm(frameEndEvent) &&
(!frameEndEvent.previousFrameEndEvent || virtualCharm.hasCharm(frameEndEvent.previousFrameEndEvent))
(!frameEndEvent.previousFrameEndEvent || !virtualCharm.hasCharm(frameEndEvent.previousFrameEndEvent))
) {
splits.push({
msIntoGame: frameEndEvent.msIntoGame,
title: `${virtualCharm.name}`,
tooltip: `Got ${virtualCharm.name}`,
imageUrl: '/charms/' + virtualCharm.spriteName,
imageUrl: `/ingame-sprites/charms/${virtualCharm.spriteName}.png`,
group: 'charmCollection',
debugInfo: undefined,
});
Expand Down

0 comments on commit 9458d59

Please sign in to comment.