@nodemod/core 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/README.md +60 -0
  2. package/dist/core/cmd.d.ts +148 -0
  3. package/dist/core/cmd.d.ts.map +1 -0
  4. package/dist/core/cmd.js +177 -0
  5. package/dist/core/cmd.js.map +1 -0
  6. package/dist/core/menu.d.ts +300 -0
  7. package/dist/core/menu.d.ts.map +1 -0
  8. package/dist/core/menu.js +449 -0
  9. package/dist/core/menu.js.map +1 -0
  10. package/dist/core/msg.d.ts +300 -0
  11. package/dist/core/msg.d.ts.map +1 -0
  12. package/dist/core/msg.js +374 -0
  13. package/dist/core/msg.js.map +1 -0
  14. package/dist/core/resource.d.ts +137 -0
  15. package/dist/core/resource.d.ts.map +1 -0
  16. package/dist/core/resource.js +171 -0
  17. package/dist/core/resource.js.map +1 -0
  18. package/dist/core/sound.d.ts +262 -0
  19. package/dist/core/sound.d.ts.map +1 -0
  20. package/dist/core/sound.js +300 -0
  21. package/dist/core/sound.js.map +1 -0
  22. package/dist/enhanced/entity.d.ts +263 -0
  23. package/dist/enhanced/entity.d.ts.map +1 -0
  24. package/dist/enhanced/entity.js +447 -0
  25. package/dist/enhanced/entity.js.map +1 -0
  26. package/dist/enhanced/events.d.ts +257 -0
  27. package/dist/enhanced/events.d.ts.map +1 -0
  28. package/dist/enhanced/events.js +350 -0
  29. package/dist/enhanced/events.js.map +1 -0
  30. package/dist/enhanced/player.d.ts +272 -0
  31. package/dist/enhanced/player.d.ts.map +1 -0
  32. package/dist/enhanced/player.js +389 -0
  33. package/dist/enhanced/player.js.map +1 -0
  34. package/dist/enhanced/trace.d.ts +198 -0
  35. package/dist/enhanced/trace.d.ts.map +1 -0
  36. package/dist/enhanced/trace.js +311 -0
  37. package/dist/enhanced/trace.js.map +1 -0
  38. package/dist/index.d.ts +88 -0
  39. package/dist/index.d.ts.map +1 -0
  40. package/dist/index.js +120 -0
  41. package/dist/index.js.map +1 -0
  42. package/dist/native/cvar.d.ts +49 -0
  43. package/dist/native/cvar.d.ts.map +1 -0
  44. package/dist/native/cvar.js +169 -0
  45. package/dist/native/cvar.js.map +1 -0
  46. package/dist/native/file.d.ts +221 -0
  47. package/dist/native/file.d.ts.map +1 -0
  48. package/dist/native/file.js +353 -0
  49. package/dist/native/file.js.map +1 -0
  50. package/dist/types/dll.d.ts +109 -0
  51. package/dist/types/engine.d.ts +319 -0
  52. package/dist/types/enums.d.ts +434 -0
  53. package/dist/types/events.d.ts +2432 -0
  54. package/dist/types/index.d.ts +38 -0
  55. package/dist/types/structures.d.ts +1144 -0
  56. package/dist/utils/util.d.ts +202 -0
  57. package/dist/utils/util.d.ts.map +1 -0
  58. package/dist/utils/util.js +318 -0
  59. package/dist/utils/util.js.map +1 -0
  60. package/package.json +167 -0
