From 02a108f98388cc75039d4ad3ab3e2e2fbc89089c Mon Sep 17 00:00:00 2001 From: Pandipipas Date: Sat, 23 May 2026 21:52:07 +0200 Subject: [PATCH] refactor: architecture base - Moved NodeCG context management to a dedicated context module. - Introduced message handling utilities for better message listening and sending. - Updated startgg integration to use new message handling methods. - Removed deprecated replicant utilities and replaced them with a new structure. - Refactored replicant imports in graphics components to align with new structure. - Added new pack-related types and schemas for better type safety. - Cleaned up unused files and consolidated pack configuration into a single module. - Updated TypeScript configurations to reflect new directory structure. --- .gitignore | 4 +- docs/refactor/PHASE_1_SUMMARY.md | 56 ++++++++++++ package.json | 2 +- schemas/availableUpdates.json | 18 ++++ schemas/downloadStates.json | 22 +++++ schemas/exampleReplicant.json | 14 --- schemas/installedPacks.json | 8 ++ schemas/packRegistry.json | 50 ++++++++++ src/browser_shared/replicants.ts | 17 ---- .../scoreko-dev/components/BracketPanel.vue | 4 +- .../components/CommentaryPanel.vue | 4 +- .../components/GamePackDownloadDialog.vue | 4 +- .../components/PlayerSidePanel.vue | 2 +- .../components/ScoreCenterPanel.vue | 6 +- .../composables/useCharacterGame.ts | 4 +- .../composables/useCountryFilter.ts | 2 +- .../scoreko-dev/composables/useIntegration.ts | 20 +--- .../composables/usePackRegistry.ts | 81 +++++------------ .../scoreko-dev/composables/usePlayerSide.ts | 6 +- src/dashboard/scoreko-dev/main.vue | 6 +- src/dashboard/scoreko-dev/views/Graphics.vue | 4 +- src/dashboard/scoreko-dev/views/Players.vue | 13 ++- src/dashboard/scoreko-dev/views/Settings.vue | 4 +- .../{scoreko-dev => }/stores/commentary.ts | 4 +- .../{scoreko-dev => }/stores/players.ts | 4 +- .../{scoreko-dev => }/stores/scoreboard.ts | 4 +- .../stores/shortcut-settings.ts | 0 .../{scoreko-dev => }/stores/store-sync.ts | 0 src/extension/challonge.ts | 13 ++- src/extension/example.ts | 15 --- src/extension/index.ts | 7 +- src/extension/modules/replicants.ts | 9 ++ src/extension/pack-manager.ts | 91 ++++--------------- src/extension/startgg.ts | 13 ++- src/extension/util/nodecg.ts | 7 -- src/extension/util/replicants.ts | 31 ------- src/graphics/commentary/main.vue | 2 +- src/graphics/scoreboard-2xko/main.vue | 4 +- src/graphics/scoreboard/main.vue | 4 +- src/nodecg/browser/messages.ts | 13 +++ src/nodecg/browser/packReplicants.ts | 52 +++++++++++ src/nodecg/browser/replicants.ts | 24 +++++ src/nodecg/extension/context.ts | 26 ++++++ src/nodecg/extension/messages.ts | 26 ++++++ src/nodecg/extension/packReplicants.ts | 36 ++++++++ src/nodecg/extension/replicants.ts | 32 +++++++ src/nodecg/messageNames.ts | 28 ++++++ src/nodecg/replicantNames.ts | 12 +++ src/shared/domain/packs/config.ts | 25 +++++ src/shared/domain/packs/index.ts | 2 + src/shared/domain/packs/types.ts | 59 ++++++++++++ src/shared/{ => domain/players}/countries.ts | 4 +- src/shared/fighting-characters.ts | 2 +- src/shared/pack-config.js | 37 -------- src/shared/pack-config.ts | 54 ----------- src/shared/pack-types.js | 6 -- src/shared/pack-types.ts | 89 ------------------ src/types/ExampleType.d.ts | 3 - src/types/index.d.ts | 1 - src/types/schemas.d.ts | 5 +- src/types/schemas/availableUpdates.d.ts | 14 +++ src/types/schemas/configschema.d.ts | 5 +- src/types/schemas/downloadStates.d.ts | 15 +++ ...mpleReplicant.d.ts => installedPacks.d.ts} | 4 +- src/types/schemas/packRegistry.d.ts | 25 +++++ tsconfig.browser.json | 5 +- tsconfig.extension.json | 6 +- 67 files changed, 687 insertions(+), 482 deletions(-) create mode 100644 docs/refactor/PHASE_1_SUMMARY.md create mode 100644 schemas/availableUpdates.json create mode 100644 schemas/downloadStates.json delete mode 100644 schemas/exampleReplicant.json create mode 100644 schemas/installedPacks.json create mode 100644 schemas/packRegistry.json delete mode 100644 src/browser_shared/replicants.ts rename src/dashboard/{scoreko-dev => }/stores/commentary.ts (95%) rename src/dashboard/{scoreko-dev => }/stores/players.ts (94%) rename src/dashboard/{scoreko-dev => }/stores/scoreboard.ts (97%) rename src/dashboard/{scoreko-dev => }/stores/shortcut-settings.ts (100%) rename src/dashboard/{scoreko-dev => }/stores/store-sync.ts (100%) delete mode 100644 src/extension/example.ts create mode 100644 src/extension/modules/replicants.ts delete mode 100644 src/extension/util/nodecg.ts delete mode 100644 src/extension/util/replicants.ts create mode 100644 src/nodecg/browser/messages.ts create mode 100644 src/nodecg/browser/packReplicants.ts create mode 100644 src/nodecg/browser/replicants.ts create mode 100644 src/nodecg/extension/context.ts create mode 100644 src/nodecg/extension/messages.ts create mode 100644 src/nodecg/extension/packReplicants.ts create mode 100644 src/nodecg/extension/replicants.ts create mode 100644 src/nodecg/messageNames.ts create mode 100644 src/nodecg/replicantNames.ts create mode 100644 src/shared/domain/packs/config.ts create mode 100644 src/shared/domain/packs/index.ts create mode 100644 src/shared/domain/packs/types.ts rename src/shared/{ => domain/players}/countries.ts (92%) delete mode 100644 src/shared/pack-config.js delete mode 100644 src/shared/pack-config.ts delete mode 100644 src/shared/pack-types.js delete mode 100644 src/shared/pack-types.ts delete mode 100644 src/types/ExampleType.d.ts create mode 100644 src/types/schemas/availableUpdates.d.ts create mode 100644 src/types/schemas/downloadStates.d.ts rename src/types/schemas/{exampleReplicant.d.ts => installedPacks.d.ts} (80%) create mode 100644 src/types/schemas/packRegistry.d.ts diff --git a/.gitignore b/.gitignore index 206cd56..2144e24 100644 --- a/.gitignore +++ b/.gitignore @@ -136,10 +136,12 @@ dist /dashboard/ /extension/ /graphics/ +/nodecg/ +/shared/domain/ /shared/dist/ # Local runtime database /db/ *.sqlite3 /scoreko-electron-dev/ -/packs/ \ No newline at end of file +/packs/ diff --git a/docs/refactor/PHASE_1_SUMMARY.md b/docs/refactor/PHASE_1_SUMMARY.md new file mode 100644 index 0000000..74228f0 --- /dev/null +++ b/docs/refactor/PHASE_1_SUMMARY.md @@ -0,0 +1,56 @@ +# Phase 1 Summary + +## Scope + +Executed the base architecture phase only. This phase focused on structure, boundaries, shared contracts and compatibility without changing UX, overlay visuals or large feature logic. + +## Completed + +- Added the `src/nodecg` boundary: + - `src/nodecg/browser` + - `src/nodecg/extension` + - centralized `replicantNames` + - centralized `messageNames` +- Moved browser replicant access out of `src/browser_shared`. +- Moved dashboard stores to `src/dashboard/stores`. +- Moved pure country helpers to `src/shared/domain/players`. +- Moved pack config and pack types to `src/shared/domain/packs`. +- Added pack replicant schemas: + - `installedPacks` + - `packRegistry` + - `downloadStates` + - `availableUpdates` +- Added generated TypeScript declarations for the new pack schemas. +- Removed dead example code: + - `exampleReplicant` schema/type + - `ExampleType` + - `src/extension/example.ts` +- Removed redundant stale JS files from `src/shared`. +- Updated extension bootstrap to use an explicit NodeCG context boundary. +- Routed browser messages through `src/nodecg/browser/messages.ts`. +- Routed extension message registration through `src/nodecg/extension/messages.ts`. +- Routed pack replicant creation through NodeCG pack boundary services. +- Updated build config so generated NodeCG/shared extension outputs are ignored and cleaned. + +## Preserved + +- No overlay UX, CSS, SVG, layout or animation logic was intentionally changed. +- No large dashboard view was split or rewritten. +- `pack-manager.ts` behavior was preserved; only imports, types, replicant/message names and boundaries were normalized. +- Public NodeCG message names were kept unchanged for compatibility. +- Public replicant names and defaults were kept unchanged. + +## Verification + +- `pnpm.cmd exec vue-tsc -p tsconfig.browser.json --noEmit`: passed. +- `pnpm.cmd exec tsc -b tsconfig.extension.json --pretty false`: passed. +- `pnpm.cmd exec eslint`: passed with 0 errors and existing Vue formatting warnings. +- `pnpm.cmd run build`: passed. + +## Remaining For Later Phases + +- Controlled rewrite of `pack-manager.ts`. +- Controlled rewrite of `usePackRegistry` and `fighting-characters.ts`. +- Formal provider module split for Start.gg and Challonge. +- Splitting `Players.vue` and `Settings.vue`. +- Overlay view models and visual baseline work. diff --git a/package.json b/package.json index 48f6928..123162f 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "type": "module", "scripts": { "autofix": "eslint --fix", - "prebuild": "trash ./extension && trash ./node_modules/.vite && trash ./shared/dist && trash ./dashboard && trash ./graphics", + "prebuild": "trash ./extension && trash ./nodecg && trash ./node_modules/.vite && trash ./shared/domain && trash ./shared/dist && trash ./dashboard && trash ./graphics", "build": "vite build && tsc -b tsconfig.extension.json", "lint": "eslint", "schema-types": "nodecg schema-types", diff --git a/schemas/availableUpdates.json b/schemas/availableUpdates.json new file mode 100644 index 0000000..d50c50d --- /dev/null +++ b/schemas/availableUpdates.json @@ -0,0 +1,18 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "additionalProperties": { + "type": "object", + "additionalProperties": false, + "properties": { + "installedVersion": { + "type": "string" + }, + "latestVersion": { + "type": "string" + } + }, + "required": ["installedVersion", "latestVersion"] + }, + "default": {} +} diff --git a/schemas/downloadStates.json b/schemas/downloadStates.json new file mode 100644 index 0000000..cc54f7f --- /dev/null +++ b/schemas/downloadStates.json @@ -0,0 +1,22 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "additionalProperties": { + "type": "object", + "additionalProperties": false, + "properties": { + "status": { + "type": "string", + "enum": ["idle", "fetching-manifest", "downloading", "done", "error"] + }, + "progress": { + "type": "number" + }, + "error": { + "type": "string" + } + }, + "required": ["status", "progress"] + }, + "default": {} +} diff --git a/schemas/exampleReplicant.json b/schemas/exampleReplicant.json deleted file mode 100644 index 55d7423..0000000 --- a/schemas/exampleReplicant.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "object", - "additionalProperties": false, - "properties": { - "exampleProperty": { - "type": "string", - "default": "exampleString" - } - }, - "required": [ - "exampleProperty" - ] -} diff --git a/schemas/installedPacks.json b/schemas/installedPacks.json new file mode 100644 index 0000000..d2da904 --- /dev/null +++ b/schemas/installedPacks.json @@ -0,0 +1,8 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "array", + "items": { + "type": "string" + }, + "default": [] +} diff --git a/schemas/packRegistry.json b/schemas/packRegistry.json new file mode 100644 index 0000000..cda76e7 --- /dev/null +++ b/schemas/packRegistry.json @@ -0,0 +1,50 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": ["object", "null"], + "additionalProperties": false, + "properties": { + "schemaVersion": { + "type": "integer" + }, + "updatedAt": { + "type": "string" + }, + "packs": { + "type": "array", + "items": { + "type": "object", + "additionalProperties": false, + "properties": { + "id": { "type": "string" }, + "name": { "type": "string" }, + "version": { "type": "string" }, + "totalSizeBytes": { "type": "number" }, + "logoPath": { "type": "string" }, + "characterCount": { "type": "integer" }, + "palette": { + "type": "object", + "additionalProperties": false, + "properties": { + "start": { "type": "string" }, + "end": { "type": "string" } + }, + "required": ["start", "end"] + }, + "bundled": { "type": "boolean" } + }, + "required": [ + "id", + "name", + "version", + "totalSizeBytes", + "logoPath", + "characterCount", + "palette", + "bundled" + ] + } + } + }, + "required": ["schemaVersion", "updatedAt", "packs"], + "default": null +} diff --git a/src/browser_shared/replicants.ts b/src/browser_shared/replicants.ts deleted file mode 100644 index a161499..0000000 --- a/src/browser_shared/replicants.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { useReplicant } from 'nodecg-vue-composable'; -import type { Schemas } from '../types'; - -// YOU MUST CHANGE THIS TO YOUR BUNDLE'S NAME! -const thisBundle = 'scoreko-dev'; - -/** - * This is where you can declare all of your replicants to import easily into other (browser based) files. - * "useReplicant" is a helper composable to make accessing/modifying replicants easier. - * For more information see https://github.com/Dan-Shields/nodecg-vue-composable - */ -export const exampleReplicant = useReplicant('exampleReplicant', thisBundle); -export const playersReplicant = useReplicant('players', thisBundle); -export const scoreboardReplicant = useReplicant('scoreboard', thisBundle); -export const graphicsSettingsReplicant = useReplicant('graphicsSettings', thisBundle); - -export const commentaryReplicant = useReplicant('commentary', thisBundle); diff --git a/src/dashboard/scoreko-dev/components/BracketPanel.vue b/src/dashboard/scoreko-dev/components/BracketPanel.vue index 5ab69fe..cec2943 100644 --- a/src/dashboard/scoreko-dev/components/BracketPanel.vue +++ b/src/dashboard/scoreko-dev/components/BracketPanel.vue @@ -1,7 +1,7 @@