Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ export * from './enums/tosu';
export * from './enums/country';

export * from './utils/config.types';
export * from './utils/config.schema';
export * from './overlay.types';
47 changes: 47 additions & 0 deletions packages/common/overlay.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
export type OverlayStatus = 'installed' | 'upgradable' | 'installable';

export interface OverlayAsset {
type: 'image' | 'video' | string;
url: string;
}

export interface RawRepositoryOverlay {
id: string;
name: string;
version: string;
author: string;
authorlinks?: string[];
compatiblewith?: string[];
usecase?: string[];
resolution?: string[];
notes?: string;
_settings?: boolean;
assets?: OverlayAsset[];
downloadLink?: string;
}

export interface OverlayAuthor {
name: string;
links: string[];
}

export interface OverlayResolution {
width: number | null;
height: number | null;
}

export interface Overlay {
id: string;
name: string;
version: string;
status: OverlayStatus;
author: OverlayAuthor;
url: string;
downloadUrl?: string;
resolution: OverlayResolution;
usecase: string[];
compatible: string[];
hasSettings: boolean;
notes: string;
assets: OverlayAsset[];
}
104 changes: 104 additions & 0 deletions packages/common/utils/config.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import type { ConfigBinding, ConfigSchema } from './config.types';

export const defaultSchema: ConfigSchema = {
enableAutoUpdate: {
binding: 'ENABLE_AUTOUPDATE',
default: true
},
openDashboardOnStartup: {
binding: 'OPEN_DASHBOARD_ON_STARTUP',
default: true
},
debugLog: {
binding: 'DEBUG_LOG',
default: false
},
calculatePP: {
binding: 'CALCULATE_PP',
default: true
},
enableKeyOverlay: {
binding: 'ENABLE_KEY_OVERLAY',
default: true
},
pollRate: {
binding: 'POLL_RATE',
default: 150,
min: 100
},
preciseDataPollRate: {
binding: 'PRECISE_DATA_POLL_RATE',
default: 10,
min: 1
},
showMpCommands: {
binding: 'SHOW_MP_COMMANDS',
default: false
},
readManiaScrollSpeed: {
binding: 'READ_MANIA_SCROLL_SPEED',
default: true
},
serverIP: {
binding: 'SERVER_IP',
default: '127.0.0.1'
},
serverPort: {
binding: 'SERVER_PORT',
default: 24050
},
staticFolderPath: {
binding: 'STATIC_FOLDER_PATH',
default: './static'
},
enableIngameOverlay: {
binding: 'ENABLE_INGAME_OVERLAY',
default: false
},
ingameOverlayKeybind: {
binding: 'INGAME_OVERLAY_KEYBIND',
default: 'Control + Shift + Space'
},
ingameOverlayMaxFps: {
binding: 'INGAME_OVERLAY_MAX_FPS',
default: 60
},
allowedIPs: {
binding: 'ALLOWED_IPS',
default: '127.0.0.1,localhost,absolute'
}
};

export const newlineInsertions: ConfigBinding[] = [
'OPEN_DASHBOARD_ON_STARTUP',
'READ_MANIA_SCROLL_SPEED',
'ENABLE_INGAME_OVERLAY',
'PRECISE_DATA_POLL_RATE',
'INGAME_OVERLAY_MAX_FPS',
'ALLOWED_IPS'
];

export const bindingOrder: ConfigBinding[] = [
'DEBUG_LOG',
'ENABLE_AUTOUPDATE',
'OPEN_DASHBOARD_ON_STARTUP',

'SHOW_MP_COMMANDS',
'CALCULATE_PP',
'READ_MANIA_SCROLL_SPEED',

'ENABLE_KEY_OVERLAY',
'ENABLE_INGAME_OVERLAY',

'POLL_RATE',
'PRECISE_DATA_POLL_RATE',

'INGAME_OVERLAY_KEYBIND',
'INGAME_OVERLAY_MAX_FPS',

'SERVER_IP',
'SERVER_PORT',
'ALLOWED_IPS',

'STATIC_FOLDER_PATH'
];
107 changes: 5 additions & 102 deletions packages/common/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,108 +16,11 @@ import { getConfigPath } from './directories';
import { wLogger } from './logger';
import { isRealNumber } from './manipulation';

