changed DDF syntax to follow JSON standards

This commit is contained in:
bluesaxman 2020-09-04 10:19:26 -06:00
parent f6ccab0919
commit 6758972a84
5 changed files with 109 additions and 96 deletions

View File

@ -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"]
}
]
]
```

View File

@ -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));
});

View File

@ -1,25 +1,22 @@
[{"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"]
},
{
"color":["red ", "black "],
"joker":["joker"]
}
"dataIndex":1,
"name":"suit",
"data":[ "♥", "♣", "♠", "♦" ]
}],
[{
"dataIndex":0,
"name":"color",
"data":["red ", "black "]
},
{
"dataIndex":1,
"name":"joker",
"data":["joker"]
}]
]

View File

@ -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":[ "♥", "♣", "♠", "♦" ]
}
]

63
uno.ddf
View File

@ -1,37 +1,32 @@
[{"color":[
"<div style=\"background:#f00;",
"<div style=\"background:#0f0;",
"<div style=\"background:#00f;",
"<div style=\"background:#ff0;"
],
"style":[" color:#fff; text-shadow:1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000; border:5px #fff solid; display:flex; justify-content:center; align-items:center; height:100%; width:100%; font-size:3em; box-sizing:border-box;\"><div style=\"display:flex; flex-direction:column; align-items:center; justify-content:center; overflow:hidden; text-align:center; border:5px #fff solid; box-sizing:border-box; border-radius:50%; height:90%; width:90%;\">"],
"value":[
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"11",
"12",
"13",
"⮌<p>Reverse",
"⊘<p>skip",
"+2<p>Draw 2"
],
"end":["</div></div>"]
[
[{
"dataIndex":0,
"name":"color",
"data":[ "<div style=\"background:#f00;", "<div style=\"background:#0f0;", "<div style=\"background:#00f;", "<div style=\"background:#ff0;"]
},
{
"draw4":["<div style=\"background:#000; color:#fff; border:5px #fff solid; display:flex; justify-content:center; align-items:center; height:100%; width:100%; font-size:3em; box-sizing:border-box;\"><div style=\"text-align:center; display:flex; flex-direction:column;\">"],
"cards":[
"+4<p>Draw 4</div></div>",
"+4<p>Draw 4</div></div>",
"+4<p>Draw 4</div></div>",
"+4<p>Draw 4</div></div>"
]
}
"dataIndex":1,
"name":"style",
"data":[" color:#fff; text-shadow:1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000; border:5px #fff solid; display:flex; justify-content:center; align-items:center; height:100%; width:100%; font-size:3em; box-sizing:border-box;\"><div style=\"display:flex; flex-direction:column; align-items:center; justify-content:center; overflow:hidden; text-align:center; border:5px #fff solid; box-sizing:border-box; border-radius:50%; height:90%; width:90%;\">"]
},
{
"dataIndex":2,
"name":"value",
"data":[ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "⮌<p>Reverse", "⊘<p>skip", "+2<p>Draw 2"]
},
{
"dataIndex":3,
"name":"end",
"data":["</div></div>"]
}],
[{
"dataIndex":0,
"name":"draw4",
"data":["<div style=\"background:#000; color:#fff; border:5px #fff solid; display:flex; justify-content:center; align-items:center; height:100%; width:100%; font-size:3em; box-sizing:border-box;\"><div style=\"text-align:center; display:flex; flex-direction:column;\">"]
},
{
"dataIndex":1,
"name":"cards",
"data":[ "+4<p>Draw 4</div></div>", "+4<p>Draw 4</div></div>", "+4<p>Draw 4</div></div>", "+4<p>Draw 4</div></div>"]
}]
]