@hotbunny/hackhub-content-sdk 0.9.5 → 0.9.6

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 (3) hide show
  1. package/README.md +5 -3
  2. package/index.d.ts +32 -4
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -42,7 +42,7 @@ export default class MyMod extends Bootstrap {
42
42
  Quests use a generic type parameter for type-safe data. `CreateData()` initializes the data once when the quest is first claimed. After that, access via `this.Data` and update via `this.SetData()`:
43
43
 
44
44
  ```typescript
45
- import { Quest, Events, Network, RegisterQuest } from "@hotbunny/hackhub-content-sdk";
45
+ import { Quest, Network, RegisterQuest } from "@hotbunny/hackhub-content-sdk";
46
46
 
47
47
  interface InfiltrationData {
48
48
  targetIp: string;
@@ -81,14 +81,16 @@ class InfiltrationQuest extends Quest<InfiltrationData> {
81
81
  children: [],
82
82
  });
83
83
 
84
- Events.on("Terminal.NmapScan", (data) => {
84
+ // Use this.Events.on() listeners are automatically cleaned up
85
+ // when the quest completes or is abandoned. No memory leaks!
86
+ this.Events.on("Terminal.NmapScan", (data) => {
85
87
  if (data.ip === this.Data.targetIp) {
86
88
  this.SetData("attempts", this.Data.attempts + 1); // type-safe key & value
87
89
  this.completeObjective("scan");
88
90
  }
89
91
  });
90
92
 
91
- Events.on("Terminal.SSH.Connected", (data) => {
93
+ this.Events.on("Terminal.SSH.Connected", (data) => {
92
94
  if (data.ip === this.Data.targetIp) this.completeObjective("connect");
93
95
  });
94
96
  }
package/index.d.ts CHANGED
@@ -1077,9 +1077,30 @@ export declare abstract class Bootstrap {
1077
1077
  /** Called when the mod is being unloaded (e.g. disabled by user). */
1078
1078
  OnModPackageUnloaded(): void;
1079
1079
  }
1080
+ /**
1081
+ * Scoped event manager for a quest. All listeners registered via
1082
+ * `this.Events.on()` are automatically removed when the quest
1083
+ * completes or is abandoned, preventing memory leaks.
1084
+ */
1085
+ export declare class QuestEvents {
1086
+ private _listeners;
1087
+ /** @internal */ _globalOn?: (event: string, callback: Function) => () => void;
1088
+ /**
1089
+ * Listen to a game event or custom event. The listener is automatically
1090
+ * removed when the quest completes or is abandoned.
1091
+ */
1092
+ on<T extends string>(event: T, callback: (data: T extends keyof ModEventMap ? ModEventMap[T] : any) => void): () => void;
1093
+ /** Remove a specific listener. */
1094
+ off(event: string, callback: Function): void;
1095
+ /** Remove all listeners registered through this quest. */
1096
+ offAll(): void;
1097
+ }
1080
1098
  /**
1081
1099
  * Base class for mod quests. Extend with a generic type for type-safe quest data.
1082
1100
  *
1101
+ * Use `this.Events.on()` instead of the global `Events.on()` so listeners
1102
+ * are automatically cleaned up when the quest completes or is abandoned.
1103
+ *
1083
1104
  * @example
1084
1105
  * ```ts
1085
1106
  * interface MyData { targetIp: string; attempts: number; }
@@ -1097,8 +1118,9 @@ export declare abstract class Bootstrap {
1097
1118
  * }
1098
1119
  *
1099
1120
  * OnStart() {
1100
- * console.log(this.Data.targetIp); // fully typed
1101
- * this.SetData("attempts", 1); // type-safe key & value
1121
+ * this.Events.on("Terminal.NmapScan", (data) => {
1122
+ * if (data.ip === this.Data.targetIp) this.completeObjective("scan");
1123
+ * });
1102
1124
  * }
1103
1125
  * }
1104
1126
  * ```
@@ -1132,9 +1154,14 @@ export declare abstract class Quest<T extends Record<string, any> = Record<strin
1132
1154
  Dialog?: QuestDialogDefinition;
1133
1155
  /** Quest data created by CreateData(). Populated at runtime by the game engine. */
1134
1156
  Data: T;
1157
+ /**
1158
+ * Scoped event manager. Listeners registered here are automatically
1159
+ * cleaned up when the quest completes or is abandoned.
1160
+ */
1161
+ Events: QuestEvents;
1135
1162
  /**
1136
1163
  * Called when the quest is first claimed/started.
1137
- * Use this to set up event listeners for objective completion.
1164
+ * Use this to set up event listeners via `this.Events.on()`.
1138
1165
  */
1139
1166
  OnStart(): void | Promise<void>;
1140
1167
  /** Called when all objectives are completed and the quest finishes. */
@@ -1316,6 +1343,7 @@ export declare abstract class App {
1316
1343
  */
1317
1344
  Exports?: Record<string, any>;
1318
1345
  }
1346
+ type () => void$1 = () => void;
1319
1347
  /**
1320
1348
  * Game events API. Allows mods to listen to in-game events
1321
1349
  * such as terminal commands, file operations, network events, etc.
@@ -1353,7 +1381,7 @@ export declare namespace Events {
1353
1381
  * For known `ModEventMap` keys, the callback is fully typed.
1354
1382
  * For custom string events, the callback receives `any`.
1355
1383
  */
1356
- export function on<T extends string>(event: T, callback: (data: T extends keyof ModEventMap ? ModEventMap[T] : any) => void): () => void;
1384
+ export function on<T extends string>(event: T, callback: (data: T extends keyof ModEventMap ? ModEventMap[T] : any) => void): () => void$1;
1357
1385
  /** Remove a specific event listener. */
1358
1386
  export function off(event: string, callback: Function): void;
1359
1387
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hotbunny/hackhub-content-sdk",
3
- "version": "0.9.5",
3
+ "version": "0.9.6",
4
4
  "description": "Official modding SDK for HackHub - Ultimate Hacker Simulator on Steam. Create custom quests, websites, terminal commands, and desktop apps.",
5
5
  "types": "index.d.ts",
6
6
  "exports": {