const defaultSchema: ConfigSchema = {
enableAutoUpdate: {
binding: 'ENABLE_AUTOUPDATE',
default: true
},
openDashboardOnStartup: {
binding: 'OPEN_DASHBOARD_ON_STARTUP',
default: true
},
debugLog: {
binding: 'DEBUG_LOG',
default: false
},
calculatePP: {
binding: 'CALCULATE_PP',
default: true
},
enableKeyOverlay: {
binding: 'ENABLE_KEY_OVERLAY',
default: true
},
pollRate: {
binding: 'POLL_RATE',
default: 150,
min: 100
},
preciseDataPollRate: {
binding: 'PRECISE_DATA_POLL_RATE',
default: 10,
min: 1
},
showMpCommands: {
binding: 'SHOW_MP_COMMANDS',
default: false
},
readManiaScrollSpeed: {
binding: 'READ_MANIA_SCROLL_SPEED',
default: true
},
serverIP: {
binding: 'SERVER_IP',
default: '127.0.0.1'
},
serverPort: {
binding: 'SERVER_PORT',
default: 24050
},
staticFolderPath: {
binding: 'STATIC_FOLDER_PATH',
default: './static'
},
enableIngameOverlay: {
binding: 'ENABLE_INGAME_OVERLAY',
default: false
},
ingameOverlayKeybind: {
binding: 'INGAME_OVERLAY_KEYBIND',
default: 'Control + Shift + Space'
},
ingameOverlayMaxFps: {
binding: 'INGAME_OVERLAY_MAX_FPS',
default: 60
},
allowedIPs: {
binding: 'ALLOWED_IPS',
default: '127.0.0.1,localhost,absolute'
}
};

const newlineInsertions: ConfigBinding[] = [
'OPEN_DASHBOARD_ON_STARTUP',
'READ_MANIA_SCROLL_SPEED',
'ENABLE_INGAME_OVERLAY',
'PRECISE_DATA_POLL_RATE',
'INGAME_OVERLAY_MAX_FPS',
'ALLOWED_IPS'
];

const bindingOrder: ConfigBinding[] = [
'DEBUG_LOG',
'ENABLE_AUTOUPDATE',
'OPEN_DASHBOARD_ON_STARTUP',

'SHOW_MP_COMMANDS',
'CALCULATE_PP',
'READ_MANIA_SCROLL_SPEED',

'ENABLE_KEY_OVERLAY',
'ENABLE_INGAME_OVERLAY',

'POLL_RATE',
'PRECISE_DATA_POLL_RATE',

'INGAME_OVERLAY_KEYBIND',
'INGAME_OVERLAY_MAX_FPS',

'SERVER_IP',
'SERVER_PORT',
'ALLOWED_IPS',

'STATIC_FOLDER_PATH'
];
import {
bindingOrder,
defaultSchema,
newlineInsertions
} from './config.schema';

export const configEvents = new EventEmitter<ConfigEvents>();

Expand Down
82 changes: 82 additions & 0 deletions packages/common/utils/directories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { homedir } from 'os';
import path from 'path';

import { config } from './config';
import { wLogger } from './logger';

export function ensureDirectoryExists(dir: string) {
if (!fs.existsSync(dir)) {
Expand Down Expand Up @@ -113,3 +114,84 @@ export function getConfigPath() {
}
return getProgramPath();
}

export interface LocalOverlayFolder {
folderName: string;
folderPath: string;
entryPath: string;
metadataPath?: string;
settingsPath?: string;
}

/**
* Scans the static directory for valid 1-level overlay folders.
* Prefers `index.html` as the entry file; fallbacks to any `*.html` file.
*
* @param staticPath The absolute path to the static overlays directory.
* @param target Optional specific overlay folder name to scan.
* @returns An array of discovered local overlay folder details.
*/
export function scanLocalOverlays(
staticPath: string,
target?: string
): LocalOverlayFolder[] {
if (!fs.existsSync(staticPath) || (target && target.startsWith('.')))
return [];

const entries = target
? [{ name: target, isDirectory: () => true }]
: fs.readdirSync(staticPath, { withFileTypes: true });

const overlays: LocalOverlayFolder[] = [];

for (const entry of entries) {
if (!entry.isDirectory() || entry.name.startsWith('.')) continue;

const folderPath = path.join(staticPath, entry.name);
if (!fs.existsSync(folderPath)) continue;

try {
const files = fs.readdirSync(folderPath);

let entryName = files.find((f) => f.toLowerCase() === 'index.html');
if (!entryName) {
entryName = files.find((f) =>
f.toLowerCase().endsWith('.html')
);
}

if (!entryName) {
wLogger.debug(
`Skipping overlay folder %${entry.name}%: No HTML entry file found.`
);
continue;
}

const hasMetadata = files.some(
(f) => f.toLowerCase() === 'metadata.txt'
);
const hasSettings = files.some(
(f) => f.toLowerCase() === 'settings.json'
);

overlays.push({
folderName: entry.name,
folderPath,
entryPath: path.join(folderPath, entryName),
metadataPath: hasMetadata
? path.join(folderPath, 'metadata.txt')
: undefined,
settingsPath: hasSettings
? path.join(folderPath, 'settings.json')
: undefined
});
} catch (error) {
wLogger.debug(
`Failed to scan overlay folder %${entry.name}%:`,
(error as Error).message
);
}
}

return overlays;
}
Loading