-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #84 from signed/fetch-item-cards-from-worldhaven
Fetch item cards from worldhaven
- Loading branch information
Showing
23 changed files
with
729 additions
and
13,578 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { writeFileSync } from 'fs' | ||
|
||
type Expansion = 'Gloomhaven' | 'Forgotten Circles' | 'Crimson Scales' | 'Trail of Ashes' | ||
type ItemData = { | ||
name: string | ||
points: number | ||
expansion: Expansion | ||
image: string | ||
xws: string | ||
} | ||
type Refined = { | ||
cardId: number | ||
path: string | ||
} | ||
|
||
function itemDataFile(strings: any, items: string) { | ||
return `// file is auto generated by running yarn update-item-data | ||
//prettier-ignore | ||
const itemData = ${items} as const; | ||
export const gloomhavenItems = itemData.reduce((acc, cur) => acc.set(cur.cardId, cur.path), new Map<number, string>()) | ||
` | ||
} | ||
|
||
;(async function () { | ||
const response = await fetch('https://raw.githubusercontent.com/any2cards/worldhaven/master/data/items.js') | ||
if (response.status !== 200) { | ||
throw new Error('could not fetch data') | ||
} | ||
const itemData: ItemData[] = await response.json() | ||
const refinedData = itemData | ||
.filter((item) => item.expansion === 'Gloomhaven' && !item.image.endsWith('-back.png')) | ||
.map((item) => { | ||
const fileName = item.image.substring(item.image.lastIndexOf('/')) | ||
const cardId = Number.parseInt(fileName.substring(4, 7), 10) | ||
const path = item.image | ||
return { | ||
cardId, | ||
path, | ||
} | ||
}) | ||
.reduce((acc, cur) => acc.set(cur.cardId, cur), new Map<number, Refined>()) | ||
const items = JSON.stringify(Array.from(refinedData.values()), null, 2) | ||
writeFileSync('src/cards/items-data.ts', itemDataFile`${items}`) | ||
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
import * as React from 'react' | ||
import * as ReactDOM from 'react-dom' | ||
import { PartyBattleGoals } from 'battlegoals/PartyBattleGoals' | ||
import * as React from 'react' | ||
import { createRoot } from 'react-dom/client' | ||
import './style.css' | ||
|
||
let app = <PartyBattleGoals /> | ||
ReactDOM.render(app, document.getElementById('root')) | ||
const container = document.getElementById('root') | ||
if (container === null) { | ||
throw new Error('root element not found') | ||
} | ||
createRoot(container).render(<PartyBattleGoals />) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.