-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdeck.cod.js
43 lines (34 loc) · 1.29 KB
/
deck.cod.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const COD_DECK_FILE_TEMPLATE = `<?xml version="1.0" encoding="UTF-8"?>
<cockatrice_deck version="1">
<deckname>{DECKNAME}</deckname>
<comments>{COMMENTS}</comments>
<zone name="main">
{CARDS}
</zone>
</cockatrice_deck>
`
const COD_DECK_CARD_TEMPLATE = '<card number="{NUMBER}" name="{NAME}"/>'
function generateCodContents(card_list_complex, date) {
// Card tenplate replacement
let codXmlCardArray = new Array
for (let i = 0; i < card_list_complex.length; i++) {
let a = COD_DECK_CARD_TEMPLATE
a = a.replace("{NUMBER}", card_list_complex[i].number)
a = a.replace("{NAME}", card_list_complex[i].name)
codXmlCardArray.push(a)
}
// console.debug(codXmlCardArray)
// Card XML plain text
let codXmlCardText = codXmlCardArray.join("\n ")
// console.debug(codXmlCardText)
// COD file final template replacement
let codFile = COD_DECK_FILE_TEMPLATE
codFile = codFile.replace("{DECKNAME}", date)
codFile = codFile.replace("{COMMENTS}", 'This deck was generated using "MTG card randomizer"')
codFile = codFile.replace("{CARDS}", codXmlCardText)
console.groupCollapsed(".cod file contents:")
console.log(codFile)
console.groupEnd()
return codFile
}
export {generateCodContents}