Skip to content

Commit

Permalink
Add option to lock backend
Browse files Browse the repository at this point in the history
  • Loading branch information
caiiiycuk committed Dec 29, 2023
1 parent a73de9e commit bfb8b33
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/components/dos-option-select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import {
import { ThemeValues, Theme, uiSlice } from "../store/ui";

export function BackendSelect() {
const locked = useSelector((state: State) => state.dos.backendLocked);
return <OptionSelect
label="emulation_backend"
values={[...BackendValues]}
disabled={locked}
selector={(state: State) => state.dos.backend}
dispatch={(newValue: Backend) => dosSlice.actions.dosBackend(newValue)}
/>;
Expand Down
12 changes: 10 additions & 2 deletions src/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export async function loadBundleFromConfg(config: DosConfig, dispatch: Dispatch)
nonSerializableStore.loadedBundle = null;

dispatch(editorSlice.actions.init(config));
dispatch(dosSlice.actions.mouseCapture(config.dosboxConf.indexOf("autolock=true") > 0));
syncWithConfig(config, dispatch);

nonSerializableStore.loadedBundle = {
bundleUrl: null,
Expand Down Expand Up @@ -80,7 +80,7 @@ async function doLoadBundle(bundleName: string,
if (config === null) {
dispatch(uiSlice.actions.frameConf());
} else {
dispatch(dosSlice.actions.mouseCapture(config.dosboxConf.indexOf("autolock=true") > 0));
syncWithConfig(config, dispatch);
}

nonSerializableStore.loadedBundle = {
Expand Down Expand Up @@ -129,3 +129,11 @@ export async function updateBundleConf() {
nonSerializableStore.loadedBundle!.bundle =
await emulators.bundleUpdateConfig(bundle, config);
}

function syncWithConfig(config: DosConfig, dispatch: Dispatch) {
if (config.dosboxConf.indexOf("sockdrive") >= 0) {
dispatch(dosSlice.actions.dosBackendLocked(true));
dispatch(dosSlice.actions.dosBackend("dosboxX"));
}
dispatch(dosSlice.actions.mouseCapture(config.dosboxConf.indexOf("autolock=true") >= 0));
}
9 changes: 9 additions & 0 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ export const Dos: DosFn = (element: HTMLDivElement,
store.dispatch(dosSlice.actions.dosBackend(backend));
}

function setBackendLocked(locked: boolean) {
store.dispatch(dosSlice.actions.dosBackendLocked(locked));
}

function setWorkerThread(workerThread: DosOptions["workerThread"]) {
store.dispatch(dosSlice.actions.dosWorker(workerThread));
}
Expand Down Expand Up @@ -120,6 +124,10 @@ export const Dos: DosFn = (element: HTMLDivElement,
setBackend(options.backend);
}

if (options.backendLoked) {
setBackendLocked(options.backendLoked);
}

if (options.workerThread !== undefined) {
setWorkerThread(options.workerThread);
}
Expand Down Expand Up @@ -155,6 +163,7 @@ export const Dos: DosFn = (element: HTMLDivElement,
setTheme,
setLang,
setBackend,
setBackendLocked,
setWorkerThread,
setMouseCapture,
setServer,
Expand Down
4 changes: 3 additions & 1 deletion src/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface DosOptions {
"night" | "coffee" | "winter",
lang: "ru" | "en",
backend: "dosbox" | "dosboxX",
backendLoked: boolean,
workerThread: boolean,
mouseCapture: boolean,
onEvent: (event: "emu-ready" | "ci-ready" | "bnd-play", ci?: any) => void,
Expand All @@ -21,7 +22,8 @@ export interface DosOptions {
export interface DosProps {
setTheme(theme: DosOptions["theme"]): void;
setLang(lang: DosOptions["lang"]): void;
setBackend(lang: DosOptions["backend"]): void;
setBackend(backend: DosOptions["backend"]): void;
setBackendLocked(locked: boolean): void;
setWorkerThread(capture: DosOptions["workerThread"]): void;
setMouseCapture(capture: DosOptions["mouseCapture"]): void;
setServer(server: DosOptions["server"]): void;
Expand Down
5 changes: 5 additions & 0 deletions src/store/dos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const initialState: {
emuVersion: string,
worker: boolean,
backend: Backend,
backendLocked: boolean,
renderBackend: RenderBackend,
renderAspect: RenderAspect,
volume: number,
Expand All @@ -78,6 +79,7 @@ const initialState: {
config: {},
worker: lStorage.getItem("worker") !== "false",
backend: (lStorage.getItem("backend") ?? "dosboxX") as Backend,
backendLocked: false,
renderBackend: (lStorage.getItem("renderBackend") ?? "webgl") as RenderBackend,
renderAspect: (lStorage.getItem("renderAspect") ?? "AsIs") as RenderAspect,
volume: (Number.parseFloat(lStorage.getItem("volume") ?? "1.0")),
Expand Down Expand Up @@ -168,6 +170,9 @@ export const dosSlice = createSlice({
s.backend = a.payload as Backend;
lStorage.setItem("backend", s.backend);
},
dosBackendLocked: (s, a: { payload: boolean }) => {
s.backendLocked = a.payload;
},
renderBackend: (s, a: { payload: RenderBackend }) => {
s.renderBackend = a.payload;
lStorage.setItem("renderBackend", s.renderBackend);
Expand Down

0 comments on commit bfb8b33

Please sign in to comment.