Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/AllCards.json

This file was deleted.

17 changes: 9 additions & 8 deletions app/partials/content-header.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<div class="content-header row well well-sm">
<div class="col-lg-3">
<div class="input-append input-group">
<input name="quickadd" ng-model="quickadd" type="text" class="form-control" typeahead="name for name in cards.select('name') | filter:$viewValue | limitTo:10" placeholder='Card name...'>
<div class="col-lg-3">
<div class="input-append input-group">
<input name="quickadd" ng-model="quickadd" type="text" class="form-control" typeahead="card.name for card in visibleCards | filter:{name: $viewValue} | limitTo:10"
typeahead-template-url="partials/typeahead_template.html" placeholder='Card name...'>
<span class='input-group-btn'>
<button class="btn btn-primary quickadd-btn" type="submit" ng-click="add(quickadd)">Add</button>
</span>
</div>
</div>
</div>

<div class="btn-group pull-right">
<button id="importBtn" class="btn btn-default" ng-click="importDialog()">Import</button>
<button id="exportBtn" class="btn btn-default" ng-click="exportDialog()">Export</button>
</div>
<div class="btn-group pull-right">
<button id="importBtn" class="btn btn-default" ng-click="importDialog()">Import</button>
<button id="exportBtn" class="btn btn-default" ng-click="exportDialog()">Export</button>
</div>
</div>
28 changes: 14 additions & 14 deletions app/partials/nav.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<div class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Lambic</a>
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Lambic</a>
</div>
<div class="collapse navbar-collapse" ng-controller='NavCtrl'>
<ul class="nav navbar-nav">
<li ng-class="{active:isActive('/')}"><a href="#">Home</a></li>
<li ng-class="{active:isActive('/help')}"><a href="#/help">Help</a></li>
</ul>
<ul class="nav navbar-nav">
<li ng-class="{active:isActive('/')}"><a href="#">Home</a></li>
<li ng-class="{active:isActive('/help')}"><a href="#/help">Help</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</div>
</div>
4 changes: 4 additions & 0 deletions app/partials/typeahead_template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<a tabindex="-1">
{{match.model.name}} {{match.model.mana_cost ? ' - ' : ''}}<img ng-repeat="symbolUrl in match.model.mana_cost | manaSymbolsAsImages track by $index"
ng-src="{{symbolUrl}}">
</a>
2 changes: 1 addition & 1 deletion app/scripts/all_cards.js

Large diffs are not rendered by default.

