|
| 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