Skip to content

Commit

Permalink
optimizing gold ui (only updating on chnage)
Browse files Browse the repository at this point in the history
  • Loading branch information
orion3dgames committed May 21, 2024
1 parent 2986430 commit 018a146
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/client/Controllers/UI/Panels/Panel_Inventory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ export class Panel_Inventory extends Panel {
this.refresh();
});
});
entity.player_data.listen("gold", (currentValue, previousValue) => {
this.updateGold();
});
}

// some ui must be constantly refreshed as things change
Expand Down Expand Up @@ -62,9 +65,6 @@ export class Panel_Inventory extends Panel {
// refresh panel
public update() {
super.update();
if (this._currentPlayer && this._goldUI) {
this._goldUI.text = "Gold: " + this._currentPlayer.player_data.gold;
}
}

// create panel
Expand Down Expand Up @@ -159,6 +159,12 @@ export class Panel_Inventory extends Panel {
this.refresh();
}

updateGold() {
if (this._goldUI) {
this._goldUI.text = "Gold: " + this._currentPlayer.player_data.gold;
}
}

///////////////////////////////////////
///////////////////////////////////////
// INVENTORY PANEL
Expand Down Expand Up @@ -243,5 +249,8 @@ export class Panel_Inventory extends Panel {
}
});
});

// update golve value just in case
this.updateGold();
}
}

0 comments on commit 018a146

Please sign in to comment.