Skip to content

Commit

Permalink
- refactoring all the things
Browse files Browse the repository at this point in the history
  • Loading branch information
atomy committed Aug 30, 2024
1 parent 893a796 commit 4257b9c
Showing 1 changed file with 42 additions and 40 deletions.
82 changes: 42 additions & 40 deletions src/renderer/components/Application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,48 +100,48 @@ function Main() {
[players],
);

const playerDataListener: PlayerDataListener = (playerInfoCollection) => {
refreshPlayers(playerInfoCollection);
};
useEffect(() => {
const playerDataListener: PlayerDataListener = (playerInfoCollection) => {
refreshPlayers(playerInfoCollection);
};

const rconAppLogListener: RconAppLogListener = (logMessage) => {
addRconClientLogMessage(logMessage);
};
const rconAppLogListener: RconAppLogListener = (logMessage) => {
addRconClientLogMessage(logMessage);
};

const rconAppFragListener: RconAppFragListener = (fragMessage) => {
addRconClientFragMessage(fragMessage);
};
const rconAppFragListener: RconAppFragListener = (fragMessage) => {
addRconClientFragMessage(fragMessage);
};

const tf2ClassRequestListener: Tf2ClassRequestListener = (
weaponEntityName: string,
) => {
// console.log(
// `handleTf2ClassRequest() in: ${weaponEntityName} - isWeaponsDbConfigLoading: ${isWeaponsDbConfigLoading} - weaponDbConfigError: ${weaponDbConfigError}`,
// );

if (isWeaponsDbConfigLoading || weaponDbConfigError) {
(window as any).electronAPI.sendTf2ClassResponse({
error: true,
classNames: [],
errorMessage: weaponDbConfigError,
});
} else {
const weaponsData = JSON.parse(weaponsDbConfig);
const classNames = determineClassesFromWeaponEntityName(
weaponEntityName,
weaponsData,
);
const tf2ClassRequestListener: Tf2ClassRequestListener = (
weaponEntityName: string,
) => {
// console.log(
// `Determined className ${JSON.stringify(classNames)} for weaponEntityName ${weaponEntityName}`,
// `handleTf2ClassRequest() in: ${weaponEntityName} - isWeaponsDbConfigLoading: ${isWeaponsDbConfigLoading} - weaponDbConfigError: ${weaponDbConfigError}`,
// );
(window as any).electronAPI.sendTf2ClassResponse({
error: false,
classNames,
});
}
};

useEffect(() => {
if (isWeaponsDbConfigLoading || weaponDbConfigError) {
(window as any).electronAPI.sendTf2ClassResponse({
error: true,
classNames: [],
errorMessage: weaponDbConfigError,
});
} else {
const weaponsData = JSON.parse(weaponsDbConfig);
const classNames = determineClassesFromWeaponEntityName(
weaponEntityName,
weaponsData,
);
// console.log(
// `Determined className ${JSON.stringify(classNames)} for weaponEntityName ${weaponEntityName}`,
// );
(window as any).electronAPI.sendTf2ClassResponse({
error: false,
classNames,
});
}
};

(window as any).electronAPI.onPlayerData(playerDataListener);
(window as any).electronAPI.onRconAppLog(rconAppLogListener);
(window as any).electronAPI.onRconAppFrag(rconAppFragListener);
Expand All @@ -155,10 +155,12 @@ function Main() {
(window as any).electronAPI.removeAllListeners('rcon-appfrag');
};
}, [
playerDataListener,
rconAppLogListener,
rconAppFragListener,
tf2ClassRequestListener,
addRconClientFragMessage,
addRconClientLogMessage,
isWeaponsDbConfigLoading,
refreshPlayers,
weaponDbConfigError,
weaponsDbConfig,
]);

useEffect(() => {
Expand Down

0 comments on commit 4257b9c

Please sign in to comment.