Skip to content

Commit

Permalink
update summon state
Browse files Browse the repository at this point in the history
  • Loading branch information
PrimalZed committed Jun 9, 2022
1 parent db4c70b commit 4443f4b
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 10 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ Installing for offline use is done as a [Progressive Web App](https://developer.

## TODO
* Better way to codify "instead" element enhancements
* Track Summons.
* Add Jaws of the Lion and Frosthaven.

### Potential future features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ConditionKey, conditions } from 'models/condition';
import { MonsterStandee } from 'models/monster-set';
import { MonsterStatCard } from 'models/monster-stat-card';
import { TabletopService } from 'services/tabletop.service';
import { updateCharacter, updateCharacterSummon } from 'store/tabletop/characters/characters.actions';
import { removeCharacterSummon, updateCharacter, updateCharacterSummon } from 'store/tabletop/characters/characters.actions';
import { removeMonsterStandee, updateMonsterStandee } from 'store/tabletop/monsters/monsters.actions';

@Component({
Expand Down Expand Up @@ -98,11 +98,15 @@ export class FigureDialogComponent {
}

remove() {
if (this.data.kind !== 'monster') {
return;
switch (this.data.kind) {
case 'summon':
this.tabletopService.dispatch(removeCharacterSummon({ key: this.key, color: this.data.figure.color }));
this.dialogRef.close();
return;
case 'monster':
this.tabletopService.dispatch(removeMonsterStandee({ key: this.data.statCard.key, id: this.data.figure.id }));
this.dialogRef.close();
break;
}

this.tabletopService.dispatch(removeMonsterStandee({ key: this.data.statCard.key, id: this.data.figure.id }));
this.dialogRef.close();
}
}
2 changes: 1 addition & 1 deletion src/app/store/tabletop/characters/characters.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const updateCharacterSummon = createAction(

export const undoUpdateCharacterSummon = createAction(
"[Tabletop] [Character] Undo Update Summon",
props<{ key: string, color: SummonColor, previousHitPoints: number, conditions: ConditionKey[] }>()
props<{ key: string, color: SummonColor, previousHitPoints: number, previousConditions: ConditionKey[] }>()
);

export const removeCharacterSummon = createAction(
Expand Down
74 changes: 73 additions & 1 deletion src/app/store/tabletop/characters/characters.ons.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { on } from '@ngrx/store';
import { CatalogService } from 'services/catalog.service';
import { TabletopState } from '../tabletop.state';
import { addCharacter, addCharacterSummon, undoAddCharacter, undoAddCharacterSummon, undoUpdateCharacter, updateCharacter } from './characters.actions';
import { addCharacter, addCharacterSummon, removeCharacterSummon, undoAddCharacter, undoAddCharacterSummon, undoRemoveCharacterSummon, undoUpdateCharacter, undoUpdateCharacterSummon, updateCharacter, updateCharacterSummon } from './characters.actions';
import { charactersAdapter } from './characters.adapter';

export function getCharactersOns(catalogService: CatalogService) {
Expand Down Expand Up @@ -102,6 +102,78 @@ export function getCharactersOns(catalogService: CatalogService) {
},
state.characters
)
})),
on<TabletopState, [typeof updateCharacterSummon]>(updateCharacterSummon, (state, { key, color, hitPoints, conditions }) => ({
...state,
characters: charactersAdapter.mapOne(
{
id: key,
map: (character) => ({
...character,
summons: character.summons
.map((summon) => summon.color === color
? {
...summon,
hitPoints,
conditions
}
: summon
)
})
},
state.characters
)
})),
on<TabletopState, [typeof undoUpdateCharacterSummon]>(undoUpdateCharacterSummon, (state, { key, color, previousHitPoints, previousConditions }) => ({
...state,
characters: charactersAdapter.mapOne(
{
id: key,
map: (character) => ({
...character,
summons: character.summons
.map((summon) => summon.color === color
? {
...summon,
hitPoints: previousHitPoints,
conditions: previousConditions
}
: summon
)
})
},
state.characters
)
})),
on<TabletopState, [typeof removeCharacterSummon]>(removeCharacterSummon, (state, { key, color }) => ({
...state,
characters: charactersAdapter.mapOne(
{
id: key,
map: (character) => ({
...character,
summons: character.summons
.filter((summon) => summon.color !== color)
})
},
state.characters
)
})),
on<TabletopState, [typeof undoRemoveCharacterSummon]>(undoRemoveCharacterSummon, (state, { key, summon }) => ({
...state,
characters: charactersAdapter.mapOne(
{
id: key,
map: (character) => ({
...character,
summons: [
...character.summons,
summon
]
})
},
state.characters
)
}))
];
}
28 changes: 27 additions & 1 deletion src/app/store/time-machine/time-machine.meta-reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ import { AppState } from 'store/app.state';
import {
addCharacter,
addCharacterSummon,
removeCharacterSummon,
undoAddCharacter,
undoAddCharacterSummon,
undoRemoveCharacterSummon,
undoUpdateCharacter,
updateCharacter
undoUpdateCharacterSummon,
updateCharacter,
updateCharacterSummon
} from 'store/tabletop/characters/characters.actions';
import {
drawMonsterAbilityCardSuccess,
Expand Down Expand Up @@ -42,6 +46,8 @@ const trackActionTypes: string[] = [
addCharacter.type,
updateCharacter.type,
addCharacterSummon.type,
updateCharacterSummon.type,
removeCharacterSummon.type,
addMonster.type,
addMonsterStandee.type,
updateMonsterStandee.type,
Expand All @@ -58,6 +64,8 @@ type ReversibleAction =
| ReturnType<typeof addCharacter>
| ReturnType<typeof updateCharacter>
| ReturnType<typeof addCharacterSummon>
| ReturnType<typeof updateCharacterSummon>
| ReturnType<typeof removeCharacterSummon>
| ReturnType<typeof addMonster>
| ReturnType<typeof addMonsterStandee>
| ReturnType<typeof updateMonsterStandee>
Expand All @@ -83,6 +91,24 @@ function getReverseAction(state: AppState, action: ReversibleAction): Action {
});
case addCharacterSummon.type:
return undoAddCharacterSummon({ key: action.key, color: action.color });
case updateCharacterSummon.type:
const updateCharacterSummonTarget = state.tabletop.characters.entities[action.key]
?.summons
.find(x => x.color === action.color);
return undoUpdateCharacterSummon({
key: action.key,
color: action.color,
previousHitPoints: updateCharacterSummonTarget?.hitPoints ?? 0,
previousConditions: updateCharacterSummonTarget?.conditions ?? []
});
case removeCharacterSummon.type:
const removeCharacterSummonTarget = state.tabletop.characters.entities[action.key]
?.summons
.find(x => x.color === action.color);
if (removeCharacterSummonTarget === undefined) {
throw `Character ${action.key} Summon ${action.color} not found`
}
return undoRemoveCharacterSummon({ key: action.key, summon: removeCharacterSummonTarget })
case addMonster.type:
return undoAddMonster({ key: action.key });
case addMonsterStandee.type:
Expand Down

0 comments on commit 4443f4b

Please sign in to comment.