add TrackedProperty

This will be used for updating inventory slots when ItemStack properties change
This commit is contained in:
Holly Stubbs 2023-12-18 11:19:51 +00:00
parent f4733f50a3
commit 797cd5db62
Signed by: tgpholly
GPG Key ID: B8583C4B7D18119E
1 changed files with 23 additions and 0 deletions

23
server/TrackedProperty.ts Normal file
View File

@ -0,0 +1,23 @@
export class TrackedProperty<T> {
private trackedValue?:T;
private updateCallback?:(value:T) => void;
constructor(initialValue?:T) {
this.trackedValue = initialValue;
}
public set OnChange(value:() => void) {
this.updateCallback = value;
}
public get Value() {
return this.trackedValue;
}
public set Value(value) {
this.trackedValue = value;
if (this.updateCallback && value) {
this.updateCallback(value);
}
}
}