Skip to content
This repository has been archived by the owner on Dec 21, 2018. It is now read-only.

Commit

Permalink
Added a unique id per card, closes #63. Also updated some NPM depende…
Browse files Browse the repository at this point in the history
…ncies
  • Loading branch information
Sembiance committed Aug 18, 2015
1 parent 6ee2c9c commit 560f550
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 13 deletions.
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@
"dependencies" :
{
"xutil" : "git://github.com/Sembiance/xutil.git",
"moment" : ">= 2.9.0",
"moment" : ">= 2.10.6",
"tiptoe" : ">= 1.0.0",
"xbase" : "git://github.com/Sembiance/xbase.git",
"domino" : ">= 1.0.18",
"rimraf" : ">= 2.2.6",
"domino" : ">= 1.0.19",
"rimraf" : ">= 2.4.2",
"cli-color" : ">= 0.2.3",
"mhash" : ">= 1.1.0"
"mhash" : ">= 2.0.2"
},
"engines" :
{
"node" : ">= 0.12.0"
},
"engineStrict" : true
}
}
2 changes: 1 addition & 1 deletion shared/C.js
Original file line number Diff line number Diff line change
Expand Up @@ -3368,7 +3368,7 @@
exports.ORACLE_FIELDS = ["layout", "name", "names", "manaCost", "cmc", "colors", "type", "supertypes", "types", "subtypes", "text", "power", "toughness", "loyalty", "hand", "life", "rulings", "printings", "legalities"];
exports.INTERNAL_ONLY_FIELDS = ["variations"];
exports.EXTRA_FIELDS = ["rulings", "foreignNames", "printings", "originalText", "originalType", "legalities", "source"];
exports.SET_SPECIFIC_FIELDS = ["rarity", "artist", "flavor", "number", "multiverseid", "watermark", "border", "timeshifted", "reserved", "releaseDate", "originalText", "originalType"];
exports.SET_SPECIFIC_FIELDS = ["rarity", "artist", "flavor", "number", "multiverseid", "watermark", "border", "timeshifted", "reserved", "releaseDate", "originalText", "originalType", "id", "foreignNames"];

exports.VINTAGE_BANNED = ["Advantageous Proclamation", "Amulet of Quoz", "Backup Plan", "Brago's Favor", "Bronze Tablet", "Chaos Orb", "Contract from Below", "Darkpact", "Demonic Attorney", "Double Stroke", "Falling Star", "Immediate Action", "Iterative Analysis", "Jeweled Bird", "Muzzio's Preparations", "Power Play", "Rebirth", "Secret Summoning", "Secrets of Paradise", "Sentinel Dispatch", "Shahrazad", "Tempest Efreet", "Timmerian Fiends", "Unexpected Potential", "Worldknit"];
exports.VINTAGE_RESTRICTED = ["Ancestral Recall", "Balance", "Black Lotus", "Brainstorm", "Channel", "Demonic Consultation", "Demonic Tutor", "Fastbond", "Flash", "Gifts Ungiven", "Imperial Seal", "Library of Alexandria", "Lion’s Eye Diamond", "Lotus Petal", "Mana Crypt", "Mana Vault", "Memory Jar", "Merchant Scroll", "Mind’s Desire", "Mox Emerald", "Mox Jet", "Mox Pearl", "Mox Ruby", "Mox Sapphire", "Mystical Tutor", "Necropotence", "Ponder", "Sol Ring", "Strip Mine", "Thirst for Knowledge", "Time Vault", "Time Walk", "Timetwister", "Tinker", "Tolarian Academy", "Trinisphere", "Vampiric Tutor", "Wheel of Fortune", "Windfall", "Yawgmoth’s Bargain", "Yawgmoth’s Will"];
Expand Down
7 changes: 7 additions & 0 deletions shared/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,14 @@ exports.performSetCorrections = function(setCorrections, fullSet)
card.foreignNames = card.foreignNames.sort(function(a, b) { var al = a.language.toLowerCase().charAt(0); var bl = b.language.toLowerCase().charAt(0); return (al<bl ? -1 : (al>bl ? 1 : 0)); });
});

