Skip to content

Commit

Permalink
web: Rename config.ts to default.ts, made config/index and export con…
Browse files Browse the repository at this point in the history
…fig as .Config
  • Loading branch information
Dinnerbone committed Oct 6, 2024
1 parent c15c273 commit 076a39f
Show file tree
Hide file tree
Showing 19 changed files with 44 additions and 61 deletions.
3 changes: 1 addition & 2 deletions web/packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
*/

export * from "./public-api";
export * from "./public/config/config";
export * from "./public/config/load-options";
export * as Config from "./public/config";
export * from "./build-info";
export * from "./movie-metadata";
export * from "./install";
Expand Down
6 changes: 1 addition & 5 deletions web/packages/core/src/internal/builder.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import type { RuffleInstanceBuilder } from "../../dist/ruffle_web";
import {
BaseLoadOptions,
Duration,
SecsDuration,
} from "../public/config/load-options";
import { BaseLoadOptions, Duration, SecsDuration } from "../public/config";

/**
* Checks if the given value is explicitly `T` (not null, not undefined)
Expand Down
4 changes: 2 additions & 2 deletions web/packages/core/src/internal/player/inner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
UnmuteOverlay,
URLLoadOptions,
WindowMode,
} from "../../public/config/load-options";
DEFAULT_CONFIG,
} from "../../public/config";
import type { MovieMetadata } from "../../movie-metadata";
import { ruffleShadowTemplate } from "../ui/shadow-template";
import { text, textAsParagraphs } from "../i18n";
Expand All @@ -25,7 +26,6 @@ import { showPanicScreen } from "../ui/panic";
import { createRuffleBuilder } from "../../load-ruffle";
import { lookupElement } from "../register-element";
import { configureBuilder } from "../builder";
import { DEFAULT_CONFIG } from "../../public/config/config";

const DIMENSION_REGEX = /^\s*(\d+(\.\d+)?(%)?)/;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import type {
DataLoadOptions,
URLLoadOptions,
} from "../../public/config/load-options";
import type { DataLoadOptions, URLLoadOptions } from "../../public/config";
import type { MovieMetadata } from "../../movie-metadata";
import { InnerPlayer, ReadyState } from "./inner";
import { Player } from "../../public/player";
Expand Down
5 changes: 1 addition & 4 deletions web/packages/core/src/polyfills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import { RuffleObjectElement } from "./internal/player/ruffle-object-element";
import { RuffleEmbedElement } from "./internal/player/ruffle-embed-element";
import { installPlugin, FLASH_PLUGIN } from "./plugin-polyfill";
import { publicPath } from "./public-path";
import type {
DataLoadOptions,
URLLoadOptions,
} from "./public/config/load-options";
import type { DataLoadOptions, URLLoadOptions } from "./public/config";
import { isExtension } from "./current-script";

const globalConfig: DataLoadOptions | URLLoadOptions | object =
Expand Down
5 changes: 1 addition & 4 deletions web/packages/core/src/public-api.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { Version } from "./version";
import { VersionRange } from "./version-range";
import { SourceAPI } from "./source-api";
import type {
DataLoadOptions,
URLLoadOptions,
} from "./public/config/load-options";
import type { DataLoadOptions, URLLoadOptions } from "./public/config";

declare global {
interface Window {
Expand Down
2 changes: 1 addition & 1 deletion web/packages/core/src/public-path.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BaseLoadOptions } from "./public/config/load-options";
import { BaseLoadOptions } from "./public/config";
import { currentScriptURL, isExtension } from "./current-script";

/**
Expand Down
2 changes: 2 additions & 0 deletions web/packages/core/src/public/config/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./default";
export * from "./load-options";
2 changes: 1 addition & 1 deletion web/packages/core/src/public/legacy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DataLoadOptions, URLLoadOptions } from "./config/load-options";
import { DataLoadOptions, URLLoadOptions } from "./config";
import { MovieMetadata } from "../movie-metadata";
import { ReadyState } from "../internal/player/inner";

Expand Down
13 changes: 8 additions & 5 deletions web/packages/demo/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Player } from "./player.tsx";
import { useRef, useState, DragEvent, useCallback } from "react";
import { BaseLoadOptions, MovieMetadata } from "ruffle-core";
import type { Config, MovieMetadata } from "ruffle-core";
import { Navbar } from "./navbar.tsx";
import { MetadataPanel } from "./metadata.tsx";

interface AppProperties {
ruffleBaseConfig: BaseLoadOptions;
ruffleBaseConfig: Config.BaseLoadOptions;
allowUrlLoading: boolean;
allowSampleSwfs: boolean;
}
Expand Down Expand Up @@ -33,9 +33,12 @@ export function App({
};

// useCallback because this will be called from useEffect, we need this function to not change
const onSelectUrl = useCallback((url: string, options: BaseLoadOptions) => {
player.current?.loadUrl(url, options);
}, []);
const onSelectUrl = useCallback(
(url: string, options: Config.BaseLoadOptions) => {
player.current?.loadUrl(url, options);
},
[],
);

const onSelectFile = (file: File) => {
player.current?.loadFile(file);
Expand Down
16 changes: 5 additions & 11 deletions web/packages/demo/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,18 @@ import "./common.css";
import "./lato.css";
import "./index.css";
import { App } from "./App.tsx";
import {
AutoPlay,
Letterbox,
LogLevel,
installRuffle,
UnmuteOverlay,
} from "ruffle-core";
import { Config, installRuffle } from "ruffle-core";

installRuffle("local");

ReactDOM.createRoot(document.getElementById("root")!).render(
<React.StrictMode>
<App
ruffleBaseConfig={{
autoplay: AutoPlay.On,
unmuteOverlay: UnmuteOverlay.Hidden,
logLevel: LogLevel.Warn,
letterbox: Letterbox.On,
autoplay: Config.AutoPlay.On,
unmuteOverlay: Config.UnmuteOverlay.Hidden,
logLevel: Config.LogLevel.Warn,
letterbox: Config.Letterbox.On,
forceScale: true,
forceAlign: true,
}}
Expand Down
4 changes: 2 additions & 2 deletions web/packages/demo/src/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
useState,
DragEvent,
} from "react";
import { BaseLoadOptions } from "ruffle-core";
import type { Config } from "ruffle-core";
import { DemoSwf, SampleSelection } from "./navbar/samples.tsx";

declare global {
Expand All @@ -25,7 +25,7 @@ interface NavbarProps {
allowSampleSwfs: boolean;
onToggleMetadata: () => void;
onReloadMovie: () => void;
onSelectUrl: (url: string, options: BaseLoadOptions) => void;
onSelectUrl: (url: string, options: Config.BaseLoadOptions) => void;
onSelectFile: (file: File) => void;
selectedFilename: string | null;
setSelectedFilename: (value: string | null) => void;
Expand Down
6 changes: 3 additions & 3 deletions web/packages/demo/src/navbar/samples.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
useEffect,
useState,
} from "react";
import { BaseLoadOptions } from "ruffle-core";
import type { Config } from "ruffle-core";

type SampleCategory = "Animation" | "Game";

Expand All @@ -20,7 +20,7 @@ export interface DemoSwf {
title?: string;
author?: string;
authorLink?: string;
config?: BaseLoadOptions;
config?: Config.BaseLoadOptions;
type: SampleCategory | null;
}

Expand All @@ -29,7 +29,7 @@ interface SampleSelectionProperties {
selectedSample: DemoSwf | null;
setSelectedSample: (value: DemoSwf | null) => void;
setSelectedFilename: (name: string | null) => void;
onSelectUrl: (url: string, config: BaseLoadOptions) => void;
onSelectUrl: (url: string, config: Config.BaseLoadOptions) => void;
}

export function SampleSelection({
Expand Down
6 changes: 3 additions & 3 deletions web/packages/demo/src/player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import {
PublicAPI,
Player as RufflePlayer,
MovieMetadata,
BaseLoadOptions,
Config,
} from "ruffle-core";

export interface PlayerAttributes {
id?: string | undefined;
children?: ReactNode;
onLoadedMetadata: (metadata: MovieMetadata) => void;
baseConfig?: BaseLoadOptions;
baseConfig?: Config.BaseLoadOptions;
onDragEnter: (event: DragEvent<HTMLElement>) => void;
onDragLeave: (event: DragEvent<HTMLElement>) => void;
onDragOver: (event: DragEvent<HTMLElement>) => void;
Expand Down Expand Up @@ -78,7 +78,7 @@ export class Player extends React.Component<PlayerAttributes> {
}
}

loadUrl(url: string, options: BaseLoadOptions) {
loadUrl(url: string, options: Config.BaseLoadOptions) {
if (!this.isLoading) {
this.isLoading = true;
this.player
Expand Down
4 changes: 2 additions & 2 deletions web/packages/extension/src/common.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as utils from "./utils";
import type { BaseLoadOptions } from "ruffle-core";
import type { Config } from "ruffle-core";

export interface Options extends BaseLoadOptions {
export interface Options extends Config.BaseLoadOptions {
ruffleEnable: boolean;
ignoreOptout: boolean;
autostart: boolean;
Expand Down
4 changes: 2 additions & 2 deletions web/packages/extension/src/messages.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { BaseLoadOptions } from "ruffle-core";
import type { Config } from "ruffle-core";

export interface LoadMessage {
type: "load";
config: BaseLoadOptions;
config: Config.BaseLoadOptions;
}

export interface PingMessage {
Expand Down
14 changes: 6 additions & 8 deletions web/packages/extension/src/player.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import * as utils from "./utils";
import { installRuffle, PublicAPI } from "ruffle-core";
import type {
Letterbox,
Player,
DataLoadOptions,
URLLoadOptions,
} from "ruffle-core";

import type { Config, Player } from "ruffle-core";

declare global {
interface Navigator {
Expand Down Expand Up @@ -39,7 +35,7 @@ const grant = document.getElementById("grant")! as HTMLButtonElement;
// This is the base config always used by the extension player.
// It has the highest priority and its options cannot be overwritten.
const baseExtensionConfig = {
letterbox: "on" as Letterbox,
letterbox: "on" as Config.Letterbox,
forceScale: true,
forceAlign: true,
showSwfDownload: true,
Expand Down Expand Up @@ -102,7 +98,9 @@ function unload() {
}
}

async function load(options: string | DataLoadOptions | URLLoadOptions) {
async function load(
options: string | Config.DataLoadOptions | Config.URLLoadOptions,
) {
unload();
player = ruffle.createPlayer();
player.id = "player";
Expand Down
4 changes: 2 additions & 2 deletions web/packages/extension/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Options } from "./common";
import { DEFAULT_CONFIG as CORE_DEFAULT_CONFIG } from "ruffle-core";
import { Config } from "ruffle-core";

const DEFAULT_OPTIONS: Required<Options> = {
...CORE_DEFAULT_CONFIG,
...Config.DEFAULT_CONFIG,
ruffleEnable: true,
ignoreOptout: false,
autostart: false,
Expand Down

0 comments on commit 076a39f

Please sign in to comment.