123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>Source: src/store/game/game.js | 12 Heroes</title>
- <script src="scripts/prettify/prettify.js"> </script>
- <script src="scripts/prettify/lang-css.js"> </script>
- <!--[if lt IE 9]>
- <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
- <![endif]-->
- <link type="text/css" rel="stylesheet" href="styles/bootstrap.min.css">
- <link type="text/css" rel="stylesheet" href="styles/prettify-jsdoc.css">
- <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
- <link type="text/css" rel="stylesheet" href="styles/tui-doc.css">
-
- </head>
- <body>
- <nav class="lnb" id="lnb">
- <div class="logo" style="">
-
- <img src="img/toast-ui.png" width="100%" height="100%">
-
- </div>
- <div class="title">
- <h1><a href="index.html" class="link">12 Heroes</a></h1>
-
- </div>
- <div class="search-container" id="search-container">
- <input type="text" placeholder="Search">
- <ul></ul>
- </div>
-
- <div class="lnb-api hidden"><h3>Namespaces</h3><ul><li><a href="Constants.html">Constants</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="Constants_sub"></div></li><li><a href="Constants.HERO.html">Constants.HERO</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="Constants.HERO_sub"><div class="member-type">Members</div><ul class="inner"><li><a href="Constants.HERO.html#.HERO_ABILITY">HERO_ABILITY</a></li><li><a href="Constants.HERO.html#.HERO_DEPLOY">HERO_DEPLOY</a></li><li><a href="Constants.HERO.html#.HERO_DISCARD">HERO_DISCARD</a></li><li><a href="Constants.HERO.html#.HERO_DISMISS">HERO_DISMISS</a></li><li><a href="Constants.HERO.html#.HERO_MOVE">HERO_MOVE</a></li><li><a href="Constants.HERO.html#.HERO_RECRUIT">HERO_RECRUIT</a></li><li><a href="Constants.HERO.html#.HERO_REPLACE">HERO_REPLACE</a></li></ul></div></li><li><a href="Constants.PLAYER.html">Constants.PLAYER</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="Constants.PLAYER_sub"><div class="member-type">Members</div><ul class="inner"><li><a href="Constants.PLAYER.html#.PLAYER_PASS">PLAYER_PASS</a></li><li><a href="Constants.PLAYER.html#.PLAYER_SUPPLY">PLAYER_SUPPLY</a></li></ul></div></li><li><a href="Constants.POS.html">Constants.POS</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="Constants.POS_sub"><div class="member-type">Members</div><ul class="inner"><li><a href="Constants.POS.html#.POS_BATTLE_CENTER">POS_BATTLE_CENTER</a></li><li><a href="Constants.POS.html#.POS_BATTLE_LEFT">POS_BATTLE_LEFT</a></li><li><a href="Constants.POS.html#.POS_BATTLE_RIGHT">POS_BATTLE_RIGHT</a></li><li><a href="Constants.POS.html#.POS_CAMP">POS_CAMP</a></li><li><a href="Constants.POS.html#.POS_DISCARD">POS_DISCARD</a></li><li><a href="Constants.POS.html#.POS_HAND">POS_HAND</a></li><li><a href="Constants.POS.html#.POS_PILE">POS_PILE</a></li></ul></div></li><li><a href="Constants.REQ.html">Constants.REQ</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="Constants.REQ_sub"><div class="member-type">Members</div><ul class="inner"><li><a href="Constants.REQ.html#.REQ_ERROR">REQ_ERROR</a></li><li><a href="Constants.REQ.html#.REQ_IDLE">REQ_IDLE</a></li><li><a href="Constants.REQ.html#.REQ_REQUESTED">REQ_REQUESTED</a></li><li><a href="Constants.REQ.html#.REQ_SUCCESS">REQ_SUCCESS</a></li></ul></div></li></ul></div><div class="lnb-api hidden"><h3>Global</h3><ul><li><a href="global.html#getDraftSets">getDraftSets</a></li><li><a href="global.html#getHeroesIdsByFaction">getHeroesIdsByFaction</a></li><li><a href="global.html#shuffleHeroes">shuffleHeroes</a></li><li><a href="global.html#TH_Ability">TH_Ability</a></li><li><a href="global.html#TH_AbilityHook">TH_AbilityHook</a></li><li><a href="global.html#TH_AdvRule">TH_AdvRule</a></li><li><a href="global.html#TH_BattleTile">TH_BattleTile</a></li><li><a href="global.html#TH_Color">TH_Color</a></li><li><a href="global.html#TH_CommStatus">TH_CommStatus</a></li><li><a href="global.html#TH_DeckMode">TH_DeckMode</a></li><li><a href="global.html#TH_Faction">TH_Faction</a></li><li><a href="global.html#TH_GameDataStore">TH_GameDataStore</a></li><li><a href="global.html#TH_GameGlobalState">TH_GameGlobalState</a></li><li><a href="global.html#TH_GameStateEnum">TH_GameStateEnum</a></li><li><a href="global.html#TH_HeroAction">TH_HeroAction</a></li><li><a href="global.html#TH_HeroCard">TH_HeroCard</a></li><li><a href="global.html#TH_HeroInGame">TH_HeroInGame</a></li><li><a href="global.html#TH_HeroPosition">TH_HeroPosition</a></li><li><a href="global.html#TH_MessageChatFrom">TH_MessageChatFrom</a></li><li><a href="global.html#TH_MessageDraftStep">TH_MessageDraftStep</a></li><li><a href="global.html#TH_MessageFaction">TH_MessageFaction</a></li><li><a href="global.html#TH_MessageTournamentDeckStep">TH_MessageTournamentDeckStep</a></li><li><a href="global.html#TH_PlayerAction">TH_PlayerAction</a></li><li><a href="global.html#TH_PlayerGameState">TH_PlayerGameState</a></li><li><a href="global.html#TH_Popularity">TH_Popularity</a></li><li><a href="global.html#TH_ReqStatus">TH_ReqStatus</a></li></ul></div>
- </nav>
- <div id="resizer"></div>
- <div class="main" id="main">
-
-
- <section>
- <article>
- <pre class="prettyprint source linenums"><code>'use strict';
- import AnyPlayer from './player/any-player';
- import allHeroesJson from '../../../server/src/client-server-shared/all-heroes.json';
- const initGameState = {
- gameState: '',
- allHeroes: [],
- deckMode: '',
- advRules: [],
- 'waitingFor/blue': false,
- 'waitingFor/red': false,
- currentPlayer: '',
- 'battleTiles/left': [],
- 'battleTiles/center': [],
- 'battleTiles/right': [],
- totalFood: 0,
- allHeroesJson
- };
- const state = Object.assign({}, initGameState);
- const getters = {
- state(state) {
- return state.gameState;
- },
- allHeroes(state) {
- return state.allHeroes;
- },
- deckMode(state) {
- return state.deckMode;
- },
- myColor(state, getters, rootState) {
- let color = 'blue';
- if (rootState.username === state.redPlayer.name) {
- color = 'red';
- }
- return color;
- },
- my: (state, getters) => target => {
- return getters.myColor + 'Player/' + target;
- },
- ennemyColor(state, getters) {
- let color = 'red';
- if (getters.myColor === 'red') {
- color = 'blue';
- }
- return color;
- },
- isItMyTurn(state, getters) {
- return state['waitingFor/' + getters.myColor];
- },
- isPopularityRule(state) {
- return state.advRules.includes('popularity');
- },
- isDiscardRule(state) {
- return state.advRules.includes('discard');
- },
- heroById: state => id => {
- return state.allHeroes.find(hero => hero.id === id);
- },
- myTwelveHeroes(state, getters) {
- let myHeroesIds = getters[getters.my('twelveHeroes')].map(hero => hero.id);
- return state.allHeroes.filter(hero => {
- return myHeroesIds.includes(hero.id);
- });
- },
- myDraftIds(state, getters) {
- return getters[getters.my('draftIds')];
- },
- filterHeroes: state =>
- /**
- * Get a filtered array of heroes
- *
- * vuex : 'game/filterHeroes'
- *
- * @param {object} filter - the filter to apply on all heroes array
- * @param {string} filter.faction - Filter on faction attribute, can be : orcs humans elves meca none all
- * @param {string} filter.popularity - Filter on popularity attribute
- * can be :
- * - none : no filter on popularity
- * - with : do not return heroes that are usable only when no popularity rule
- * - without : do not return heroes that are usable only when popularity rule
- * @param {string} filter.draft - Filter on draft attribute, can be : yes no all
- * @param {number} filter.minPower - Filter on power attribute >= minPower
- * @param {number} filter.maxPower - Filter on power attribute <= maxPower
- * @param {number} filter.minCost - Filter on cost attribute >= minCost
- * @param {number} filter.maxCost - Filter on cost attribute <= maxCost
- * @param {boolean} filter.byName - Activate filter on Hero's name
- * @param {string} filter.name - Filter on Hero's name
- * @param {number[]} filter.byId - Filter on Heroes Id(s). Do not filter in Ids if array is empty
- * @param state
- * @returns {object[]} Filtered array of heroes
- */
- filter => {
- if (!filter.faction) filter.faction = 'all';
- if (!filter.popularity) filter.popularity = 'without';
- if (!filter.minPower) filter.minPower = 0;
- if (!filter.maxPower) filter.maxPower = 8;
- if (!filter.minCost) filter.minCost = 0;
- if (!filter.maxCost) filter.minCost = 8;
- let draftFilter = 'all';
- switch (filter.draft) {
- case 'yes':
- draftFilter = true;
- break;
- case 'no':
- draftFilter = false;
- break;
- default:
- draftFilter = 'all';
- break;
- }
- return state.allHeroes.filter(hero => {
- if (filter.faction !== 'all' && hero.faction !== filter.faction)
- return false;
- if (
- filter.popularity !== 'none' &&
- hero.popularity !== 'any' &&
- hero.popularity !== filter.popularity
- )
- return false;
- if (draftFilter !== 'all' && hero.isDraftable !== draftFilter)
- return false;
- if (hero.power < filter.minPower || hero.power > filter.maxPower)
- return false;
- if (hero.cost < filter.minCost || hero.cost > filter.maxCost)
- return false;
- if (
- filter.byName === true &&
- !hero.name.toLowerCase().includes(filter.name.toLowerCase())
- )
- return false;
- if (
- filter.byId &&
- filter.byId.length > 0 &&
- !filter.byId.includes(hero.id)
- ) {
- return false;
- }
- return true;
- });
- }
- };
- const mutations = {
- SET_HEROES: (state, payload) => {
- state.allHeroes = payload;
- },
- SET_FULL_GAME_STATE: (state, payload) => {
- Object.assign(state, payload);
- },
- INIT_GAME_STATE: state => {
- Object.assign(state, initGameState);
- },
- SET_WAITING_FOR: (state, payload) => {
- state['waitingFor/' + payload.color] = payload.value;
- }
- };
- const actions = {
- /**
- * Sets the array containing all heroes
- *
- * vuex : 'game/setHeroes'
- *
- * @param {object[]} payload - the array with all heroes
- */
- setHeroes: ({ commit }, payload) => {
- commit('SET_HEROES', payload);
- },
- /**
- * Update the full game state (main + players)
- *
- * Will be called by the game master to update the game state
- *
- * vuex : 'game/update'
- *
- * @param {object} Context - vuex context
- * @param {Function} Context.commit - vuex commit func
- * @param {object} payload - the full game state
- * @param {object} payload.game - match store state in game.js
- * @param {object} payload.bluePlayer - match store state in any-player.js for blue
- * @param {object} payload.redPlayer - match store state in any-player.js for red
- */
- update: ({ commit }, payload) => {
- commit('SET_FULL_GAME_STATE', payload.game);
- commit('bluePlayer/SET_FULL_PLAYER_STATE', payload.bluePlayer);
- commit('redPlayer/SET_FULL_PLAYER_STATE', payload.redPlayer);
- },
- /**
- * Reset the whole game state
- *
- * vuex : 'game/resetGameState'
- *
- * Typically to call when game is stopped or user disconnects
- *
- * @param {object} Context - vuex context
- * @param {Function} Context.commit - vuex commit func
- */
- resetGameState: ({ commit }) => {
- commit('INIT_GAME_STATE');
- commit('bluePlayer/INIT_PLAYER_STATE');
- commit('redPlayer/INIT_PLAYER_STATE');
- },
- /**
- * Submit chosen faction to the game master
- *
- * vuex : 'game/submitMyFaction'
- *
- * @param {string} payload - the faction name (lowercase)
- */
- submitMyFaction: ({ dispatch, getters }, payload) => {
- dispatch(getters.my('submitFaction'), payload);
- }
- };
- const bluePlayer = new AnyPlayer();
- const redPlayer = new AnyPlayer();
- export default {
- namespaced: true,
- state,
- getters,
- mutations,
- actions,
- modules: {
- bluePlayer: {
- namespaced: true,
- ...bluePlayer
- },
- redPlayer: {
- namespaced: true,
- ...redPlayer
- }
- }
- };
- </code></pre>
- </article>
- </section>
- </div>
- <footer>
- <img class="logo" src="img/toast-ui.png" style="">
- <div class="footer-text">NHN Entertainment. Frontend Development Lab</div>
- </footer>
- <script>prettyPrint();</script>
- <script src="scripts/jquery.min.js"></script>
- <script src="scripts/tui-doc.js"></script>
- <script src="scripts/linenumber.js"></script>
- <script>
- var id = '_sub'.replace(/"/g, '_');
- var selectedApi = document.getElementById(id); // do not use jquery selector
- var $selectedApi = $(selectedApi);
- $selectedApi.removeClass('hidden');
- $selectedApi.parent().find('.glyphicon').removeClass('glyphicon-plus').addClass('glyphicon-minus');
- showLnbApi();
- </script>
- </body>
- </html>
|