aboutsummaryrefslogtreecommitdiff
path: root/src/utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils.js')
-rw-r--r--src/utils.js48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/utils.js b/src/utils.js
index e69de29..05e519d 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -0,0 +1,48 @@
+function parseYdk(ydkContent) {
+ const lines = ydkContent.split('\n');
+ const deck = {
+ main: [],
+ extra: [],
+ side: [],
+ };
+ let currentSection = null;
+ for (const line of lines) {
+ const trimmedLine = line.trim();
+ if (!trimmedLine || trimmedLine.startsWith('#') && !['#main', '#extra'].includes(trimmedLine)) {
+ continue;
+ }
+ if (trimmedLine === '#main') {
+ currentSection = 'main';
+ } else if (trimmedLine === '#extra') {
+ currentSection = 'extra';
+ } else if (trimmedLine === '!side') {
+ currentSection = 'side';
+ } else if (currentSection) {
+ const cardId = parseInt(trimmedLine, 10);
+ if (!isNaN(cardId)) {
+ deck[currentSection].push(String(cardId));
+ }
+ }
+ }
+ return deck;
+}
+
+function genYdk(deck) {
+ let ydkContent = '#created by ygodeck.mistivia.com\n';
+
+ ydkContent += '#main\n';
+ ydkContent += deck.main.join('\n') + '\n';
+
+ ydkContent += '#extra\n';
+ ydkContent += deck.extra.join('\n') + '\n';
+
+ ydkContent += '!side\n';
+ ydkContent += deck.side.join('\n') + '\n';
+
+ return ydkContent;
+}
+
+export {
+ parseYdk,
+ genYdk,
+};