Skip to content

Commit

Permalink
자동 수락 - 대기시간 기능 추가 및 안내 오버레이
Browse files Browse the repository at this point in the history
  • Loading branch information
2skydev committed Mar 13, 2023
1 parent e49236e commit 6abd72a
Show file tree
Hide file tree
Showing 19 changed files with 227 additions and 25 deletions.
5 changes: 4 additions & 1 deletion app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class AppContext {
`${this.RESOURCES_PATH}/icons/${this.IS_MAC ? 'logo@512.png' : 'logo@256.ico'}`,
);

// preload script path
readonly PRELOAD_PATH = join(__dirname, 'preload/index.js');

// electron window
window: BrowserWindow | null = null;

Expand Down Expand Up @@ -86,7 +89,7 @@ class AppContext {
frame: false,
icon: this.ICON,
webPreferences: {
preload: join(__dirname, 'preload/index.js'),
preload: this.PRELOAD_PATH,
},
});

Expand Down
34 changes: 33 additions & 1 deletion app/modules/league/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { BrowserWindow } from 'electron';
import { OverlayController, OVERLAY_WINDOW_OPTS } from 'electron-overlay-window';

import { ModuleFunction } from '@app/app';
import { configStore } from '@app/stores/config';
import IPCServer from '@app/utils/IPCServer';
Expand Down Expand Up @@ -39,6 +42,18 @@ const LeagueModule: ModuleFunction = async context => {
});

client.on('ready', () => {
const clientOverlay = new BrowserWindow({
...OVERLAY_WINDOW_OPTS,
webPreferences: {
preload: context.PRELOAD_PATH,
},
});

clientOverlay.loadURL('http://localhost:3000/#/overlays/client');

OverlayController.attachByTitle(clientOverlay, 'League of Legends');
OverlayController.activateOverlay();

context.window?.webContents.send('league/connect-change', 'connect');

client.subscribe('/lol-champ-select/v1/session', data => {
Expand All @@ -54,11 +69,28 @@ const LeagueModule: ModuleFunction = async context => {
});

client.subscribe('/lol-matchmaking/v1/ready-check', async data => {
if (data?.playerResponse === 'None' && configStore.get('game').autoAccept) {
console.log(data);

if (data?.playerResponse === 'None') {
const { autoAccept = false, autoAcceptDelaySeconds = 0 } = configStore.get('game');

if (!autoAccept) return;
if (data?.timer < autoAcceptDelaySeconds) return;

context.window?.webContents.send('league/auto-accept', {
timer: data.timer,
playerResponse: data.playerResponse,
autoAcceptDelaySeconds,
});

await client.request({
method: 'POST',
url: '/lol-matchmaking/v1/ready-check/accept',
});
} else {
context.window?.webContents.send('league/auto-accept', {
playerResponse: data.playerResponse,
});
}
});
});
Expand Down
2 changes: 2 additions & 0 deletions app/stores/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface ConfigStoreValues {
};
game: {
autoAccept: boolean;
autoAcceptDelaySeconds: number;
};
}

Expand All @@ -23,6 +24,7 @@ export const configStore = new Store<ConfigStoreValues>({
},
game: {
autoAccept: false,
autoAcceptDelaySeconds: 0,
},
},
});
Expand Down
5 changes: 5 additions & 0 deletions app/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface AutoAcceptData {
timer?: number;
playerResponse: string;
autoAcceptDelaySeconds?: number;
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"clsx": "^1.2.1",
"dayjs": "^1.11.7",
"electron-log": "^4.4.8",
"electron-overlay-window": "^3.2.0",
"electron-store": "^8.1.0",
"electron-updater": "^5.3.0",
"fast-deep-equal": "^3.1.3",
Expand Down
14 changes: 14 additions & 0 deletions public/fonts.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@
font-display: swap;
}

@font-face {
src: url('./fonts/BeaufortforLOL/BeaufortforLOL-Regular.woff2');
font-family: 'BeaufortforLOL';
font-weight: normal;
font-display: swap;
}

