Skip to content

Commit

Permalink
Merge pull request #89 from 2skydev/dev
Browse files Browse the repository at this point in the history
v0.0.18
  • Loading branch information
2skydev committed Aug 21, 2023
2 parents fba5ef5 + 75e80c1 commit aafafbc
Show file tree
Hide file tree
Showing 15 changed files with 185 additions and 60 deletions.
4 changes: 4 additions & 0 deletions src/main/modules/config/config.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export interface ConfigStoreValues {
autoAcceptDelaySeconds: number
useCurrentPositionChampionData: boolean
autoRuneSetting: boolean
autoSummonerSpellSetting: boolean
flashKey: 'D' | 'F'
}
}

Expand All @@ -36,6 +38,8 @@ export const configStore = new Store<ConfigStoreValues>({
autoAcceptDelaySeconds: 0,
useCurrentPositionChampionData: true,
autoRuneSetting: true,
autoSummonerSpellSetting: true,
flashKey: 'F',
},
},
})
15 changes: 15 additions & 0 deletions src/main/modules/league/league.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,21 @@ export class LeagueAPIClient {
return res
}

public async patch(url: string, body?: any) {
if (!this.credentials) throw new Error('Credentials not found')

const res = await createHttp1Request(
{
method: 'PATCH',
url,
body,
},
this.credentials,
)

return res
}

public async delete(url: string, body?: any) {
if (!this.credentials) throw new Error('Credentials not found')

Expand Down
2 changes: 2 additions & 0 deletions src/main/modules/league/league.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export const LADA_RUNE_PAGE_NAME_PREFIX = 'LADA '

export const LANE_IDS = [0, 1, 2, 3, 4] as const

export const FLASH_SUMMONER_SPELL_ID = 4

export const LANE_EN_TO_LANE_ID_MAP = {
TOP: 0,
JUNGLE: 1,
Expand Down
5 changes: 5 additions & 0 deletions src/main/modules/league/league.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ export class LeagueController {
return this.leagueService.setRunePageByRuneIds(...args)
}

@IPCHandle()
public async setSummonerSpell(...args: Parameters<LeagueService['setSummonerSpell']>) {
return this.leagueService.setSummonerSpell(...args)
}

@IPCSender({
windowKeys: [ELECTRON_MAIN_WINDOW_KEY, LEAGUE_CLIENT_OVERLAY_WINDOW_KEY],
})
Expand Down
88 changes: 57 additions & 31 deletions src/main/modules/league/league.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import { ElectronService } from '@main/modules/electron/electron.service'
import { LeagueDataDragonProvider } from '@main/modules/league/league-data-dragon.provider'
import { LeagueAPIClient } from '@main/modules/league/league.client'
import {
FLASH_SUMMONER_SPELL_ID,
LADA_RUNE_PAGE_NAME_PREFIX,
LANE_ID_TO_LABEL_MAP,
LEAGUE_CLIENT_OVERLAY_WINDOW_KEY,
} from '@main/modules/league/league.constants'
import { LeagueController } from '@main/modules/league/league.controller'
import { ChampionSelectSession } from '@main/modules/league/types/champion-select-session.types'
import { LaneId } from '@main/modules/league/types/lane.types'
import { Lobby } from '@main/modules/league/types/lobby.types'
import { Summoner } from '@main/modules/league/types/summoner.types'
import { convertLaneEnToLaneId } from '@main/modules/league/utils/lane.utils'
Expand Down Expand Up @@ -154,12 +154,15 @@ export class LeagueService implements OnModuleInit {
}

// 현재 롤 클라이언트가 챔피언 선택 중인지 확인
public async isLeagueChampSelecting() {
public async isChampionSelecting() {
if (!this.isConnected) return false

const data = await this.client.get('/lol-champ-select/v1/session')

return data !== null
try {
const data = await this.client.get('/lol-champ-select/v1/session')
return Boolean(data && data?.httpStatus !== 404)
} catch {
return false
}
}

private async isCanAddRunePage(): Promise<boolean> {
Expand Down Expand Up @@ -238,33 +241,62 @@ export class LeagueService implements OnModuleInit {
}
}

// 자동 룬 설정 트리거 (설정에서 활성화 시에만 동작)
public async triggerAutoRuneSetting(championId: number | null, laneId: LaneId | null) {
if (championId === null) return
if (!this.configService.get('game.autoRuneSetting')) return
public async setSummonerSpell(summonerSpellIds: number[]) {
const flashIndex = summonerSpellIds.findIndex(x => x === FLASH_SUMMONER_SPELL_ID)

if (flashIndex !== -1) {
const flashKey = this.configService.get('game.flashKey')

summonerSpellIds = [summonerSpellIds[+!flashIndex], FLASH_SUMMONER_SPELL_ID]

if (flashKey === 'D') {
summonerSpellIds.reverse()
}
}

await this.client.patch('/lol-champ-select/v1/session/my-selection', {
spell1Id: summonerSpellIds[0],
spell2Id: summonerSpellIds[1],
})
}

// 자동 설정 트리거 (설정에서 활성화 시에만 동작)
public async triggerAutoSetting(championSelectSession: ChampionSelectSession) {
const { championId, tempChampionId, laneId } = championSelectSession
const viewChampionId = championId || tempChampionId

// 선택한 챔피언이 없거나 이전에 선택한 챔피언과 같은 경우 무시
if (viewChampionId === null) return
if (this.beforeChampionId === viewChampionId) return

this.beforeChampionId = viewChampionId

const useCurrentPositionChampionData = this.configService.get(
'game.useCurrentPositionChampionData',
)

const {
runeBuilds,
champion: { name },
summary: { laneId: laneIdFromStats },
} = await this.statsProviderIntegrationService.getChampionStats(championId, {
laneId: useCurrentPositionChampionData ? laneId ?? undefined : undefined,
})
const championStats = await this.statsProviderIntegrationService.getChampionStats(
viewChampionId,
{
laneId: useCurrentPositionChampionData ? laneId ?? undefined : undefined,
},
)

const mainRuneBuild = runeBuilds[0]
// 룬 자동 설정
if (this.configService.get('game.autoRuneSetting')) {
const mainRuneBuild = championStats.runeBuilds[0]
if (!mainRuneBuild) return

if (!mainRuneBuild) {
return
await this.setRunePageByRuneIds(
[...mainRuneBuild.mainRuneIds, ...mainRuneBuild.subRuneIds, ...mainRuneBuild.shardRuneIds],
`${LANE_ID_TO_LABEL_MAP[championStats.summary.laneId]} ${championStats.champion.name}`,
)
}

await this.setRunePageByRuneIds(
[...mainRuneBuild.mainRuneIds, ...mainRuneBuild.subRuneIds, ...mainRuneBuild.shardRuneIds],
`${LANE_ID_TO_LABEL_MAP[laneIdFromStats]} ${name}`,
)
// 소환사 주문 자동 설정
if (this.configService.get('game.autoSummonerSpellSetting')) {
await this.setSummonerSpell(championStats.summary.spells.map(spell => spell.id))
}
}

private handleCurrentSummoner(data: any) {
Expand All @@ -283,14 +315,8 @@ export class LeagueService implements OnModuleInit {

this.controller.onChangeChampionSelectSession(convertedData!)

const championId = convertedData.championId || convertedData.tempChampionId

if (this.beforeChampionId !== championId) {
this.beforeChampionId = championId

if (!this.electronService.window) {
this.triggerAutoRuneSetting(championId, convertedData.laneId)
}
if (!this.electronService.window) {
this.triggerAutoSetting(convertedData)
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/main/modules/migration/migration.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,9 @@ export class MigrationModule {
configStore.set('game.statsProvider', 'LOL.PS')
configStore.set('game.autoRuneSetting', true)
}

public static async 'v0.0.18'() {
configStore.set('game.autoSummonerSpellSetting', true)
configStore.set('game.flashKey', 'F')
}
}
8 changes: 4 additions & 4 deletions src/main/modules/update/update.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ export class UpdateService implements OnModuleInit {
@ExecuteLog()
async autoUpdate() {
return new Promise<boolean>(async resolve => {
let isLeagueChampSelectingPromise: Promise<boolean> | null = null
let isChampionSelectingPromise: Promise<boolean> | null = null

if (!this.electronService.IS_HIDDEN_LAUNCH) {
isLeagueChampSelectingPromise = this.leagueService.isLeagueChampSelecting()
isChampionSelectingPromise = this.leagueService.isChampionSelecting()
}

const stopAutoUpdate = () => {
Expand All @@ -72,9 +72,9 @@ export class UpdateService implements OnModuleInit {

const handleUpdateAvailable = async () => {
if (!this.electronService.IS_HIDDEN_LAUNCH) {
const isLeagueChampSelecting = await isLeagueChampSelectingPromise
const isChampionSelecting = await isChampionSelectingPromise

if (isLeagueChampSelecting) {
if (isChampionSelecting) {
// 챔피언 선택 중이면 업데이트 안함
this.electronService.isNeedUpdateLater = true
stopAutoUpdate()
Expand Down
1 change: 1 addition & 0 deletions src/preload/generated-ipc-invoke-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const generatedIpcInvokeContext = {
getLobby: async (...args: Parameters<typeof LeagueController.prototype.getLobby>): Promise<ReturnType<typeof LeagueController.prototype.getLobby>> => ipcRenderer.invoke('getLobby', ...args),
getChampionSelectSession: async (...args: Parameters<typeof LeagueController.prototype.getChampionSelectSession>): Promise<ReturnType<typeof LeagueController.prototype.getChampionSelectSession>> => ipcRenderer.invoke('getChampionSelectSession', ...args),
setRunePageByRuneIds: async (...args: Parameters<typeof LeagueController.prototype.setRunePageByRuneIds>): Promise<ReturnType<typeof LeagueController.prototype.setRunePageByRuneIds>> => ipcRenderer.invoke('setRunePageByRuneIds', ...args),
setSummonerSpell: async (...args: Parameters<typeof LeagueController.prototype.setSummonerSpell>): Promise<ReturnType<typeof LeagueController.prototype.setSummonerSpell>> => ipcRenderer.invoke('setSummonerSpell', ...args),

// StatsProviderIntegrationController
getChampionStats: async (...args: Parameters<typeof StatsProviderIntegrationController.prototype.getChampionStats>): Promise<ReturnType<typeof StatsProviderIntegrationController.prototype.getChampionStats>> => ipcRenderer.invoke('getChampionStats', ...args),
Expand Down
15 changes: 14 additions & 1 deletion src/renderer/src/features/champ/ChampDetail/ChampDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,16 @@ export interface ChampDetailProps {
champId: number
defaultLaneId?: LaneId
autoRuneSetting?: boolean
autoSummonerSpellSetting?: boolean
}

const ChampDetail = ({ className, champId, defaultLaneId, autoRuneSetting }: ChampDetailProps) => {
const ChampDetail = ({
className,
champId,
defaultLaneId,
autoRuneSetting,
autoSummonerSpellSetting,
}: ChampDetailProps) => {
const [autoRuneSettingArguments, setAutoRuneSettingArguments] = useState<{
runeIds: number[]
name: string
Expand Down Expand Up @@ -116,6 +123,12 @@ const ChampDetail = ({ className, champId, defaultLaneId, autoRuneSetting }: Cha
}
}, [autoRuneSettingArguments])

useEffect(() => {
if (autoSummonerSpellSetting && data && !isNoData) {
window.electron.setSummonerSpell(data.summary.spells.map(spell => spell.id))
}
}, [autoSummonerSpellSetting, data, isNoData])

return (
<ChampDetailStyled className={clsx('ChampDetail', className)}>
{!data && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const ReadyTimerOverlay = ({ className }: ReadyTimerOverlayProps) => {
useEffect(() => {
const unsubscribe = window.electron.onAutoAccept(event => {
if (event.playerResponse === 'None') {
setData(data)
setData(event)
} else {
setData(null)
}
Expand Down
1 change: 0 additions & 1 deletion src/renderer/src/hooks/useAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const useAPI = <FnName extends ElectronContextPropertyName>(
revalidateOnFocus: false,
revalidateOnReconnect: false,
fetcher: async ([, args]: typeof key) => {
console.log('useAPI', fnName, args)
// @ts-ignore
const response = await window.electron[fnName](...args)

Expand Down
9 changes: 7 additions & 2 deletions src/renderer/src/pages/live/champion-select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const LiveChampionSelect = () => {

const LiveChampionDetail = () => {
const {
game: { useCurrentPositionChampionData, autoRuneSetting },
game: { useCurrentPositionChampionData, autoRuneSetting, autoSummonerSpellSetting },
} = useAtomValue(configAtom)

const { championId, tempChampionId, laneId } = useAtomValue(championSelectSessionAtom)!
Expand All @@ -33,7 +33,12 @@ const LiveChampionDetail = () => {
const defaultLaneId = laneId === null || !useCurrentPositionChampionData ? undefined : laneId

return (
<ChampDetail champId={id!} defaultLaneId={defaultLaneId} autoRuneSetting={autoRuneSetting} />
<ChampDetail
champId={id!}
defaultLaneId={defaultLaneId}
autoRuneSetting={autoRuneSetting}
autoSummonerSpellSetting={autoSummonerSpellSetting}
/>
)
}

Expand Down
Loading

0 comments on commit aafafbc

Please sign in to comment.