11'use strict' ;
22
3+ var socket_io ;
4+ var pokemonActions ;
5+
36$ ( document ) . ready ( function ( ) {
47 mapView . init ( ) ;
5- var socket = io . connect ( 'http://' + document . domain + ':' + location . port + '/event' ) ;
6- socket . on ( 'connect' , function ( ) {
8+ socket_io = io . connect ( 'http://' + document . domain + ':' + location . port + '/event' ) ;
9+ socket_io . on ( 'connect' , function ( ) {
710 console . log ( 'connected!' ) ;
811 } ) ;
9- socket . on ( 'logging' , function ( msg ) {
12+ socket_io . on ( 'logging' , function ( msg ) {
1013 for ( var i = 0 ; i < msg . length ; i ++ ) {
1114 mapView . log ( {
1215 message : msg [ i ] . output ,
1316 color : msg [ i ] . color + "-text"
1417 } ) ;
1518 }
1619 } ) ;
20+
21+ pokemonActions = function ( socket_io ) {
22+ var actions = {
23+ releasePokemon : {
24+ button : function ( pokemon , user_id ) {
25+ return '<a href="#!" onClick="pokemonActions.releasePokemon.action(\'' + pokemon . unique_id + '\')">Release</a>' ;
26+ } ,
27+ action : function ( id ) {
28+ if ( confirm ( "Are you sure you want to release this pokemon? THIS CANNOT BE UNDONE!" ) ) {
29+ socket_io . emit ( 'user_action' , { 'event' :'release_pokemon' , data : { 'pokemon_id' : id } } ) ;
30+ mapView . sortAndShowBagPokemon ( false , false ) ;
31+ }
32+ }
33+ } ,
34+
35+ evolvePokemon : {
36+ button : function ( pokemon , user_id ) {
37+ var pkmnData = mapView . pokemonArray [ pokemon . id - 1 ] ,
38+ candy = mapView . getCandy ( pokemon . id , user_id ) ,
39+ canEvolve = false ;
40+ if ( "undefined" != typeof pkmnData [ 'Next evolution(s)' ] && "undefined" != typeof pkmnData [ 'Next Evolution Requirements' ] ) {
41+ canEvolve = ( candy >= pkmnData [ 'Next Evolution Requirements' ] [ 'Amount' ] )
42+ }
43+ return ( canEvolve ? '<a href="#!" onClick="pokemonActions.evolvePokemon.action(\'' + pokemon . unique_id + '\')">Evolve</a>' : false ) ;
44+ } ,
45+ action : function ( id ) {
46+ if ( confirm ( "Are you sure you want to evolve this pokemon? THIS CANNOT BE UNDONE!" ) ) {
47+ socket_io . emit ( 'user_action' , { 'event' :'evolve_pokemon' , data : { 'pokemon_id' : id } } ) ;
48+ mapView . sortAndShowBagPokemon ( false , false ) ;
49+ }
50+ }
51+ }
52+ }
53+
54+ var enabledActions = { } ;
55+ for ( var i in actions ) {
56+ if ( mapView . settings . actionsEnabled === true ) {
57+ enabledActions [ i ] = actions [ i ] ;
58+ } else if ( Array . isArray ( mapView . settings . actionsEnabled ) ) {
59+ if ( mapView . settings . actionsEnabled . indexOf ( i ) !== - 1 ) {
60+ enabledActions [ i ] = actions [ i ] ;
61+ }
62+ }
63+ }
64+
65+ return enabledActions ;
66+ } ( socket_io )
1767} ) ;
1868
1969var mapView = {
@@ -534,8 +584,8 @@ var mapView = {
534584 eggs = 0 ,
535585 sortedPokemon = [ ] ,
536586 out = '' ,
537- user = self . user_data [ self . settings . users [ user_id ] ] ,
538- user_id = user_id || 0 ;
587+ user_id = user_id || 0 ,
588+ user = self . user_data [ self . settings . users [ user_id ] ] ;
539589
540590 if ( ! user . bagPokemon . length ) return ;
541591
@@ -547,6 +597,7 @@ var mapView = {
547597 }
548598 var pokemonData = user . bagPokemon [ i ] . inventory_item_data . pokemon_data ,
549599 pkmID = pokemonData . pokemon_id ,
600+ pkmUID = pokemonData . id ,
550601 pkmnName = self . pokemonArray [ pkmID - 1 ] . Name ,
551602 pkmCP = pokemonData . cp ,
552603 pkmIVA = pokemonData . individual_attack || 0 ,
@@ -560,6 +611,7 @@ var mapView = {
560611 sortedPokemon . push ( {
561612 "name" : pkmnName ,
562613 "id" : pkmID ,
614+ "unique_id" : pkmUID ,
563615 "cp" : pkmCP ,
564616 "iv" : pkmIV ,
565617 "attack" : pkmIVA ,
@@ -628,6 +680,7 @@ var mapView = {
628680 }
629681 for ( var i = 0 ; i < sortedPokemon . length ; i ++ ) {
630682 var pkmnNum = sortedPokemon [ i ] . id ,
683+ pkmnUnique = sortedPokemon [ i ] . unique_id ,
631684 pkmnImage = self . pad_with_zeroes ( pkmnNum , 3 ) + '.png' ,
632685 pkmnName = self . pokemonArray [ pkmnNum - 1 ] . Name ,
633686 pkmnCP = sortedPokemon [ i ] . cp ,
@@ -647,8 +700,36 @@ var mapView = {
647700 '<br><b>CP:</b>' + pkmnCP +
648701 '<br><b>IV:</b> ' + ( pkmnIV >= 0.8 ? '<span style="color: #039be5">' + pkmnIV + '</span>' : pkmnIV ) +
649702 '<br><b>A/D/S:</b> ' + pkmnIVA + '/' + pkmnIVD + '/' + pkmnIVS +
650- '<br><b>Candy: </b>' + candyNum +
651- '</div>' ;
703+ '<br><b>Candy: </b>' + candyNum
704+ ;
705+
706+ if ( Object . keys ( pokemonActions ) . length ) {
707+ var actionsOut = ''
708+ for ( var pa in pokemonActions ) {
709+ var content = pokemonActions [ pa ] . button ( sortedPokemon [ i ] , user_id ) ;
710+ if ( content ) {
711+ actionsOut += '<li>' + pokemonActions [ pa ] . button ( sortedPokemon [ i ] , user_id ) + '</li>' ;
712+ }
713+ }
714+
715+ if ( actionsOut ) {
716+ out +=
717+ '<div>' +
718+ ' <a class="dropdown-button btn" href="#" data-activates="poke-actions-' + pkmnUnique + '">' +
719+ ' Actions' +
720+ ' </a>' +
721+ ' <ul id="poke-actions-' + pkmnUnique + '" class="dropdown-content">' +
722+ actionsOut +
723+ ' </ul>' +
724+ '</div><br>' ;
725+ } else {
726+ out += '<div>' +
727+ ' <a class="dropdown-button btn disabled" href="#">Actions</a>' +
728+ '</div><br>' ;
729+ }
730+ }
731+
732+ out += '</div>' ;
652733 }
653734 // Add number of eggs
654735 out += '<div class="col s12 m4 l3 center" style="float: left;"><img src="image/items/Egg.png" class="png_img"><br><b>You have ' + eggs + ' egg' + ( eggs !== 1 ? "s" : "" ) + '</div>' ;
@@ -677,6 +758,7 @@ var mapView = {
677758 return ( nth % 4 === 0 ) ? '</div></div><div class="row"><div' : match ;
678759 } ) ;
679760 $ ( '#subcontent' ) . html ( out ) ;
761+ $ ( '.dropdown-button' ) . dropdown ( ) ;
680762 } ,
681763 sortAndShowPokedex : function ( sortOn , user_id ) {
682764 var self = this ,
0 commit comments