@font-face {
src: url('./fonts/BeaufortforLOL/BeaufortforLOL-Bold.woff2');
font-family: 'BeaufortforLOL';
font-weight: bold;
font-display: swap;
}

* {
margin: 0;
padding: 0;
Expand Down
Binary file not shown.
Binary file not shown.
39 changes: 39 additions & 0 deletions src/features/overlay/ReadyTimerOverlay/ReadyTimerOverlay.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { useEffect, useState } from 'react';

import clsx from 'clsx';

import { AutoAcceptData } from '@app/types';

import { ReadyTimerOverlayStyled } from './styled';

export interface ReadyTimerOverlayProps {
className?: string;
}

const ReadyTimerOverlay = ({ className }: ReadyTimerOverlayProps) => {
const [data, setData] = useState<AutoAcceptData | null>(null);

useEffect(() => {
window.electron.subscribeLeague('league/auto-accept', (data: AutoAcceptData) => {
if (data.playerResponse === 'None') {
setData(data);
} else {
setData(null);
}
});

return () => {
window.electron.unsubscribeLeague('league/auto-accept');
};
}, []);

if (!data) return null;

return (
<ReadyTimerOverlayStyled className={clsx('ReadyTimerOverlay', className)}>
자동 수락까지 {data.autoAcceptDelaySeconds! - data.timer!}초 남았습니다
</ReadyTimerOverlayStyled>
);
};

export default ReadyTimerOverlay;
3 changes: 3 additions & 0 deletions src/features/overlay/ReadyTimerOverlay/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// === Automatically generated file. Don't edit it. ===
export * from './ReadyTimerOverlay';
export { default } from './ReadyTimerOverlay';
11 changes: 11 additions & 0 deletions src/features/overlay/ReadyTimerOverlay/styled.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import styled from 'styled-components';

export const ReadyTimerOverlayStyled = styled.div`
position: absolute;
top: calc(50% + 100px);
left: calc(50%);
transform: translate(-50%, -50%);
color: ${props => props.theme.colors.gold};
text-align: center;
font-family: 'BeaufortforLOL';
`;
21 changes: 14 additions & 7 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useMemo } from 'react';
import { Outlet } from 'react-router-dom';
import { Outlet, useLocation } from 'react-router-dom';

import { ConfigProvider, GlobalToken, theme } from 'antd';
import antdLocaleKR from 'antd/locale/ko_KR';
Expand Down Expand Up @@ -33,6 +33,7 @@ const App = () => {
};

const AppInner = () => {
const { pathname } = useLocation();
const antdToken = theme.useToken();

const [update, setUpdate] = useRecoilState(updateStore);
Expand Down Expand Up @@ -81,6 +82,8 @@ const AppInner = () => {
[],
);

const isOverlay = pathname.includes('/overlays');

useEffect(() => {
bootstrap();
}, []);
Expand All @@ -89,13 +92,17 @@ const AppInner = () => {
<ThemeProvider theme={styledTheme}>
<InitGlobalStyled />

<div id="app">
<Titlebar />
{isOverlay && <Outlet />}

{!isOverlay && (
<div id="app">
<Titlebar />

<Layout>
<Outlet />
</Layout>
</div>
<Layout>
<Outlet />
</Layout>
</div>
)}
</ThemeProvider>
);
};
Expand Down
12 changes: 12 additions & 0 deletions src/pages/overlays/client.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import ReadyTimerOverlay from '~/features/overlay/ReadyTimerOverlay';
import { OverlaysClientPageStyled } from '~/styles/pageStyled/overlaysClientPageStyled';

const OverlaysClient = () => {
return (
<OverlaysClientPageStyled>
<ReadyTimerOverlay />
</OverlaysClientPageStyled>
);
};

export default OverlaysClient;
47 changes: 35 additions & 12 deletions src/pages/settings/game.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Controller } from 'react-hook-form';

