SES-115 #44

Merged
s426134 merged 3 commits from SES-115 into dev 2020-12-29 15:31:52 +01:00
7 changed files with 44 additions and 5 deletions
Showing only changes of commit 18d1b75c4a - Show all commits

View File

@ -6,7 +6,7 @@
<mat-list-item *ngFor="let character of charactersList">
<mat-icon mat-list-icon>account_circle</mat-icon>
<div mat-line>{{character.name}}</div>
<mat-icon matSuffix class="arrow-forward arrow-select" (click)="onCharacterClick()">arrow_forward</mat-icon>
<mat-icon matSuffix class="arrow-forward arrow-select" (click)="onCharacterClick(character.id)">arrow_forward</mat-icon>
<div mat-line> {{character.className}} level: {{character.level}}</div>
<mat-divider></mat-divider>
</mat-list-item>

View File

@ -8,6 +8,7 @@ import {Store} from "@ngrx/store";
import {AppState} from "../../store/models/app-state.model";
import {CharacterService} from "../../../services/character.service";
import {CharacterForLoginViewModel} from "../../../types/viewmodels/character-viewmodels/CharacterForLoginViewModel";
import {AddCharacterId} from "../../store/actions/player.action";
@Component({
selector: 'app-select-character',
@ -36,7 +37,8 @@ export class SelectCharacterComponent implements OnInit {
});
}
onCharacterClick(){
onCharacterClick(characterId: number){
this.store.dispatch(new AddCharacterId({characterId}))
this.router.navigate(['player'])
}

View File

@ -1,4 +1,3 @@
import {AppStoreModel} from '../models/app-store.model';
import {Action} from '@ngrx/store';
export enum AppActionTypes {
@ -26,7 +25,8 @@ export class ClearUserId implements Action {
constructor() {
}
}
export type AppAction = AddUserId | AddRole | ClearUserId;

View File

@ -0,0 +1,15 @@
import {Action} from "@ngrx/store";
export enum PlayerActionTypes {
ADD_CHARACTER_ID= '[PLAYER] Add character id'
}
export class AddCharacterId implements Action {
readonly type = PlayerActionTypes.ADD_CHARACTER_ID;
constructor(public payload: {characterId: number}) {
}
}
export type PlayerAction = AddCharacterId;

View File

@ -1,11 +1,15 @@
import {AppStoreModel} from './app-store.model';
import {ActionReducerMap} from '@ngrx/store';
import {AppReducer} from '../reducers/app.reducer';
import {PlayerStoreModel} from "./player-store.model";
import {PlayerReducer} from "../reducers/player.reducer";
export interface AppState {
appStore: AppStoreModel;
playerStore: PlayerStoreModel;
}
export const reducers: ActionReducerMap<AppState> = {
appStore: AppReducer,
playerStore: PlayerReducer,
};

View File

@ -0,0 +1,3 @@
export interface PlayerStoreModel {
characterId: number;
}

View File

@ -0,0 +1,15 @@
import {PlayerStoreModel} from "../models/player-store.model";
import {PlayerAction, PlayerActionTypes} from "../actions/player.action";
const initialState: PlayerStoreModel = {
characterId: null
};
export function PlayerReducer(state: PlayerStoreModel = initialState, action: PlayerAction) {
switch (action.type) {
case PlayerActionTypes.ADD_CHARACTER_ID:
return {...state, characterId: action.payload.characterId};
default:
return state;
}
}