add TrackedProperty
This will be used for updating inventory slots when ItemStack properties change
This commit is contained in:
parent
f4733f50a3
commit
797cd5db62
1 changed files with 23 additions and 0 deletions
23
server/TrackedProperty.ts
Normal file
23
server/TrackedProperty.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue