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: 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. 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. 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":["♥","♣","♠","♦"] {
},{ "dataIndex":0,
"color":["red ", "black "], "name":"value",
"joker":["joker"] "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) { function generateDeck(DDF) {
var cards = [""]; var cards = [""];
for (var attribute in DDF) { DDF.sort(function (a,b) {
return a.dataIndex - b.dataIndex;
});
DDF.forEach( function (data) {
var tempcards = []; var tempcards = [];
cards.forEach( function (current) { cards.forEach( function (current) {
DDF[attribute].forEach( function (value) { DDF.data.forEach( function (value) {
tempcards.push(current+value); tempcards.push(current+value);
} ); } );
} ); } );
cards = tempcards.slice(); cards = tempcards.slice();
} });
return cards; return cards;
} }
@ -49,7 +52,7 @@ function shuffleDeck(deck) {
} }
function deckFromJSON(ourFile) { function deckFromJSON(ourFile) {
if ( Array.isArray(ourFile) ) { if ( Array.isArray(ourFile[0]) ) {
ourFile.forEach(function (deck) { ourFile.forEach(function (deck) {
window.deck = window.deck.concat(generateDeck(deck)); window.deck = window.deck.concat(generateDeck(deck));
}); });

View File

@ -1,25 +1,22 @@
[{"value":[ [
"A", [{
"2", "dataIndex":0,
"3", "name":"value",
"4", "data":[ "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"]
"5", },
"6", {
"7", "dataIndex":1,
"8", "name":"suit",
"9", "data":[ "♥", "♣", "♠", "♦" ]
"10", }],
"J", [{
"Q", "dataIndex":0,
"K"], "name":"color",
"shape":[ "data":["red ", "black "]
"♥", },
"♣", {
"♠", "dataIndex":1,
"♦" "name":"joker",
]}, "data":["joker"]
{ }]
"color":["red ", "black "],
"joker":["joker"]
}
] ]

View File

@ -1,21 +1,12 @@
{"value":[ [
"A", {
"2", "dataIndex":0,
"3", "name":"value",
"4", "data":[ "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"]
"5", },
"6", {
"7", "dataIndex":1,
"8", "name":"suit",
"9", "data":[ "♥", "♣", "♠", "♦" ]
"10", }
"J", ]
"Q",
"K"],
"shape":[
"♥",
"♣",
"♠",
"♦"
]}

67
uno.ddf
View File

@ -1,37 +1,32 @@
[{"color":[ [
"<div style=\"background:#f00;", [{
"<div style=\"background:#0f0;", "dataIndex":0,
"<div style=\"background:#00f;", "name":"color",
"<div style=\"background:#ff0;" "data":[ "<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":[ "dataIndex":1,
"1", "name":"style",
"2", "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%;\">"]
"3", },
"4", {
"5", "dataIndex":2,
"6", "name":"value",
"7", "data":[ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "⮌<p>Reverse", "⊘<p>skip", "+2<p>Draw 2"]
"8", },
"9", {
"10", "dataIndex":3,
"11", "name":"end",
"12", "data":["</div></div>"]
"13", }],
"⮌<p>Reverse", [{
"⊘<p>skip", "dataIndex":0,
"+2<p>Draw 2" "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;\">"]
"end":["</div></div>"] },
}, {
{ "dataIndex":1,
"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;\">"], "name":"cards",
"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>"]
"+4<p>Draw 4</div></div>", }]
"+4<p>Draw 4</div></div>",
"+4<p>Draw 4</div></div>",
"+4<p>Draw 4</div></div>"
]
}
] ]