diff --git a/demo/js/butterchurnOptions.ts b/demo/js/butterchurnOptions.ts index f3c85189ad..270a93df9d 100644 --- a/demo/js/butterchurnOptions.ts +++ b/demo/js/butterchurnOptions.ts @@ -1,4 +1,4 @@ -import { ButterchurnOptions } from "../../js/types"; +import { ButterchurnOptions, Preset } from "../../js/types"; const KNOWN_PRESET_URLS_REGEXES = [ /^https:\/\/unpkg\.com\/butterchurn-presets\/.*\.json$/, @@ -20,14 +20,20 @@ function presetNameFromURL(url: string) { } } -async function loadButterchurnPresetMapURL(url: string) { - const resp = await fetch(url); - const namesToPresetUrls = await resp.json(); +function restructureButterchurnPresetMap(namesToPresetUrls: { + [key: string]: string; +}): Preset[] { return Object.keys(namesToPresetUrls).map((name: string) => { return { name, butterchurnPresetUrl: namesToPresetUrls[name] }; }); } +async function loadButterchurnPresetMapURL(url: string) { + const resp = await fetch(url); + const namesToPresetUrls = await resp.json(); + return restructureButterchurnPresetMap(namesToPresetUrls); +} + export function getButterchurnOptions( startWithMilkdropHidden: boolean ): ButterchurnOptions { @@ -48,7 +54,7 @@ export function getButterchurnOptions( }, presetConverterEndpoint: "https://p2tpeb5v8b.execute-api.us-east-2.amazonaws.com/default/milkdropShaderConverter", - getPresets: async () => { + getPresets: async (): Promise => { if ("URLSearchParams" in window) { const params = new URLSearchParams(location.search); const butterchurnPresetUrlParam = params.get("butterchurnPresetUrl"); @@ -89,10 +95,12 @@ export function getButterchurnOptions( throw new Error("We still need to implement this"); } } - // TODO: Fallback to some other presets? - return loadButterchurnPresetMapURL( - "https://unpkg.com/butterchurn-presets-weekly@0.0.2/weeks/week1/presets.json" + + const presetMap = await import( + /* webpackChunkName: "milkdrop-presets-weekly" */ + "butterchurn-presets-weekly/weeks/week1/presets.json" ); + return restructureButterchurnPresetMap(presetMap.default); }, butterchurnOpen: !startWithMilkdropHidden, }; diff --git a/package.json b/package.json index fc20f50ccf..9c623b37ae 100644 --- a/package.json +++ b/package.json @@ -152,6 +152,7 @@ "trailingComma": "es5" }, "dependencies": { + "butterchurn-presets-weekly": "^0.0.4", "eslint-plugin-react-hooks": "^2.1.2", "fscreen": "^1.0.2", "react-dropzone": "^10.1.7", diff --git a/yarn.lock b/yarn.lock index cabdf5fd08..b20389521f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2734,6 +2734,11 @@ builtin-status-codes@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/builtin-status-codes/-/builtin-status-codes-3.0.0.tgz#85982878e21b98e1c66425e03d0174788f569ee8" +butterchurn-presets-weekly@^0.0.4: + version "0.0.4" + resolved "https://registry.yarnpkg.com/butterchurn-presets-weekly/-/butterchurn-presets-weekly-0.0.4.tgz#2ab8b8bc1f90269c8d6861ea734d27e2e6e52184" + integrity sha512-vEc7PgNSOOsYU4G72riAMCy3RidImgfsAYQJLchOI1bugVhXdkAqZzyLqh0aEqoZ7xTZC1xBQFHqLm6NbKfZjg== + butterchurn@^2.6.7: version "2.6.7" resolved "https://registry.yarnpkg.com/butterchurn/-/butterchurn-2.6.7.tgz#1ff0c1365731a4fb7ada7bb16ae1c6f09a110c12"