1-
21import StoryUpgrades from './story-upgrades.js' ;
32import StoryPickTeam from './story-pick-team.js' ;
43import StoryRecruitList from './story-recruit-list.js' ;
@@ -8,12 +7,14 @@ const DEBUG = false;
87const CITY_STATE = {
98 'LOCKED' : 0 ,
109 'OPEN' : 1 ,
11- 'DONE' : 2
10+ 'OPTIONALS_LEFT' : 2 ,
11+ 'DONE' : 3
1212} ;
1313
1414const CITY_ICON_MAP = [
1515 'imgs/story/lock-100px.png' , // LOCKED
16- '' ,
16+ '' , // OPEN
17+ 'imgs/story/checkmark-outline-100px.png' , // OPTIONALS_LEFT
1718 'imgs/story/checkmark-100px.png' // DONE
1819] ;
1920
@@ -193,7 +194,7 @@ export default {
193194 <b-button block
194195 @click="$refs.pickTeamPopup.show(challenge)"
195196 v-bind:variant="challengeCompleted(challenge.id)? 'outline-dark' : 'outline-primary' ">
196- {{challenge.display}}
197+ {{!!challenge.optional ? "Optional: " + challenge.display : challenge.display}}
197198 </b-button>
198199 </b-list-group-item>
199200 </b-list-group>
@@ -273,7 +274,6 @@ export default {
273274 return result ;
274275 } ,
275276 recruit_list : function ( ) {
276- const completed = this . saveState . challenges_completed ;
277277 let recruits = { } ;
278278
279279 for ( let city of Object . keys ( this . challenges ) ) {
@@ -306,13 +306,17 @@ export default {
306306 return ;
307307 }
308308 else {
309- let open_cities = Object . keys (
310- this . cityDisplayInfo ) . filter ( ( city ) =>
311- this . getCityState ( city ) == CITY_STATE . OPEN ) ;
312-
313- let random = open_cities [ Math . floor ( Math . random ( ) * open_cities . length ) ] ;
314- console . log ( random ) ;
315- this . selectedCityId = random ;
309+ let open_cities = Object . keys ( this . cityDisplayInfo )
310+ . filter ( ( city ) => this . getCityState ( city ) == CITY_STATE . OPEN ) ;
311+ // Fall back to cities with optional challenges left
312+ if ( open_cities . length === 0 )
313+ open_cities = Object . keys ( this . cityDisplayInfo )
314+ . filter ( ( city ) => this . getCityState ( city ) == CITY_STATE . OPTIONALS_LEFT ) ;
315+ // Fall back to cur
316+ if ( open_cities . length === 0 )
317+ this . selectedCityId = cur ;
318+ else
319+ this . selectedCityId = open_cities [ Math . floor ( Math . random ( ) * open_cities . length ) ] ;
316320 }
317321 } ,
318322 challengeCompleted : function ( id ) {
@@ -325,6 +329,7 @@ export default {
325329 const suffix = [
326330 'is still locked.' ,
327331 'is open to challenge!' ,
332+ 'has optional challenges!' ,
328333 'has been completed!'
329334 ] ;
330335 return displayName + ' ' + suffix [ state ] ;
@@ -341,13 +346,23 @@ export default {
341346 let state = CITY_STATE . LOCKED ;
342347
343348 let prereqs = this . cityDisplayInfo [ city ] . prereqs ;
344- if ( prereqs . every ( c => ( this . getCityState ( c ) === CITY_STATE . DONE ) ) ) {
345- state = CITY_STATE . OPEN ;
349+ if ( prereqs . every ( c => [ CITY_STATE . DONE , CITY_STATE . OPTIONALS_LEFT ] . includes ( this . getCityState ( c ) ) ) ) {
350+ let anyOptionalsLeft = false
351+ let anyRequiredLeft = false
346352
347- // only need to check completion of challenges if we are open
348353 let cityChallenges = this . challenges [ city ] ;
349- if ( cityChallenges . every ( c => this . challengeCompleted ( c . id ) ) ) {
350- state = CITY_STATE . DONE ;
354+ for ( const c of cityChallenges ) {
355+ if ( ! this . challengeCompleted ( c . id ) ) {
356+ if ( ! ! c . optional ) anyOptionalsLeft = true
357+ else anyRequiredLeft = true
358+ }
359+ }
360+ if ( anyRequiredLeft ) {
361+ state = CITY_STATE . OPEN
362+ } else if ( anyOptionalsLeft ) {
363+ state = CITY_STATE . OPTIONALS_LEFT
364+ } else {
365+ state = CITY_STATE . DONE
351366 }
352367 }
353368 return state ;
0 commit comments