Skip to content

Commit

Permalink
fix enka import re builds (#2261)
Browse files Browse the repository at this point in the history
* fix enka import re builds

* refactor Item to behave with old data

* put back "Imported"
  • Loading branch information
srliao authored Oct 26, 2024
1 parent 91a107d commit cd0557a
Show file tree
Hide file tree
Showing 8 changed files with 217 additions and 168 deletions.
14 changes: 8 additions & 6 deletions ui/packages/types/src/sim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface SimResults {
modified?: boolean;
key_type?: string;
standard?: string;

initial_character?: string;
character_details?: Character[];
target_details?: Enemy[];
Expand Down Expand Up @@ -223,12 +223,14 @@ export interface Character {
snapshot: number[];
sets: Set;
date_added?: string;
enka_build_name?: string;
source?: string; // allow for both GOOD and enka import
}

export interface Enemy {
level?: number;
hp?: number;
resist?: { [key: string]: number };
resist?: {[key: string]: number};
position?: Coord;
particle_drop_threshold?: number;
particle_drop_count?: number;
Expand Down Expand Up @@ -267,16 +269,16 @@ export type LogDetails = {
frame: number;
msg: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
logs: { [key in string]: any };
ordering?: { [key: string]: number };
logs: {[key in string]: any};
ordering?: {[key: string]: number};
};

export type StatusType = "idle" | "loading" | "done" | "error";
export type StatusType = 'idle' | 'loading' | 'done' | 'error';

export interface ParsedResult {
characters: ParsedCharacterProfile[];
errors: string[];
player_initial_pos: { x: number; y: number; r: number };
player_initial_pos: {x: number; y: number; r: number};
}

export interface ParsedCharacterProfile {
Expand Down
43 changes: 23 additions & 20 deletions ui/packages/ui/src/Components/Select/OmniSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import React from "react";
import { ItemPredicate, ItemRenderer, Omnibar } from "@blueprintjs/select";
import { MenuItem } from "@blueprintjs/core";
import { CharMap } from "../../Data";
import i18n from "i18next";
import {MenuItem} from '@blueprintjs/core';
import {ItemPredicate, ItemRenderer, Omnibar} from '@blueprintjs/select';
import i18n from 'i18next';
import React from 'react';
import {CharMap} from '../../Data';

type CharSource = 'user' | 'default';
export interface Item {
key: string;
text: string;
label: string;
notes?: string;
key: string; // this is UI key
char_key: string; // this is the unique gcsim character key
char_source: CharSource; // this denotes the source for the char data
text: string; // main text showing up on search
label: string; // secondary notes
}

type Props = {
Expand All @@ -29,21 +31,21 @@ export function OmniSelect(props: Props) {

const filter: ItemPredicate<Item> = (query, item, _index) => {
//ignore filtered items
if (disabled.findIndex((v) => v === item.key) > -1) {
if (disabled.findIndex((v) => v === item.char_key) > -1) {
return false;
}
const normalizedQuery = query.toLowerCase();
//the key search should maybe return the result even if not typed in
//the translated language but wont work for element etc
return (
`${item.label} ${item.key} ${item.text} ${item.notes}`
`${item.label} ${item.key} ${item.text}`
.toLowerCase()
.indexOf(normalizedQuery) >= 0
);
};
return (
<CharacterOmnibar
overlayProps={{ usePortal: false }}
overlayProps={{usePortal: false}}
resetOnSelect
items={props.items}
itemRenderer={OmniSelectRenderer}
Expand All @@ -57,26 +59,25 @@ export function OmniSelect(props: Props) {

const OmniSelectRenderer: ItemRenderer<Item> = (
item: Item,
{ handleClick, modifiers, query }
{handleClick, modifiers, query},
) => {
if (!modifiers.matchesPredicate) {
return null;
}
const text = item.notes ? `${item.text} (${item.notes})` : item.text;
return (
<MenuItem
active={modifiers.active}
disabled={modifiers.disabled}
label={item.label}
key={text}
key={item.char_source + '-' + item.key} // it's possible for item.key to be duplicated across 2 diff sources
onClick={handleClick}
text={highlightText(text, query)}
text={highlightText(item.text, query)}
/>
);
};

function escapeRegExpChars(text: string) {
return text.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
return text.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, '\\$1');
}

function highlightText(text: string, query: string) {
Expand All @@ -88,7 +89,7 @@ function highlightText(text: string, query: string) {
if (words.length === 0) {
return [text];
}
const regexp = new RegExp(words.join("|"), "gi");
const regexp = new RegExp(words.join('|'), 'gi');
const tokens: React.ReactNode[] = [];
while (true) {
const match = regexp.exec(text);
Expand All @@ -115,8 +116,10 @@ export function GenerateDefaultCharacters(): Item[] {
const ele = i18n.t(`elements.${CharMap[k].element}`);
return {
key: k,
text: i18n.t("game:character_names." + k),
label: i18n.t(`elements.${CharMap[k].element}`),
char_key: k,
char_source: 'default',
text: i18n.t('game:character_names.' + k),
label: '',
};
});
}
Loading

0 comments on commit cd0557a

Please sign in to comment.