Skip to content

Commit 7965af2

Browse files
Torgenon3iro
authored andcommitted
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).
1 parent df5cac1 commit 7965af2

File tree

35 files changed

+431
-176
lines changed

35 files changed

+431
-176
lines changed

src/Redux/Store/Randomizer/BasicNemesisCards/PlayerCount/__test__/reducer.test.ts

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/Redux/Store/Randomizer/BasicNemesisCards/PlayerCount/__test__/selectors.test.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/Redux/Store/Randomizer/BasicNemesisCards/PlayerCount/actions.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/Redux/Store/Randomizer/BasicNemesisCards/PlayerCount/index.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/Redux/Store/Randomizer/BasicNemesisCards/PlayerCount/reducer.ts

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/Redux/Store/Randomizer/BasicNemesisCards/PlayerCount/selectors.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/Redux/Store/Randomizer/BasicNemesisCards/PlayerCount/types.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/Redux/Store/Randomizer/BasicNemesisCards/RandomCards/actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as types from 'aer-types/types'
44

55
import { ActionTypes } from './types'
66

7-
import { PlayerCount } from '../PlayerCount/types'
7+
import { PlayerCount } from 'aer-types/types/data'
88

99
export const actions = {
1010
noOp: () => createAction('@@REDUX_LOOP/ENFORCE_DEFAULT_HANDLING'),
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,25 @@
11
import { combineReducers } from 'redux-loop'
22

3-
import * as PlayerCount from './PlayerCount'
43
import * as RandomCards from './RandomCards'
54

65
export type State = {
7-
PlayerCount: PlayerCount.State
86
RandomCards: RandomCards.State
97
}
108

11-
export type Action = PlayerCount.Action | RandomCards.Action
9+
export type Action = RandomCards.Action
1210

1311
export const selectors = {
14-
PlayerCount: PlayerCount.selectors,
1512
RandomCards: RandomCards.selectors,
1613
}
1714

1815
export const actions = {
19-
PlayerCount: PlayerCount.actions,
2016
RandomCards: RandomCards.actions,
2117
}
2218

2319
export const initialState = {
24-
PlayerCount: PlayerCount.initialState,
2520
RandomCards: RandomCards.initialState,
2621
}
2722

2823
export const Reducer = combineReducers({
29-
PlayerCount: PlayerCount.Reducer,
3024
RandomCards: RandomCards.Reducer,
3125
})
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import { createAction, ActionsUnion } from '@martin_hotell/rex-tils'
2+
import { LoopReducer } from 'redux-loop'
3+
4+
import * as types from 'aer-types/types'
5+
6+
import { getRandomEntity, createIdList, createArrayWithDefaultValues } from 'Redux/helpers'
7+
import { PlayerCount } from 'aer-types/types/data'
8+
9+
///////////
10+
// STATE //
11+
///////////
12+
13+
export type State = Readonly<{ friend?: string, foe?: string, banners?: string[] }>
14+
export const initialState: State = {}
15+
16+
/////////////
17+
// ACTIONS //
18+
/////////////
19+
20+
export enum ActionTypes {
21+
SET_RANDOM_FRIEND = 'FriendFoe/SET_RANDOM_FRIEND',
22+
SET_RANDOM_FOE = 'FriendFoe/SET_RANDOM_FOE',
23+
SET_RANDOM_BANNERS = 'FriendFoe/SET_RANDOM_BANNERS',
24+
}
25+
26+
export const actions = {
27+
noOp: () => createAction('@@REDUX_LOOP/ENFORCE_DEFAULT_HANDLING'),
28+
setRandomFriend: (
29+
availableFriends: ReadonlyArray<types.Friend>,
30+
seed?: types.Seed
31+
) =>
32+
createAction(ActionTypes.SET_RANDOM_FRIEND, {
33+
friend: getRandomEntity(availableFriends, seed),
34+
}),
35+
setRandomFoe: (
36+
availableFoes: ReadonlyArray<types.Foe>,
37+
seed?: types.Seed
38+
) =>
39+
createAction(ActionTypes.SET_RANDOM_FOE, {
40+
foe: getRandomEntity(availableFoes, seed),
41+
}),
42+
setRandomBanners: (
43+
availableBanners: ReadonlyArray<types.ICard>,
44+
playerCount: PlayerCount,
45+
seed?: types.Seed
46+
) => {
47+
const length = Math.min(availableBanners.length, playerCount + 2)
48+
const slotList = createArrayWithDefaultValues(length, 'EMPTY')
49+
const banners = createIdList(availableBanners.map((x: types.ICard) => x.id), slotList, getRandomEntity, seed).result
50+
return createAction(ActionTypes.SET_RANDOM_BANNERS, { banners })
51+
},
52+
}
53+
54+
export type Action = ActionsUnion<typeof actions>
55+
56+
/////////////
57+
// REDUCER //
58+
/////////////
59+
60+
export const Reducer: LoopReducer<State, Action> = (
61+
state: State = initialState,
62+
action: Action
63+
) => {
64+
switch (action.type) {
65+
case ActionTypes.SET_RANDOM_FRIEND: {
66+
return {
67+
...state,
68+
friend: action.payload.friend.entity.id,
69+
}
70+
}
71+
case ActionTypes.SET_RANDOM_FOE: {
72+
return {
73+
...state,
74+
foe: action.payload.foe.entity.id,
75+
}
76+
}
77+
case ActionTypes.SET_RANDOM_BANNERS: {
78+
return {
79+
...state,
80+
banners: action.payload.banners
81+
}
82+
}
83+
84+
default: {
85+
return state
86+
}
87+
}
88+
}
89+
90+
///////////////
91+
// SELECTORS //
92+
///////////////
93+
94+
export type FriendFoeStateSlice = {
95+
Randomizer: {
96+
FriendFoe: State
97+
}
98+
}
99+
100+
const getFriend = (state: FriendFoeStateSlice) => state.Randomizer.FriendFoe.friend
101+
const getFoe = (state: FriendFoeStateSlice) => state.Randomizer.FriendFoe.foe
102+
const getBanners = (state: FriendFoeStateSlice) => state.Randomizer.FriendFoe.banners
103+
104+
export const selectors = {
105+
getFriend,
106+
getFoe,
107+
getBanners,
108+
}

src/Redux/Store/Randomizer/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,51 @@ import * as Nemesis from './Nemesis'
44
import * as BasicNemesisCards from './BasicNemesisCards'
55
import * as Mages from './Mages'
66
import * as Supply from './Supply'
7+
import * as FriendFoe from './FriendFoe'
78

89
export type State = {
910
Nemesis: Nemesis.State
1011
BasicNemesisCards: BasicNemesisCards.State
1112
Mages: Mages.State
1213
Supply: Supply.State
14+
FriendFoe: FriendFoe.State
1315
}
1416

1517
export const actions = {
1618
Nemesis: Nemesis.actions,
1719
BasicNemesisCards: BasicNemesisCards.actions,
1820
Mages: Mages.actions,
1921
Supply: Supply.actions,
22+
FriendFoe: FriendFoe.actions
2023
}
2124

2225
export const selectors = {
2326
Nemesis: Nemesis.selectors,
2427
BasicNemesisCards: BasicNemesisCards.selectors,
2528
Mages: Mages.selectors,
2629
Supply: Supply.selectors,
30+
FriendFoe: FriendFoe.selectors,
2731
}
2832

2933
export type Action =
3034
| Nemesis.Action
3135
| BasicNemesisCards.Action
3236
| Mages.Action
3337
| Supply.Action
38+
| FriendFoe.Action
3439

3540
export const initialState = {
3641
Nemesis: Nemesis.initialState,
3742
BasicNemesisCards: BasicNemesisCards.initialState,
3843
Mages: Mages.initialState,
3944
Supply: Supply.initialState,
45+
FriendFoe: FriendFoe.initialState
4046
}
4147

4248
export const Reducer = combineReducers({
4349
Nemesis: Nemesis.Reducer,
4450
BasicNemesisCards: BasicNemesisCards.Reducer,
4551
Mages: Mages.Reducer,
4652
Supply: Supply.Reducer,
53+
FriendFoe: FriendFoe.Reducer
4754
})

src/Redux/Store/Settings/Expansions/Banners/selected/reducerHelpers/toggleBanner.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ export const toggle = (
88
state: State,
99
action: ReturnType<typeof actions.toggle>
1010
) => {
11-
console.log(state)
12-
console.log(action)
1311
const newState = state.includes(action.payload)
1412
? state.filter((id) => id !== action.payload)
1513
: [...state, action.payload]

src/Redux/Store/Settings/Expansions/helpers.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ export const getContentByIdWithLanguageFallback = <T extends Entity>(
3434
content: ContentStruct<T>,
3535
id: string
3636
) => {
37-
console.log(id)
38-
console.log(content)
3937
// Just get the corresponding expansion id from the english version
4038
const language = languages[content.ENG[id].expansion]
4139

src/Redux/Store/Settings/Expansions/selectors.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import * as Mages from './Mages'
1111
import * as Treasures from './Treasures'
1212
import * as BasicNemesisCards from './BasicNemesisCards'
1313
import * as UpgradedBasicNemesisCards from './UpgradedBasicNemesisCards'
14+
import * as Friends from './Friends'
15+
import * as Foes from './Foes'
16+
import * as Banners from './Banners'
1417

1518
// FIXME any typing sucks ;)
1619
export const getSelectedEntitiesForSelectedExpansions = <T>(
@@ -122,3 +125,15 @@ export const getSelectedBasicNemesisCardIdsForSelectedExpansions = createSelecto
122125
[getSelectedBasicNemesisCardsForSelectedExpansions],
123126
(basicNemesisCards) => basicNemesisCards.map((card) => card.id)
124127
)
128+
129+
export const getSelectedFriendsForSelectedExpansions = getSelectedEntitiesForSelectedExpansions(
130+
Friends.selectors.getSelectedFriends
131+
)
132+
133+
export const getSelectedFoesForSelectedExpansions = getSelectedEntitiesForSelectedExpansions(
134+
Foes.selectors.getSelectedFoes
135+
)
136+
137+
export const getSelectedBannersForSelectedExpansions = getSelectedEntitiesForSelectedExpansions(
138+
Banners.selectors.getSelectedBanners
139+
)

src/Redux/helpers.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,13 @@ export const createIdList = (
266266
seed?: types.Seed
267267
) => generateListFrom(availableIds, slots, getEntity, stringsEqual, seed)
268268

269+
export const createBannerList = (
270+
availableBanners: ReadonlyArray<types.ICard>,
271+
slots: Array<types.Slot>,
272+
getEntity: types.SeededEntityGetter,
273+
seed?: types.Seed
274+
) => generateListFrom(availableBanners, slots, getEntity, entitiesEqual, seed)
275+
269276
/**
270277
* Gets a random value from a list. (The wording of entities is just used for semantic context)
271278
* @param availableEntities: List of entities to pick from

0 commit comments

Comments
 (0)