-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow randomizing the Friends & Foes module
As a quality of life thing I unified the player count controls between basic nemesis cards, banners, and the turn order deck, since I figured if you rolled friend foe and banners for 4 players then went to turn order, you were probably about to play a game with 4 players and a friend and foe. I didn't do that for mages since drawing more mages than players is already a thing (e.g. for expeditions).
- Loading branch information
Showing
35 changed files
with
431 additions
and
176 deletions.
There are no files selected for viewing
26 changes: 0 additions & 26 deletions
26
src/Redux/Store/Randomizer/BasicNemesisCards/PlayerCount/__test__/reducer.test.ts
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
src/Redux/Store/Randomizer/BasicNemesisCards/PlayerCount/__test__/selectors.test.ts
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
src/Redux/Store/Randomizer/BasicNemesisCards/PlayerCount/actions.ts
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
src/Redux/Store/Randomizer/BasicNemesisCards/PlayerCount/index.ts
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
src/Redux/Store/Randomizer/BasicNemesisCards/PlayerCount/reducer.ts
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
src/Redux/Store/Randomizer/BasicNemesisCards/PlayerCount/selectors.ts
This file was deleted.
Oops, something went wrong.
23 changes: 0 additions & 23 deletions
23
src/Redux/Store/Randomizer/BasicNemesisCards/PlayerCount/types.ts
This file was deleted.
Oops, something went wrong.
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,31 +1,25 @@ | ||
import { combineReducers } from 'redux-loop' | ||
|
||
import * as PlayerCount from './PlayerCount' | ||
import * as RandomCards from './RandomCards' | ||
|
||
export type State = { | ||
PlayerCount: PlayerCount.State | ||
RandomCards: RandomCards.State | ||
} | ||
|
||
export type Action = PlayerCount.Action | RandomCards.Action | ||
export type Action = RandomCards.Action | ||
|
||
export const selectors = { | ||
PlayerCount: PlayerCount.selectors, | ||
RandomCards: RandomCards.selectors, | ||
} | ||
|
||
export const actions = { | ||
PlayerCount: PlayerCount.actions, | ||
RandomCards: RandomCards.actions, | ||
} | ||
|
||
export const initialState = { | ||
PlayerCount: PlayerCount.initialState, | ||
RandomCards: RandomCards.initialState, | ||
} | ||
|
||
export const Reducer = combineReducers({ | ||
PlayerCount: PlayerCount.Reducer, | ||
RandomCards: RandomCards.Reducer, | ||
}) |
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,108 @@ | ||
import { createAction, ActionsUnion } from '@martin_hotell/rex-tils' | ||
import { LoopReducer } from 'redux-loop' | ||
|
||
import * as types from 'aer-types/types' | ||
|
||
import { getRandomEntity, createIdList, createArrayWithDefaultValues } from 'Redux/helpers' | ||
import { PlayerCount } from 'aer-types/types/data' | ||
|
||
/////////// | ||
// STATE // | ||
/////////// | ||
|
||
export type State = Readonly<{ friend?: string, foe?: string, banners?: string[] }> | ||
export const initialState: State = {} | ||
|
||
///////////// | ||
// ACTIONS // | ||
///////////// | ||
|
||
export enum ActionTypes { | ||
SET_RANDOM_FRIEND = 'FriendFoe/SET_RANDOM_FRIEND', | ||
SET_RANDOM_FOE = 'FriendFoe/SET_RANDOM_FOE', | ||
SET_RANDOM_BANNERS = 'FriendFoe/SET_RANDOM_BANNERS', | ||
} | ||
|
||
export const actions = { | ||
noOp: () => createAction('@@REDUX_LOOP/ENFORCE_DEFAULT_HANDLING'), | ||
setRandomFriend: ( | ||
availableFriends: ReadonlyArray<types.Friend>, | ||
seed?: types.Seed | ||
) => | ||
createAction(ActionTypes.SET_RANDOM_FRIEND, { | ||
friend: getRandomEntity(availableFriends, seed), | ||
}), | ||
setRandomFoe: ( | ||
availableFoes: ReadonlyArray<types.Foe>, | ||
seed?: types.Seed | ||
) => | ||
createAction(ActionTypes.SET_RANDOM_FOE, { | ||
foe: getRandomEntity(availableFoes, seed), | ||
}), | ||
setRandomBanners: ( | ||
availableBanners: ReadonlyArray<types.ICard>, | ||
playerCount: PlayerCount, | ||
seed?: types.Seed | ||
) => { | ||
const length = Math.min(availableBanners.length, playerCount + 2) | ||
const slotList = createArrayWithDefaultValues(length, 'EMPTY') | ||
const banners = createIdList(availableBanners.map((x: types.ICard) => x.id), slotList, getRandomEntity, seed).result | ||
return createAction(ActionTypes.SET_RANDOM_BANNERS, { banners }) | ||
}, | ||
} | ||
|
||
export type Action = ActionsUnion<typeof actions> | ||
|
||
///////////// | ||
// REDUCER // | ||
///////////// | ||
|
||
export const Reducer: LoopReducer<State, Action> = ( | ||
state: State = initialState, | ||
action: Action | ||
) => { | ||
switch (action.type) { | ||
case ActionTypes.SET_RANDOM_FRIEND: { | ||
return { | ||
...state, | ||
friend: action.payload.friend.entity.id, | ||
} | ||
} | ||
case ActionTypes.SET_RANDOM_FOE: { | ||
return { | ||
...state, | ||
foe: action.payload.foe.entity.id, | ||
} | ||
} | ||
case ActionTypes.SET_RANDOM_BANNERS: { | ||
return { | ||
...state, | ||
banners: action.payload.banners | ||
} | ||
} | ||
|
||
default: { | ||
return state | ||
} | ||
} | ||
} | ||
|
||
/////////////// | ||
// SELECTORS // | ||
/////////////// | ||
|
||
export type FriendFoeStateSlice = { | ||
Randomizer: { | ||
FriendFoe: State | ||
} | ||
} | ||
|
||
const getFriend = (state: FriendFoeStateSlice) => state.Randomizer.FriendFoe.friend | ||
const getFoe = (state: FriendFoeStateSlice) => state.Randomizer.FriendFoe.foe | ||
const getBanners = (state: FriendFoeStateSlice) => state.Randomizer.FriendFoe.banners | ||
|
||
export const selectors = { | ||
getFriend, | ||
getFoe, | ||
getBanners, | ||
} |
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
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.