Feat: Add commander and Bset stats
This commit is contained in:
parent
b2010dae41
commit
64a4c5fb87
24 changed files with 626 additions and 977 deletions
|
@ -47,7 +47,6 @@ interface bsetJson extends bset {
|
|||
interface cardEntryAPIProps {
|
||||
amount: number,
|
||||
sanitized_name: string,
|
||||
set: string
|
||||
}
|
||||
|
||||
interface deckAPIProps {
|
||||
|
@ -97,24 +96,10 @@ export default function Signin() {
|
|||
|
||||
function getDataFromLine(line: string){
|
||||
if(line != "") {
|
||||
const values = line.split(" ")
|
||||
if (values.length >= 4) {
|
||||
const amount: number = parseInt(values.at(0)!.toString())
|
||||
|
||||
let set_index = 0
|
||||
for(let i = 1; i < values.length; i++){
|
||||
if(values.at(-i)!.toString().match(/\([A-Z]{3}\)/gm)){
|
||||
set_index = -i
|
||||
}
|
||||
}
|
||||
|
||||
const set = values.at(set_index)!.toString().replace(/[()]/gm,"").toLowerCase()
|
||||
const card_name = values.slice(1,set_index).join(" ").replace(/[^a-zA-Z0-9]/gim,"-").toLowerCase()
|
||||
const card_data : cardEntryAPIProps = {amount, sanitized_name: card_name, set}
|
||||
return card_data
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
const data = line.split(" ")
|
||||
const amount = parseInt(data[0])
|
||||
const name = data.slice(1).join(" ").split("/")[0].replace(/[^a-zA-Z0-9]/gim,"-").toLowerCase()
|
||||
return {"sanitized_name":name, "amount":amount}
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
|
@ -136,14 +121,15 @@ export default function Signin() {
|
|||
function updateDeckInput(txt:string){
|
||||
setDeckImporter(txt)
|
||||
const lines = txt.split("\n")
|
||||
setDeckCommanderName(lines[0])
|
||||
setDeckCommanderName(lines[lines.length - 1])
|
||||
}
|
||||
|
||||
function importDeck(){
|
||||
const deckText = deckImporter
|
||||
const lines = deckText.split("\n")
|
||||
let lines = deckText.split("\n")
|
||||
lines = lines.filter((line) => line.match(/[0-9]+\s[\w]+/) != undefined)
|
||||
const dataToSend : deckAPIProps = { name: deckName, selected_bset: selectedBset.replace(/[^a-zA-Z0-9]/gim,"-").toLowerCase() ,commander_name: getDataFromLine(deckCommanderName)!.sanitized_name, cards: [] }
|
||||
lines.slice(1).forEach((line: string) => {
|
||||
lines.slice(0, lines.length - 1).forEach((line: string) => {
|
||||
const data = getDataFromLine(line)
|
||||
if(data != null) {
|
||||
dataToSend.cards.push(data)
|
||||
|
@ -151,7 +137,6 @@ export default function Signin() {
|
|||
});
|
||||
console.log(dataToSend)
|
||||
|
||||
|
||||
fetch('http://localhost:3000/api/account/decks/create', {
|
||||
method: "POST",
|
||||
headers: {Authorization: 'Bearer ' + token},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue