import { createSlice , PayloadAction } from "@reduxjs/toolkit" ; import { Card , CreatureType , DefinitionClass } from "@creature-chess/models" ; export type CardShopState = { cards : ( Card | null ) [ ] ; locked : boolean ; } ; type ReplaceCards = { newCard : Card ; } ; const initialState = { cards : [ { id : "0005" , definitionId : 37 , name : "Arbelder" , type : CreatureType . Wood , class : DefinitionClass . VALIANT , cost : 5 } , { id : "0001" , definitionId : 10 , name : "Chenipode" , type : CreatureType . Earth , class : DefinitionClass . CUNNING , cost : 2 } , { id : "0002" , definitionId : 24 , name : "Ruption" , type : CreatureType . Fire , class : DefinitionClass . ARCANE , cost : 3 } , { id : "0003" , definitionId : 32 , name : "Cairfrey" , type : CreatureType . Metal , class : DefinitionClass . ARCANE , cost : 3 } , { id : "0004" , definitionId : 46 , name : "Eaglace" , type : CreatureType . Water , class : DefinitionClass . CUNNING , cost : 5 } ] , locked : false } ; const { actions , reducer : cardShopReducer , } = createSlice ( { name : "cards" , initialState , reducers : { addCardCommand : ( state , { payload : { newCard } } ) => { state . cards . push ( newCard ) ; } , removeCardCommand : ( state , { payload : id } ) => { state . cards . pop ( ) ; } , updateCardsCommand : ( state , { payload : cards } ) => ( { ... state , cards } ) , updateShopLockCommand : ( state , { payload : locked } ) => ( { ... state , locked } ) } } ) ; const updateCardsCommand = actions . updateCardsCommand ; const addCardCommand = actions . addCardCommand ; const removeCardCommand = actions . removeCardCommand ; const updateShopLockCommand = actions . updateShopLockCommand ; export { updateCardsCommand , updateShopLockCommand , removeCardCommand , addCardCommand , cardShopReducer } ;