diff --git a/README.md b/README.md index c0ed7c4..e9bb3e6 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,18 @@ Deckard is a simple deck shuffeling and card drawing program, its designed to us An example of a deck definition file: ``` -{ -"value":[ "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"], -"suit":[ "♥", "♣", "♠", "♦"] -} +[ + { + "dataIndex":0, + "name":"value", + "data":[ "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"] + }, + { + "dataIndex":1, + "name":"suit", + "data":[ "♥", "♣", "♠", "♦"] + } +] ``` Using this you can make all kinds of decks. @@ -17,11 +25,30 @@ Using this you can make all kinds of decks. A more advanced example uses an array of "decks" to build a single deck. ``` -[{ -"value":["A","2","3","4","5","6","7","8","9","10","J","Q","K"], -"shape":["♥","♣","♠","♦"] -},{ -"color":["red ", "black "], -"joker":["joker"] -}] +[ + [ + { + "dataIndex":0, + "name":"value", + "data":["A","2","3","4","5","6","7","8","9","10","J","Q","K"] + }, + { + "dataIndex":1, + "name":"suit", + "data":["♥","♣","♠","♦"] + } + ], + [ + { + "dataIndex":0, + "name":"color", + "data":["red ", "black "] + }, + { + "dataIndex":1, + "name":"joker", + "data":["joker"] + } + ] +] ``` diff --git a/index.html b/index.html index 1102ce0..0a41da9 100644 --- a/index.html +++ b/index.html @@ -27,15 +27,18 @@ function updateEvent() { function generateDeck(DDF) { var cards = [""]; - for (var attribute in DDF) { + DDF.sort(function (a,b) { + return a.dataIndex - b.dataIndex; + }); + DDF.forEach( function (data) { var tempcards = []; cards.forEach( function (current) { - DDF[attribute].forEach( function (value) { + DDF.data.forEach( function (value) { tempcards.push(current+value); } ); } ); cards = tempcards.slice(); - } + }); return cards; } @@ -49,7 +52,7 @@ function shuffleDeck(deck) { } function deckFromJSON(ourFile) { - if ( Array.isArray(ourFile) ) { + if ( Array.isArray(ourFile[0]) ) { ourFile.forEach(function (deck) { window.deck = window.deck.concat(generateDeck(deck)); }); diff --git a/jokers.ddf b/jokers.ddf index 3dfd8f3..019bfbe 100644 --- a/jokers.ddf +++ b/jokers.ddf @@ -1,25 +1,22 @@ -[{"value":[ - "A", - "2", - "3", - "4", - "5", - "6", - "7", - "8", - "9", - "10", - "J", - "Q", - "K"], -"shape":[ - "♥", - "♣", - "♠", - "♦" -]}, -{ -"color":["red ", "black "], -"joker":["joker"] -} +[ + [{ + "dataIndex":0, + "name":"value", + "data":[ "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"] + }, + { + "dataIndex":1, + "name":"suit", + "data":[ "♥", "♣", "♠", "♦" ] + }], + [{ + "dataIndex":0, + "name":"color", + "data":["red ", "black "] + }, + { + "dataIndex":1, + "name":"joker", + "data":["joker"] + }] ] diff --git a/standardfaces.ddf b/standardfaces.ddf index 5cc8507..104f032 100644 --- a/standardfaces.ddf +++ b/standardfaces.ddf @@ -1,21 +1,12 @@ -{"value":[ - "A", - "2", - "3", - "4", - "5", - "6", - "7", - "8", - "9", - "10", - "J", - "Q", - "K"], -"shape":[ - "♥", - "♣", - "♠", - "♦" -]} - +[ + { + "dataIndex":0, + "name":"value", + "data":[ "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"] + }, + { + "dataIndex":1, + "name":"suit", + "data":[ "♥", "♣", "♠", "♦" ] + } +] diff --git a/uno.ddf b/uno.ddf index 5b83276..8c55a52 100644 --- a/uno.ddf +++ b/uno.ddf @@ -1,37 +1,32 @@ -[{"color":[ - "
Reverse", - "⊘
skip", - "+2
Draw 2" -], -"end":["
Draw 4
Draw 4", - "+4
Draw 4", - "+4
Draw 4" -] -} +[ + [{ + "dataIndex":0, + "name":"color", + "data":[ "
Reverse", "⊘
skip", "+2
Draw 2"] + }, + { + "dataIndex":3, + "name":"end", + "data":["
Draw 4
Draw 4", "+4
Draw 4", "+4
Draw 4"] + }] ]