21 changes: 9 additions & 12 deletions app/scripts/controllers/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,27 @@ function AppCtrl($scope,
NamesFromTextService, onBeforeUnload) {

PoolService.subscribe(function(pool) {
if ($scope.plaintext == '') {
$scope.confirmLeaving()
}
$scope.plaintext = pool.select('name').join('\n');
$scope.pool = pool;
});

$scope.makePool = function() {
$scope.confirmLeaving()
PoolService.set(NamesFromTextService.getNames($scope.plaintext));
$scope.pool = PoolService.get();
};

$scope.cards = CardCacheService.insert(all_cards);

// https://github.com/gdi2290/angular-beforeunload
var beforeUnload = $scope.$on('$locationChangeStart', function() {
if ($scope.plaintext) {
onBeforeUnload.init(
'Are you sure you want to leave?',
'Copy your pool on the left if you want to save it for later'
);
}
});

$scope.submitPage = function() {
$scope.confirmLeaving = function() {
// If you invoking your reference then your listener becomes null.
beforeUnload();
onBeforeUnload.init(
'Are you sure you want to leave?',
'Copy your pool on the left if you want to save it for later'
);
};
}

Expand Down
79 changes: 60 additions & 19 deletions app/scripts/directives/directives.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ angular.module('lambicApp.directives', ['ng-depthchart']).
controller: function($scope, PoolService, CardCacheService) {
$scope.add = function(name) {
PoolService.add(name);
}
};

$scope.visibleCards = [];
$scope.$watch('selectedCategory.value.category', function() {
Expand Down Expand Up @@ -138,26 +138,67 @@ angular.module('lambicApp.directives', ['ng-depthchart']).

controller: function($scope) {

// $scope.categories = [
// {name: 'White', category: 'MonoWhite', active: true},
// {name: 'Blue', category: 'MonoBlue'},
// {name: 'Black', category: 'MonoBlack'},
// {name: 'Red', category: 'MonoRed'},
// {name: 'Green', category: 'MonoGreen'},
// {name: 'Colorless', category: 'Colorless/!Land'},
// {name: 'Land', category: 'Colorless/Land', spec: [[
// {category: 'Any', label: 'Sources', subcategories: [
// {category: 'WhiteSource', label: 'White Sources', cards: []},
// {category: 'BlueSource', label: 'Blue Sources', cards: []},
// {category: 'BlackSource', label: 'Black Sources', cards: []},
// {category: 'RedSource', label: 'Red Sources', cards: []},
// {category: 'GreenSource', label: 'Green Sources', cards: []},
// {category: '!WhiteSource/!BlueSource/!BlackSource/!RedSource/!GreenSource',
// label: 'Colorless', cards: []}
// ]}
// ]]},
// {name: 'Multicolor', category: 'Multicolor'},
// {name: 'All', category: 'Any'}
// ];
$scope.categories = [
{name: 'White', category: 'MonoWhite', active: true},
{name: 'Blue', category: 'MonoBlue'},
{name: 'Black', category: 'MonoBlack'},
{name: 'Red', category: 'MonoRed'},
{name: 'Green', category: 'MonoGreen'},
{name: 'All', category: 'Any', active: true},
// {name: 'White', category: 'WhiteColorIdentityExclusive'},
// {name: 'Blue', category: 'BlueColorIdentityExclusive'},
// {name: 'Black', category: 'BlackColorIdentityExclusive'},
// {name: 'Red', category: 'RedColorIdentityExclusive'},
// {name: 'Green', category: 'GreenColorIdentityExclusive'},
// {name: 'Colorless', category: 'Colorless/!Land'},
{name: 'Bant-relevant', category: 'White&Blue&GreenColorIdentityInclusive/!Land'},
{name: 'Azban-relevant', category: 'White&Black&GreenColorIdentityInclusive/!Land'},
{name: 'Esper-relevant', category: 'White&Black&BlueColorIdentityInclusive/!Land'},
{name: 'Sultai-relevant', category: 'Green&Black&BlueColorIdentityInclusive/!Land'},
{name: 'Jund-relevant', category: 'Green&Black&RedColorIdentityInclusive/!Land'},
{name: 'Temur-relevant', category: 'Green&Blue&RedColorIdentityInclusive/!Land'},
{name: 'Naya-relevant', category: 'Green&White&RedColorIdentityInclusive/!Land'},
{name: 'Mardu-relevant', category: 'Black&White&RedColorIdentityInclusive/!Land'},
{name: 'Grixis-relevant', category: 'Black&Blue&RedColorIdentityInclusive/!Land'},
{name: 'Jeskai-relevant', category: 'White&Blue&RedColorIdentityInclusive/!Land'},
{name: 'Colorless', category: 'Colorless/!Land'},
{name: 'Land', category: 'Colorless/Land', spec: [[
{category: 'Any', label: 'Sources', subcategories: [
{category: 'WhiteSource', label: 'White Sources', cards: []},
{category: 'BlueSource', label: 'Blue Sources', cards: []},
{category: 'BlackSource', label: 'Black Sources', cards: []},
{category: 'RedSource', label: 'Red Sources', cards: []},
{category: 'GreenSource', label: 'Green Sources', cards: []},
{category: '!WhiteSource/!BlueSource/!BlackSource/!RedSource/!GreenSource',
label: 'Colorless', cards: []}
]}
]]},
{name: 'Multicolor', category: 'Multicolor'},
{name: 'All', category: 'Any'}
{name: 'Bant-Castable', category: 'White&Blue&GreenCastable'},
{name: 'Azban-Castable', category: 'White&Black&GreenCastable'},
{name: 'Esper-Castable', category: 'White&Black&BlueCastable'},
{name: 'Sultai-Castable', category: 'Green&Black&BlueCastable'},
{name: 'Jund-Castable', category: 'Green&Black&RedCastable'},
{name: 'Temur-Castable', category: 'Green&Blue&RedCastable'},
{name: 'Naya-Castable', category: 'Green&White&RedCastable'},
{name: 'Mardu-Castable', category: 'Black&White&RedCastable'},
{name: 'Grixis-Castable', category: 'Black&Blue&RedCastable'},
{name: 'Jeskai-Castable', category: 'White&Blue&RedCastable'},
// {name: 'Azorious', category: 'White&BlueColorIdentityExclusive'},
// {name: 'Orzhov', category: 'White&BlackColorIdentityExclusive'},
// {name: 'Dimir', category: 'Black&BlueColorIdentityExclusive'},
// {name: 'Simic', category: 'Green&BlueColorIdentityExclusive'},
// {name: 'Jund', category: 'Green&Black&RedColorIdentityExclusive'},
// {name: 'Izzet', category: 'Blue&RedColorIdentityExclusive'},
// {name: 'Gruul', category: 'Green&RedColorIdentityExclusive'},
// {name: 'Boros', category: 'White&RedColorIdentityExclusive'},
// {name: 'Rakdos', category: 'Black&RedColorIdentityExclusive'},
// {name: 'Selesnya', category: 'White&GreenColorIdentityExclusive'}

];

$scope.selectedCategory = {value: $scope.categories[0]};
Expand Down
75 changes: 57 additions & 18 deletions app/scripts/services/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,13 @@ angular.module('lambicApp.services', [])
};

return {
isColorPresent: function(name) {
return new RegExp(this._nameToAbbrev(name), 'i');
isColorPresent: function(color) {
return new RegExp([
'('+this._mono(color)+')',
'('+this._mono_hybrid(color)+')',
'('+this._phyrexian(color)+')',
'('+this._hybrid_involving(color)+')'
].join('|'));
},
_nameToAbbrev: function(name) {
return _color_to_abbrev_mapping[name.toLowerCase()];
Expand All @@ -101,7 +106,7 @@ angular.module('lambicApp.services', [])
return '{'+this._nameToAbbrev(color)+'/P}';
},
_mono_hybrid: function(color) {
return '{'+this._nameToAbbrev(color)+'/2}';
return '{2/'+this._nameToAbbrev(color)+'}';
},
_hybrid_involving: function(color) {
var _color_on_top = this._nameToAbbrev(color)+'/'+_any_color;
Expand Down Expand Up @@ -150,17 +155,15 @@ angular.module('lambicApp.services', [])
_selected = selected
},

estimateColors: function(card) {

estimateColors: function(field) {
var includedColors = [];

if (!card.mana_cost) {
if (!field) {
return includedColors;
}

angular.forEach(UtilityService.colorList(), function(color) {
var colorRegex = ManaCostRegexService.isColorPresent(color);
if (colorRegex.exec(card.mana_cost)) {
if (colorRegex.exec(field)) {
includedColors.push(color)
}
});
Expand Down Expand Up @@ -237,8 +240,47 @@ angular.module('lambicApp.services', [])

var colors = colorMatch[1].split(/\s*&\s*/);

return ManaCostRegexService.isCastableBy(colors, card.mana_cost);
return ManaCostRegexService.isCastableBy(colors, card.manaCost);

},

_checkForExclusiveColorIdentity: function(category, card) {
if (category.indexOf('ColorIdentityExclusive') === -1) {
return 'na'
}

var colorMatch = /(.+?)\s*ColorIdentityExclusive/i.exec(category);

if (!colorMatch) {
return 'na';
}

var colors = colorMatch[1].split(/\s*&\s*/);

return angular.equals(colors.sort(), card.colorIdentity.sort());
},

_checkForInclusiveColorIdentity: function(category, card) {
if (category.indexOf('ColorIdentityInclusive') === -1) {
return 'na'
}

var colorMatch = /(.+?)\s*ColorIdentityInclusive/i.exec(category);

if (!colorMatch) {
return 'na';
}

var colors = colorMatch[1].split(/\s*&\s*/);

var included = true;
angular.forEach(card.colorIdentity, function(color) {

if (included) {
included = UtilityService.inArray(color, colors) !== -1
}
});
return included;
},

_checkForManaSource: function(category, card) {
Expand Down Expand Up @@ -314,7 +356,7 @@ angular.module('lambicApp.services', [])
var match = cmcRegex.exec(category);
if (match) {
var integerCMC;
var cardCMC = card['converted_mana_cost'];
var cardCMC = card['cmc'];
if (cardCMC==-1) {
// -1 is what we're using to represent 'X' spells
cardCMC = Number.POSITIVE_INFINITY;
Expand Down Expand Up @@ -403,6 +445,8 @@ angular.module('lambicApp.services', [])
var shouldContinueChecking = true;

angular.forEach([
self._checkForExclusiveColorIdentity,
self._checkForInclusiveColorIdentity,
self._checkForCastability,
self._checkForColor,
self._checkForType,
Expand Down Expand Up @@ -501,12 +545,7 @@ angular.module('lambicApp.services', [])
set: function(names) {
pool().remove(true);

CardCacheService.get_cards(names, function(cards) {
pool.insert(cards);
angular.forEach(callbacks, function(callback) {
callback(pool());
});
});
this.addMany(names);
},

addMany: function(names) {
Expand Down Expand Up @@ -739,11 +778,11 @@ angular.module('lambicApp.services', [])
.factory('CardCacheService', function($cacheFactory, HeuristicService, CardCategoryService, $log) {
var cache = new TAFFY();


return {
onInsert: function(card) {

card.colors = HeuristicService.estimateColors(card);
card.colors = HeuristicService.estimateColors(card.manaCost);
card.colorIdentity = HeuristicService.estimateColors(card.text + card.manaCost);

return card;
},
Expand Down
14 changes: 0 additions & 14 deletions test/unit/controllerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,5 @@ describe('MainCtrl', function(){
spyOn(onBeforeUnload, 'init');
}));

// issue #13
it('should prompt before leaving if sidebar is not empty', function() {
scope.plaintext = 'Some Name\nSome other Name';
scope.$broadcast('$locationChangeStart');
expect(beforeUnload.init).toHaveBeenCalled();
});

// issue #13
it('should NOT prompt before leaving if sidebar is empty', function() {
scope.plaintext = '';
scope.$broadcast('$locationChangeStart');
expect(beforeUnload.init).not.toHaveBeenCalled();
});

});
});
Loading