package/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # NodeMod Core
2
+
3
+ TypeScript-first NodeMod core library for Half-Life server plugins.
4
+
5
+ ## Overview
6
+
7
+ NodeMod Core provides a comprehensive, type-safe API for developing Half-Life server plugins using TypeScript. It offers enhanced utilities, event handling, player management, and entity manipulation while maintaining full compatibility with the underlying NodeMod system.
8
+
9
+ ## Features
10
+
11
+ ### Core Modules
12
+ - **Command System** - Register and handle server commands
13
+ - **Menu System** - Create interactive menus for players
14
+ - **Message System** - Send various types of messages to clients
15
+ - **Resource Management** - Handle server resources and downloads
16
+ - **Sound System** - Play sounds and manage audio
17
+
18
+ ### Enhanced Modules
19
+ - **Player Management** - Advanced player utilities and information
20
+ - **Entity System** - Enhanced entity manipulation and wrapping
21
+ - **Event Handling** - Comprehensive event system with type safety
22
+ - **Trace System** - Ray tracing and collision detection
23
+
24
+ ### Native Modules
25
+ - **CVar System** - Server variable management
26
+ - **File System** - File operations and management
27
+
28
+ ### Utility Modules
29
+ - **General Utilities** - Common helper functions and tools
30
+ - **Entity Debugging** - Debug entity private data and offsets
31
+ - **Message Helpers** - Chat, HUD, and communication utilities
32
+
33
+ ## Installation
34
+
35
+ ```bash
36
+ npm install @nodemod/core
37
+ ```
38
+
39
+ ## Basic Usage
40
+
41
+ ```typescript
42
+ import nodemodCore from '@nodemod/core';
43
+
44
+ // Send a message to all players
45
+ nodemodCore.util.messageAll('Hello from NodeMod Core!');
46
+
47
+ // Get all connected players
48
+ const players = nodemodCore.player.getAll();
49
+
50
+ // Create an entity
51
+ const entity = nodemodCore.entity.create('info_target');
52
+ ```
53
+
54
+ ## Documentation
55
+
56
+ Full API documentation is available in the `/docs` directory.
57
+
58
+ ## License
59
+
60
+ MIT
@@ -0,0 +1,148 @@
1
+ /**
2
+ * Context object containing information about a command execution.
3
+ */
4
+ export interface CommandContext {
5
+ /** The raw command text as entered by the client */
6
+ text: string;
7
+ /** Array of parsed command arguments, including the command name as the first element */
8
+ args: string[];
9
+ /** The client entity that issued the command */
10
+ client: nodemod.Entity;
11
+ }
12
+ /**
13
+ * Handler function for client commands.
14
+ */
15
+ export interface CommandHandler {
16
+ (ctx: CommandContext): void;
17
+ }
18
+ /**
19
+ * Handler function for server commands.
20
+ */
21
+ export interface ServerCommandHandler {
22
+ (): void;
23
+ }
24
+ /**
25
+ * Configuration options for registering a command.
26
+ */
27
+ export interface CommandOptions {
28
+ /** The command name (without prefix) */
29
+ name: string;
30
+ /** Whether this is a client or server command */
31
+ type: 'client' | 'server';
32
+ /** The handler function to execute when the command is invoked */
33
+ handler: CommandHandler | ServerCommandHandler;
34
+ }
35
+ /**
36
+ * Command manager for handling both client and server commands in the nodemod plugin system.
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * // Register a client command
41
+ * nodemodCore.cmd.add({
42
+ * name: 'hello',
43
+ * type: 'client',
44
+ * handler: (ctx) => {
45
+ * console.log(`Hello ${ctx.client.name}!`);
46
+ * }
47
+ * });
48
+ *
49
+ * // Register a server command
50
+ * nodemodCore.cmd.add({
51
+ * name: 'restart',
52
+ * type: 'server',
53
+ * handler: () => {
54
+ * console.log('Server restarting...');
55
+ * }
56
+ * });
57
+ * ```
58
+ */
59
+ export default class NodemodCmd {
60
+ /** Array of registered commands */
61
+ private commands;
62
+ /**
63
+ * Parses a command string into an array of arguments, respecting quoted strings.
64
+ *
65
+ * @param command - The raw command string to parse
66
+ * @returns Array of parsed arguments
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * parseCommand('say "hello world" test') // Returns: ['say', 'hello world', 'test']
71
+ * parseCommand('kick player reason') // Returns: ['kick', 'player', 'reason']
72
+ * ```
73
+ */
74
+ private parseCommand;
75
+ /**
76
+ * Creates a new NodemodCmd instance and sets up command event listeners.
77
+ * Automatically handles client command events from the nodemod system.
78
+ */
79
+ constructor();
80
+ /**
81
+ * Retrieves a registered command by name and type.
82
+ *
83
+ * @param commandName - The name of the command to find
84
+ * @param type - The type of command ('client' or 'server')
85
+ * @returns The command options if found, undefined otherwise
86
+ */
87
+ getCommand(commandName: string, type: string): CommandOptions | undefined;
88
+ /**
89
+ * Adds a new command to the command registry.
90
+ * For server commands, automatically registers them with the native engine.
91
+ *
92
+ * @param options - Command configuration options
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * // Client command
97
+ * nodemodCore.cmd.add({
98
+ * name: 'info',
99
+ * type: 'client',
100
+ * handler: (ctx) => {
101
+ * console.log(`Player: ${ctx.client.name}, Args: ${ctx.args.join(' ')}`);
102
+ * }
103
+ * });
104
+ *
105
+ * // Server command
106
+ * nodemodCore.cmd.add({
107
+ * name: 'status',
108
+ * type: 'server',
109
+ * handler: () => {
110
+ * console.log('Server is running');
111
+ * }
112
+ * });
113
+ * ```
114
+ */
115
+ add(options: CommandOptions): void;
116
+ /**
117
+ * Convenience method to register a client command with a simplified handler signature.
118
+ * The handler receives the client entity and arguments (excluding the command name).
119
+ *
120
+ * @param name - The command name
121
+ * @param handler - Function that receives the client and arguments
122
+ *
123
+ * @example
124
+ * ```typescript
125
+ * nodemodCore.cmd.register('kick', (client, args) => {
126
+ * const targetName = args[0];
127
+ * const reason = args.slice(1).join(' ');
128
+ * console.log(`${client.name} wants to kick ${targetName}: ${reason}`);
129
+ * });
130
+ * ```
131
+ */
132
+ register(name: string, handler: (client: nodemod.Entity, args: string[]) => void): void;
133
+ /**
134
+ * Executes a server command through the native engine.
135
+ * Automatically appends a newline character to the command.
136
+ *
137
+ * @param command - The server command to execute
138
+ *
139
+ * @example
140
+ * ```typescript
141
+ * nodemodCore.cmd.run('changelevel de_dust2');
142
+ * nodemodCore.cmd.run('kick "Player Name"');
143
+ * nodemodCore.cmd.run('say "Server announcement"');
144
+ * ```
145
+ */
146
+ run(command: string): void;
147
+ }
148
+ //# sourceMappingURL=cmd.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cmd.d.ts","sourceRoot":"","sources":["../../src/core/cmd.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,oDAAoD;IACpD,IAAI,EAAE,MAAM,CAAC;IACb,yFAAyF;IACzF,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,gDAAgD;IAChD,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,CAAC,GAAG,EAAE,cAAc,GAAG,IAAI,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,IAAI,IAAI,CAAC;CACV;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,wCAAwC;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,iDAAiD;IACjD,IAAI,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC1B,kEAAkE;IAClE,OAAO,EAAE,cAAc,GAAG,oBAAoB,CAAC;CAChD;AAID;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B,mCAAmC;IACnC,OAAO,CAAC,QAAQ,CAAwB;IAExC;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,YAAY;IA8BpB;;;OAGG;;IAiBH;;;;;;OAMG;IACH,UAAU,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS;IAIzE;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,GAAG,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI;IAelC;;;;;;;;;;;;;;;OAeG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,IAAI,GAAG,IAAI;IAQvF;;;;;;;;;;;;OAYG;IACH,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;CAG3B"}
@@ -0,0 +1,177 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // Extend the nodemod namespace to include missing methods
4
+ /**
5
+ * Command manager for handling both client and server commands in the nodemod plugin system.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * // Register a client command
10
+ * nodemodCore.cmd.add({
11
+ * name: 'hello',
12
+ * type: 'client',
13
+ * handler: (ctx) => {
14
+ * console.log(`Hello ${ctx.client.name}!`);
15
+ * }
16
+ * });
17
+ *
18
+ * // Register a server command
19
+ * nodemodCore.cmd.add({
20
+ * name: 'restart',
21
+ * type: 'server',
22
+ * handler: () => {
23
+ * console.log('Server restarting...');
24
+ * }
25
+ * });
26
+ * ```
27
+ */
28
+ class NodemodCmd {
29
+ /** Array of registered commands */
30
+ commands = [];
31
+ /**
32
+ * Parses a command string into an array of arguments, respecting quoted strings.
33
+ *
34
+ * @param command - The raw command string to parse
35
+ * @returns Array of parsed arguments
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * parseCommand('say "hello world" test') // Returns: ['say', 'hello world', 'test']
40
+ * parseCommand('kick player reason') // Returns: ['kick', 'player', 'reason']
41
+ * ```
42
+ */
43
+ parseCommand(command) {
44
+ const args = [];
45
+ let current = '';
46
+ let inQuotes = false;
47
+ let i = 0;
48
+ while (i < command.length) {
49
+ const char = command[i];
50
+ if (char === '"') {
51
+ inQuotes = !inQuotes;
52
+ }
53
+ else if (char === ' ' && !inQuotes) {
54
+ if (current.length > 0) {
55
+ args.push(current);
56
+ current = '';
57
+ }
58
+ }
59
+ else {
60
+ current += char;
61
+ }
62
+ i++;
63
+ }
64
+ // Add the last argument if there is one
65
+ if (current.length > 0) {
66
+ args.push(current);
67
+ }
68
+ return args;
69
+ }
70
+ /**
71
+ * Creates a new NodemodCmd instance and sets up command event listeners.
72
+ * Automatically handles client command events from the nodemod system.
73
+ */
74
+ constructor() {
75
+ nodemod.on('dllClientCommand', (client, rtext) => {
76
+ const args = this.parseCommand(rtext);
77
+ const commandName = args[0];
78
+ const ctx = { text: rtext, args, client };
79
+ const command = this.getCommand(commandName, 'client');
80
+ if (!command) {
81
+ return;
82
+ }
83
+ nodemod.setMetaResult(4 /* nodemod.META_RES.SUPERCEDE */); // Supercede the command
84
+ return command.handler(ctx);
85
+ });
86
+ }
87
+ /**
88
+ * Retrieves a registered command by name and type.
89
+ *
90
+ * @param commandName - The name of the command to find
91
+ * @param type - The type of command ('client' or 'server')
92
+ * @returns The command options if found, undefined otherwise
93
+ */
94
+ getCommand(commandName, type) {
95
+ return this.commands.find(v => v.name === commandName && v.type === type);
96
+ }
97
+ /**
98
+ * Adds a new command to the command registry.
99
+ * For server commands, automatically registers them with the native engine.
100
+ *
101
+ * @param options - Command configuration options
102
+ *
103
+ * @example
104
+ * ```typescript
105
+ * // Client command
106
+ * nodemodCore.cmd.add({
107
+ * name: 'info',
108
+ * type: 'client',
109
+ * handler: (ctx) => {
110
+ * console.log(`Player: ${ctx.client.name}, Args: ${ctx.args.join(' ')}`);
111
+ * }
112
+ * });
113
+ *
114
+ * // Server command
115
+ * nodemodCore.cmd.add({
116
+ * name: 'status',
117
+ * type: 'server',
118
+ * handler: () => {
119
+ * console.log('Server is running');
120
+ * }
121
+ * });
122
+ * ```
123
+ */
124
+ add(options) {
125
+ this.commands.push(options);
126
+ // Register server commands with the engine
127
+ if (options.type === 'server') {
128
+ // Create a wrapper function that calls our handler
129
+ const serverHandler = () => {
130
+ options.handler();
131
+ };
132
+ // Register with the native engine
133
+ nodemod.eng.addServerCommand(options.name, serverHandler);
134
+ }
135
+ }
136
+ /**
137
+ * Convenience method to register a client command with a simplified handler signature.
138
+ * The handler receives the client entity and arguments (excluding the command name).
139
+ *
140
+ * @param name - The command name
141
+ * @param handler - Function that receives the client and arguments
142
+ *
143
+ * @example
144
+ * ```typescript
145
+ * nodemodCore.cmd.register('kick', (client, args) => {
146
+ * const targetName = args[0];
147
+ * const reason = args.slice(1).join(' ');
148
+ * console.log(`${client.name} wants to kick ${targetName}: ${reason}`);
149
+ * });
150
+ * ```
151
+ */
152
+ register(name, handler) {
153
+ this.add({
154
+ name,
155
+ type: 'client',
156
+ handler: (ctx) => handler(ctx.client, ctx.args.slice(1))
157
+ });
158
+ }
159
+ /**
160
+ * Executes a server command through the native engine.
161
+ * Automatically appends a newline character to the command.
162
+ *
163
+ * @param command - The server command to execute
164
+ *
165
+ * @example
166
+ * ```typescript
167
+ * nodemodCore.cmd.run('changelevel de_dust2');
168
+ * nodemodCore.cmd.run('kick "Player Name"');
169
+ * nodemodCore.cmd.run('say "Server announcement"');
170
+ * ```
171
+ */
172
+ run(command) {
173
+ nodemod.eng.serverCommand(command + '\n');
174
+ }
175
+ }
176
+ exports.default = NodemodCmd;
177
+ //# sourceMappingURL=cmd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cmd.js","sourceRoot":"","sources":["../../src/core/cmd.ts"],"names":[],"mappings":";;AAsCA,0DAA0D;AAE1D;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAqB,UAAU;IAC7B,mCAAmC;IAC3B,QAAQ,GAAqB,EAAE,CAAC;IAExC;;;;;;;;;;;OAWG;IACK,YAAY,CAAC,OAAe;QAClC,MAAM,IAAI,GAAa,EAAE,CAAC;QAC1B,IAAI,OAAO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@@ -0,0 +1,300 @@
1
+ /**
2
+ * Handler function for menu item actions.
3
+ */
4
+ export interface MenuHandler {
5
+ (client: nodemod.Entity, menu?: Menu): void | Promise<void>;
6
+ }
7
+ /**
8
+ * Configuration for a single menu item.
9
+ */
10
+ export interface MenuItem {
11
+ /** Display name of the menu item */
12
+ name: string;
13
+ /** Handler function to execute when item is selected */
14
+ handler?: MenuHandler;
15
+ /** Submenu to navigate to when item is selected */
16
+ submenu?: Menu;
17
+ /** Whether this item is disabled and cannot be selected */
18
+ disabled?: boolean;
19
+ }
20
+ /**
21
+ * Configuration options for creating a menu.
22
+ */
23
+ export interface MenuOptions {
24
+ /** Title displayed at the top of the menu */
25
+ title: string;
26
+ /** Array of menu items */
27
+ items: MenuItem[];
28
+ /** Specific entity to show menu to (if undefined, shows to all players) */
29
+ entity?: nodemod.Entity;
30
+ /** Auto-close timeout in seconds (-1 for no timeout) */
31
+ time?: number;
32
+ /** Callback when menu times out */
33
+ onTimeout?: (client: nodemod.Entity) => void;
34
+ /** Callback when menu is exited */
35
+ onExit?: (client: nodemod.Entity) => void;
36
+ /** Text for exit button */
37
+ exitText?: string;
38
+ /** Text for back button */
39
+ backText?: string;
40
+ /** Text for next page button */
41
+ nextText?: string;
42
+ /** Text for previous page button */
43
+ prevText?: string;
44
+ /** Custom formatting functions */
45
+ formatters?: MenuFormatters;
46
+ }
47
+ /**
48
+ * Functions for customizing menu display formatting.
49
+ */
50
+ export interface MenuFormatters {
51
+ /** Format the menu title */
52
+ title?: (title: string) => string;
53
+ /** Format individual menu items */
54
+ item?: (item: MenuItem, index: number, isDisabled: boolean) => string;
55
+ /** Format pagination display */
56
+ pagination?: (current: number, total: number) => string;
57
+ /** Format divider between title and items */
58
+ divider?: () => string;
59
+ }
60
+ /**
61
+ * Internal state tracking for active menus.
62
+ */
63
+ export interface MenuState {
64
+ /** Currently displayed menu */
65
+ menu: Menu;
66
+ /** Current page number (0-based) */
67
+ currentPage: number;
68
+ /** Navigation history for back functionality */
69
+ history: Menu[];
70
+ /** Whether this menu is shown to all players */
71
+ isAll: boolean;
72
+ /** Array of client indices that have used this menu */
73
+ used: number[];
74
+ /** Timeout ID for auto-close functionality */
75
+ timeoutId?: any;
76
+ }
77
+ /**
78
+ * Map of menu states indexed by client or 'all' for global menus.
79
+ */
80
+ export interface MenuStateMap {
81
+ [key: string]: MenuState;
82
+ [key: number]: MenuState;
83
+ }
84
+ /**
85
+ * Represents a menu that can be displayed to players with navigable items and submenus.
86
+ *
87
+ * @example
88
+ * ```typescript
89
+ * const menu = new Menu({
90
+ * title: 'Player Actions',
91
+ * items: [
92
+ * {
93
+ * name: 'Kick Player',
94
+ * handler: (client) => {
95
+ * console.log(`${client.name} selected kick player`);
96
+ * }
97
+ * },
98
+ * {
99
+ * name: 'Ban Player',
100
+ * handler: (client) => {
101
+ * console.log(`${client.name} selected ban player`);
102
+ * }
103
+ * }
104
+ * ]
105
+ * });
106
+ * ```
107
+ */
108
+ export declare class Menu {
109
+ /** Menu title displayed at the top */
110
+ title: string;
111
+ /** Array of menu items */
112
+ items: MenuItem[];
113
+ /** Specific entity this menu is for (undefined = all players) */
114
+ entity?: nodemod.Entity;
115
+ /** Auto-close timeout in seconds (-1 for no timeout) */
116
+ time: number;
117
+ /** Callback when menu times out */
118
+ onTimeout?: (client: nodemod.Entity) => void;
119
+ /** Callback when menu is exited */
120
+ onExit?: (client: nodemod.Entity) => void;
121
+ /** Text for exit button */
122
+ exitText: string;
123
+ /** Text for back button */
124
+ backText: string;
125
+ /** Text for next page button */
126
+ nextText: string;
127
+ /** Text for previous page button */
128
+ prevText: string;
129
+ /** Formatting functions for menu display */
130
+ formatters: Required<MenuFormatters>;
131
+ /** Parent menu for navigation hierarchy */
132
+ parent?: Menu;
133
+ /**
134
+ * Creates a new Menu instance.
135
+ *
136
+ * @param options - Menu configuration options
137
+ */
138
+ constructor(options: MenuOptions);
139
+ /**
140
+ * Static template methods for creating common menu types.
141
+ */
142
+ static template: {
143
+ /**
144
+ * Creates a simple menu with string items and optional handlers.
145
+ *
146
+ * @param title - Menu title
147
+ * @param items - Array of item names
148
+ * @param handlers - Optional array of handlers (must match items length)
149
+ * @returns Configured Menu instance
150
+ *
151
+ * @example
152
+ * ```typescript
153
+ * const menu = Menu.template.simple(
154
+ * 'Choose Action',
155
+ * ['Option 1', 'Option 2', 'Option 3'],
156
+ * [(client) => console.log('Option 1'), (client) => console.log('Option 2')]
157
+ * );
158
+ * ```
159
+ */
160
+ simple: (title: string, items: string[], handlers?: MenuHandler[]) => Menu;
161
+ /**
162
+ * Creates a Yes/No confirmation menu.
163
+ *
164
+ * @param title - Menu title/question
165
+ * @param onYes - Handler for Yes selection
166
+ * @param onNo - Handler for No selection
167
+ * @returns Configured Menu instance
168
+ *
169
+ * @example
170
+ * ```typescript
171
+ * const menu = Menu.template.yesNo(
172
+ * 'Are you sure?',
173
+ * (client) => console.log('User confirmed'),
174
+ * (client) => console.log('User declined')
175
+ * );
176
+ * ```
177
+ */
178
+ yesNo: (title: string, onYes: MenuHandler, onNo: MenuHandler) => Menu;
179
+ /**
180
+ * Creates a confirmation menu with Confirm/Cancel options.
181
+ *
182
+ * @param message - Confirmation message
183
+ * @param onConfirm - Handler for Confirm selection
184
+ * @param onCancel - Optional handler for Cancel selection
185
+ * @returns Configured Menu instance
186
+ *
187
+ * @example
188
+ * ```typescript
189
+ * const menu = Menu.template.confirm(
190
+ * 'Delete all data?',
191
+ * (client) => deleteData(),
192
+ * (client) => console.log('Cancelled')
193
+ * );
194
+ * ```
195
+ */
196
+ confirm: (message: string, onConfirm: MenuHandler, onCancel?: MenuHandler) => Menu;
197
+ };
198
+ }
199
+ import type NodemodMsg from './msg';
200
+ import type NodemodUtil from '../utils/util';
201
+ /**
202
+ * Menu system manager for handling interactive menus in the nodemod plugin system.
203
+ * Supports pagination, navigation, timeouts, and both client-specific and global menus.
204
+ *
205
+ * @example
206
+ * ```typescript
207
+ * // Show a menu to all players
208
+ * nodemodCore.menu.show({
209
+ * title: 'Admin Menu',
210
+ * items: [
211
+ * { name: 'Kick Player', handler: handleKick },
212
+ * { name: 'Change Map', handler: handleMapChange }
213
+ * ]
214
+ * });
215
+ *
216
+ * // Show a menu to a specific player
217
+ * nodemodCore.menu.show({
218
+ * title: 'Player Options',
219
+ * entity: specificPlayer,
220
+ * items: [
221
+ * { name: 'View Stats', handler: showStats }
222
+ * ]
223
+ * });
224
+ * ```
225
+ */
226
+ export default class NodemodMenu {
227
+ /** Map of active menu states by client index or 'all' */
228
+ private menuStates;
229
+ /** Message service for sending menu data */
230
+ private msg;
231
+ /** Utility service */
232
+ private util;
233
+ /** Maximum items per page (leaves slots for navigation) */
234
+ private readonly ITEMS_PER_PAGE;
235
+ /**
236
+ * Creates a new NodemodMenu instance.
237
+ *
238
+ * @param msgService - Message service for sending menu displays
239
+ * @param utilService - Utility service
240
+ */
241
+ constructor(msgService: NodemodMsg, utilService: NodemodUtil);
242
+ /**
243
+ * Initializes event handlers for menu interactions.
244
+ */
245
+ private initializeEventHandlers;
246
+ /**
247
+ * Handles menu selection commands from clients.
248
+ *
249
+ * @param client - The client entity that sent the command
250
+ * @param text - The command text containing menu selection
251
+ */
252
+ private handleMenuCommand;
253
+ private handleBackExit;
254
+ private handlePrevPage;
255
+ private handleNextPage;
256
+ private handleItemSelection;
257
+ private cleanupMenuState;
258
+ /**
259
+ * Displays a menu to players. Can show to all players or a specific entity.
260
+ *
261
+ * @param options - Menu configuration or Menu instance
262
+ *
263
+ * @example
264
+ * ```typescript
265
+ * // Show to all players
266
+ * nodemodCore.menu.show({
267
+ * title: 'Server Menu',
268
+ * items: [
269
+ * { name: 'Option 1', handler: (client) => console.log('Selected 1') }
270
+ * ]
271
+ * });
272
+ *
273
+ * // Show to specific player
274
+ * nodemodCore.menu.show({
275
+ * title: 'Personal Menu',
276
+ * entity: player,
277
+ * time: 30, // Auto-close after 30 seconds
278
+ * items: [
279
+ * { name: 'View Profile', handler: showProfile }
280
+ * ]
281
+ * });
282
+ * ```
283
+ */
284
+ show(options: MenuOptions | Menu): void;
285
+ private showMenuInternal;
286
+ private buildMenuDisplay;
287
+ /**
288
+ * Closes the menu for a specific client.
289
+ *
290
+ * @param client - The client to close the menu for
291
+ */
292
+ closeMenu(client: nodemod.Entity): void;
293
+ /**
294
+ * Closes all active menus and clears all menu states.
295
+ */
296
+ closeAllMenus(): void;
297
+ /** Export Menu class for external use */
298
+ static Menu: typeof Menu;
299
+ }
300
+ //# sourceMappingURL=menu.d.ts.map