Skip to content

Commit

Permalink
extracted keyword noAttack to its own JavaScript file, also impleme…
Browse files Browse the repository at this point in the history
…nted the actual noAttack functionality
  • Loading branch information
Zomis committed May 4, 2015
1 parent e98dedb commit 7884810
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
1 change: 1 addition & 0 deletions extra-resources/JSGame.js
Expand Up @@ -2,6 +2,7 @@ load('keywords.js');
load('keywords-creatures.js');
load('keywords-enchantments.js');
load('keywords-systems.js');
load('keyword-noattack.js');

function createResource(name) {
return new com.cardshifter.modapi.resources.ECSResourceDefault(name);
Expand Down
13 changes: 13 additions & 0 deletions extra-resources/keyword-noattack.js
@@ -0,0 +1,13 @@
var noAttackCreatures = new java.util.HashSet();

keywords.cards.noAttack = function (entity, obj, value) {
if (!obj.creature) {
throw new Error("expected creature");
}
noAttackCreatures.add(obj.name);
}

keywords.afterCards.push(function (game) {
var System = Java.type("net.zomis.cardshifter.ecs.usage.DenyActionForNames");
game.addSystem(new System(ATTACK_ACTION, noAttackCreatures));
});
10 changes: 0 additions & 10 deletions extra-resources/keywords-creatures.js
@@ -1,6 +1,3 @@
var noAttackCreatures = [];

keywords.cards = {};
keywords.cards.name = function (entity, obj, value) {
com.cardshifter.modapi.attributes.ECSAttributeMap.createOrGetFor(entity).set(com.cardshifter.modapi.attributes.Attributes.NAME, value);
}
Expand Down Expand Up @@ -61,13 +58,6 @@ keywords.cards.sickness = function (entity, obj, value) {
SICKNESS.retriever.set(entity, value);
}

keywords.cards.noAttack = function (entity, obj, value) {
if (!obj.creature) {
throw new Error("expected creature");
}
noAttackCreatures.push(obj.name);
}

keywords.cards.denyCounterAttack = function (entity, obj, value) {
if (!obj.creature) {
throw new Error("expected creature");
Expand Down
14 changes: 5 additions & 9 deletions extra-resources/keywords.js
@@ -1,5 +1,7 @@
var ECSAction = Java.type("com.cardshifter.modapi.actions.ECSAction");
var keywords = {};
keywords.cards = {};
keywords.afterCards = [];

function applyEntity(game, card, entity, keyword) {
print("applyEntity " + card + ": " + entity);
Expand All @@ -20,21 +22,15 @@ function applyEntity(game, card, entity, keyword) {


function applyCardKeywords(game, zone, data) {

for (var i = 0; i < data.cards.length; i++) {
var card = data.cards[i];
var entity = game.newEntity();
applyEntity(game, card, entity, keywords.cards);
zone.addOnBottom(entity);
}
}

function applyKeywords(game, data) {

beforeApplyKeywords(game, data);
applyKeywords(game, data);
afterApplyKeywords(game, data);

for (var i = 0; i < keywords.afterCards.length; i++) {
keywords.afterCards[i](game);
}
}

function applySystem(game, data, keyword) {
Expand Down

0 comments on commit 7884810

Please sign in to comment.