Feat: Add card list and top structure
This commit is contained in:
parent
8e33dd45fe
commit
eec6c6bfe8
19 changed files with 994 additions and 24 deletions
122
app/tools/createJson.mjs
Normal file
122
app/tools/createJson.mjs
Normal file
|
@ -0,0 +1,122 @@
|
|||
import { PrismaClient } from '@prisma/client'
|
||||
import { writeFileSync } from 'fs'
|
||||
|
||||
const db = new PrismaClient()
|
||||
|
||||
const color_names = {
|
||||
"mono-white": ["W"],
|
||||
"mono-black": ["B"],
|
||||
"mono-blue": ["U"],
|
||||
"mono-green": ["G"],
|
||||
"mono-red": ["R"],
|
||||
"colorless": [],
|
||||
"azorius": ["W","U"],
|
||||
"dimir": ["U","B"],
|
||||
"rakdos": ["B","R"],
|
||||
"gruul": ["R","G"],
|
||||
"selesnya": ["G","W"],
|
||||
"orzhov": ["W","B"],
|
||||
"izzet": ["U","R"],
|
||||
"golgari": ["B","G"],
|
||||
"boros": ["R","W"],
|
||||
"simic": ["G","U"],
|
||||
"esper": ["W","U","B"],
|
||||
"grixis": ["U","B","R"],
|
||||
"jund": ["B","R","G"],
|
||||
"naya": ["R","G","W"],
|
||||
"bant": ["G","W","U"],
|
||||
"abzan": ["W","B","G"],
|
||||
"jeskai": ["U","R","W"],
|
||||
"sultai": ["B","G","U"],
|
||||
"mardu": ["R","W","B"],
|
||||
"temur": ["G","U","R"],
|
||||
"yore-tiller": ["W","U","B","R"],
|
||||
"glint-eye": ["U","B","R","G"],
|
||||
"dune-brood": ["B","R","G","W"],
|
||||
"ink-treader": ["R","G","W","U"],
|
||||
"witch-maw": ["G","W","U","B"],
|
||||
"five-color": ["G","W","U","B","R"],
|
||||
}
|
||||
|
||||
function getColorName(colorArray) {
|
||||
const colorArrayID = colorArray.sort().join(',')
|
||||
for (const colorName of Object.keys(color_names)) {
|
||||
if(colorArrayID === color_names[colorName].sort().join(',')){
|
||||
return(colorName)
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// I need to create
|
||||
// Lands
|
||||
// lands.json
|
||||
// All jsons lands from colors
|
||||
// Types
|
||||
|
||||
async function createJson() {
|
||||
console.log("Fetching data...")
|
||||
const bsets = await db.bset.findMany({
|
||||
relationLoadStrategy: "join",
|
||||
include: {
|
||||
sets: {
|
||||
include: {
|
||||
cards: true
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
let all_cards = []
|
||||
bsets.forEach((bset) => {
|
||||
bset.sets.forEach((set) => {
|
||||
all_cards = [...all_cards, ...set.cards]
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
const landsData = {}
|
||||
for (const colorName of Object.keys(color_names)) {
|
||||
landsData[colorName] = []
|
||||
}
|
||||
const type_dict = {"creature": [],"land": [],"instant": [],"sorcery": [], "planeswalker": [], "artifact": [], "enchantment": []}
|
||||
const colorsData = {"mono-white": structuredClone(type_dict),"mono-black": structuredClone(type_dict),"mono-blue": structuredClone(type_dict),"mono-green": structuredClone(type_dict),"mono-red": structuredClone(type_dict),"colorless": structuredClone(type_dict),"multicolor": structuredClone(type_dict)}
|
||||
|
||||
for (const card of all_cards) {
|
||||
const colorName = getColorName(card.colors)
|
||||
if (card.type == "land") {
|
||||
if (colorName != "") {
|
||||
landsData[colorName].push(card)
|
||||
}
|
||||
}
|
||||
|
||||
if (card.colors.length <= 1) {
|
||||
colorsData[colorName][card.type].push(card)
|
||||
} else {
|
||||
colorsData["multicolor"][card.type].push(card)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (const index of Object.keys(colorsData)) {
|
||||
writeFileSync(import.meta.dirname + "/json/top/" + index + ".json",JSON.stringify(colorsData[index]), 'utf8')
|
||||
}
|
||||
|
||||
const landsJsonRoot = [[],[],[],[]]
|
||||
for (const colorName of Object.keys(color_names)){
|
||||
if(color_names[colorName].length <= 3){
|
||||
let index = color_names[colorName].length - 1
|
||||
if(index < 0) { index = 0 }
|
||||
landsJsonRoot[index].push({ "name": colorName, "count": landsData[colorName].length})
|
||||
} else {
|
||||
landsJsonRoot[3].push({ "name": colorName, "count": landsData[colorName].length})
|
||||
}
|
||||
writeFileSync(import.meta.dirname + "/json/lands/" + colorName + ".json",JSON.stringify(landsData[colorName]), 'utf8')
|
||||
}
|
||||
writeFileSync(import.meta.dirname + "/json/lands/lands.json",JSON.stringify(landsJsonRoot), 'utf8')
|
||||
}
|
||||
|
||||
createJson()
|
Loading…
Add table
Add a link
Reference in a new issue