Skip to content

Commit

Permalink
option to disable hardware acceleration, create auto presets on app s…
Browse files Browse the repository at this point in the history
…tart and game launch
  • Loading branch information
Shazbot committed Apr 17, 2023
1 parent 269d8ab commit 1febd41
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "wh3mm",
"productName": "wh3mm",
"version": "1.33.1",
"version": "1.34.0",
"description": "WH3 Mod Manager",
"main": ".webpack/main",
"scripts": {
Expand Down
10 changes: 9 additions & 1 deletion src/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ import Creatable from "react-select/creatable";
import Select, { ActionMeta, SingleValue } from "react-select";
import React, { useCallback, useEffect, useState } from "react";
import { useAppDispatch, useAppSelector } from "./hooks";
import { addPreset, deletePreset, replacePreset, selectPreset, setFilter } from "./appSlice";
import {
addPreset,
deletePreset,
replacePreset,
selectPreset,
setFilter,
createOnGameStartPreset,
} from "./appSlice";
import { Tooltip } from "flowbite-react";
import { UpdateNotification } from "./UpdateNotification";
import OptionsDrawer from "./OptionsDrawer";
Expand Down Expand Up @@ -39,6 +46,7 @@ const Sidebar = React.memo(() => {
const lastSelectedPreset: Preset | null = useAppSelector((state) => state.app.lastSelectedPreset);

const playGameClicked = () => {
dispatch(createOnGameStartPreset());
window.api?.startGame(mods, {
isMakeUnitsGeneralsEnabled,
isSkipIntroMoviesEnabled,
Expand Down
5 changes: 4 additions & 1 deletion src/TopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const TopBar = memo(() => {
const mods = useAppSelector((state) => state.app.currentPreset.mods);
const alwaysEnabledMods = useAppSelector((state) => state.app.alwaysEnabledMods);
const hiddenMods = useAppSelector((state) => state.app.hiddenMods);
const startArgs = useAppSelector((state) => state.app.startArgs);
const isHardwareAccelerationDisabled = startArgs.some((arg) => arg == "-nogpu");

const enabledMods = mods.filter(
(iterMod) => iterMod.isEnabled || alwaysEnabledMods.find((mod) => mod.name === iterMod.name)
Expand All @@ -15,7 +17,8 @@ const TopBar = memo(() => {
);
const title =
`WH3 Mod Manager v${appPackage.version}: ${enabledMods.length} mods enabled` +
(hiddenAndEnabledMods.length > 0 ? ` (${hiddenAndEnabledMods.length} of those hidden)` : "");
(hiddenAndEnabledMods.length > 0 ? ` (${hiddenAndEnabledMods.length} of those hidden)` : "") +
((isHardwareAccelerationDisabled && " nogpu") || "");

return (
<div id="top-bar" className="h-[28px] bg-gray-700 w-full sticky top-0 flex items-center z-50">
Expand Down
2 changes: 2 additions & 0 deletions src/appData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface AppData {
dataPack?: Pack;
overwrittenDataPackedFiles: Record<string, string[]>;
enabledMods: Mod[];
startArgs: string[];
}

export type AppFolderPaths = { gamePath: string; contentFolder: string };
Expand All @@ -33,4 +34,5 @@ export default {
currentlyReadingModPaths: [],
overwrittenDataPackedFiles: {},
enabledMods: [],
startArgs: [],
} as AppData;
28 changes: 27 additions & 1 deletion src/appSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const appSlice = createSlice({
appFolderPaths: { gamePath: "", contentFolder: "" },
isSetAppFolderPathsDone: false,
overwrittenDataPackedFiles: {},
startArgs: [],
} as AppState,
reducers: {
toggleMod: (state: AppState, action: PayloadAction<Mod>) => {
Expand Down Expand Up @@ -109,7 +110,7 @@ const appSlice = createSlice({

state.dataFromConfig.currentPreset.mods
.filter((mod) => mod !== undefined)
.map((mod) => {
.forEach((mod) => {
const existingMod = state.currentPreset.mods.find((statelyMod) => statelyMod.name == mod.name);
if (existingMod) {
existingMod.isEnabled = mod.isEnabled;
Expand All @@ -118,6 +119,14 @@ const appSlice = createSlice({
}
});
}

const appStartIndex = state.presets.findIndex((preset) => preset.name === "On App Start");
const newPreset = { name: "On App Start", mods: [...state.currentPreset.mods] };
if (appStartIndex != -1) {
state.presets.splice(appStartIndex, 1, newPreset);
} else {
state.presets.push(newPreset);
}
},
addMod: (state: AppState, action: PayloadAction<Mod>) => {
const mod = action.payload;
Expand Down Expand Up @@ -298,6 +307,18 @@ const appSlice = createSlice({
state.presets.push(newPreset);
state.lastSelectedPreset = newPreset;
},
createOnGameStartPreset: (state: AppState) => {
const appStartIndex = state.presets.findIndex((preset) => preset.name === "On Last Game Launch");
const newPreset = {
name: "On Last Game Launch",
mods: [...state.currentPreset.mods],
};
if (appStartIndex != -1) {
state.presets.splice(appStartIndex, 1, newPreset);
} else {
state.presets.push(newPreset);
}
},
selectPreset: (state: AppState, action: PayloadAction<[string, PresetSelection]>) => {
const [name, presetSelection] = action.payload;

Expand Down Expand Up @@ -463,6 +484,9 @@ const appSlice = createSlice({
setIsDev: (state: AppState, action: PayloadAction<boolean>) => {
state.isDev = action.payload;
},
setStartArgs: (state: AppState, action: PayloadAction<string[]>) => {
state.startArgs = action.payload;
},
createdMergedPack: (state: AppState, action: PayloadAction<string>) => {
const path = action.payload;
state.newMergedPacks.push({ path, creationTime: Date.now() });
Expand Down Expand Up @@ -499,6 +523,7 @@ export const {
disableAll,
addPreset,
selectPreset,
createOnGameStartPreset,
replacePreset,
deletePreset,
setFilter,
Expand All @@ -513,6 +538,7 @@ export const {
toggleAreThumbnailsEnabled,
toggleIsClosedOnPlay,
setIsDev,
setStartArgs,
setPackHeaderData,
toggleMakeUnitsGenerals,
toggleIsScriptLoggingEnabled,
Expand Down
1 change: 1 addition & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ declare global {
isClosedOnPlay: boolean;
isAuthorEnabled: boolean;
isDev: boolean;
startArgs: string[];
isMakeUnitsGeneralsEnabled: boolean;
isScriptLoggingEnabled: boolean;
isSkipIntroMoviesEnabled: boolean;
Expand Down
9 changes: 9 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ const gotTheLock = app.requestSingleInstanceLock();
if (!gotTheLock) {
app.quit();
} else {
console.log("ARGVS:", process.argv);
appData.startArgs = process.argv.slice(1);

if (process.argv.find((arg) => arg == "-nogpu")) {
console.log("DISABLED HARDWARE ACCELERATION");
app.disableHardwareAcceleration();
}

process.noAsar = true;

// Handle creating/removing shortcuts on Windows when installing/uninstalling.
Expand Down Expand Up @@ -956,6 +964,7 @@ if (!gotTheLock) {
ipcMain.on("sendApiExists", async () => {
mainWindow?.webContents.send("handleLog", "API now exists");
mainWindow?.webContents.send("setIsDev", isDev);
mainWindow?.webContents.send("setStartArgs", appData.startArgs);
});
};

Expand Down
2 changes: 2 additions & 0 deletions src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const api = {
ipcRenderer.on("createdMergedPack", callback),
setIsDev: (callback: (event: Electron.IpcRendererEvent, isDev: boolean) => void) =>
ipcRenderer.on("setIsDev", callback),
setStartArgs: (callback: (event: Electron.IpcRendererEvent, startArgs: string[]) => void) =>
ipcRenderer.on("setStartArgs", callback),
packsInSave: (callback: (event: Electron.IpcRendererEvent, packNames: string[]) => void) =>
ipcRenderer.on("packsInSave", callback),
sendApiExists: () => ipcRenderer.send("sendApiExists"),
Expand Down
6 changes: 6 additions & 0 deletions src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
setOverwrittenDataPackedFiles,
setDataModLastChangedLocal,
selectDBTable,
setStartArgs,
} from "./appSlice";
import store from "./store";
import { PackCollisions } from "./packFileTypes";
Expand Down Expand Up @@ -70,6 +71,11 @@ window.api?.setIsDev((event, isDev) => {
store.dispatch(setIsDev(isDev));
});

window.api?.setStartArgs((event, startArgs) => {
console.log("Start args are:", startArgs);
store.dispatch(setStartArgs(startArgs));
});

window.api?.packsInSave((event, packNames: string[]) => {
console.log("packs in save: ", packNames);
store.dispatch(enableModsByName(packNames));
Expand Down

0 comments on commit 1febd41

Please sign in to comment.