// Finalize printings
cards.forEach(exports.finalizePrintings);

// Generate ID
cards.forEach(function(card)
{
card.id = hash("sha1", (fullSet.code + card.name + card.imageName));
});
};

exports.generateCacheFilePath = generateCacheFilePath;
Expand Down
2 changes: 1 addition & 1 deletion util/clearCacheForSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function clearCacheForSet(code, cacheType, cb)
var set = JSON.parse(setRaw);
if(cacheType==="mcilist")
{
if(!set.magicCardsInfoCode)
if(!set.isMCISet)
return this.finish();

var urls = [];
Expand Down
16 changes: 12 additions & 4 deletions util/tmp.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ var base = require("xbase"),
fileUtil = require("xutil").file,
diffUtil = require("xutil").diff,
path = require("path"),
hash = require("mhash"),
tiptoe = require("tiptoe");

var uniqueHashes = [];

tiptoe(
function processSets()
{
Expand All @@ -34,9 +37,6 @@ tiptoe(

function checkSet(setCode, cb)
{
if(setCode!=="pWPN")
return cb();

tiptoe(
function getJSON()
{
Expand All @@ -48,7 +48,15 @@ function checkSet(setCode, cb)

set.cards.forEach(function(card)
{
base.info("%s %d\t%s", card.releaseDate, card.number, card.name);
var id = hash("sha1", (setCode + card.name + card.imageName));
base.info(id);
if(uniqueHashes.contains(id))
{
base.error("COLLISION!");
process.exit(0);
}

uniqueHashes.push(id);
});

//fs.writeFile(path.join(__dirname, "..", "json", setCode + ".json"), JSON.stringify(set), {encoding : "utf8"}, this);
Expand Down
3 changes: 2 additions & 1 deletion web/changelog.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"Removed the 'languagesPrinted' set field. See <a href=\"https://github.com/Sembiance/mtgjson/issues/12\">GitHub Issue #12</a> for more details.",
"Renamed the 'printingCodes' card field to be 'printings'. Thus the 'printings' field is now an array of set codes, rather than set names. See docs or <a href=\"https://github.com/Sembiance/mtgjson/issues/65\">GitHub Issue #65</a> for more details.",
"The 'legalities' card field is now an array of objects rather than a flat object. See docs or <a href=\"https://github.com/Sembiance/mtgjson/issues/66\">GitHub Issue #66</a> for more details.",
"The pWPN is now named 'Wizards Play Network' and now only contains the WPN cards. The Gateway cards are now part of a new promo set, pGTW. See <a href=\"https://github.com/Sembiance/mtgjson/issues/50\">GitHub Issue #50</a> for more details."
"The pWPN is now named 'Wizards Play Network' and now only contains the WPN cards. The Gateway cards are now part of a new promo set, pGTW. See <a href=\"https://github.com/Sembiance/mtgjson/issues/50\">GitHub Issue #50</a> for more details.",
"Every card now has a unique 'id' field. See docs or <a href=\"https://github.com/Sembiance/mtgjson/issues/63\">GitHub Issue #63</a> for more details."
],
"newSetFiles" : ["pGTW", "pGTW-x"],
"updatedSetFiles" : []
Expand Down
19 changes: 19 additions & 0 deletions web/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,25 @@ function checkSetForProblems(setCode, cb)
}
}

// Check set for id missing or collision
var cardids = [];
setData.cards.forEach(function(card)
{
if(!card.hasOwnProperty("id"))
{
base.info("%s: Card is missing 'id' field: %s", setCode, card.name);
return;
}

if(cardids.contains(card.id))
{
base.info("%s: Card (%s) has an id COLLISION: %s", setCode, card.name, card.id);
return;
}

cardids.push(card.id);
});

this();
},
function finish(err)
Expand Down

0 comments on commit 560f550

Please sign in to comment.