mirror of
https://github.com/exane/not-gwent-online
synced 2024-11-23 19:36:53 +00:00
fix morale boost + improved events
This commit is contained in:
parent
2c307a4fb8
commit
730e8f714a
@ -31,14 +31,24 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"morale_boost": {
|
"morale_boost": {
|
||||||
onAfterPlace: function(card) {
|
|
||||||
var field = this.field[card.getType()];
|
|
||||||
var cards = field.get();
|
|
||||||
|
|
||||||
cards.forEach(function(_card) {
|
onEachCardPlace: function(card){
|
||||||
if(_card.getID() == card.getID()) return;
|
var field = this.field[card.getType()];
|
||||||
if(_card.getRawPower() === -1) return;
|
var id = card.getID();
|
||||||
_card.boost(1);
|
if(!field.isOnField(card)){
|
||||||
|
field.get().forEach(function(_card){
|
||||||
|
if(_card.getID() == id) return;
|
||||||
|
if(_card.getType() != card.getType()) return;
|
||||||
|
_card.setBoost(id, 0);
|
||||||
|
})
|
||||||
|
this.off("EachCardPlace", card.getUidEvents("EachCardPlace"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
field.get().forEach(function(_card){
|
||||||
|
if(_card.getID() == id) return;
|
||||||
|
if(_card.getType() != card.getType()) return;
|
||||||
|
_card.setBoost(id, 1);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -164,31 +174,13 @@ module.exports = {
|
|||||||
this.placeCard(card);
|
this.placeCard(card);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"francesca_leader1": {
|
"francesca_leader1": {},
|
||||||
|
"francesca_leader2": {},
|
||||||
},
|
"francesca_leader3": {},
|
||||||
"francesca_leader2": {
|
"francesca_leader4": {},
|
||||||
|
"eredin_leader1": {},
|
||||||
},
|
"eredin_leader2": {},
|
||||||
"francesca_leader3": {
|
"eredin_leader3": {},
|
||||||
|
"eredin_leader4": {},
|
||||||
},
|
"hero": {}
|
||||||
"francesca_leader4": {
|
|
||||||
|
|
||||||
},
|
|
||||||
"eredin_leader1": {
|
|
||||||
|
|
||||||
},
|
|
||||||
"eredin_leader2": {
|
|
||||||
|
|
||||||
},
|
|
||||||
"eredin_leader3": {
|
|
||||||
|
|
||||||
},
|
|
||||||
"eredin_leader4": {
|
|
||||||
|
|
||||||
},
|
|
||||||
"hero": {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -105,7 +105,7 @@ var SideView = Backbone.View.extend({
|
|||||||
'</div>'),
|
'</div>'),
|
||||||
templateCards: Handlebars.compile('{{#each this}}' +
|
templateCards: Handlebars.compile('{{#each this}}' +
|
||||||
'<div class="card{{#if _disabled}} disabled{{/if}}" data-key="{{_key}}" data-id="{{_id}}">' +
|
'<div class="card{{#if _disabled}} disabled{{/if}}" data-key="{{_key}}" data-id="{{_id}}">' +
|
||||||
'{{#if _boost}}<span>+{{_boost}}</span>{{/if}}' +
|
'{{#if boost}}<span>+{{boost}}</span>{{/if}}' +
|
||||||
'<img src="../assets/cards/{{_data.img}}.png">' +
|
'<img src="../assets/cards/{{_data.img}}.png">' +
|
||||||
'</div>' +
|
'</div>' +
|
||||||
'{{/each}}'),
|
'{{/each}}'),
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
var Battleside = require("./Battleside");
|
var Battleside = require("./Battleside");
|
||||||
var Card = require("./Card");
|
var Card = require("./Card");
|
||||||
|
var shortid = require("shortid");
|
||||||
|
|
||||||
|
|
||||||
var Battle = (function(){
|
var Battle = (function(){
|
||||||
@ -39,7 +40,8 @@ var Battle = (function(){
|
|||||||
|
|
||||||
r.init = function(){
|
r.init = function(){
|
||||||
/*PubSub.subscribe("update", this.update.bind(this));*/
|
/*PubSub.subscribe("update", this.update.bind(this));*/
|
||||||
this.on("Update", this.update);/*
|
this.on("Update", this.update);
|
||||||
|
/*
|
||||||
this.on("AfterPlace", this.checkAbilityOnAfterPlace)*/
|
this.on("AfterPlace", this.checkAbilityOnAfterPlace)*/
|
||||||
|
|
||||||
|
|
||||||
@ -57,11 +59,23 @@ var Battle = (function(){
|
|||||||
r.start = function(){
|
r.start = function(){
|
||||||
this.p1.setLeadercard();
|
this.p1.setLeadercard();
|
||||||
this.p2.setLeadercard();
|
this.p2.setLeadercard();
|
||||||
this.p1.draw(10);
|
this.p1.draw(5);
|
||||||
this.p2.draw(10);
|
this.p2.draw(5);
|
||||||
|
|
||||||
this.p1.hand.add(Card("kaedweni_siege_expert"));
|
this.p1.hand.add(Card("kaedweni_siege_expert"));
|
||||||
this.p2.hand.add(Card("kaedweni_siege_expert"));
|
this.p2.hand.add(Card("kaedweni_siege_expert"));
|
||||||
|
this.p1.hand.add(Card("ballista"));
|
||||||
|
this.p2.hand.add(Card("ballista"));
|
||||||
|
this.p1.hand.add(Card("ballista"));
|
||||||
|
this.p2.hand.add(Card("ballista"));
|
||||||
|
this.p1.hand.add(Card("ballista"));
|
||||||
|
this.p2.hand.add(Card("ballista"));
|
||||||
|
this.p1.hand.add(Card("ballista"));
|
||||||
|
this.p2.hand.add(Card("ballista"));
|
||||||
|
this.p1.hand.add(Card("ballista"));
|
||||||
|
this.p2.hand.add(Card("ballista"));
|
||||||
|
this.p1.hand.add(Card("decoy"));
|
||||||
|
this.p2.hand.add(Card("decoy"));
|
||||||
/*
|
/*
|
||||||
this.p1.hand.add(Card("dun_banner_medic"));
|
this.p1.hand.add(Card("dun_banner_medic"));
|
||||||
this.p2.hand.add(Card("dun_banner_medic"));
|
this.p2.hand.add(Card("dun_banner_medic"));
|
||||||
@ -151,19 +165,28 @@ var Battle = (function(){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
r.runEvent = function(eventid, ctx, args){
|
r.runEvent = function(eventid, ctx, args, uid){
|
||||||
ctx = ctx || this;
|
ctx = ctx || this;
|
||||||
|
uid = uid || null;
|
||||||
args = args || [];
|
args = args || [];
|
||||||
var event = "on" + eventid;
|
var event = "on" + eventid;
|
||||||
|
|
||||||
if(!this.events[event]){
|
if(!this.events[event]){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.events[event].forEach(function(e){
|
|
||||||
var obj = e;
|
if(uid){
|
||||||
|
var obj = this.events[event][uid];
|
||||||
obj.cb = obj.cb.bind(ctx)
|
obj.cb = obj.cb.bind(ctx)
|
||||||
obj.cb.apply(ctx, obj.onArgs.concat(args));
|
obj.cb.apply(ctx, obj.onArgs.concat(args));
|
||||||
});
|
}
|
||||||
|
else {
|
||||||
|
for(var _uid in this.events[event]) {
|
||||||
|
var obj = this.events[event][_uid];
|
||||||
|
obj.cb = obj.cb.bind(ctx)
|
||||||
|
obj.cb.apply(ctx, obj.onArgs.concat(args));
|
||||||
|
}
|
||||||
|
}
|
||||||
this.update();
|
this.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,6 +194,7 @@ var Battle = (function(){
|
|||||||
ctx = ctx || null;
|
ctx = ctx || null;
|
||||||
args = args || [];
|
args = args || [];
|
||||||
var event = "on" + eventid;
|
var event = "on" + eventid;
|
||||||
|
var uid_event = shortid.generate();
|
||||||
|
|
||||||
var obj = {};
|
var obj = {};
|
||||||
if(!ctx){
|
if(!ctx){
|
||||||
@ -182,29 +206,32 @@ var Battle = (function(){
|
|||||||
obj.onArgs = args;
|
obj.onArgs = args;
|
||||||
|
|
||||||
if(!(event in this.events)){
|
if(!(event in this.events)){
|
||||||
this.events[event] = [];
|
/*this.events[event] = [];*/
|
||||||
|
this.events[event] = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
if(typeof cb !== "function"){
|
if(typeof cb !== "function"){
|
||||||
throw new Error("cb not a function");
|
throw new Error("cb not a function");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(args){
|
this.events[event][uid_event] = obj;
|
||||||
this.events[event].push(obj);
|
|
||||||
|
return uid_event;
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
r.off = function(eventid, uid){
|
||||||
this.events[event].push(obj);
|
uid = uid || null;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
r.off = function(eventid){
|
|
||||||
var event = "on" + eventid;
|
var event = "on" + eventid;
|
||||||
if(!this.events[event]) return;
|
if(!this.events[event]) return;
|
||||||
this.events[event].forEach(function(e){
|
if(uid){
|
||||||
e = null;
|
this.events[event][uid] = null;
|
||||||
});
|
delete this.events[event][uid];
|
||||||
delete this.events[event];
|
return;
|
||||||
|
}
|
||||||
|
for(var _uid in this.events[event]){
|
||||||
|
this.events[event][_uid] = null;
|
||||||
|
delete this.events[event][_uid];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
r.checkIfIsOver = function(){
|
r.checkIfIsOver = function(){
|
||||||
|
@ -330,9 +330,11 @@ Battleside = (function(){
|
|||||||
if(ability.changeSide){
|
if(ability.changeSide){
|
||||||
obj.targetSide = this.foe;
|
obj.targetSide = this.foe;
|
||||||
}
|
}
|
||||||
|
if(ability.onReset){
|
||||||
|
this.on("Reset", ability.onReset, this, [card])
|
||||||
|
}
|
||||||
if(ability.replaceWith){
|
if(ability.replaceWith){
|
||||||
obj._cancelPlacement = true;
|
obj._cancelPlacement = true;
|
||||||
|
|
||||||
this.on("Decoy:replaceWith", function(replaceCard){
|
this.on("Decoy:replaceWith", function(replaceCard){
|
||||||
if(replaceCard.getType() == Card.TYPE.LEADER ||
|
if(replaceCard.getType() == Card.TYPE.LEADER ||
|
||||||
replaceCard.getType() == Card.TYPE.WEATHER ||
|
replaceCard.getType() == Card.TYPE.WEATHER ||
|
||||||
@ -345,6 +347,7 @@ Battleside = (function(){
|
|||||||
|
|
||||||
|
|
||||||
field.replaceWith(replaceCard, card);
|
field.replaceWith(replaceCard, card);
|
||||||
|
self.runEvent("EachCardPlace");
|
||||||
|
|
||||||
self.hand.add(replaceCard);
|
self.hand.add(replaceCard);
|
||||||
self.hand.remove(card);
|
self.hand.remove(card);
|
||||||
@ -354,11 +357,12 @@ Battleside = (function(){
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
if(ability.onEachTurn){
|
if(ability.onEachTurn){
|
||||||
this.on("EachTurn", ability.onEachTurn, this, [card])
|
var uid = this.on("EachTurn", ability.onEachTurn, this, [card])
|
||||||
|
card._uidEvents["EachTurn"] = uid;
|
||||||
}
|
}
|
||||||
if(ability.onEachCardPlace){
|
if(ability.onEachCardPlace){
|
||||||
//PubSub.subscribe("onEachCardPlace", ability.onEachCardPlace.bind(this, card));
|
var uid = this.on("EachCardPlace", ability.onEachCardPlace, this, [card]);
|
||||||
this.on("EachCardPlace", ability.onEachCardPlace, this, [card]);
|
card._uidEvents["EachCardPlace"] = uid;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.update();
|
this.update();
|
||||||
|
@ -9,16 +9,15 @@ var Card = (function(){
|
|||||||
/**
|
/**
|
||||||
* constructor here
|
* constructor here
|
||||||
*/
|
*/
|
||||||
|
this._uidEvents = {};
|
||||||
this.setDisabled(false);
|
this.setDisabled(false);
|
||||||
this.channel = {};
|
|
||||||
this._key = key;
|
this._key = key;
|
||||||
this._data = CardData[key];
|
this._data = CardData[key];
|
||||||
this._data.key = key;
|
this._data.key = key;
|
||||||
this._boost = 0;
|
this._boost = {};
|
||||||
this._forcedPower = -1;
|
this._forcedPower = -1;
|
||||||
this._init();
|
this._init();
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
var r = Card.prototype;
|
var r = Card.prototype;
|
||||||
/**
|
/**
|
||||||
@ -44,8 +43,11 @@ var Card = (function(){
|
|||||||
WEATHER: 5
|
WEATHER: 5
|
||||||
};
|
};
|
||||||
|
|
||||||
r.channel = null
|
r._uidEvents = null;
|
||||||
|
|
||||||
|
r.getUidEvents = function(key) {
|
||||||
|
return this._uidEvents[key];
|
||||||
|
}
|
||||||
|
|
||||||
r._init = function(){
|
r._init = function(){
|
||||||
this._id = ++Card.__id;
|
this._id = ++Card.__id;
|
||||||
@ -57,20 +59,20 @@ var Card = (function(){
|
|||||||
r.getPower = function(){
|
r.getPower = function(){
|
||||||
if(this._data.power === -1) return 0;
|
if(this._data.power === -1) return 0;
|
||||||
if(this._forcedPower > -1){
|
if(this._forcedPower > -1){
|
||||||
return (this._forcedPower > this._data.power ? this._data.power : this._forcedPower) + this._boost;
|
return (this._forcedPower > this._data.power ? this._data.power : this._forcedPower) + this.getBoost();
|
||||||
}
|
}
|
||||||
return this._data.power + this._boost;
|
return this._data.power + this.getBoost();
|
||||||
}
|
}
|
||||||
r.getRawPower = function(){
|
r.getRawPower = function(){
|
||||||
return this._data.power;
|
return this._data.power;
|
||||||
}
|
}
|
||||||
r.calculateBoost = function(){
|
/*r.calculateBoost = function(){
|
||||||
this._boost = 0;
|
this._boost = 0;
|
||||||
for(var key in this._boosts) {
|
for(var key in this._boosts) {
|
||||||
var boost = this._boosts[key];
|
var boost = this._boosts[key];
|
||||||
this.boost(boost.getPower());
|
this.boost(boost.getPower());
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
r.setForcedPower = function(nr){
|
r.setForcedPower = function(nr){
|
||||||
this._forcedPower = nr;
|
this._forcedPower = nr;
|
||||||
}
|
}
|
||||||
@ -110,9 +112,23 @@ var Card = (function(){
|
|||||||
return this._id;
|
return this._id;
|
||||||
}
|
}
|
||||||
|
|
||||||
r.boost = function(nr){
|
/*r.boost = function(nr){
|
||||||
/*this.getPower(); //to recalculate this._power;*/
|
this.getPower(); //to recalculate this._power;
|
||||||
this._boost += nr;
|
this._boost += nr;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
r.getBoost = function() {
|
||||||
|
var res = 0;
|
||||||
|
for(var key in this._boost) {
|
||||||
|
res += this._boost[key];
|
||||||
|
}
|
||||||
|
this.boost = res;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
r.setBoost = function(key, val) {
|
||||||
|
this._boost[key] = val;
|
||||||
|
this.getBoost(); //to recalculate this.boost
|
||||||
}
|
}
|
||||||
|
|
||||||
r.isDisabled = function(){
|
r.isDisabled = function(){
|
||||||
@ -128,9 +144,10 @@ var Card = (function(){
|
|||||||
return this._data[prop];
|
return this._data[prop];
|
||||||
}
|
}
|
||||||
|
|
||||||
r.resetBoost = function(){
|
r.reset = function(){
|
||||||
this._changedType = null;
|
this._changedType = null;
|
||||||
this._boost = 0;
|
this._boost = {};
|
||||||
|
this.boost = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Card;
|
return Card;
|
||||||
|
@ -48,10 +48,14 @@ var Field = (function(){
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
r.isOnField = function(card){
|
||||||
|
return this.getPosition(card) >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
r.replaceWith = function(oldCard, newCard){
|
r.replaceWith = function(oldCard, newCard){
|
||||||
var index = this.getPosition(oldCard);
|
var index = this.getPosition(oldCard);
|
||||||
this._cards[index] = newCard;
|
this._cards[index] = newCard;
|
||||||
oldCard.resetBoost();
|
oldCard.reset();
|
||||||
return oldCard;
|
return oldCard;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,7 +70,7 @@ var Field = (function(){
|
|||||||
r.removeAll = function(){
|
r.removeAll = function(){
|
||||||
var tmp = this._cards.slice();
|
var tmp = this._cards.slice();
|
||||||
tmp.forEach(function(card){
|
tmp.forEach(function(card){
|
||||||
card.resetBoost();
|
card.reset();
|
||||||
})
|
})
|
||||||
this._cards = [];
|
this._cards = [];
|
||||||
return tmp;
|
return tmp;
|
||||||
|
File diff suppressed because one or more lines are too long
@ -1,59 +1,48 @@
|
|||||||
|
var Battle = require("../../server/Battle");
|
||||||
|
var Card = require("../../server/Card");
|
||||||
|
var data = require("../../assets/data/abilities");
|
||||||
|
|
||||||
describe("pubsub", function(){
|
describe("pubsub", function(){
|
||||||
var battle;
|
var battle, card1, card2;
|
||||||
|
|
||||||
beforeEach(function(){
|
beforeEach(function(){
|
||||||
battle = Battle();
|
battle = {};
|
||||||
|
battle.runEvent = Battle.prototype.runEvent;
|
||||||
|
battle.on = Battle.prototype.on;
|
||||||
|
battle.off = Battle.prototype.off;
|
||||||
|
battle.events = {};
|
||||||
|
battle.update = function() {};
|
||||||
|
|
||||||
|
card1 = Card("kaedweni_siege_expert");
|
||||||
|
card2 = Card("dun_banner_medic");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("on: has correct arguments", function(){
|
it("on: has correct arguments", function(){
|
||||||
//this.on("EachTurn", ability.onEachTurn, this, [card])
|
//this.on("EachTurn", ability.onEachTurn, this, [card])
|
||||||
var CARD = {
|
|
||||||
_id: 1,
|
|
||||||
_name: "cardy"
|
|
||||||
}
|
|
||||||
|
|
||||||
battle.on("EachTurn", function(card){
|
battle.on("EachTurn", function(card){
|
||||||
expect(card).toEqual(CARD);
|
expect(card).toEqual(card1);
|
||||||
}, this, [CARD]);
|
}, this, [card1]);
|
||||||
battle.runEvent("EachTurn");
|
battle.runEvent("EachTurn");
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
it("runEvent: has correct arguments", function(){
|
it("runEvent: has correct arguments", function(){
|
||||||
//this.on("EachTurn", ability.onEachTurn, this, [card])
|
//this.on("EachTurn", ability.onEachTurn, this, [card])
|
||||||
var CARD = {
|
battle.on("EachTurn", function(c){
|
||||||
_id: 1,
|
expect(c).toEqual(card1);
|
||||||
_name: "cardy"
|
|
||||||
}
|
|
||||||
|
|
||||||
battle.on("EachTurn", function(card) {
|
|
||||||
expect(card).toEqual(CARD);
|
|
||||||
});
|
});
|
||||||
battle.runEvent("EachTurn", null, [CARD]);
|
battle.runEvent("EachTurn", null, [card1]);
|
||||||
})
|
})
|
||||||
it("on + runEvent: has correct arguments", function(){
|
it("on + runEvent: has correct arguments", function(){
|
||||||
//this.on("EachTurn", ability.onEachTurn, this, [card])
|
//this.on("EachTurn", ability.onEachTurn, this, [card])
|
||||||
var CARD = {
|
battle.on("EachTurn", function(c1, c2){
|
||||||
_id: 1,
|
expect(c1).toEqual(card1);
|
||||||
_name: "cardy"
|
expect(c2).toEqual(card2);
|
||||||
}
|
}, null, [card1]);
|
||||||
var CARD2 = {
|
battle.runEvent("EachTurn", null, [card2]);
|
||||||
_id: 2,
|
|
||||||
_name: "cardooo"
|
|
||||||
}
|
|
||||||
|
|
||||||
battle.on("EachTurn", function(card1, card2) {
|
|
||||||
expect(card1).toEqual(CARD);
|
|
||||||
expect(card2).toEqual(CARD2);
|
|
||||||
}, null, [CARD]);
|
|
||||||
battle.runEvent("EachTurn", null, [CARD2]);
|
|
||||||
})
|
})
|
||||||
it("test context", function(){
|
it("test context", function(){
|
||||||
//this.on("EachTurn", ability.onEachTurn, this, [card])
|
|
||||||
var Card = function(id, name){
|
|
||||||
this.id = id;
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
var card1 = new Card(1, "cardy");
|
|
||||||
var card2 = new Card(2, "cardoo");
|
|
||||||
|
|
||||||
battle.on("EachTurn", function(card){
|
battle.on("EachTurn", function(card){
|
||||||
expect(card.id).toEqual(card1.id);
|
expect(card.id).toEqual(card1.id);
|
||||||
@ -62,13 +51,6 @@ describe("pubsub", function() {
|
|||||||
battle.runEvent("EachTurn");
|
battle.runEvent("EachTurn");
|
||||||
})
|
})
|
||||||
it("test context", function(){
|
it("test context", function(){
|
||||||
//this.on("EachTurn", ability.onEachTurn, this, [card])
|
|
||||||
var Card = function(id, name){
|
|
||||||
this.id = id;
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
var card1 = new Card(1, "cardy");
|
|
||||||
var card2 = new Card(2, "cardoo");
|
|
||||||
|
|
||||||
battle.on("EachTurn", function(card){
|
battle.on("EachTurn", function(card){
|
||||||
expect(card.id).toEqual(card1.id);
|
expect(card.id).toEqual(card1.id);
|
||||||
@ -77,13 +59,6 @@ describe("pubsub", function() {
|
|||||||
battle.runEvent("EachTurn", card2);
|
battle.runEvent("EachTurn", card2);
|
||||||
})
|
})
|
||||||
it("test context", function(){
|
it("test context", function(){
|
||||||
//this.on("EachTurn", ability.onEachTurn, this, [card])
|
|
||||||
var Card = function(id, name){
|
|
||||||
this.id = id;
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
var card1 = new Card(1, "cardy");
|
|
||||||
var card2 = new Card(2, "cardoo");
|
|
||||||
|
|
||||||
battle.on("EachTurn", function(card){
|
battle.on("EachTurn", function(card){
|
||||||
expect(card.id).toEqual(card1.id);
|
expect(card.id).toEqual(card1.id);
|
||||||
@ -92,5 +67,32 @@ describe("pubsub", function() {
|
|||||||
battle.runEvent("EachTurn", card2);
|
battle.runEvent("EachTurn", card2);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should handle off correctly", function() {
|
||||||
|
var cb1 = function(){}, cb2 = function() {};
|
||||||
|
var obj = {
|
||||||
|
cb1: cb1,
|
||||||
|
cb2: cb2
|
||||||
|
}
|
||||||
|
|
||||||
|
spyOn(obj, "cb1");
|
||||||
|
spyOn(obj, "cb2");
|
||||||
|
|
||||||
|
|
||||||
|
var uid1 = battle.on("EachCardPlace", obj.cb1, battle, [card1]);
|
||||||
|
var uid2 = battle.on("EachCardPlace", obj.cb2, battle, [card2]);
|
||||||
|
|
||||||
|
|
||||||
|
battle.off("EachCardPlace", uid2);
|
||||||
|
battle.runEvent("EachCardPlace");
|
||||||
|
|
||||||
|
|
||||||
|
expect(obj.cb1).toHaveBeenCalled();
|
||||||
|
expect(obj.cb2).not.toHaveBeenCalled();
|
||||||
|
|
||||||
|
/*battle.off("EachCardPlace", uid1);
|
||||||
|
|
||||||
|
expect(battle.events).toEqual({});*/
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
require("./filterSpec");
|
require("./filterSpec");
|
||||||
|
require("./PubSubSpec");
|
||||||
|
|
||||||
(function main(){
|
(function main(){
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user