mirror of
https://github.com/Nioux/AideDeJeu.git
synced 2025-10-29 06:26:02 +00:00
BloC
This commit is contained in:
parent
765d65afd4
commit
25da74dfd2
4 changed files with 129 additions and 118 deletions
|
|
@ -1,127 +1,11 @@
|
|||
import 'package:aidedejeu_flutter/blocs/player_character/player_character_event.dart';
|
||||
import 'package:aidedejeu_flutter/blocs/player_character/player_character_state.dart';
|
||||
import 'package:aidedejeu_flutter/database.dart';
|
||||
import 'package:aidedejeu_flutter/models/items.dart';
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
class PlayerCharacterState extends Equatable {
|
||||
final BuildContext context;
|
||||
|
||||
final RaceItem race;
|
||||
final SubRaceItem subRace;
|
||||
final List<RaceItem> races;
|
||||
final List<SubRaceItem> subRaces;
|
||||
|
||||
final BackgroundItem background;
|
||||
final SubBackgroundItem subBackground;
|
||||
final List<BackgroundItem> backgrounds;
|
||||
final List<SubBackgroundItem> subBackgrounds;
|
||||
|
||||
PlayerCharacterState({
|
||||
this.context,
|
||||
this.race,
|
||||
this.races,
|
||||
this.subRace,
|
||||
this.subRaces,
|
||||
this.background,
|
||||
this.backgrounds,
|
||||
this.subBackground,
|
||||
this.subBackgrounds,
|
||||
});
|
||||
|
||||
PlayerCharacterState copyWith({
|
||||
BuildContext context,
|
||||
RaceItem race,
|
||||
List<RaceItem> races,
|
||||
SubRaceItem subRace,
|
||||
List<SubRaceItem> subRaces,
|
||||
BackgroundItem background,
|
||||
List<BackgroundItem> backgrounds,
|
||||
SubBackgroundItem subBackground,
|
||||
List<SubBackgroundItem> subBackgrounds,
|
||||
}) {
|
||||
return PlayerCharacterState(
|
||||
context: context ?? this.context,
|
||||
race: race ?? this.race,
|
||||
races: races ?? this.races,
|
||||
subRace: subRace ?? this.subRace,
|
||||
subRaces: subRaces ?? this.subRaces,
|
||||
background: background ?? this.background,
|
||||
backgrounds: backgrounds ?? this.backgrounds,
|
||||
subBackground: subBackground ?? this.subBackground,
|
||||
subBackgrounds: subBackgrounds ?? this.subBackgrounds,
|
||||
);
|
||||
}
|
||||
|
||||
PlayerCharacterState copyWithClean({
|
||||
BuildContext context,
|
||||
RaceItem race,
|
||||
List<RaceItem> races,
|
||||
SubRaceItem subRace,
|
||||
List<SubRaceItem> subRaces,
|
||||
BackgroundItem background,
|
||||
List<BackgroundItem> backgrounds,
|
||||
SubBackgroundItem subBackground,
|
||||
List<SubBackgroundItem> subBackgrounds,
|
||||
}) {
|
||||
return PlayerCharacterState(
|
||||
context: context ?? this.context,
|
||||
race: race ?? this.race,
|
||||
races: races ?? this.races,
|
||||
subRace: race != null ? null : subRace ?? this.subRace,
|
||||
subRaces: race != null ? subRaces : subRaces ?? this.subRaces,
|
||||
background: background ?? this.background,
|
||||
backgrounds: backgrounds ?? this.backgrounds,
|
||||
subBackground: background != null ? null : subBackground ?? this.subBackground,
|
||||
subBackgrounds: background != null ? subBackgrounds : subBackgrounds ?? this.subBackgrounds,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object> get props => [
|
||||
race,
|
||||
subRace,
|
||||
races,
|
||||
subRaces,
|
||||
background,
|
||||
subBackground,
|
||||
backgrounds,
|
||||
subBackgrounds
|
||||
];
|
||||
}
|
||||
|
||||
abstract class PlayerCharacterEvent extends Equatable {}
|
||||
|
||||
class RaceEvent extends SetItemEvent<RaceItem> {
|
||||
RaceEvent(RaceItem item) : super(item);
|
||||
}
|
||||
|
||||
class SubRaceEvent extends SetItemEvent<SubRaceItem> {
|
||||
SubRaceEvent(SubRaceItem item) : super(item);
|
||||
}
|
||||
|
||||
class SetItemEvent<T> extends PlayerCharacterEvent {
|
||||
final T item;
|
||||
|
||||
@override
|
||||
List<Object> get props => [item];
|
||||
|
||||
SetItemEvent(T item) : this.item = item;
|
||||
}
|
||||
|
||||
class BackgroundEvent extends SetItemEvent<BackgroundItem> {
|
||||
BackgroundEvent(BackgroundItem item) : super(item);
|
||||
}
|
||||
|
||||
class SubBackgroundEvent extends SetItemEvent<SubBackgroundItem> {
|
||||
SubBackgroundEvent(SubBackgroundItem item) : super(item);
|
||||
}
|
||||
|
||||
class LoadEvent extends PlayerCharacterEvent {
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class PlayerCharacterBloc
|
||||
extends Bloc<PlayerCharacterEvent, PlayerCharacterState> {
|
||||
BuildContext context;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
import 'package:aidedejeu_flutter/models/items.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
abstract class PlayerCharacterEvent extends Equatable {}
|
||||
|
||||
class RaceEvent extends SetItemEvent<RaceItem> {
|
||||
RaceEvent(RaceItem item) : super(item);
|
||||
}
|
||||
|
||||
class SubRaceEvent extends SetItemEvent<SubRaceItem> {
|
||||
SubRaceEvent(SubRaceItem item) : super(item);
|
||||
}
|
||||
|
||||
class SetItemEvent<T> extends PlayerCharacterEvent {
|
||||
final T item;
|
||||
|
||||
@override
|
||||
List<Object> get props => [item];
|
||||
|
||||
SetItemEvent(T item) : this.item = item;
|
||||
}
|
||||
|
||||
class BackgroundEvent extends SetItemEvent<BackgroundItem> {
|
||||
BackgroundEvent(BackgroundItem item) : super(item);
|
||||
}
|
||||
|
||||
class SubBackgroundEvent extends SetItemEvent<SubBackgroundItem> {
|
||||
SubBackgroundEvent(SubBackgroundItem item) : super(item);
|
||||
}
|
||||
|
||||
class LoadEvent extends PlayerCharacterEvent {
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,90 @@
|
|||
import 'package:aidedejeu_flutter/models/items.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
class PlayerCharacterState extends Equatable {
|
||||
final BuildContext context;
|
||||
|
||||
final RaceItem race;
|
||||
final SubRaceItem subRace;
|
||||
final List<RaceItem> races;
|
||||
final List<SubRaceItem> subRaces;
|
||||
|
||||
final BackgroundItem background;
|
||||
final SubBackgroundItem subBackground;
|
||||
final List<BackgroundItem> backgrounds;
|
||||
final List<SubBackgroundItem> subBackgrounds;
|
||||
|
||||
PlayerCharacterState({
|
||||
this.context,
|
||||
this.race,
|
||||
this.races,
|
||||
this.subRace,
|
||||
this.subRaces,
|
||||
this.background,
|
||||
this.backgrounds,
|
||||
this.subBackground,
|
||||
this.subBackgrounds,
|
||||
});
|
||||
|
||||
PlayerCharacterState copyWith({
|
||||
BuildContext context,
|
||||
RaceItem race,
|
||||
List<RaceItem> races,
|
||||
SubRaceItem subRace,
|
||||
List<SubRaceItem> subRaces,
|
||||
BackgroundItem background,
|
||||
List<BackgroundItem> backgrounds,
|
||||
SubBackgroundItem subBackground,
|
||||
List<SubBackgroundItem> subBackgrounds,
|
||||
}) {
|
||||
return PlayerCharacterState(
|
||||
context: context ?? this.context,
|
||||
race: race ?? this.race,
|
||||
races: races ?? this.races,
|
||||
subRace: subRace ?? this.subRace,
|
||||
subRaces: subRaces ?? this.subRaces,
|
||||
background: background ?? this.background,
|
||||
backgrounds: backgrounds ?? this.backgrounds,
|
||||
subBackground: subBackground ?? this.subBackground,
|
||||
subBackgrounds: subBackgrounds ?? this.subBackgrounds,
|
||||
);
|
||||
}
|
||||
|
||||
PlayerCharacterState copyWithClean({
|
||||
BuildContext context,
|
||||
RaceItem race,
|
||||
List<RaceItem> races,
|
||||
SubRaceItem subRace,
|
||||
List<SubRaceItem> subRaces,
|
||||
BackgroundItem background,
|
||||
List<BackgroundItem> backgrounds,
|
||||
SubBackgroundItem subBackground,
|
||||
List<SubBackgroundItem> subBackgrounds,
|
||||
}) {
|
||||
return PlayerCharacterState(
|
||||
context: context ?? this.context,
|
||||
race: race ?? this.race,
|
||||
races: races ?? this.races,
|
||||
subRace: race != null ? null : subRace ?? this.subRace,
|
||||
subRaces: race != null ? subRaces : subRaces ?? this.subRaces,
|
||||
background: background ?? this.background,
|
||||
backgrounds: backgrounds ?? this.backgrounds,
|
||||
subBackground: background != null ? null : subBackground ?? this.subBackground,
|
||||
subBackgrounds: background != null ? subBackgrounds : subBackgrounds ?? this.subBackgrounds,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object> get props => [
|
||||
race,
|
||||
subRace,
|
||||
races,
|
||||
subRaces,
|
||||
background,
|
||||
subBackground,
|
||||
backgrounds,
|
||||
subBackgrounds
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -1,4 +1,6 @@
|
|||
import 'package:aidedejeu_flutter/blocs/player_character/player_character_bloc.dart';
|
||||
import 'package:aidedejeu_flutter/blocs/player_character/player_character_event.dart';
|
||||
import 'package:aidedejeu_flutter/blocs/player_character/player_character_state.dart';
|
||||
import 'package:aidedejeu_flutter/localization.dart';
|
||||
import 'package:aidedejeu_flutter/models/items.dart';
|
||||
import 'package:aidedejeu_flutter/widgets/library.dart';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue