Skip to content

Commit

Permalink
move buildSplitsFileName to lss.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
slaurent22 committed Jul 13, 2024
1 parent 9225a4f commit b46b6e7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 26 deletions.
32 changes: 6 additions & 26 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ import JSON5 from "json5";
import useQueryString, { QueryStringResult } from "use-query-string";
import { getCategoryConfigJSON, getCategoryDirectory } from "../lib/categories";
import { CategoryDefinition } from "../asset/hollowknight/categories/category-directory.json";
import { Config, createSplitsXml, importSplitsXml } from "../lib/lss";
import {
Config,
createSplitsXml,
importSplitsXml,
buildSplitsFileName,
} from "../lib/lss";
import CategoryAnyPercent from "../asset/hollowknight/categories/any.json";
import ArrowButton from "./ArrowButton";
import Header from "./Header";
Expand Down Expand Up @@ -201,31 +206,6 @@ export default function App(): ReactElement {
});
};

const buildSplitsFileName = (splitsConfig: Config) => {
const filename = (splitsConfig?.categoryName || "splits")
.toLowerCase() // Make file name compatible:
.replace(/['"]/g, "") // remove ' and "
.replace(/[^a-z0-9]/gi, "_") // replace non-alphanum with _
.replace(/^_+|_+$/g, "") // remove outer _
.replace(/^_+|_+$/g, "") // remove outer _
.replace(/_{2,}/g, "_"); // join multiple _
let suffix = "";
if (splitsConfig.variables?.glitch) {
const glitch = splitsConfig.variables?.glitch;
switch (glitch) {
case "No Main Menu Storage":
suffix = "-nmms";
break;
case "All Glitches":
suffix = "-ag";
break;
default:
break; // nmg categories don't need suffix
}
}
return `${filename}${suffix}`;
};

const onDownload = (): void => {
const output = state.splitOutput;
const outBlob = new Blob([output]);
Expand Down
25 changes: 25 additions & 0 deletions src/lib/lss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,31 @@ interface ParsedSplitId {
const MANUAL_SPLIT_RE = /%(?<name>.+)/;
export const SUB_SPLIT_RE = /-(?<name>.+)/;

export function buildSplitsFileName(splitsConfig: Config): string {
const filename = (splitsConfig?.categoryName || "splits")
.toLowerCase() // Make file name compatible:
.replace(/['"]/g, "") // remove ' and "
.replace(/[^a-z0-9]/gi, "_") // replace non-alphanum with _
.replace(/^_+|_+$/g, "") // remove outer _
.replace(/^_+|_+$/g, "") // remove outer _
.replace(/_{2,}/g, "_"); // join multiple _
let suffix = "";
if (splitsConfig.variables?.glitch) {
const glitch = splitsConfig.variables?.glitch;
switch (glitch) {
case "No Main Menu Storage":
suffix = "-nmms";
break;
case "All Glitches":
suffix = "-ag";
break;
default:
break; // nmg categories don't need suffix
}
}
return `${filename}${suffix}`;
}

function boolRepr(bool: boolean): string {
return bool ? "True" : "False";
}
Expand Down

0 comments on commit b46b6e7

Please sign in to comment.