Skip to content

Commit 5d04552

Browse files
Merge pull request #182 from SwiTool/feat/mod/show-pods
✨ feat: show pods in inventory
2 parents 3042d03 + b8bccfb commit 5d04552

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

src/app/mods/general/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ export { HideShop } from "./hide-shop";
55
export { Inactivity } from "./inactivity";
66
export { JsFixes } from "./js-fixes";
77
export { KeyboardInput } from "./keyboardInput";
8-
8+
export { ShowPods } from "./show-pods";

src/app/mods/general/show-pods.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { Mod } from "../mod";
2+
3+
export class ShowPods extends Mod {
4+
private equipmentWindow;
5+
private podsLabel;
6+
private evtInventoryWeightMessage = this.onInventoryWeightMessage.bind(this);
7+
private evtInit = this.init.bind(this);
8+
9+
startMod(): void {
10+
this.equipmentWindow = this.wGame.gui.windowsContainer
11+
.getChildren()
12+
.find((w) => w.id === "equipment")
13+
.on("open", () => {
14+
if (this.equipmentWindow.openState) {
15+
this.evtInit();
16+
} else {
17+
this.equipmentWindow.once("opened", this.evtInit);
18+
}
19+
});
20+
}
21+
22+
private init() {
23+
const podContainer = this.equipmentWindow.storageBox._childrenList[0]._childrenList.find((c) =>
24+
c.hasClassName("podContainer")
25+
);
26+
const progressBarContainer = podContainer._childrenList.find((c) => c.hasClassName("progressBarContainer"));
27+
this.podsLabel = progressBarContainer._childrenList[0];
28+
29+
const pods = this.formatNumber(
30+
this.wGame.gui.playerData.inventory.maxWeight - this.wGame.gui.playerData.inventory.weight
31+
);
32+
this.podsLabel.setText(`${pods} Pods:`);
33+
this.wGame.connectionManager.on("InventoryWeightMessage", this.evtInventoryWeightMessage);
34+
}
35+
36+
private onInventoryWeightMessage(msg) {
37+
const pods = this.formatNumber(msg.weightMax - msg.weight);
38+
this.podsLabel.setText(`${pods} Pods:`);
39+
}
40+
41+
private formatNumber(x) {
42+
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " ");
43+
}
44+
45+
reset() {
46+
this.wGame.connectionManager.removeListener("InventoryWeightMessage", this.evtInventoryWeightMessage);
47+
this.equipmentWindow && this.equipmentWindow.removeListener("opened", this.evtInit);
48+
}
49+
}

0 commit comments

Comments
 (0)