diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4120ae2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +# VSC +.vscode + +# Pipeline +dist/js +build diff --git a/dist/home_overlay.html b/dist/home_overlay.html new file mode 100644 index 0000000..cab4dea --- /dev/null +++ b/dist/home_overlay.html @@ -0,0 +1,12 @@ + + + + + + Home Overlay + + + + + + \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..6c86fce --- /dev/null +++ b/package.json @@ -0,0 +1,11 @@ +{ + "name": "undefined-tv", + "version": "0.0.1", + "description": "", + "scripts": { + "build": "webpack" + }, + "keywords": [], + "author": "Sunpy", + "license": "GPL 3.0" +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..2e6182d --- /dev/null +++ b/src/index.ts @@ -0,0 +1,8 @@ +import { InputHandler } from "./inputManager"; + +const inputHandler: InputHandler = InputHandler.getInstance(); + +function test(e: KeyboardEvent) { + console.log(e); +} +inputHandler.addHandler(test); \ No newline at end of file diff --git a/src/inputManager.ts b/src/inputManager.ts new file mode 100644 index 0000000..1d777b6 --- /dev/null +++ b/src/inputManager.ts @@ -0,0 +1,47 @@ +export class InputHandler { + private static instance: InputHandler; + private handlers: { (e: KeyboardEvent): void; } [] = []; + private bound_onkeydown: { (e: KeyboardEvent): void; } = this.onkeydown.bind(this); + + private constructor() { + this.enable(); + } + + public enable = () => addEventListener("keydown", this.bound_onkeydown); + public disable = () => removeEventListener("keydown", this.bound_onkeydown); + + private onkeydown(e: KeyboardEvent) { + this.handlers.forEach(f => f(e)); + } + + public addHandler(handler: { (e: KeyboardEvent): void; }) { + if (this.handlers.indexOf(handler) !== -1) + return; + + this.handlers.push(handler); + } + + public removeHandler(handler: { (e: KeyboardEvent): void; }) { + this.handlers = this.handlers.filter(f => f !== handler); + } + + public static getInstance(): InputHandler { + if (!InputHandler.instance) + InputHandler.instance = new InputHandler(); + return InputHandler.instance; + } +} + +const KEYS_TV = { + PLAY: 80, + PAUSE: 81, + STOP: 83, + + RED: 116, + GREEN: 117, + YELLOW: 118, + BLUE: 119, + + FAST_FWD: 70, + REWIND: 82, +}; \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..a1522e0 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ES6", + "module": "ES6", + "esModuleInterop": true, + "experimentalDecorators": true, + "jsx": "preserve", + "strictFunctionTypes": true, + "sourceMap": true, + "removeComments": true, + "outDir": "./build/", + "lib": [ + "dom", + "es6" + ] + }, + "include": [ + "src/*.ts" + ], + "exclude": [ + "node_modules", + "**/node_modules/*" + ] +} \ No newline at end of file diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 0000000..e848c5e --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,24 @@ +const path = require('path'); +module.exports = { + watch: true, + devtool: 'inline-source-map', + entry: path.join(__dirname, 'build', 'index'), + module: { + rules: [ + { + test: /\.tsx?$/, + use: 'ts-loader', + exclude: '/node_modules/' + }, + ], + }, + resolve: { + extensions: ['.tsx', '.ts', '.js'], + }, + output: { + path: path.join(__dirname, 'dist', 'js'), + publicPath: '/dist/', + filename: "bundle.js", + chunkFilename: '[name].js' + } +}; \ No newline at end of file