import { Switch } from 'antd';
import { InputNumber, Switch } from 'antd';
import clsx from 'clsx';
import { useRecoilState } from 'recoil';

import LayoutConfig from '~/components/LayoutConfig';
Expand All @@ -23,6 +24,8 @@ const GameSettings = () => {
},
});

const isAutoAccept = form.watch('autoAccept');

return (
<SettingsPageStyled>
<LayoutConfig breadcrumbs={['설정', '게임 설정']} />
Expand All @@ -36,18 +39,38 @@ const GameSettings = () => {
</div>
}
>
<Controller
name="autoAccept"
control={form.control}
render={({ field }) => (
<Switch
checked={field.value}
onChange={checked => field.onChange(checked)}
checkedChildren={<i className="bx bx-check" />}
unCheckedChildren={<i className="bx bx-x" />}
<div className="autoAcceptField">
<Controller
name="autoAccept"
control={form.control}
render={({ field }) => (
<Switch
checked={field.value}
onChange={checked => field.onChange(checked)}
checkedChildren={<i className="bx bx-check" />}
unCheckedChildren={<i className="bx bx-x" />}
/>
)}
/>

<div className={clsx('delay', !isAutoAccept && 'disabled')}>
<div>자동 수락까지 대기시간</div>
<Controller
name="autoAcceptDelaySeconds"
control={form.control}
render={({ field }) => (
<InputNumber
min={0}
max={8}
value={field.value}
onChange={value => field.onChange(value)}
/>
)}
/>
)}
/>

<div></div>
</div>
</div>
</Section>

<SaveButton defaultValues={config.game} form={form} />
Expand Down
11 changes: 9 additions & 2 deletions src/styles/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ export const InitGlobalStyled = memo(createGlobalStyle`
}
#app {
width: 100vw;
height: 100vh;
color: ${props => props.theme.colors.textColor1};
background-color: ${props => props.theme.colors.sidebarBG};
}
html {
Expand All @@ -89,8 +91,6 @@ export const InitGlobalStyled = memo(createGlobalStyle`
body {
font-size: 14px;
background-color: ${props => props.theme.colors.sidebarBG};
color: ${props => props.theme.colors.textColor1};
.ant-switch {
height: 28px;
Expand Down Expand Up @@ -207,6 +207,13 @@ export const InitGlobalStyled = memo(createGlobalStyle`
.ant-input-number-handler {
border-color: ${props => props.theme.colors.borderColor};
background-color: ${props => props.theme.colors.sidebarBG};
color: white;
.ant-input-number-handler-up-inner,
.ant-input-number-handler-down-inner {
color: ${props => props.theme.colors.textColor2};
}
&:active {
background-color: ${props => props.theme.colors.sidebarBG};
Expand Down
7 changes: 7 additions & 0 deletions src/styles/pageStyled/overlaysClientPageStyled.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import styled from 'styled-components';

export const OverlaysClientPageStyled = styled.div`
width: 100vw;
height: 100vh;
position: relative;
`;
24 changes: 23 additions & 1 deletion src/styles/pageStyled/settingsPageStyled.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
import styled from 'styled-components';

export const SettingsPageStyled = styled.div`
.autoAcceptField {
display: inline-flex;
align-items: center;
.delay {
display: flex;
align-items: center;
background: ${props => props.theme.colors.formFieldBG};
padding: 0.6rem 1rem;
border-radius: 8px;
margin-left: 1rem;
transition: 250ms opacity;
&.disabled {
opacity: 0.5;
}
.ant-input-number {
width: 3.5rem;
margin: 0 0.5rem;
}
}
}
`;
1 change: 1 addition & 0 deletions src/styles/themes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const _colors = {
error: '#FE6968',
relic: '#ff6000',
ancient: '#c9a472',
gold: '#e0b667',
};

_colors.selectedBG = rgba(_colors.primary, 0.1);
Expand Down
Loading

0 comments on commit 6abd72a

Please sign in to comment.