Bind callbacks to object
parent
a968f89bb3
commit
abb3c475db
File diff suppressed because one or more lines are too long
|
@ -31,12 +31,12 @@ export default class ItemBuilder {
|
|||
}
|
||||
|
||||
withUseCallback(callback) {
|
||||
this.item.useCallback = callback;
|
||||
this.item.addUseCallback(callback);
|
||||
return this;
|
||||
}
|
||||
|
||||
withTakeCallback(callback) {
|
||||
this.item.takeCallback = callback;
|
||||
this.item.addTakeCallback(callback);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,4 +17,12 @@ export default class Item {
|
|||
async onTake() {
|
||||
if (this.takeCallback) return this.takeCallback();
|
||||
}
|
||||
|
||||
addUseCallback(callback) {
|
||||
this.useCallback = callback.bind(this);
|
||||
}
|
||||
|
||||
addTakeCallback(callback) {
|
||||
this.takeCallback = callback.bind(this);
|
||||
}
|
||||
}
|
|
@ -50,23 +50,23 @@ export default class Room {
|
|||
}
|
||||
|
||||
addEnterCallback(callback) {
|
||||
this.enterCallback = callback;
|
||||
this.enterCallback = callback.bind(this);
|
||||
}
|
||||
|
||||
addExitCallback(callback) {
|
||||
this.exitCallback = callback;
|
||||
this.exitCallback = callback.bind(this);
|
||||
}
|
||||
|
||||
addEnterLogic(func) {
|
||||
this.canEnterLogic = func;
|
||||
this.canEnterLogic = func.bind(this);
|
||||
}
|
||||
|
||||
addExitLogic(func) {
|
||||
this.canExitLogic = func;
|
||||
this.canExitLogic = func.bind(this);
|
||||
}
|
||||
|
||||
addTickCallback(callback) {
|
||||
this.tickCallback = callback;
|
||||
this.tickCallback = callback.bind(this);
|
||||
}
|
||||
|
||||
getItems() {
|
||||
|
|
|
@ -7,9 +7,9 @@ export default new ItemBuilder()
|
|||
.isTakeable(true)
|
||||
.isUsable(true)
|
||||
.withTakeCallback(async function(context) {
|
||||
context.output.say("It feels heavy in your hands.");
|
||||
context.print(`The ${this.id} feels heavy in your hands.`);
|
||||
})
|
||||
.withUseCallback(async function(context) {
|
||||
context.output.say("You can't really figure out what to do with this yet.");
|
||||
context.print(`You can't really figure out what to do with ${this.name} yet`);
|
||||
})
|
||||
.create();
|
Loading…
Reference in New Issue