├── .gitignore ├── assets ├── icon.png ├── banner.jpg └── league-respawn-timer-icon.woff ├── .vscode-test.mjs ├── .vscodeignore ├── .vscode ├── extensions.json ├── tasks.json ├── settings.json └── launch.json ├── CHANGELOG.md ├── src ├── extension.ts ├── const.ts ├── test │ └── extension.test.ts ├── notification.ts ├── api.ts ├── config.ts ├── event-handler.ts ├── commands.ts ├── quick-pick.ts ├── game-event-listener.ts ├── status-bar.ts ├── api.d.ts └── respawn-timer.ts ├── tsconfig.json ├── .eslintrc.json ├── LICENSE ├── README.zh-CN.md ├── README.md └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | out 2 | dist 3 | node_modules 4 | .vscode-test/ 5 | *.vsix 6 | -------------------------------------------------------------------------------- /assets/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LeagueTavern/vscode-league-respawn-timer/HEAD/assets/icon.png -------------------------------------------------------------------------------- /assets/banner.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LeagueTavern/vscode-league-respawn-timer/HEAD/assets/banner.jpg -------------------------------------------------------------------------------- /.vscode-test.mjs: -------------------------------------------------------------------------------- 1 | import { defineConfig } from '@vscode/test-cli'; 2 | 3 | export default defineConfig({ 4 | files: 'out/test/**/*.test.js', 5 | }); 6 | -------------------------------------------------------------------------------- /assets/league-respawn-timer-icon.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LeagueTavern/vscode-league-respawn-timer/HEAD/assets/league-respawn-timer-icon.woff -------------------------------------------------------------------------------- /.vscodeignore: -------------------------------------------------------------------------------- 1 | .vscode/** 2 | .vscode-test/** 3 | src/** 4 | .gitignore 5 | .yarnrc 6 | vsc-extension-quickstart.md 7 | **/tsconfig.json 8 | **/.eslintrc.json 9 | **/*.map 10 | **/*.ts 11 | **/.vscode-test.* 12 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See http://go.microsoft.com/fwlink/?LinkId=827846 3 | // for the documentation about the extensions.json format 4 | "recommendations": [ 5 | "dbaeumer.vscode-eslint", 6 | "ms-vscode.extension-test-runner" 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to the "league-respawn-timer" extension will be documented in this file. 4 | 5 | Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file. 6 | 7 | ## [Unreleased] 8 | 9 | - Initial release -------------------------------------------------------------------------------- /src/extension.ts: -------------------------------------------------------------------------------- 1 | import { registerCommands } from "./commands"; 2 | import { registerEvents } from "./event-handler"; 3 | import { registerConfig } from "./config"; 4 | 5 | import type { ExtensionContext } from "vscode"; 6 | 7 | export function activate(context: ExtensionContext) { 8 | registerCommands(context); 9 | registerConfig(context); 10 | registerEvents(); 11 | } 12 | 13 | export function deactivate() {} 14 | -------------------------------------------------------------------------------- /src/const.ts: -------------------------------------------------------------------------------- 1 | export const COMMAND_ENABLE_TIMER = "league-respawn-timer.enable-timer"; 2 | export const COMMAND_DISABLE_TIMER = "league-respawn-timer.disable-timer"; 3 | export const COMMAND_SHOW_MENU = "league-respawn-timer.show-menu"; 4 | export const COMMAND_SHOW_CONFIG = "workbench.action.openSettings"; 5 | 6 | export const CONFIG_ENABLE = "league-respawn-timer.enable"; 7 | export const CONFIG_ENABLE_NOTIFICATION = 8 | "league-respawn-timer.enable-notification"; 9 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | // See https://go.microsoft.com/fwlink/?LinkId=733558 2 | // for the documentation about the tasks.json format 3 | { 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "type": "npm", 8 | "script": "watch", 9 | "problemMatcher": "$tsc-watch", 10 | "isBackground": true, 11 | "presentation": { 12 | "reveal": "never" 13 | }, 14 | "group": { 15 | "kind": "build", 16 | "isDefault": true 17 | } 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | // Place your settings in this file to overwrite default and user settings. 2 | { 3 | "files.exclude": { 4 | "out": false // set this to true to hide the "out" folder with the compiled JS files 5 | }, 6 | "search.exclude": { 7 | "out": true // set this to false to include "out" folder in search results 8 | }, 9 | // Turn off tsc task auto detection since we have the necessary tasks as npm scripts 10 | "typescript.tsc.autoDetect": "off", 11 | "cmake.configureOnOpen": false 12 | } -------------------------------------------------------------------------------- /src/test/extension.test.ts: -------------------------------------------------------------------------------- 1 | import * as assert from 'assert'; 2 | 3 | // You can import and use all API from the 'vscode' module 4 | // as well as import your extension to test it 5 | import * as vscode from 'vscode'; 6 | // import * as myExtension from '../../extension'; 7 | 8 | suite('Extension Test Suite', () => { 9 | vscode.window.showInformationMessage('Start all tests.'); 10 | 11 | test('Sample test', () => { 12 | assert.strictEqual(-1, [1, 2, 3].indexOf(5)); 13 | assert.strictEqual(-1, [1, 2, 3].indexOf(0)); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /src/notification.ts: -------------------------------------------------------------------------------- 1 | import { window } from "vscode"; 2 | import { getConfiguration } from "./config"; 3 | import { CONFIG_ENABLE_NOTIFICATION } from "./const"; 4 | 5 | export const Notication = new (class Notication { 6 | isVisible() { 7 | return getConfiguration(CONFIG_ENABLE_NOTIFICATION) as boolean; 8 | } 9 | 10 | respawn() { 11 | this.isVisible() && 12 | window.showInformationMessage(`You have respawned, return to the game!`); 13 | } 14 | 15 | failedToLoadSummonerInfo() { 16 | this.isVisible() && 17 | window.showErrorMessage(`Failed to load summoner info.`); 18 | } 19 | })(); 20 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "Node16", 4 | "target": "ES2022", 5 | "outDir": "out", 6 | "lib": ["ES2022"], 7 | "forceConsistentCasingInFileNames": true, 8 | "sourceMap": true, 9 | "rootDir": "src", 10 | "strict": true /* enable all strict type-checking options */ 11 | /* Additional Checks */ 12 | // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ 13 | // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ 14 | // "noUnusedParameters": true, /* Report errors on unused parameters. */ 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | // A launch configuration that compiles the extension and then opens it inside a new window 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | { 6 | "version": "0.2.0", 7 | "configurations": [ 8 | { 9 | "name": "Run Extension", 10 | "type": "extensionHost", 11 | "request": "launch", 12 | "args": [ 13 | "--extensionDevelopmentPath=${workspaceFolder}" 14 | ], 15 | "outFiles": [ 16 | "${workspaceFolder}/out/**/*.js" 17 | ], 18 | "preLaunchTask": "${defaultBuildTask}" 19 | } 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /src/api.ts: -------------------------------------------------------------------------------- 1 | import axios from "axios"; 2 | import https from "https"; 3 | 4 | import { 5 | IResponseActivePlay, 6 | IResponseEventData, 7 | IResponseGamestats, 8 | } from "./api.d"; 9 | 10 | const client = axios.create({ 11 | baseURL: "https://127.0.0.1:2999/", 12 | timeout: 5000, 13 | httpsAgent: new https.Agent({ 14 | rejectUnauthorized: false, 15 | }), 16 | }); 17 | export class APIClient { 18 | static getGameEventData() { 19 | return client.get("/liveclientdata/eventdata"); 20 | } 21 | 22 | static getActivePlayer() { 23 | return client.get("/liveclientdata/activeplayer"); 24 | } 25 | 26 | static getGameStats() { 27 | return client.get("/liveclientdata/gamestats"); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "parser": "@typescript-eslint/parser", 4 | "parserOptions": { 5 | "ecmaVersion": 6, 6 | "sourceType": "module" 7 | }, 8 | "plugins": [ 9 | "@typescript-eslint" 10 | ], 11 | "rules": { 12 | "@typescript-eslint/naming-convention": [ 13 | "warn", 14 | { 15 | "selector": "import", 16 | "format": [ "camelCase", "PascalCase" ] 17 | } 18 | ], 19 | "@typescript-eslint/semi": "warn", 20 | "curly": "warn", 21 | "eqeqeq": "warn", 22 | "no-throw-literal": "warn", 23 | "semi": "off" 24 | }, 25 | "ignorePatterns": [ 26 | "out", 27 | "dist", 28 | "**/*.d.ts" 29 | ] 30 | } -------------------------------------------------------------------------------- /src/config.ts: -------------------------------------------------------------------------------- 1 | import { workspace, commands } from "vscode"; 2 | import { 3 | COMMAND_DISABLE_TIMER, 4 | COMMAND_ENABLE_TIMER, 5 | CONFIG_ENABLE, 6 | } from "./const"; 7 | 8 | import type { ExtensionContext } from "vscode"; 9 | 10 | export function registerConfig(context: ExtensionContext) { 11 | const dynamicConfigLoad = () => { 12 | const enable = getConfiguration(CONFIG_ENABLE) as boolean; 13 | 14 | enable 15 | ? commands.executeCommand(COMMAND_ENABLE_TIMER) 16 | : commands.executeCommand(COMMAND_DISABLE_TIMER); 17 | }; 18 | 19 | workspace.onDidChangeConfiguration(dynamicConfigLoad); 20 | dynamicConfigLoad(); 21 | } 22 | 23 | export function getConfiguration(key: string) { 24 | return workspace.getConfiguration().get(key); 25 | } 26 | 27 | export function setConfiguration(key: string, value: unknown) { 28 | const config = workspace.getConfiguration(); 29 | if (config.get(key) !== value) { 30 | return config.update(key, value); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 ButterCookies 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/event-handler.ts: -------------------------------------------------------------------------------- 1 | import { Notication } from "./notification"; 2 | import { RespawnTimer } from "./respawn-timer"; 3 | import { GameEventListener } from "./game-event-listener"; 4 | import { StatusBar, StatusBarStatus } from "./status-bar"; 5 | 6 | export function registerEvents() { 7 | GameEventListener.on("event", (event) => { 8 | switch (event.EventName) { 9 | case "ChampionKill": { 10 | if (event.VictimName === RespawnTimer.getRiotIdGameName()) { 11 | RespawnTimer.start(event.EventTime); 12 | StatusBar.setStatus(StatusBarStatus.Timing); 13 | } 14 | break; 15 | } 16 | } 17 | }); 18 | 19 | GameEventListener.on("connected", () => { 20 | RespawnTimer.init() 21 | .then((riotIdGameName) => 22 | StatusBar.setStatus(StatusBarStatus.Connected, riotIdGameName) 23 | ) 24 | .catch(() => Notication.failedToLoadSummonerInfo()); 25 | }); 26 | 27 | GameEventListener.on("disconnected", () => { 28 | StatusBar.setStatus(StatusBarStatus.NotConnected); 29 | RespawnTimer.clearTimer(); 30 | }); 31 | 32 | RespawnTimer.on("update", (time) => { 33 | StatusBar.updateTimingValue(time); 34 | }); 35 | 36 | RespawnTimer.on("dead", () => {}); 37 | RespawnTimer.on("respawn", () => { 38 | StatusBar.setStatus(StatusBarStatus.Connected); 39 | Notication.respawn(); 40 | }); 41 | } 42 | -------------------------------------------------------------------------------- /src/commands.ts: -------------------------------------------------------------------------------- 1 | import { commands } from "vscode"; 2 | import { GameEventListener } from "./game-event-listener"; 3 | import { StatusBar, StatusBarStatus } from "./status-bar"; 4 | import { 5 | COMMAND_DISABLE_TIMER, 6 | COMMAND_ENABLE_TIMER, 7 | COMMAND_SHOW_MENU, 8 | CONFIG_ENABLE, 9 | } from "./const"; 10 | import { openQuickPick } from "./quick-pick"; 11 | 12 | import type { ExtensionContext } from "vscode"; 13 | import { setConfiguration } from "./config"; 14 | 15 | export function registerCommands(context: ExtensionContext) { 16 | const enableTimer = () => { 17 | if (GameEventListener.enable()) { 18 | StatusBar.setStatus(StatusBarStatus.NotConnected); 19 | setConfiguration(CONFIG_ENABLE, true); 20 | } 21 | }; 22 | 23 | const disableTimer = () => { 24 | if (GameEventListener.disable()) { 25 | StatusBar.setStatus(StatusBarStatus.Disabled); 26 | setConfiguration(CONFIG_ENABLE, false); 27 | } 28 | }; 29 | 30 | const enableTimerCommand = commands.registerCommand( 31 | COMMAND_ENABLE_TIMER, 32 | enableTimer 33 | ); 34 | const disableTimerCommand = commands.registerCommand( 35 | COMMAND_DISABLE_TIMER, 36 | disableTimer 37 | ); 38 | const showMenuCommand = commands.registerCommand( 39 | COMMAND_SHOW_MENU, 40 | openQuickPick 41 | ); 42 | 43 | context.subscriptions.push( 44 | enableTimerCommand, 45 | disableTimerCommand, 46 | showMenuCommand 47 | ); 48 | } 49 | -------------------------------------------------------------------------------- /src/quick-pick.ts: -------------------------------------------------------------------------------- 1 | import { window, commands, QuickPickItemKind } from "vscode"; 2 | import { 3 | COMMAND_DISABLE_TIMER, 4 | COMMAND_ENABLE_TIMER, 5 | COMMAND_SHOW_CONFIG, 6 | } from "./const"; 7 | 8 | import type { QuickPickItem } from "vscode"; 9 | 10 | export function openQuickPick() { 11 | return window 12 | .showQuickPick( 13 | [ 14 | { 15 | label: "$(lrt-leagueoflegends-online) Enable Respawn Timer", 16 | detail: "Enable League Respawn Timer", 17 | meta: { 18 | script: () => commands.executeCommand(COMMAND_ENABLE_TIMER), 19 | }, 20 | }, 21 | { 22 | label: "$(lrt-leagueoflegends-disabled) Disable Respawn Timer", 23 | detail: "Disable League Respawn Timer", 24 | meta: { 25 | script: () => commands.executeCommand(COMMAND_DISABLE_TIMER), 26 | }, 27 | }, 28 | { 29 | label: "", 30 | kind: QuickPickItemKind.Separator, 31 | }, 32 | { 33 | label: "$(settings-gear) Configurations", 34 | detail: "Configure League Respawn Timer", 35 | meta: { 36 | script: () => 37 | commands.executeCommand( 38 | COMMAND_SHOW_CONFIG, 39 | "league-respawn-timer" 40 | ), 41 | }, 42 | }, 43 | ], 44 | { 45 | title: "League Respawn Timer Options", 46 | canPickMany: false, 47 | } 48 | ) 49 | .then((item?: QuickPickItem) => { 50 | if (item) { 51 | const meta = ( 52 | item as QuickPickItem & { meta: Record<"script", () => void> } 53 | ).meta; 54 | const script = meta.script; 55 | script(); 56 | } 57 | }); 58 | } 59 | -------------------------------------------------------------------------------- /README.zh-CN.md: -------------------------------------------------------------------------------- 1 | ![image](https://raw.githubusercontent.com/Coooookies/vscode-league-respawn-timer/master/assets/banner.jpg) 2 | 3 | 一款在 [Visual Studio Code](https://code.visualstudio.com) 里显示 **`《英雄联盟》`** 玩家重生时间的插件。 4 | 5 | [English](https://github.com/Coooookies/vscode-league-respawn-timer/blob/master/README.md) | 简体中文 6 | 7 | [![Version](https://img.shields.io/visual-studio-marketplace/v/ButterCookies.league-respawn-timer?logo=visualstudiocode&style=flat-square)](https://marketplace.visualstudio.com/items?itemName=ButterCookies.league-respawn-timer) [![Installs](https://img.shields.io/visual-studio-marketplace/i/ButterCookies.league-respawn-timer?style=flat-square)](https://marketplace.visualstudio.com/items?itemName=ButterCookies.league-respawn-timer) [![Ratings](https://img.shields.io/visual-studio-marketplace/r/ButterCookies.league-respawn-timer?style=flat-square)](https://marketplace.visualstudio.com/items?itemName=ButterCookies.league-respawn-timer) [![Stars](https://img.shields.io/github/stars/Coooookies/vscode-league-respawn-timer?logo=github&style=flat-square)](https://github.com/Coooookies/vscode-league-respawn-timer) [![License](https://img.shields.io/github/license/Coooookies/vscode-league-respawn-timer?style=flat-square)](https://github.com/Coooookies/vscode-league-respawn-timer) 8 | 9 | #### 为什么我会制作这款插件? 10 | 11 | _我的大多数开发项目都与《英雄联盟》游戏相关。有时为了测试我的项目,我不得不用匹配/排位进行调试,当我角色死亡之后,我时常会切屏出来对我的代码进行改进,但我经常忘记了我的复活时间,导致频繁切屏,为了解决这个问题,我开发了这个插件。_ 12 | 13 | ## 🕹️ 功能 14 | 15 | - [x] **显示重生时间** 16 | 17 | ## 🔧 如何使用 18 | 19 | 1. **安装插件。** 20 | 2. **启动你的 `游戏客户端` 并且开始游戏。** 21 | 当你进入游戏对局后,你的 `游戏名称` 将会被显示在 Vscode 的状态栏上。当你死时, 你的重生时间会显示在你`游戏名称`的位置。 22 | 23 | ## 🪣 命令 24 | 25 | 按下 `Ctrl+Shift+P` 打开快速命令面板, 输入 `League Respawn Timer` 并选择你想要运行的命令。 26 | 27 | - `league-respawn-timer.enable-timer`: 启用本插件。 28 | - `league-respawn-timer.disable-timer`: 禁用本插件。 29 | - `league-respawn-timer.show-menu`: 显示菜单。 30 | 31 | ## 🛠️ 配置项 32 | 33 | | 名称 | 类型 | 默认值 | 介绍 | 34 | | :----------------------------------------- | :-------: | :----: | :----------- | 35 | | `league-respawn-timer.enable` | `Boolean` | `true` | 启用本插件。 | 36 | | `league-respawn-timer.enable-notification` | `Boolean` | `true` | 启用插件通知 | 37 | 38 | ## 协议 39 | 40 | 本插件遵循 [MIT](LICENSE) 协议 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![image](https://raw.githubusercontent.com/Coooookies/vscode-league-respawn-timer/master/assets/banner.jpg) 2 | 3 | An extension to display **`League of Legends`** player respawn time in [Visual Studio Code](https://code.visualstudio.com). 4 | 5 | English | [简体中文](https://github.com/Coooookies/vscode-league-respawn-timer/blob/master/README.zh-CN.md) 6 | 7 | [![Version](https://img.shields.io/visual-studio-marketplace/v/ButterCookies.league-respawn-timer?logo=visualstudiocode&style=flat-square)](https://marketplace.visualstudio.com/items?itemName=ButterCookies.league-respawn-timer) [![Installs](https://img.shields.io/visual-studio-marketplace/i/ButterCookies.league-respawn-timer?style=flat-square)](https://marketplace.visualstudio.com/items?itemName=ButterCookies.league-respawn-timer) [![Ratings](https://img.shields.io/visual-studio-marketplace/r/ButterCookies.league-respawn-timer?style=flat-square)](https://marketplace.visualstudio.com/items?itemName=ButterCookies.league-respawn-timer) [![Stars](https://img.shields.io/github/stars/Coooookies/vscode-league-respawn-timer?logo=github&style=flat-square)](https://github.com/Coooookies/vscode-league-respawn-timer) [![License](https://img.shields.io/github/license/Coooookies/vscode-league-respawn-timer?style=flat-square)](https://github.com/Coooookies/vscode-league-respawn-timer) 8 | 9 | #### Why did I make this extension? 10 | 11 | _I play **`League of Legends`** and work on projects related to the game. To enhance my productivity, I'm planning to develop an extension that allows me to code and enjoy the game seamlessly._ 12 | 13 | ## 🕹️ Features 14 | 15 | - [x] **Display player respawn time** 16 | 17 | ## 🔧 How to use 18 | 19 | 1. **Install this extension.** 20 | 2. **Launch your `LeagueClient` and start your game.** 21 | When you are in the game, your `SummonerName` will be displayed in the status bar. Upon death, your respawn time will be displayed in the status bar instead of your `SummonerName`. 22 | 23 | ## 🪣 Commands 24 | 25 | Press `Ctrl+Shift+P` to open the command palette, type `League Respawn Timer` and select the command you want to run. 26 | 27 | - `league-respawn-timer.enable-timer`: Enable this extension. 28 | - `league-respawn-timer.disable-timer`: Disable this extension. 29 | - `league-respawn-timer.show-menu`: Show the menu. 30 | 31 | ## 🛠️ Configuration 32 | 33 | | Name | Type | Default | Description | 34 | | :----------------------------------------- | :-------: | :-----: | :----------------------------- | 35 | | `league-respawn-timer.enable` | `Boolean` | `true` | Enable or disable this plugin | 36 | | `league-respawn-timer.enable-notification` | `Boolean` | `true` | Enable or disable notification | 37 | 38 | ## LICENSE 39 | 40 | This extension is licensed under the [MIT](LICENSE) 41 | -------------------------------------------------------------------------------- /src/game-event-listener.ts: -------------------------------------------------------------------------------- 1 | import Nanobus from "nanobus"; 2 | import { APIClient } from "./api"; 3 | 4 | import type { IGameEvent, IResponseEventData } from "./api.d"; 5 | 6 | type GameEventListenerEvent = { 7 | connected: () => void; 8 | disconnected: () => void; 9 | event: (event: IGameEvent) => void; 10 | }; 11 | 12 | export const GameEventListener = 13 | new (class GameEventListener extends Nanobus { 14 | private allowConnect = false; 15 | private isConnected = false; 16 | private lastEventID = -1; 17 | 18 | enable() { 19 | if (this.allowConnect) { 20 | return false; 21 | } 22 | 23 | const loop = () => { 24 | if (!this.allowConnect) { 25 | return; 26 | } 27 | 28 | APIClient.getGameEventData() 29 | .then( 30 | ({ data }) => this.allowConnect && this.onEventDataReceived(data) 31 | ) 32 | .then(() => { 33 | if (this.allowConnect && !this.isConnected) { 34 | this.isConnected = true; 35 | this.emit("connected"); 36 | } 37 | }) 38 | .catch(() => { 39 | if (this.allowConnect && this.isConnected) { 40 | this.isConnected = false; 41 | this.lastEventID = 0; 42 | this.emit("disconnected"); 43 | } 44 | }) 45 | .finally(() => { 46 | this.allowConnect && 47 | setTimeout(loop, this.isConnected ? 1000 : 5000); 48 | }); 49 | }; 50 | 51 | this.allowConnect = true; 52 | this.reset(); 53 | loop(); 54 | 55 | return true; 56 | } 57 | 58 | disable() { 59 | if (!this.allowConnect) { 60 | return false; 61 | } 62 | 63 | this.allowConnect = false; 64 | this.isConnected && this.emit("disconnected"); 65 | return true; 66 | } 67 | 68 | isGameConnected() { 69 | return this.isConnected; 70 | } 71 | 72 | isEnable() { 73 | return this.allowConnect; 74 | } 75 | 76 | private reset() { 77 | this.lastEventID = -1; 78 | this.isConnected = false; 79 | } 80 | 81 | private onEventDataReceived(data: IResponseEventData) { 82 | const newEvents = data.Events.filter( 83 | (event) => event.EventID > this.lastEventID 84 | ); 85 | const getLastEventID = () => 86 | data.Events.length > 0 87 | ? data.Events[data.Events.length - 1].EventID 88 | : -1; 89 | 90 | if (newEvents.length === 0) { 91 | return; 92 | } 93 | 94 | if (this.lastEventID === -1) { 95 | this.lastEventID = getLastEventID(); 96 | return; 97 | } 98 | 99 | this.lastEventID = getLastEventID(); 100 | newEvents.forEach((event) => this.emit("event", event)); 101 | } 102 | })(); 103 | -------------------------------------------------------------------------------- /src/status-bar.ts: -------------------------------------------------------------------------------- 1 | import { StatusBarAlignment, ThemeColor, window } from "vscode"; 2 | import { COMMAND_SHOW_MENU } from "./const"; 3 | 4 | export enum StatusBarStatus { 5 | NotConnected = 1, 6 | Connected = 2, 7 | Timing = 3, 8 | Disabled = 4, 9 | } 10 | 11 | export const StatusBar = new (class StatusBar { 12 | private statusBarStatus!: StatusBarStatus; 13 | private statusBarItem = window.createStatusBarItem(StatusBarAlignment.Right); 14 | private statusBarTimingValue = 0; 15 | private statusBarNameValue = ""; 16 | 17 | constructor() { 18 | this.statusBarItem.command = COMMAND_SHOW_MENU; 19 | this.setStatus(StatusBarStatus.Disabled); 20 | } 21 | 22 | public setStatus(status: StatusBarStatus.Disabled): void; 23 | public setStatus(status: StatusBarStatus.NotConnected): void; 24 | public setStatus(status: StatusBarStatus.Timing): void; 25 | public setStatus(status: StatusBarStatus.Connected, name?: string): void; 26 | public setStatus( 27 | status: StatusBarStatus, 28 | name: string = this.statusBarNameValue 29 | ): void { 30 | this.statusBarStatus = status; 31 | switch (status) { 32 | case StatusBarStatus.Connected: { 33 | this.statusBarNameValue = name!; 34 | this.statusBarItem.text = `$(lrt-champion) ${name}`; 35 | this.statusBarItem.tooltip = `League Respawn Timer - Player: ${name}`; 36 | this.statusBarItem.backgroundColor = new ThemeColor( 37 | "statusBarItem.fourgroundBackground" 38 | ); 39 | break; 40 | } 41 | case StatusBarStatus.Timing: { 42 | this.statusBarItem.text = `$(lrt-timing) Calculating...`; 43 | this.statusBarItem.tooltip = `League Respawn Timer - Timing`; 44 | this.statusBarItem.backgroundColor = new ThemeColor( 45 | "statusBarItem.warningBackground" 46 | ); 47 | break; 48 | } 49 | case StatusBarStatus.Disabled: { 50 | this.statusBarItem.text = `$(lrt-leagueoflegends-disabled) Disabled`; 51 | this.statusBarItem.tooltip = `League Respawn Timer - Disabled`; 52 | this.statusBarItem.backgroundColor = new ThemeColor( 53 | "statusBarItem.fourgroundBackground" 54 | ); 55 | break; 56 | } 57 | default: { 58 | this.statusBarItem.text = `$(lrt-leagueoflegends-online) Ready`; 59 | this.statusBarItem.tooltip = `League Respawn Timer - Ready`; 60 | this.statusBarItem.backgroundColor = new ThemeColor( 61 | "statusBarItem.fourgroundBackground" 62 | ); 63 | } 64 | } 65 | this.statusBarItem.show(); 66 | } 67 | 68 | public updateTimingValue(value: number) { 69 | this.statusBarTimingValue = value; 70 | 71 | if (this.statusBarStatus === StatusBarStatus.Timing) { 72 | this.statusBarItem.text = `$(lrt-timing) Respawn in ${this.statusBarTimingValue}s`; 73 | this.statusBarItem.backgroundColor = new ThemeColor( 74 | value % 2 === 0 75 | ? "statusBarItem.errorBackground" 76 | : "statusBarItem.warningBackground" 77 | ); 78 | } 79 | } 80 | 81 | public show() { 82 | this.statusBarItem.show(); 83 | } 84 | 85 | public hide() { 86 | this.statusBarItem.hide(); 87 | } 88 | })(); 89 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "league-respawn-timer", 3 | "displayName": "League Respawn Timer", 4 | "description": "Display player respawn timer in Visual Studio Code.", 5 | "version": "1.0.1", 6 | "publisher": "ButterCookies", 7 | "license": "MIT", 8 | "icon": "assets/icon.png", 9 | "author": { 10 | "name": "ButterCookies", 11 | "email": "admin@mitay.net" 12 | }, 13 | "homepage": "https://mitay.net", 14 | "bugs": { 15 | "url": "https://github.com/Coooookies/vscode-league-respawn-timer/issues" 16 | }, 17 | "repository": { 18 | "type": "git", 19 | "url": "https://github.com/Coooookies/vscode-league-respawn-timer" 20 | }, 21 | "engines": { 22 | "vscode": "^1.84.0" 23 | }, 24 | "categories": [ 25 | "Other" 26 | ], 27 | "activationEvents": [ 28 | "onStartupFinished" 29 | ], 30 | "main": "./out/extension.js", 31 | "contributes": { 32 | "commands": [ 33 | { 34 | "command": "league-respawn-timer.enable-timer", 35 | "title": "League Respawn Timer: Enable Respawn Timer" 36 | }, 37 | { 38 | "command": "league-respawn-timer.disable-timer", 39 | "title": "League Respawn Timer: Disable Respawn Timer" 40 | }, 41 | { 42 | "command": "league-respawn-timer.show-menu", 43 | "title": "League Respawn Timer: Show Menu" 44 | } 45 | ], 46 | "configuration": { 47 | "title": "League Respawn Timer Configuration", 48 | "properties": { 49 | "league-respawn-timer.enable": { 50 | "type": "boolean", 51 | "default": true, 52 | "description": "Enable respawn timer." 53 | }, 54 | "league-respawn-timer.enable-notification": { 55 | "type": "boolean", 56 | "default": true, 57 | "description": "Enable extension notification." 58 | } 59 | } 60 | }, 61 | "icons": { 62 | "lrt-leagueoflegends-online": { 63 | "description": "League of Legends online icon", 64 | "default": { 65 | "fontPath": "assets/league-respawn-timer-icon.woff", 66 | "fontCharacter": "\\e900" 67 | } 68 | }, 69 | "lrt-leagueoflegends-disabled": { 70 | "description": "League of Legends disabled icon", 71 | "default": { 72 | "fontPath": "assets/league-respawn-timer-icon.woff", 73 | "fontCharacter": "\\e904" 74 | } 75 | }, 76 | "lrt-leagueoflegends": { 77 | "description": "League of Legends icon", 78 | "default": { 79 | "fontPath": "assets/league-respawn-timer-icon.woff", 80 | "fontCharacter": "\\e902" 81 | } 82 | }, 83 | "lrt-champion": { 84 | "description": "League of Legends champion icon", 85 | "default": { 86 | "fontPath": "assets/league-respawn-timer-icon.woff", 87 | "fontCharacter": "\\e901" 88 | } 89 | }, 90 | "lrt-timing": { 91 | "description": "LRT timing icon", 92 | "default": { 93 | "fontPath": "assets/league-respawn-timer-icon.woff", 94 | "fontCharacter": "\\e903" 95 | } 96 | } 97 | } 98 | }, 99 | "scripts": { 100 | "vscode:prepublish": "npm run compile", 101 | "compile": "tsc -p ./", 102 | "watch": "tsc -watch -p ./", 103 | "pretest": "npm run compile && npm run lint", 104 | "lint": "eslint src --ext ts", 105 | "test": "vscode-test" 106 | }, 107 | "devDependencies": { 108 | "@types/mocha": "^10.0.6", 109 | "@types/node": "^18.19.86", 110 | "@types/vscode": "^1.84.0", 111 | "@typescript-eslint/eslint-plugin": "^6.13.1", 112 | "@typescript-eslint/parser": "^6.13.1", 113 | "@vscode/test-cli": "^0.0.4", 114 | "@vscode/test-electron": "^2.3.8", 115 | "eslint": "^8.54.0", 116 | "typescript": "^5.3.2" 117 | }, 118 | "dependencies": { 119 | "axios": "^1.6.2", 120 | "nanobus": "^4.5.0" 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /src/api.d.ts: -------------------------------------------------------------------------------- 1 | 2 | export type IGameEvent = 3 | | { 4 | EventID: number; 5 | EventName: "GameStart"; 6 | EventTime: number; 7 | } 8 | | { 9 | EventID: number; 10 | EventName: "MinionsSpawning"; 11 | EventTime: number; 12 | } 13 | | { 14 | EventID: number; 15 | EventName: "InhibRespawned"; 16 | EventTime: number; 17 | InhibRespawned: "Barracks_T2_C1"; 18 | } 19 | | { 20 | EventID: number; 21 | EventName: "InhibRespawningSoon"; 22 | EventTime: number; 23 | InhibRespawningSoon: string; 24 | } 25 | | { 26 | EventID: number; 27 | EventName: "FirstBrick"; 28 | EventTime: number; 29 | KillerName: string; 30 | } 31 | | { 32 | EventID: number; 33 | EventName: "TurretKilled"; 34 | EventTime: number; 35 | TurretKilled: "Turret_T2_L_03_A"; 36 | KillerName: string; 37 | Assisters: string[]; 38 | } 39 | | { 40 | EventID: number; 41 | EventName: "InhibKilled"; 42 | EventTime: number; 43 | InhibKilled: "Barracks_T2_R1"; 44 | KillerName: string; 45 | Assisters: string[]; 46 | } 47 | | { 48 | EventID: number; 49 | EventName: "DragonKill"; 50 | EventTime: number; 51 | DragonType: "Earth"; 52 | Stolen: "False" | "True"; 53 | KillerName: string; 54 | Assisters: string[]; 55 | } 56 | | { 57 | EventID: number; 58 | EventName: "DragonKill"; 59 | EventTime: number; 60 | DragonType: "Elder"; 61 | Stolen: "False" | "True"; 62 | KillerName: string; 63 | Assisters: string[]; 64 | } 65 | | { 66 | EventID: number; 67 | EventName: "HeraldKill"; 68 | EventTime: number; 69 | Stolen: "False" | "True"; 70 | KillerName: string; 71 | Assisters: string[]; 72 | } 73 | | { 74 | EventID: number; 75 | EventName: "BaronKill"; 76 | EventTime: number; 77 | Stolen: "False" | "True"; 78 | KillerName: string; 79 | Assisters: string[]; 80 | } 81 | | { 82 | EventID: number; 83 | EventName: "ChampionKill"; 84 | EventTime: number; 85 | VictimName: string; 86 | KillerName: string; 87 | Assisters: string[]; 88 | } 89 | | { 90 | EventID: number; 91 | EventName: "Multikill"; 92 | EventTime: number; 93 | KillerName: string; 94 | KillStreak: number; 95 | } 96 | | { 97 | EventID: number; 98 | EventName: "Ace"; 99 | EventTime: number; 100 | Acer: string; 101 | AcingTeam: string; 102 | }; 103 | 104 | export type IResponseActivePlay = { 105 | abilities: Record< 106 | "Q" | "W" | "E" | "R", 107 | Record< 108 | "displayName" | "id" | "rawDescription" | "rawDisplayName", 109 | string 110 | > & { abilityLevel: number } 111 | > & { 112 | Passive: Record< 113 | "displayName" | "id" | "rawDescription" | "rawDisplayName", 114 | string 115 | >; 116 | }; 117 | championStats: Record< 118 | | "abilityHaste" 119 | | "abilityPower" 120 | | "armor" 121 | | "armorPenetrationFlat" 122 | | "armorPenetrationPercent" 123 | | "attackDamage" 124 | | "attackRange" 125 | | "attackSpeed" 126 | | "bonusArmorPenetrationPercent" 127 | | "bonusMagicPenetrationPercent" 128 | | "critChance" 129 | | "critDamage" 130 | | "currentHealth" 131 | | "healShieldPower" 132 | | "healthRegenRate" 133 | | "lifeSteal" 134 | | "magicLethality" 135 | | "magicPenetrationFlat" 136 | | "magicPenetrationPercent" 137 | | "magicResist" 138 | | "maxHealth" 139 | | "moveSpeed" 140 | | "omnivamp" 141 | | "physicalLethality" 142 | | "physicalVamp" 143 | | "resourceMax" 144 | | "resourceRegenRate" 145 | | "resourceType" 146 | | "resourceValue" 147 | | "spellVamp" 148 | | "tenacity", 149 | number 150 | >; 151 | currentGold: number; 152 | fullRunes: { 153 | generalRunes: { 154 | displayName: string; 155 | id: number; 156 | rawDescription: string; 157 | rawDisplayName: string; 158 | }[]; 159 | statRunes: { 160 | id: number; 161 | rawDescription: string; 162 | }[]; 163 | } & Record< 164 | "keystone" | "primaryRuneTree" | "secondaryRuneTree", 165 | { 166 | displayName: string; 167 | id: number; 168 | rawDescription: string; 169 | rawDisplayName: string; 170 | } 171 | >; 172 | level: number; 173 | summonerName: string; 174 | riotId: string; 175 | riotIdGameName: string; 176 | riotIdTagLine: string; 177 | teamRelativeColors: boolean; 178 | }; 179 | 180 | export type IResponseGamestats = { 181 | gameMode: string; 182 | gameTime: number; 183 | mapName: string; 184 | mapNumber: number; 185 | mapTerrain: string; 186 | }; 187 | 188 | export type IResponseEventData = { 189 | Events: IGameEvent[]; 190 | }; -------------------------------------------------------------------------------- /src/respawn-timer.ts: -------------------------------------------------------------------------------- 1 | import Nanobus from "nanobus"; 2 | import { APIClient } from "./api"; 3 | 4 | import type { IResponseActivePlay, IResponseGamestats } from "./api.d"; 5 | 6 | type RespawnTimerEvent = { 7 | dead: () => void; 8 | update: (time: number) => void; 9 | respawn: () => void; 10 | }; 11 | 12 | export const RespawnTimer = 13 | new (class RespawnTimer extends Nanobus { 14 | private deatRealTime = 0; 15 | private deadGameTime = 0; 16 | private gameMode = ""; 17 | private respawnTime = 0; 18 | private remainingTimeInterval: NodeJS.Timeout | null = null; 19 | private riotIdGameName = ""; 20 | 21 | init() { 22 | return new Promise((resolve, reject) => { 23 | const onStatsLoaded = ( 24 | activePlayer: IResponseActivePlay, 25 | gameStats: IResponseGamestats 26 | ) => { 27 | this.gameMode = gameStats.gameMode; 28 | this.riotIdGameName = activePlayer.riotIdGameName; 29 | return activePlayer.riotIdGameName; 30 | }; 31 | 32 | Promise.all([APIClient.getActivePlayer(), APIClient.getGameStats()]) 33 | .then(([activePlayer, gameStats]) => ({ 34 | player: activePlayer.data, 35 | stats: gameStats.data, 36 | })) 37 | .then(({ player, stats }) => onStatsLoaded(player, stats)) 38 | .then(resolve) 39 | .catch(reject); 40 | }); 41 | } 42 | 43 | start(time: number) { 44 | return new Promise((resolve, reject) => { 45 | this.deadGameTime = time; 46 | this.deatRealTime = Date.now(); 47 | 48 | APIClient.getActivePlayer() 49 | .then(({ data }) => { 50 | this.respawnTime = 51 | this.deatRealTime + 52 | this.calcaulateRespawnRemainTime( 53 | this.gameMode, 54 | this.deadGameTime, 55 | data.level 56 | ) * 57 | 1000; 58 | 59 | this.createTimer(); 60 | return this.respawnTime; 61 | }) 62 | .then(resolve) 63 | .catch(reject); 64 | }); 65 | } 66 | 67 | createTimer() { 68 | const onRespawnEvent = () => { 69 | this.clearTimer(); 70 | this.emit("respawn"); 71 | }; 72 | 73 | const onTimerLoopEvent = () => { 74 | const currentTime = new Date().getTime(); 75 | const remainTime = Math.floor((this.respawnTime - currentTime) / 1000); 76 | 77 | this.emit("update", remainTime); 78 | 79 | if (remainTime <= 0) { 80 | onRespawnEvent(); 81 | } else { 82 | APIClient.getActivePlayer() 83 | .then( 84 | ({ data }) => 85 | data.championStats.currentHealth !== 0 && onRespawnEvent() 86 | ) 87 | .catch(() => {}); 88 | } 89 | }; 90 | 91 | this.emit("dead"); 92 | this.clearTimer(); 93 | this.remainingTimeInterval = setInterval(onTimerLoopEvent, 1000); 94 | onTimerLoopEvent(); 95 | } 96 | 97 | clearTimer() { 98 | clearInterval(this.remainingTimeInterval!); 99 | this.remainingTimeInterval = null; 100 | } 101 | 102 | calcaulateRespawnRemainTime(mode: string, gameTime: number, level: number) { 103 | // https://leagueoflegends.fandom.com/wiki/Death 104 | 105 | switch (mode) { 106 | case "ARAM": { 107 | return level * 2 + 4; 108 | } 109 | default: { 110 | const calcTimeIncreaseFactor = (gameTime: number) => { 111 | const currentMinutes = gameTime / 60; 112 | 113 | if (currentMinutes < 15) { 114 | return 0; 115 | } else if (currentMinutes < 30) { 116 | return (Math.ceil(2 * (currentMinutes - 15)) * 0.425) / 100; 117 | } else if (currentMinutes < 45) { 118 | return ( 119 | 0.1275 + (Math.ceil(2 * (currentMinutes - 30)) * 0.3) / 100 120 | ); 121 | } else { 122 | return ( 123 | 0.2175 + 124 | (Math.ceil(2 * (Math.min(currentMinutes, 55) - 45)) * 1.45) / 125 | 100 126 | ); 127 | } 128 | }; 129 | 130 | // Level 1-18 131 | const baseRespawnTimeMap = [ 132 | 6, 6, 8, 8, 10, 12, 16, 21, 26, 32.5, 35, 37.5, 40, 42.5, 45, 47.5, 133 | 50, 52.5, 134 | ]; 135 | 136 | // TIF & BRW 137 | const timeIncreaseFactor = calcTimeIncreaseFactor(gameTime); 138 | const baseRespawnWaittime = baseRespawnTimeMap[level - 1]; 139 | 140 | // result 141 | const deathTime = 142 | baseRespawnWaittime + baseRespawnWaittime * timeIncreaseFactor; 143 | return Math.floor(deathTime); 144 | } 145 | } 146 | } 147 | 148 | getRiotIdGameName() { 149 | return this.riotIdGameName; 150 | } 151 | })(); 152 | --------------------------------------------------------------------------------