HeroesDisplay.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <template>
  2. <div>
  3. <heroes-selector
  4. v-if="selectHeroes"
  5. :factionSelected="factionSelected"
  6. ></heroes-selector>
  7. <hr />
  8. <h4 v-if="areHeroesSelectable">Select Heroes from below</h4>
  9. <div v-if="noFilter === false">
  10. <button class="btn btn-primary" @click="showFilter = !showFilter">
  11. Show/Hide filter
  12. </button>
  13. <button class="btn btn-primary" @click="resetFilter">
  14. Reset filter
  15. </button>
  16. <heroes-filter
  17. v-if="showFilter"
  18. :filter-options="filterOptions"
  19. v-model="filter"
  20. ></heroes-filter>
  21. </div>
  22. <div
  23. class="row row-cols-2 row-cols-sm-2 row-cols-md-3 row-cols-lg-4 row-cols-xl-6 mt-3"
  24. >
  25. <div class="col mb-4" v-for="hero in heroesToDisplay" :key="hero.id">
  26. <hero
  27. :hero="hero"
  28. :selectable="areHeroesSelectable"
  29. :removable="false"
  30. ></hero>
  31. </div>
  32. </div>
  33. </div>
  34. </template>
  35. <script>
  36. import { mapGetters } from 'vuex';
  37. import Hero from './components/Hero';
  38. import HeroesFilter from './components/HeroesFilter';
  39. import HeroesSelector from './components/HeroesSelector';
  40. import { Constants } from 'const/constants';
  41. let initialFilter = function(filterOptions) {
  42. return {
  43. minPower: 0,
  44. maxPower: 6,
  45. minCost: 0,
  46. maxCost: 7,
  47. faction: filterOptions.faction[0],
  48. popularity: filterOptions.popularity[0],
  49. draft: filterOptions.draft[0],
  50. name: '',
  51. byName: false
  52. };
  53. };
  54. export default {
  55. // selectHeroes : if true it means we are not just displaying the cards
  56. // we need to offer a way to user to select heroes based on current game mode
  57. props: {
  58. selectHeroes: {
  59. type: Boolean,
  60. default: false
  61. },
  62. display12heroesOnly: {
  63. type: Boolean,
  64. default: false
  65. },
  66. noFilter: {
  67. type: Boolean,
  68. default: false
  69. },
  70. displayCustomListOfHeroes: {
  71. type: Array,
  72. default: () => []
  73. }
  74. },
  75. data() {
  76. return {
  77. showFilter: this.selectHeroes === true && this.deckMode === 'faction',
  78. filter: {
  79. minPower: 0,
  80. maxPower: 6,
  81. minCost: 0,
  82. maxCost: 7,
  83. faction: '',
  84. popularity: '',
  85. draft: '',
  86. name: '',
  87. byName: false,
  88. byId: []
  89. }
  90. };
  91. },
  92. components: {
  93. Hero,
  94. HeroesFilter,
  95. HeroesSelector
  96. },
  97. computed: {
  98. ...mapGetters({
  99. filterHeroes: 'game/filterHeroes',
  100. allHeroes: 'game/allHeroes',
  101. deckMode: 'game/deckMode',
  102. isPopularityRule: 'game/isPopularityRule',
  103. myColor: 'game/myColor',
  104. getSelectableDraftIds: 'game/myDraftIds',
  105. myTwelveHeroes: 'game/myTwelveHeroes',
  106. chosenIds: 'chosenIds',
  107. isItMyTurn: 'game/isItMyTurn'
  108. }),
  109. filterOptions() {
  110. // init filter options will all
  111. let factionFilter = ['all', 'orcs', 'humans', 'elves', 'meca', 'none'];
  112. let popularityFilter = ['without', 'with'];
  113. let draftFilter = ['all', 'yes', 'no'];
  114. if (this.selectHeroes === true) {
  115. draftFilter = ['all'];
  116. // if tournament and pop rule ON, let's authorize to select between all golems
  117. if (this.isPopularityRule === true && this.deckMode !== 'tournament') {
  118. popularityFilter = ['with'];
  119. } else if (this.isPopularityRule === false) {
  120. popularityFilter = ['without'];
  121. }
  122. if (this.deckMode === 'faction') {
  123. factionFilter = ['orcs', 'humans', 'elves', 'meca'];
  124. }
  125. }
  126. if (this.display12heroesOnly === true) {
  127. popularityFilter = ['none'];
  128. }
  129. return {
  130. faction: factionFilter,
  131. popularity: popularityFilter,
  132. draft: draftFilter,
  133. power: true,
  134. cost: true,
  135. byName: true
  136. };
  137. },
  138. heroesToDisplay() {
  139. //Possibility here to display heroes we want
  140. if (this.displayCustomListOfHeroes.length > 0) {
  141. return this.displayCustomListOfHeroes;
  142. }
  143. if (this.display12heroesOnly === true) {
  144. return this.myTwelveHeroes;
  145. }
  146. if (this.selectHeroes === true) {
  147. return this.filterHeroes(
  148. this.filter,
  149. this.deckMode === 'draft' || this.deckMode === 'tournament'
  150. );
  151. } else {
  152. return this.allHeroes;
  153. }
  154. },
  155. factionSelected() {
  156. return this.filter.faction;
  157. },
  158. areHeroesSelectable() {
  159. if (this.selectHeroes === true && this.isItMyTurn === true) {
  160. if (
  161. (this.deckMode === 'draft' &&
  162. this.chosenIds.length < Constants.NB_CARDS_TO_PICK_DRAFT) ||
  163. (this.deckMode === 'tournament' &&
  164. this.chosenIds.length < Constants.NB_CARDS_TO_PICK_TOURNAMENT)
  165. ) {
  166. return true;
  167. }
  168. }
  169. return false;
  170. }
  171. },
  172. methods: {
  173. resetFilter() {
  174. Object.assign(this.filter, initialFilter(this.filterOptions));
  175. }
  176. },
  177. created() {
  178. Object.assign(this.filter, initialFilter(this.filterOptions));
  179. this.showFilter = this.selectHeroes === true && this.deckMode === 'faction';
  180. },
  181. watch: {
  182. 'filter.byName'(newValue) {
  183. if (newValue === false) {
  184. this.filter.name = '';
  185. }
  186. }
  187. }
  188. };
  189. </script>
  190. <style scoped>
  191. div {
  192. color: antiquewhite;
  193. }
  194. </style>