diff --git a/packages/common/src/library/libraries/abstracts/index.ts b/packages/common/src/library/libraries/abstracts/index.ts index bd509189..7d2d8a10 100644 --- a/packages/common/src/library/libraries/abstracts/index.ts +++ b/packages/common/src/library/libraries/abstracts/index.ts @@ -1,4 +1,5 @@ export { BaseAssetManagerLibrary } from "./asset-manager.library.abstract"; export { BaseComponentSystemLibrary } from "./component-system.library.abstract"; export { BaseGraphicsLibrary } from "./graphics.library.abstract"; +export { BaseInputLibrary } from "./input.library.abstract"; export { BaseNetworkLibrary } from "./network.library.abstract"; diff --git a/packages/common/src/library/libraries/abstracts/input.library.abstract.ts b/packages/common/src/library/libraries/abstracts/input.library.abstract.ts new file mode 100644 index 00000000..afa8a19e --- /dev/null +++ b/packages/common/src/library/libraries/abstracts/input.library.abstract.ts @@ -0,0 +1,7 @@ +import { type InitContext } from "../../../context"; +import { type IInputLibrary } from "../interfaces"; +import { Library } from "../library"; + +export abstract class BaseInputLibrary extends Library implements IInputLibrary { + public abstract init(context: InitContext): Promise; +} diff --git a/packages/common/src/library/libraries/consts/library-label.const.ts b/packages/common/src/library/libraries/consts/library-label.const.ts index 581e577d..0e487ffb 100644 --- a/packages/common/src/library/libraries/consts/library-label.const.ts +++ b/packages/common/src/library/libraries/consts/library-label.const.ts @@ -2,3 +2,4 @@ export const COMPONENT_SYSTEM_LIBRARY = Symbol("COMPONENT_SYSTEM_LIBRARY"); export const GRAPHICS_LIBRARY = Symbol("GRAPHICS_LIBRARY"); export const NETWORK_LIBRARY = Symbol("NETWORK_LIBRARY"); export const ASSET_MANAGER_LIBRARY = Symbol("ASSET_MANAGER_LIBRARY"); +export const INPUT_LIBRARY = Symbol("INPUT_LIBRARY"); diff --git a/packages/common/src/library/libraries/interfaces/finals/input.library.type.ts b/packages/common/src/library/libraries/interfaces/finals/input.library.type.ts new file mode 100644 index 00000000..596a519b --- /dev/null +++ b/packages/common/src/library/libraries/interfaces/finals/input.library.type.ts @@ -0,0 +1,3 @@ +import { type IExposedLibrary } from "../bases/exposed.library.type"; + +export interface IInputLibrary extends IExposedLibrary {} diff --git a/packages/common/src/library/libraries/interfaces/index.ts b/packages/common/src/library/libraries/interfaces/index.ts index 1f1aea24..50807a1b 100644 --- a/packages/common/src/library/libraries/interfaces/index.ts +++ b/packages/common/src/library/libraries/interfaces/index.ts @@ -3,4 +3,5 @@ export { IRunnerLibrary } from "./bases/runner.library.type"; export { IAssetManagerLibrary } from "./finals/asset-manager.library.type"; export { IComponentSystemLibrary } from "./finals/component-system.library.type"; export { IGraphicsLibrary } from "./finals/graphics.library.type"; +export { IInputLibrary } from "./finals/input.library.type"; export { INetworkLibrary } from "./finals/network.library.type"; diff --git a/packages/common/src/library/manager/managers/library.manager.ts b/packages/common/src/library/manager/managers/library.manager.ts index ab1ae5be..2aa8f01c 100644 --- a/packages/common/src/library/manager/managers/library.manager.ts +++ b/packages/common/src/library/manager/managers/library.manager.ts @@ -5,6 +5,7 @@ import { type IAssetManagerLibrary, type IComponentSystemLibrary, type IGraphicsLibrary, + type IInputLibrary, type INetworkLibrary, NETWORK_LIBRARY, } from "../../libraries"; @@ -13,6 +14,7 @@ import { BaseLibraryManager } from "./base-library.manager"; export enum DefaultLibrariesEnum { ASSET_MANAGER, + INPUT, COMPONENT_SYSTEM, NETWORK, GRAPHICS, @@ -48,6 +50,10 @@ export class LibraryManager extends BaseLibraryManager { return this._get(DefaultLibrariesEnum.NETWORK); } + public getInput(): LibraryHandle { + return this._get(DefaultLibrariesEnum.INPUT); + } + public getAssetManager< T extends IAssetManagerLibrary = IAssetManagerLibrary, >(): LibraryHandle { diff --git a/packages/core/src/application/application-config.ts b/packages/core/src/application/application-config.ts index 956eb3df..e29dbbd6 100644 --- a/packages/core/src/application/application-config.ts +++ b/packages/core/src/application/application-config.ts @@ -2,6 +2,7 @@ import { type IAssetManagerLibrary, type IComponentSystemLibrary, type IGraphicsLibrary, + type IInputLibrary, type ILibrary, type INetworkLibrary, type LibraryHandle, @@ -59,4 +60,12 @@ export class ApplicationConfig { public useAssetManagerLibrary(library: IAssetManagerLibrary) { this._libraryManager.setAssetManager(library); } + + public getInputLibrary() { + return this._libraryManager.getInput(); + } + + public useInputLibrary(library: IInputLibrary) { + this._libraryManager.setInput(library); + } } diff --git a/packages/core/src/application/nanoforge-client.ts b/packages/core/src/application/nanoforge-client.ts index 1f237e94..66d0534c 100644 --- a/packages/core/src/application/nanoforge-client.ts +++ b/packages/core/src/application/nanoforge-client.ts @@ -1,4 +1,4 @@ -import { type IGraphicsLibrary } from "@nanoforge/common"; +import { type IGraphicsLibrary, type IInputLibrary } from "@nanoforge/common"; import { NanoforgeApplication } from "./nanoforge-application"; @@ -6,4 +6,8 @@ export class NanoforgeClient extends NanoforgeApplication { public useGraphics(library: IGraphicsLibrary) { this.applicationConfig.useGraphicsLibrary(library); } + + public useInput(library: IInputLibrary) { + this.applicationConfig.useInputLibrary(library); + } } diff --git a/packages/core/src/common/library/manager/library.manager.ts b/packages/core/src/common/library/manager/library.manager.ts index 049846de..8f6090e7 100644 --- a/packages/core/src/common/library/manager/library.manager.ts +++ b/packages/core/src/common/library/manager/library.manager.ts @@ -6,7 +6,9 @@ import { type IAssetManagerLibrary, type IComponentSystemLibrary, type IGraphicsLibrary, + type IInputLibrary, type ILibrary, + INPUT_LIBRARY, type INetworkLibrary, type IRunnerLibrary, type LibraryHandle, @@ -52,6 +54,10 @@ export class EditableLibraryManager extends LibraryManager { this._set(DefaultLibrariesEnum.NETWORK, NETWORK_LIBRARY, library, new EditableLibraryContext()); } + public setInput(library: IInputLibrary): void { + this._set(DefaultLibrariesEnum.INPUT, INPUT_LIBRARY, library, new EditableLibraryContext()); + } + public getLibraries(): LibraryHandle[] { return this._libraries; } diff --git a/packages/input/.gitignore b/packages/input/.gitignore new file mode 100644 index 00000000..9f6061cc --- /dev/null +++ b/packages/input/.gitignore @@ -0,0 +1,272 @@ +### VisualStudioCode template +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +!.vscode/*.code-snippets + +# Local History for Visual Studio Code +.history/ + +# Built Visual Studio Code Extensions +*.vsix + +### C++ template +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app + +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### Node template +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) +web_modules/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional stylelint cache +.stylelintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variable files +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# parcel-bundler cache (https://parceljs.org/) +.cache +.parcel-cache + +# Next.js build output +.next +out + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and not Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# vuepress v2.x temp and cache directory +.temp +.cache + +# Docusaurus cache and generated files +.docusaurus + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port + +# Stores VSCode versions used for testing VSCode extensions +.vscode-test + +# yarn v2 +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* + +### Private + +# NX +.nx/ + +# Compiled files +src/**/*.js +src/**/*.d.ts + +# pubilc directory +public/ +compile_commands.json +emsdk/ diff --git a/packages/input/.idea/.gitignore b/packages/input/.idea/.gitignore new file mode 100644 index 00000000..13566b81 --- /dev/null +++ b/packages/input/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/packages/input/.idea/.name b/packages/input/.idea/.name new file mode 100644 index 00000000..c81648b1 --- /dev/null +++ b/packages/input/.idea/.name @@ -0,0 +1 @@ +[NanoForge] Engine Input \ No newline at end of file diff --git a/packages/input/.idea/[NanoForge] Engine Input.iml b/packages/input/.idea/[NanoForge] Engine Input.iml new file mode 100644 index 00000000..24643cc3 --- /dev/null +++ b/packages/input/.idea/[NanoForge] Engine Input.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/input/.idea/codeStyles/Project.xml b/packages/input/.idea/codeStyles/Project.xml new file mode 100644 index 00000000..a57ead77 --- /dev/null +++ b/packages/input/.idea/codeStyles/Project.xml @@ -0,0 +1,172 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/input/.idea/codeStyles/codeStyleConfig.xml b/packages/input/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 00000000..79ee123c --- /dev/null +++ b/packages/input/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/packages/input/.idea/editor.xml b/packages/input/.idea/editor.xml new file mode 100644 index 00000000..d9ec4dfd --- /dev/null +++ b/packages/input/.idea/editor.xml @@ -0,0 +1,106 @@ + + + + + \ No newline at end of file diff --git a/packages/input/.idea/git_toolbox_blame.xml b/packages/input/.idea/git_toolbox_blame.xml new file mode 100644 index 00000000..7dc12496 --- /dev/null +++ b/packages/input/.idea/git_toolbox_blame.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/packages/input/.idea/git_toolbox_prj.xml b/packages/input/.idea/git_toolbox_prj.xml new file mode 100644 index 00000000..02b915b8 --- /dev/null +++ b/packages/input/.idea/git_toolbox_prj.xml @@ -0,0 +1,15 @@ + + + + + + + \ No newline at end of file diff --git a/packages/input/.idea/inspectionProfiles/Project_Default.xml b/packages/input/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 00000000..41ec19c1 --- /dev/null +++ b/packages/input/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,12 @@ + + + + \ No newline at end of file diff --git a/packages/input/.idea/jsLinters/eslint.xml b/packages/input/.idea/jsLinters/eslint.xml new file mode 100644 index 00000000..541945bb --- /dev/null +++ b/packages/input/.idea/jsLinters/eslint.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/packages/input/.idea/misc.xml b/packages/input/.idea/misc.xml new file mode 100644 index 00000000..7ecbce57 --- /dev/null +++ b/packages/input/.idea/misc.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/input/.idea/modules.xml b/packages/input/.idea/modules.xml new file mode 100644 index 00000000..d1ef2191 --- /dev/null +++ b/packages/input/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/packages/input/.idea/prettier.xml b/packages/input/.idea/prettier.xml new file mode 100644 index 00000000..0c83ac4e --- /dev/null +++ b/packages/input/.idea/prettier.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/packages/input/.idea/vcs.xml b/packages/input/.idea/vcs.xml new file mode 100644 index 00000000..b2bdec2d --- /dev/null +++ b/packages/input/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/packages/input/.nvmrc b/packages/input/.nvmrc new file mode 100644 index 00000000..c9758a53 --- /dev/null +++ b/packages/input/.nvmrc @@ -0,0 +1 @@ +v23.6.0 diff --git a/packages/input/.prettierignore b/packages/input/.prettierignore new file mode 100644 index 00000000..e814a634 --- /dev/null +++ b/packages/input/.prettierignore @@ -0,0 +1,8 @@ +# Ignore files for PNPM, NPM and YARN +pnpm-lock.yaml +package-lock.json +yarn.lock +bun.lock + +*.js +*.d.ts diff --git a/packages/input/.prettierrc b/packages/input/.prettierrc new file mode 100644 index 00000000..d5f635c3 --- /dev/null +++ b/packages/input/.prettierrc @@ -0,0 +1,11 @@ +{ + "plugins": ["@trivago/prettier-plugin-sort-imports"], + "importOrderSeparation": true, + "importOrderSortSpecifiers": true, + "importOrderParserPlugins": ["typescript", "decorators-legacy"], + "importOrder": ["^~/(.*)$", "^[./]"], + "useTabs": false, + "singleQuote": false, + "trailingComma": "all", + "printWidth": 100 +} diff --git a/packages/input/README.md b/packages/input/README.md new file mode 100644 index 00000000..33e4d472 --- /dev/null +++ b/packages/input/README.md @@ -0,0 +1 @@ +# Engine Input diff --git a/packages/input/eslint.config.js b/packages/input/eslint.config.js new file mode 100644 index 00000000..4a7529ef --- /dev/null +++ b/packages/input/eslint.config.js @@ -0,0 +1,63 @@ +import pluginJs from "@eslint/js"; +import eslintConfigPrettier from "eslint-config-prettier"; +import globals from "globals"; +import tseslint from "typescript-eslint"; +import pluginJest from "eslint-plugin-jest"; + +export default [ + { + files: ["src/**/*.{ts}"], + }, + { languageOptions: { globals: globals.node } }, + + + pluginJs.configs.recommended, + ...tseslint.configs.recommended, + ...tseslint.configs.strict, + eslintConfigPrettier, + { ignores: ["**/*.js"] }, + { + rules: { + "@typescript-eslint/consistent-type-imports": [ + "error", + { + disallowTypeAnnotations: true, + fixStyle: "inline-type-imports", + prefer: "type-imports", + }, + ], + "@typescript-eslint/no-extraneous-class": "off", + "@typescript-eslint/no-empty-object-type": "off", + "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/ban-ts-comment": "off", + "@typescript-eslint/member-ordering": [ + "error", + { + default: [ + "static-field", + "field", + "public-static-method", + "constructor", + "method", + "protected-method", + "private-method", + ], + }, + ], + }, + }, + { + files: ["**/*.spec.ts"], + plugins: { jest: pluginJest }, + languageOptions: { + globals: pluginJest.environments.globals.globals, + }, + rules: { + "jest/no-disabled-tests": "warn", + "jest/no-focused-tests": "error", + "jest/no-identical-title": "error", + "jest/prefer-to-have-length": "warn", + "jest/valid-expect": "error", + } + } +]; diff --git a/packages/input/package.json b/packages/input/package.json new file mode 100644 index 00000000..087a9862 --- /dev/null +++ b/packages/input/package.json @@ -0,0 +1,64 @@ +{ + "name": "@nanoforge/input", + "version": "1.0.0", + "description": "NanoForge Engine - Input", + "homepage": "https://github.com/NanoForge-dev/Engine#readme", + "license": "MIT", + "contributors": [ + "Bill", + "Exelo", + "Fexkoser", + "Tchips" + ], + "funding": { + "type": "individual", + "url": "" + }, + "type": "module", + "main": "src/index.ts", + "repository": { + "type": "git", + "url": "git+https://github.com/NanoForge-dev/Engine.git", + "directory": "packages/input" + }, + "scripts": { + "build": "tsc -b .", + "clean": "pnpm clean:types && pnpm clean:scripts && rm -f tsconfig.build.tsbuildinfo", + "clean:types": "find src -name '*.d.ts' -delete", + "clean:scripts": "find src -name '*.js' -delete", + "lint": "eslint . && prettier --check .", + "fix": "eslint . --fix && prettier --write .", + "taze": "taze major -w", + "lint-staged": "lint-staged" + }, + "dependencies": { + "@nanoforge/common": "workspace:^" + }, + "devDependencies": { + "@commitlint/cli": "^19.8.0", + "@commitlint/config-conventional": "^19.8.0", + "@eslint/js": "^9.22.0", + "@trivago/prettier-plugin-sort-imports": "^5.2.2", + "@types/node": "^22.13.10", + "eslint": "^9.22.0", + "eslint-config-prettier": "^10.1.1", + "eslint-plugin-format": "^1.0.1", + "eslint-plugin-jest": "^28.11.0", + "eslint-plugin-prettier": "^5.2.3", + "globals": "^16.0.0", + "lint-staged": "^15.4.3", + "prettier": "^3.5.3", + "typescript": "^5.8.2", + "typescript-eslint": "^8.26.0" + }, + "engines": { + "node": "23.6.0", + "pnpm": "10.6.2" + }, + "lint-staged": { + "**/*.{js,ts}": [ + "eslint --fix", + "prettier --write" + ] + } +} diff --git a/packages/input/src/index.ts b/packages/input/src/index.ts new file mode 100644 index 00000000..7d7f3d59 --- /dev/null +++ b/packages/input/src/index.ts @@ -0,0 +1,2 @@ +export { InputLibrary } from "./input.library"; +export { InputEnum } from "./input.enum"; diff --git a/packages/input/src/input-handler.ts b/packages/input/src/input-handler.ts new file mode 100644 index 00000000..56416b01 --- /dev/null +++ b/packages/input/src/input-handler.ts @@ -0,0 +1,19 @@ +import { type InputEnum } from "./input.enum"; + +export class InputHandler { + public inputs: Record = {}; + + constructor() { + window.addEventListener("keydown", (e: KeyboardEvent) => { + this.inputs[e.code] = true; + }); + + window.addEventListener("keyup", (e: KeyboardEvent) => { + this.inputs[e.code] = false; + }); + } + + getKeyStatus(key: InputEnum): boolean { + return this.inputs[key]; + } +} diff --git a/packages/input/src/input.enum.ts b/packages/input/src/input.enum.ts new file mode 100644 index 00000000..cb1899c7 --- /dev/null +++ b/packages/input/src/input.enum.ts @@ -0,0 +1,144 @@ +export enum InputEnum { + Escape = "Escape", + Digit1 = "Digit1", + Digit2 = "Digit2", + Digit3 = "Digit3", + Digit4 = "Digit4", + Digit5 = "Digit5", + Digit6 = "Digit6", + Digit7 = "Digit7", + Digit8 = "Digit8", + Digit9 = "Digit9", + Digit0 = "Digit0", + Minus = "Minus", + Equal = "Equal", + Backspace = "Backspace", + Tab = "Tab", + KeyQ = "KeyQ", + KeyW = "KeyW", + KeyE = "KeyE", + KeyR = "KeyR", + KeyT = "KeyT", + KeyY = "KeyY", + KeyU = "KeyU", + KeyI = "KeyI", + KeyO = "KeyO", + KeyP = "KeyP", + BracketLeft = "BracketLeft", + BracketRight = "BracketRight", + Enter = "Enter", + ControlLeft = "ControlLeft", + KeyA = "KeyA", + KeyS = "KeyS", + KeyD = "KeyD", + KeyF = "KeyF", + KeyG = "KeyG", + KeyH = "KeyH", + KeyJ = "KeyJ", + KeyK = "KeyK", + KeyL = "KeyL", + Semicolon = "Semicolon", + Quote = "Quote", + Backquote = "Backquote", + ShiftLeft = "ShiftLeft", + Backslash = "Backslash", + KeyZ = "KeyZ", + KeyX = "KeyX", + KeyC = "KeyC", + KeyV = "KeyV", + KeyB = "KeyB", + KeyN = "KeyN", + KeyM = "KeyM", + Comma = "Comma", + Period = "Period", + Slash = "Slash", + ShiftRight = "ShiftRight", + NumpadMultiply = "NumpadMultiply", + AltLeft = "AltLeft", + Space = "Space", + CapsLock = "CapsLock", + F1 = "F1", + F2 = "F2", + F3 = "F3", + F4 = "F4", + F5 = "F5", + F6 = "F6", + F7 = "F7", + F8 = "F8", + F9 = "F9", + F10 = "F10", + Pause = "Pause", + ScrollLock = "ScrollLock", + Numpad7 = "Numpad7", + Numpad8 = "Numpad8", + Numpad9 = "Numpad9", + NumpadSubtract = "NumpadSubtract", + Numpad4 = "Numpad4", + Numpad5 = "Numpad5", + Numpad6 = "Numpad6", + NumpadAdd = "NumpadAdd", + Numpad1 = "Numpad1", + Numpad2 = "Numpad2", + Numpad3 = "Numpad3", + Numpad0 = "Numpad0", + NumpadDecimal = "NumpadDecimal", + IntlBackslash = "IntlBackslash", + F11 = "F11", + F12 = "F12", + NumpadEqual = "NumpadEqual", + F13 = "F13", + F14 = "F14", + F15 = "F15", + F16 = "F16", + F17 = "F17", + F18 = "F18", + F19 = "F19", + F20 = "F20", + F21 = "F21", + F22 = "F22", + F23 = "F23", + KanaMode = "KanaMode", + Lang2 = "Lang2", + Lang1 = "Lang1", + IntlRo = "IntlRo", + F24 = "F24", + Convert = "Convert", + NonConvert = "NonConvert", + IntlYen = "IntlYen", + NumpadComma = "NumpadComma", + MediaTrackPrevious = "MediaTrackPrevious", + MediaTrackNext = "MediaTrackNext", + NumpadEnter = "NumpadEnter", + ControlRight = "ControlRight", + AudioVolumeMute = "AudioVolumeMute", + LaunchApp2 = "LaunchApp2", + MediaPlayPause = "MediaPlayPause", + MediaStop = "MediaStop", + BrowserHome = "BrowserHome", + NumpadDivide = "NumpadDivide", + PrintScreen = "PrintScreen", + AltRight = "AltRight", + NumLock = "NumLock", + Home = "Home", + ArrowUp = "ArrowUp", + PageUp = "PageUp", + ArrowLeft = "ArrowLeft", + ArrowRight = "ArrowRight", + End = "End", + ArrowDown = "ArrowDown", + PageDown = "PageDown", + Insert = "Insert", + Delete = "Delete", + MetaLeft = "MetaLeft", + MetaRight = "MetaRight", + ContextMenu = "ContextMenu", + Power = "Power", + BrowserSearch = "BrowserSearch", + BrowserFavorites = "BrowserFavorites", + BrowserRefresh = "BrowserRefresh", + BrowserStop = "BrowserStop", + BrowserForward = "BrowserForward", + BrowserBack = "BrowserBack", + LaunchApp1 = "LaunchApp1", + LaunchMail = "LaunchMail", +} diff --git a/packages/input/src/input.library.ts b/packages/input/src/input.library.ts new file mode 100644 index 00000000..a06e3737 --- /dev/null +++ b/packages/input/src/input.library.ts @@ -0,0 +1,29 @@ +import { BaseInputLibrary } from "@nanoforge/common"; + +import { InputHandler } from "./input-handler"; +import { type InputEnum } from "./input.enum"; + +export class InputLibrary extends BaseInputLibrary { + private _inputHandler: InputHandler; + + get name(): string { + return "InputLibrary"; + } + + public async init(): Promise { + this._inputHandler = new InputHandler(); + } + + public isKeyPressed(key: InputEnum): boolean { + return this._inputHandler.getKeyStatus(key); + } + + public getPressedKeys(): InputEnum[] { + const res: InputEnum[] = []; + for (const rawKey in this._inputHandler.inputs) { + const key = rawKey as InputEnum; + if (this._inputHandler.getKeyStatus(key)) res.push(key); + } + return res; + } +} diff --git a/packages/input/tsconfig.build.json b/packages/input/tsconfig.build.json new file mode 100644 index 00000000..a7e09c73 --- /dev/null +++ b/packages/input/tsconfig.build.json @@ -0,0 +1,16 @@ +{ + "extends": "../tsconfig.build.json", + "compilerOptions": { + "outDir": ".", + "rootDir": ".", + "paths": { + "@nanoforge/common": ["../common"] + } + }, + "exclude": ["node_modules", "dist", "test/**/*", "*.spec.ts"], + "references": [ + { + "path": "../common/tsconfig.build.json" + } + ] +} diff --git a/packages/input/tsconfig.json b/packages/input/tsconfig.json new file mode 100644 index 00000000..a74c8e2d --- /dev/null +++ b/packages/input/tsconfig.json @@ -0,0 +1,13 @@ +{ + "extends": "../tsconfig.build.json", + "compilerOptions": { + "types": ["jest", "node"] + }, + "files": [], + "include": [], + "references": [ + { + "path": "./tsconfig.build.json" + } + ] +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d277974e..86245707 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -328,6 +328,58 @@ importers: specifier: ^8.26.0 version: 8.26.1(eslint@9.22.0(jiti@2.4.2))(typescript@5.8.2) + packages/input: + dependencies: + '@nanoforge/common': + specifier: workspace:^ + version: link:../common + devDependencies: + '@commitlint/cli': + specifier: ^19.8.0 + version: 19.8.0(@types/node@22.13.10)(typescript@5.8.2) + '@commitlint/config-conventional': + specifier: ^19.8.0 + version: 19.8.0 + '@eslint/js': + specifier: ^9.22.0 + version: 9.22.0 + '@trivago/prettier-plugin-sort-imports': + specifier: ^5.2.2 + version: 5.2.2(prettier@3.5.3) + '@types/node': + specifier: ^22.13.10 + version: 22.13.10 + eslint: + specifier: ^9.22.0 + version: 9.22.0(jiti@2.4.2) + eslint-config-prettier: + specifier: ^10.1.1 + version: 10.1.1(eslint@9.22.0(jiti@2.4.2)) + eslint-plugin-format: + specifier: ^1.0.1 + version: 1.0.1(eslint@9.22.0(jiti@2.4.2)) + eslint-plugin-jest: + specifier: ^28.11.0 + version: 28.11.0(@typescript-eslint/eslint-plugin@8.26.1(@typescript-eslint/parser@8.26.1(eslint@9.22.0(jiti@2.4.2))(typescript@5.8.2))(eslint@9.22.0(jiti@2.4.2))(typescript@5.8.2))(eslint@9.22.0(jiti@2.4.2))(jest@29.7.0(@types/node@22.13.10))(typescript@5.8.2) + eslint-plugin-prettier: + specifier: ^5.2.3 + version: 5.2.3(eslint-config-prettier@10.1.1(eslint@9.22.0(jiti@2.4.2)))(eslint@9.22.0(jiti@2.4.2))(prettier@3.5.3) + globals: + specifier: ^16.0.0 + version: 16.0.0 + lint-staged: + specifier: ^15.4.3 + version: 15.4.3 + prettier: + specifier: ^3.5.3 + version: 3.5.3 + typescript: + specifier: ^5.8.2 + version: 5.8.2 + typescript-eslint: + specifier: ^8.26.0 + version: 8.26.1(eslint@9.22.0(jiti@2.4.2))(typescript@5.8.2) + packages: '@ampproject/remapping@2.3.0':