Skip to content

Commit

Permalink
FEATURE: Add 'ANY' card type to supply setups
Browse files Browse the repository at this point in the history
  • Loading branch information
on3iro committed Jul 12, 2020
1 parent 13aa61f commit c92a4a3
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ describe('Custom Supply Setup creation and run through', () => {
// Should be a Gem with operation ANY
cy.get('[data-test=select-type]')
.find('input')
.should('have.attr', 'value', 'Gem')
.should('have.attr', 'value', 'ANY')
cy.get('[data-test=select-operation]')
.find('input')
.should('have.attr', 'value', 'ANY')
Expand Down Expand Up @@ -352,37 +352,37 @@ describe('Custom Supply Setup creation and run through', () => {
.find('li')
.eq(0)
.should('have.attr', 'type', 'gem')
.should('contain', 'ANY')
.closest('[data-test=supply-setup-wrapper]')
.find('li')
.eq(1)
.should('have.attr', 'type', 'gem')
.should('contain', '< 4')
.closest('[data-test=supply-setup-wrapper]')
.find('li')
.eq(2)
.eq(1)
.should('have.attr', 'type', 'gem')
.should('contain', '> 5')
.closest('[data-test=supply-setup-wrapper]')
.find('li')
.eq(3)
.eq(2)
.should('have.attr', 'type', 'relic')
.should('contain', '<= 2')
.closest('[data-test=supply-setup-wrapper]')
.find('li')
.eq(4)
.eq(3)
.should('have.attr', 'type', 'relic')
.should('contain', '5')
.closest('[data-test=supply-setup-wrapper]')
.find('li')
.eq(5)
.eq(4)
.should('have.attr', 'type', 'spell')
.should('contain', '3/5')
.closest('[data-test=supply-setup-wrapper]')
.find('li')
.eq(6)
.eq(5)
.should('have.attr', 'type', 'spell')
.should('contain', '>= 8')
.closest('[data-test=supply-setup-wrapper]')
.find('li')
.eq(6)
.should('have.attr', 'type', 'any')
.should('contain', 'ANY')
})

it('should role correct cards for the created custom supply setup', () => {
Expand All @@ -394,16 +394,13 @@ describe('Custom Supply Setup creation and run through', () => {
.should('exist')
.click()
cy.get('[data-test=btn-create-market]').click()
cy.get('[data-test=market-tile-gem]').should('have.length', 3)
cy.get('[data-test=market-tile-relic]').should('have.length', 2)
cy.get('[data-test=market-tile-spell]').should('have.length', 2)
cy.get('[data-test=market-tile-gem]')
.eq(0)
.find('[data-test=market-tile-cost] span')
.invoke('text')
.then(value => expect(parseInt(value)).to.be.lt(4))
cy.get('[data-test=market-tile-gem]')
.eq(2)
.eq(1)
.find('[data-test=market-tile-cost] span')
.invoke('text')
.then(value => expect(parseInt(value)).to.be.gt(5))
Expand All @@ -422,10 +419,6 @@ describe('Custom Supply Setup creation and run through', () => {
.find('[data-test=market-tile-cost] span')
.invoke('text')
.then(value => expect(parseInt(value)).to.be.oneOf([3, 5]))
cy.get('[data-test=market-tile-spell]')
.eq(1)
.find('[data-test=market-tile-cost] span')
.invoke('text')
.then(value => expect(parseInt(value)).to.be.gte(8))
// FIXME find good way to test ANY type and ANY operation
})
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@types/seedrandom": "^2.4.28",
"@types/shortid": "^0.0.29",
"aer-data": "^2.0.0",
"aer-types": "^1.0.4",
"aer-types": "^1.0.11",
"ajv": "^6.12.0",
"classnames": "^2.2.6",
"core-js": "^3.2.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const getSupplyIds = ({
Relic: types.ICard[]
Spell: types.ICard[]
EMPTY: never[]
ANY: never[]
}
}) => {
const baseResult = {
Expand Down Expand Up @@ -242,6 +243,7 @@ export const handleCustomRewards = (
expeditionId,
}),
EMPTY: [],
ANY: [],
}

const stillAvailableTreasureIdsByLevel = {
Expand Down
52 changes: 40 additions & 12 deletions src/Redux/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,12 @@ export const getRandomCardsByType = (
seed?: types.Seed
): CardListReduceResult => {
const cardSlots = tileSetups.filter(({ type }) => type === cardType)
const availableCardsOfType = availableCards.filter(
({ type }) => type === cardType
)
const availableCardsOfType =
cardType === 'ANY'
? (availableCards as types.ICard[])
: availableCards.filter(({ type }) => type === cardType)

console.log({ availableCardsOfType })

return createCardList(availableCardsOfType, cardSlots, getRandomEntity, seed)
}
Expand All @@ -125,25 +128,50 @@ export const createSupply = (
tileSetups: ReadonlyArray<types.IBluePrint>,
seed?: types.Seed
) => {
const gems = getRandomCardsByType(availableCards, tileSetups, 'Gem', seed)
const relics = getRandomCardsByType(
const gemsResult = getRandomCardsByType(
availableCards,
tileSetups,
'Gem',
seed
)
const relicsResult = getRandomCardsByType(
availableCards,
tileSetups,
'Relic',
gems.seed
gemsResult.seed
)
const spells = getRandomCardsByType(
const spellsResult = getRandomCardsByType(
availableCards,
tileSetups,
'Spell',
relics.seed
relicsResult.seed
)

const anyResult = getRandomCardsByType(
availableCards,
tileSetups,
'ANY',
spellsResult.seed
)

const gems = [
...gemsResult.result,
...anyResult.result.filter(c => c.type === 'Gem'),
]
const relics = [
...relicsResult.result,
...anyResult.result.filter(c => c.type === 'Relic'),
]
const spells = [
...spellsResult.result,
...anyResult.result.filter(c => c.type === 'Spell'),
]

return {
gems: gems.result,
relics: relics.result,
spells: spells.result,
seed: spells.seed,
gems,
relics,
spells,
seed: anyResult.seed,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const bluePrintReducer = (
...state,
[id]: {
id,
type: 'Gem',
type: 'ANY',
operation: 'ANY',
},
}
Expand Down
4 changes: 4 additions & 0 deletions src/mainTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ export const mainTheme = {
},
cards: {
...treasureColors,
any: {
color: '#ecf0f1',
background: '#ecf0f1',
},
gem: {
color: '#B39DDB',
background: '#EDE7F6',
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1977,10 +1977,10 @@ aer-data@^2.0.0:
resolved "https://registry.yarnpkg.com/aer-data/-/aer-data-2.2.0.tgz#7b2d443c4ddf728ac75531cd340c0d8a1de4a1f4"
integrity sha512-Gxra20m5J3vWJd5gtcqBPgPSzr01nT+3CN0UpRi5xpRpIu/pmzIF0Y1P2EqbaHzAeYWXnK4HHoWmAQNuoCxtMw==

aer-types@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/aer-types/-/aer-types-1.0.4.tgz#7e4abc5e92fadcf120dd34f6e1cffb69043f98cf"
integrity sha512-rjYRGQBR7Up81gS3jE36FI9gTjQYYYGigRGnEOIDM7Bas5774uElPE55jsDBs8rmCixuQX5thm10ro1ugVF2GA==
aer-types@^1.0.11:
version "1.0.11"
resolved "https://registry.yarnpkg.com/aer-types/-/aer-types-1.0.11.tgz#03e5070d9f891323620d51a138c0f1800076a847"
integrity sha512-ehf6vYBPlxmzpXniW3lyzNc2VG714035JFlFBzD/CFMaE0nBwHal9fu1kddLKYWm8nV7IFLBZsg+uGNjLLlKZw==

aggregate-error@^3.0.0:
version "3.0.1"
Expand Down

0 comments on commit c92a4a3

Please sign in to comment.