diff --git a/.env.example b/.env.example index cd06cc8..3958b4a 100644 --- a/.env.example +++ b/.env.example @@ -33,3 +33,6 @@ PUSHER_APP_ID= PUSHER_APP_KEY= PUSHER_APP_SECRET= PUSHER_APP_CLUSTER=mt1 + +POE_VERSION=3.2 +POE_LEAGUES='Abyss,Hardcore Abyss,SSF Abyss,SSF Abyss HC,10 Day Mayhem' diff --git a/app/Account.php b/app/Account.php index fa4ea43..ce5b7d0 100644 --- a/app/Account.php +++ b/app/Account.php @@ -28,7 +28,7 @@ public function ladderChars() protected function getNewAccInfo($acc){ // $html = HtmlDomParser::file_get_html('https://www.pathofexile.com/account/view-profile/'. $acc .'/characters'); - //problem with HtmlDomParser::file_get_html with php 7.1 + //problem with HtmlDomParser::file_get_html with php 7.1 //get with Guzzle and then str_get_html $client = new \GuzzleHttp\Client([ 'base_uri' => 'https://www.pathofexile.com/', @@ -37,7 +37,7 @@ protected function getNewAccInfo($acc){ $response = $client->request('GET', '/account/view-profile/'. $acc .'/characters'); $body = $response->getBody()->getContents(); $html = HtmlDomParser::str_get_html($body); - + //filter for accoutn name $name = $html->find('.container-content h2',0); @@ -79,7 +79,7 @@ public function updateLastChar(){ private function getLastCharFrom($html){ if($html==null){ // $html = HtmlDomParser::file_get_html('https://www.pathofexile.com/account/view-profile/'. $this->name .'/characters'); - //problem with HtmlDomParser::file_get_html with php 7.1 + //problem with HtmlDomParser::file_get_html with php 7.1 //get with Guzzle and then str_get_html $client = new \GuzzleHttp\Client([ @@ -136,7 +136,7 @@ public function getItemsFor($char){ //get cahce if no cache get from poe api $acc=$this->name; $key='items/'.$acc.'/'.$char; - $items_response = \Cache::remember($key, 5, function () use ($acc,$char){ + $items_response = \Cache::remember($key, config('app.poe_cache_time'), function () use ($acc,$char){ $client = new \GuzzleHttp\Client(); //make Requests to PathOfExile website to retrieve Character Items try { diff --git a/app/Build.php b/app/Build.php deleted file mode 100644 index 60aa748..0000000 --- a/app/Build.php +++ /dev/null @@ -1,91 +0,0 @@ -attributes['tree_data'] = $tree_data; - } - - public function getTreeDataAttribute($value) - { - // dd($value); - $tree_data = base64_decode($value); - $tree_data = gzuncompress($tree_data); - return json_decode($tree_data, true); - } - - // Item_Data Mutator & Accessor - public function setItemDataAttribute($value) - { - $item_data = gzcompress($value); - $item_data = base64_encode($item_data); - $this->attributes['item_data'] = $item_data; - } - - public function getItemDataAttribute($value) - { - $item_data = base64_decode($value); - $item_data = gzuncompress($item_data); - return json_decode($item_data, true); - } - - // Stats Mutator & Accessor - public function setStatsAttribute($value) - { - $stats = gzcompress(json_encode($value, true)); - $stats = base64_encode($stats); - $this->attributes['stats'] = $stats; - } - - public function getStatsAttribute($value) - { - $stats = base64_decode($value); - $stats = gzuncompress($stats); - return json_decode($stats, true); - } - - public function getStats() - { - $stManager = new Stats_Manager; - - //items - $banItems = ['Flask', 'Weapon2', 'Offhand2']; - if (isset($_GET['offHand'])) { - $banItems = ['Flask', 'Weapon', 'Offhand']; - } - - $items = array_filter($this->item_data['items'], function ($item) use (&$banItems) { - return in_array($item['inventoryId'], $banItems); - }); - - $stManager->addItems($items); - - //tree - $treeNodesJewels = new CharacterTreePoints; - $nodes = $treeNodesJewels->getPoints($this->tree_data); - $stManager->addTreeNode($nodes); - - //base stats - $character = $this->item_data['character']; - $baseStat = new Base_Stats; - $baseStat = $baseStat->getStats($character['level'], $character['classId']); - foreach ($baseStat as $stat) { - $stManager->addBaseMods($stat); - } - - return $stManager->getStats(); - } -} diff --git a/app/Http/Controllers/ApiController.php b/app/Http/Controllers/ApiController.php index b49b66a..7aca1fa 100644 --- a/app/Http/Controllers/ApiController.php +++ b/app/Http/Controllers/ApiController.php @@ -10,13 +10,12 @@ class ApiController extends CacheController { public function getItems(Request $request) { - if (!$request->has('account') && !$request->has('character')) { return; } $b = explode('::', $request->input('account')); if($b[0] == 'build'){ - return \App\Build::find($b[1])->item_data['items']; + return \App\Snapshot::where('hash','=',$b[1])->get()->item_data['items']; } $acc=$request->input('account'); $char=$request->input('character'); @@ -34,9 +33,13 @@ public function getStats(Request $request) $b = explode('::', $acc); if ($b[0] == 'build') { - return \App\Build::find($b[1])->getStats(); + $build=\App\Snapshot::where('hash','=',$b[1])->first(); + if(!$build){ + return []; + } + return $build->getStats(); } - //getItemsCache() is from parant class CacheController + //getStatsCache() is from parant class CacheController return $this->getStatsCache($acc, $char); } @@ -82,12 +85,11 @@ public function getFavsChars() public function getLadder(Request $request) { - + if ($request->has('searchFilter')) { $respond = \App\LadderCharacter::with('account')->whereHas('account', function ($query) use (&$request) { $query->where('name', 'like', '%'.$request->input ('searchFilter').'%'); })->orWhere('name', 'like', '%'.$request->input ('searchFilter').'%')->paginate(); - return $respond; } @@ -116,7 +118,7 @@ public function getLadder(Request $request) return $respond; } - if ($request->has('leagueFilter')) { + if ($request->has('leagueFilter')) { $respond = \App\LadderCharacter::with('account')->where('league', '=', $request->input('leagueFilter')) ->orderBy('rank', 'asc')->paginate(); return $respond; @@ -161,7 +163,6 @@ public function getXML(Request $request) $itemsData = $this->getItemsCache($acc, $char, true); $treeJson = $this->getTreeCache($acc, $char); $pob = new PobXMLBuilder($itemsData, $treeJson); - // show XML ----> // Header('Content-type: text/xml'); @@ -170,59 +171,42 @@ public function getXML(Request $request) return $pob->encodedXML(); } - public function defaultBuild(Request $request) + public function getBuild($hash) { - $id = $request->input('id'); - $name = $request->input('name'); - - $build = \App\Build::where('id', '=', $id)->where('name', '=', $name)->first(); - + $build = \App\Snapshot::where('hash', '=', $hash)->first(); return $build; } public function saveBuild(Request $request) { - $client = new \GuzzleHttp\Client(); - $treeData = $client->request( - 'GET', - 'https://www.pathofexile.com/character-window/get-passive-skills', - [ - 'query' => [ - 'accountName' => $request->input('account'), - 'character' => $request->input('char') - ] - ] - ); - $treeData = (string)$treeData->getBody(); - - $itemData = $client->request( - 'GET', - 'https://www.pathofexile.com/character-window/get-items', - [ - 'query' => [ - 'accountName' => $request->input('account'), - 'character' => $request->input('char') - ] - ] - ); - $itemData = (string)$itemData->getBody(); + $acc=$request->input('account'); + $char=$request->input('char'); + + //getItemsCache() true to get the whole respons + $itemData = $this->getItemsCache($acc, $char, true); + $itemData = json_encode($itemData); + $treeData = $this->getTreeCache($acc, $char); + $treeData = json_encode($treeData); + + $hash = md5($treeData.'/'.$itemData); + $snapshot = \App\Snapshot::where('hash', '=', $hash)->first(); + if(!$snapshot){ + $version = env('POE_VERSION'); + $original_char = $acc .'/'. $char; + $snapshot = \App\Snapshot::create([ + 'hash' => $hash, + 'tree_data' => $treeData, + 'item_data' => $itemData, + 'original_char' => $original_char, + 'poe_version' => $version + ]); + $snapshot->original_level = $snapshot->item_data['character']['level']; + $snapshot->save(); + } - $currentLeagues = explode(',', env('POE_LEAGUES')); - $buildName = str_replace(' ', '_', $request->input('name')); - $build = \App\Build::create([ - 'name' => $buildName, - 'tree_data' => $treeData, - 'item_data' => $itemData, - 'poe_version' => $currentLeagues[0] - ]); - $build->stats = $build->getStats(); - $build->save(); - - $favStore = $build->item_data['character']; - $favStore['name'] = $buildName; + $favStore = $snapshot->item_data['character']; $favStore['league'] = 'localBuild'; - $favStore['buildId'] = $build->id; - + $favStore['buildId'] = $snapshot->hash; return $favStore; } } diff --git a/app/Http/Controllers/CacheController.php b/app/Http/Controllers/CacheController.php index 175a8ff..c98c417 100644 --- a/app/Http/Controllers/CacheController.php +++ b/app/Http/Controllers/CacheController.php @@ -20,7 +20,7 @@ class CacheController extends BaseController //get chars for acc from cache if no get from poe site protected function getCharsCache($acc) { - $chars = \Cache::remember($acc, 5, function () use ($acc) { + $chars = \Cache::remember($acc, config('app.poe_cache_time'), function () use ($acc) { $client = new \GuzzleHttp\Client(); try { $response = $client->request( @@ -57,7 +57,6 @@ protected function getCharsCache($acc) return $chars; } - //get items for acc/char from cache if no get from poe site protected function getItemsCache($acc, $char, $response=false) { @@ -83,43 +82,10 @@ protected function getStatsCache($acc, $char) } // dd(config('app.poe_cache_time')); $stats = \Cache::remember($key, config('app.poe_cache_time'), function () use ($acc,$dbAcc,$char,$itemsRes) { - $stManager = new Stats_Manager; - - //add Stats from Items - - //filter for secondary items and flasks - $banItems = ['Flask', 'Weapon2', 'Offhand2']; - if (isset($_GET['offHand'])) { - $banItems = ['Flask', 'Weapon', 'Offhand']; - } - - $filterItems = array_filter($itemsRes['items'], function($item) use (&$banItems) { - return !in_array($item['inventoryId'], $banItems); - }); - - $stManager->addItems($filterItems); - if ($dbAcc->last_character==$itemsRes['character']['name']) { $dbAcc->updateLastCharInfo($itemsRes); } - //end Stats from Items - - //add Stats from Tree - //make Requests to PathOfExile website to retrieve Pasive Tree - - $treeNodesJewels = new CharacterTreePoints; - $nodes = $treeNodesJewels->getPoints($this->getTreeCache($acc, $char)); - $stManager->addTreeNode($nodes); - - //add Stats Base for Class and Level - $character = $itemsRes['character']; - $baseStat = new Base_Stats; - $baseStat = $baseStat->getStats($character['level'], $character['classId']); - foreach ($baseStat as $stat) { - $stManager->addBaseMods($stat); - } - //end Stats Base - + $stManager = new Stats_Manager($itemsRes, $this->getTreeCache($acc, $char)); return $stManager->getStats(); }); @@ -142,15 +108,10 @@ public function getTreeCache($acc, $char) ] ] ); - + return json_decode((string)$responseTree->getBody(), true); }); } - protected function getLocalItems(Request $request) - { - $jsonAcc = \Storage::disk('accounts')->get($request->input('accName') . '.txt'); - $acc = json_decode($jsonAcc); - return response()->json($acc); - } + } diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/ProfileController.php similarity index 59% rename from app/Http/Controllers/HomeController.php rename to app/Http/Controllers/ProfileController.php index 10a4d51..2b80584 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/ProfileController.php @@ -7,7 +7,7 @@ use App\Stash; use App\Item; -class HomeController extends CacheController +class ProfileController extends CacheController { /** * Create a new controller instance. @@ -19,36 +19,6 @@ public function __construct() // $this->middleware('auth'); } - /** - * Show the application dashboard. - * - * @return \Illuminate\Http\Response - */ - public function index(Request $request) - { - if($request->cookie('default-acc')){ - //return redirect()->route('view.profile'); - } - return view('index'); - } - - public function home() - { - return view('index'); - } - - public function profileDefault(Request $request) - { - $char = ''; - $acc = $request->cookie('default-acc'); - if(!$acc){ - flash('No main profile .', 'warning'); - return redirect()->route('home'); - } - - return redirect()->route('get.profile',$acc); - } - public function postProfile(Request $request) { $acc = $request->input('account'); @@ -62,16 +32,6 @@ public function postProfile(Request $request) return redirect()->route('get.profile',$acc); } - //set default-acc for profile - public function postSetProfile(Request $request){ - //session(['default-acc' => $request->input('account')]); - $acc=$request->input('account'); - flash('Аccount '.$acc.' is set as your main profil next time you load '.config('app.url').'/profile is going to load '.$acc, 'success'); - - return redirect()->route('get.profile',$acc) - ->withCookie(cookie()->forever('default-acc', $acc, null, null, false, false)); - //return redirect()->route('view.profile'); - } public function getProfile($acc) { //getCharsCache() is from parant class CacheController @@ -97,16 +57,16 @@ public function getProfile($acc) $dbAcc->updateViews(); } + $chars = collect($chars); return view('profile', compact('acc', 'char', 'chars', 'dbAcc')); } - public function profile($acc, $char) + public function getProfileChar($acc, $char) { //getCharsCache() is from parant class CacheController $chars = $this->getCharsCache($acc); if(!$chars){ flash('Аccount is private or does not exist. ', 'warning'); - return redirect()->route('home'); } $dbAcc = \App\Account::with(['ladderChars', 'streamer'])->where('name', $acc)->first(); @@ -121,47 +81,38 @@ public function profile($acc, $char) flash('Character with name "'.$char.'" does not exist in account '.$acc.' or is removed.', 'warning'); return redirect()->route('get.profile',$acc); } - // json_encode($value [, $options, $depth]) + $chars = collect($chars); return view('profile', compact('acc', 'char', 'chars', 'dbAcc')); } - public function getProfileRanks($acc){ - + public function getProfileRanks($acc) + { $rankArchives = \App\LadderCharacter::with('account')->whereHas('account', function ($query) use (&$acc) { $query->where('name', '=', $acc); })->get(); - $dbAcc = \App\Account::with(['ladderChars', 'streamer'])->where('name', $acc)->first(); - return view('ranks', compact('acc', 'rankArchives', 'dbAcc')); } public function indexBuild() { - $acc = ''; - $char = ''; - - $dbAcc = '[]'; - $chars = null; - - return view('profile', compact('acc', 'char', 'chars', 'dbAcc')); + $build = null; + $loadBuild = "true"; + return view('profile', compact('acc', 'build', 'loadBuild')); } - public function showBuild($id, $name) + public function showBuild($hash) { - $build = \App\Build::where('id', '=', $id)->where('name', '=', $name)->first(); + $build = \App\Snapshot::where('hash', '=', $hash)->first(); + $loadBuild = "true"; + $acc = 'build::'.$hash; if ($build == null) { - flash("Wrong build Name")->warning()->important(); - return redirect()->route('index.builds'); + flash("404 Build snapshot ".$hash." Not Found")->warning()->important(); + return view('profile', compact('acc', 'build', 'loadBuild')); } - - $acc = 'build::'.$id; - $char = $build->name; - - $dbAcc = $build; - $chars = null; - - return view('profile', compact('acc', 'char', 'chars', 'dbAcc')); + // $char = ""; + // $dbAcc = $build; + return view('profile', compact('acc', 'build', 'loadBuild')); } } diff --git a/app/Http/Controllers/SkillTreeController.php b/app/Http/Controllers/SkillTreeController.php new file mode 100644 index 0000000..aaa7e10 --- /dev/null +++ b/app/Http/Controllers/SkillTreeController.php @@ -0,0 +1,36 @@ +middleware('auth'); + } + + public function showSkillTree(){ + return view('tree'); + } + + public function getPassiveSkills() + { + $b = explode('::', $_GET['accountName']); + if($b[0] == 'build'){ + $snapshot=\App\Snapshot::where('hash','=',$b[1])->first(); + return $snapshot->tree_data; + } + $dbAcc = \App\Account::where('name', $_GET['accountName'])->first(); + $acc=$dbAcc->name; + $char=$_GET['character']; + $responseThree = $this->getTreeCache($acc, $char); + return $responseThree; + } +} diff --git a/app/Parse_mods/Stats_Manager.php b/app/Parse_mods/Stats_Manager.php index b9f05aa..8bd8e03 100644 --- a/app/Parse_mods/Stats_Manager.php +++ b/app/Parse_mods/Stats_Manager.php @@ -1,81 +1,6 @@ stats = [ 'misc' => [ - new Totems, - new Rarity, - new Quantity, - new Skill_Effect_Duration, - new Projectile_Speed, - new Flask_Charges_Gained, - new Flask_Effect_Duration, - new Reduced_Flask_Charges, - new Effect_of_Curses, - new Reduced_Mana_Reserved, - new Effect_of_Auras, - new Physical_Attack_Life_Leech, - new Physical_Attack_Mana_Leech, - new Totem_Damage, - new Totem_Life, - new Totem_Placement_Speed, - new Totem_Duration, - new Totem_Physical_Reduction, - new Totem_Resistances, - new Endurance_Charges, - new Endurance_Charges_Duration, - new Power_Charges, - new Power_Charges_Duration, - new Frenzy_Charges, - new Frenzy_Charges_Duration, + new misc_stats\Totems, + new misc_stats\Rarity, + new misc_stats\Quantity, + new misc_stats\Skill_Effect_Duration, + new misc_stats\Projectile_Speed, + new misc_stats\Flask_Charges_Gained, + new misc_stats\Flask_Effect_Duration, + new misc_stats\Reduced_Flask_Charges, + new misc_stats\Effect_of_Curses, + new misc_stats\Reduced_Mana_Reserved, + new misc_stats\Effect_of_Auras, + new misc_stats\Physical_Attack_Life_Leech, + new misc_stats\Physical_Attack_Mana_Leech, + new misc_stats\Totem_Damage, + new misc_stats\Totem_Life, + new misc_stats\Totem_Placement_Speed, + new misc_stats\Totem_Duration, + new misc_stats\Totem_Physical_Reduction, + new misc_stats\Totem_Resistances, + new misc_stats\Endurance_Charges, + new misc_stats\Endurance_Charges_Duration, + new misc_stats\Power_Charges, + new misc_stats\Power_Charges_Duration, + new misc_stats\Frenzy_Charges, + new misc_stats\Frenzy_Charges_Duration, ], 'defense' => [ - new Resist_Fire, - new Resist_Cold, - new Resist_Lightning, - new Resist_Chaos, - new Armor, - new Percentage_Armor, - new Evasion, - new Percentage_Evasion, - new Life, - new Percentage_Life, - new Mana, - new Percentage_Mana, - new Energy_Shield, - new Percentage_ES, - new Strength, - new Intelligence, - new Dexterity, - new Block, - new Life_Regen, - new Mana_Regen_Rate, + new defense_stats\Resist_Cold, + new defense_stats\Resist_Cold, + new defense_stats\Resist_Lightning, + new defense_stats\Resist_Chaos, + new defense_stats\Armor, + new defense_stats\Percentage_Armor, + new defense_stats\Evasion, + new defense_stats\Percentage_Evasion, + new defense_stats\Life, + new defense_stats\Percentage_Life, + new defense_stats\Mana, + new defense_stats\Percentage_Mana, + new defense_stats\Energy_Shield, + new defense_stats\Percentage_ES, + new base_stats\Strength, + new base_stats\Intelligence, + new base_stats\Dexterity, + new defense_stats\Block, + new defense_stats\Life_Regen, + new defense_stats\Mana_Regen_Rate, + new defense_stats\Movement_Speed ], 'offense' => [ - new Attack_Speed, - new Cast_Speed, - new Wands_Damage, - new Physical_Damage, - new Melee_Phys_Damage, - new Attack_Critical_Chance, - new Spells_Critical_Chance, - new Radius_of_Area_Skills, - new Area_Damage, - new Attack_Critical_Multiplier, - new Spell_Critical_Multiplier, - new Spell_Damage, - new Elemental_Damage, - new Weapons_Elemental_Damage, - new Fire_Damage, - new Cold_Damage, - new Lightning_Damage, - new Chaos_Damage, - new Increased_Damage, - new Projectile_Damage, - new Accuracity, - new Accuracy_Rating, - new Damage_Over_Time, - new Movement_Speed + new offence_stats\Attack_Speed, + new offence_stats\Cast_Speed, + new offence_stats\Wands_Damage, + new offence_stats\Physical_Damage, + new offence_stats\Melee_Phys_Damage, + new offence_stats\Attack_Critical_Chance, + new offence_stats\Spells_Critical_Chance, + new offence_stats\Radius_of_Area_Skills, + new offence_stats\Area_Damage, + new offence_stats\Attack_Critical_Multiplier, + new offence_stats\Spell_Critical_Multiplier, + new offence_stats\Spell_Damage, + new offence_stats\Elemental_Damage, + new offence_stats\Weapons_Elemental_Damage, + new offence_stats\Fire_Damage, + new offence_stats\Cold_Damage, + new offence_stats\Lightning_Damage, + new offence_stats\Chaos_Damage, + new offence_stats\Increased_Damage, + new offence_stats\Projectile_Damage, + new offence_stats\Accuracity, + new offence_stats\Accuracy_Rating, + new offence_stats\Damage_Over_Time, ] ]; + + //items + $banItems = ['Flask', 'Weapon2', 'Offhand2']; + if (isset($_GET['offHand'])) { + $banItems = ['Flask', 'Weapon', 'Offhand']; + } + + $items = array_filter($items['items'], function ($item) use (&$banItems) { + return !in_array($item['inventoryId'], $banItems); + }); + + $this->addItems($items); + + //tree + $treeNodesJewels = new CharacterTreePoints; + $nodes = $treeNodesJewels->getPoints($treeData); + $this->addTreeNode($nodes); + + //base stats + $baseStat = new Base_Stats; + $baseStat = $baseStat->getStats($character['level'], $character['classId']); + foreach ($baseStat as $stat) { + $this->addBaseMods($stat); + } + } public function addItems($items) @@ -186,7 +137,7 @@ public function addItems($items) } $this->addAbyssJewels($item); } - + } public function addTreeNode($nodes) @@ -282,7 +233,7 @@ private function getTypeFromIcon($icon) } private function addAbyssJewels($item) - { + { //To Do get all Abyss jewels and creaate TYPE and count them LIKE "Belt Abyssal Socket 1" $countAbys = 0; if (array_key_exists('socketedItems', $item)) { diff --git a/app/Snapshot.php b/app/Snapshot.php new file mode 100644 index 0000000..d3a462b --- /dev/null +++ b/app/Snapshot.php @@ -0,0 +1,51 @@ +attributes['tree_data'] = $tree_data; + } + + public function getTreeDataAttribute($value) + { + // dd($value); + $tree_data = base64_decode($value); + $tree_data = gzuncompress($tree_data); + return json_decode($tree_data, true); + } + + // Item_Data Mutator & Accessor + public function setItemDataAttribute($value) + { + $item_data = gzcompress($value); + $item_data = base64_encode($item_data); + $this->attributes['item_data'] = $item_data; + } + + public function getItemDataAttribute($value) + { + $item_data = base64_decode($value); + $item_data = gzuncompress($item_data); + return json_decode($item_data, true); + } + + public function getStats() + { + // var_dump($this->item_data); + $stManager = new Stats_Manager($this->item_data,$this->tree_data); + return $stManager->getStats(); + } +} diff --git a/config/app.php b/config/app.php index 96000c8..1bac744 100644 --- a/config/app.php +++ b/config/app.php @@ -2,6 +2,12 @@ return [ + /* + | This is seting Caching time in minutes for PoE API + */ + 'poe_cache_time' => env('POE_CACHE_TIME', 4), + + 'poe_leagues' => env('POE_LEAGUES', 'Standard,Hardcore'), /* |-------------------------------------------------------------------------- | Application Name diff --git a/database/migrations/2018_02_25_154245_create_builds_table.php b/database/migrations/2018_02_25_154245_create_builds_table.php index 547ce0e..0ccb6b6 100644 --- a/database/migrations/2018_02_25_154245_create_builds_table.php +++ b/database/migrations/2018_02_25_154245_create_builds_table.php @@ -13,16 +13,23 @@ class CreateBuildsTable extends Migration */ public function up() { - Schema::create('builds', function (Blueprint $table) { + Schema::create('snapshots', function (Blueprint $table) { $table->increments('id'); - $table->string('name'); + $table->string('hash')->unique(); $table->text('tree_data'); $table->text('item_data'); - $table->text('stats')->nullable(); $table->string('poe_version'); + $table->string('original_char')->nullable(); + $table->string('original_level')->nullable(); $table->dateTime('last_visit')->nullable(); $table->timestamps(); }); + + Schema::table('snapshots', function($table) { + $table->index('hash'); + $table->index('original_char'); + }); + } /** @@ -32,6 +39,6 @@ public function up() */ public function down() { - Schema::dropIfExists('saved_builds'); + Schema::dropIfExists('snapshots'); } } diff --git a/resources/assets/js/components/home/ListCharacters.vue b/resources/assets/js/components/home/ListCharacters.vue index 2a96e93..31a2082 100644 --- a/resources/assets/js/components/home/ListCharacters.vue +++ b/resources/assets/js/components/home/ListCharacters.vue @@ -8,7 +8,7 @@ - +
diff --git a/resources/assets/js/components/profile/ListCharacters.vue b/resources/assets/js/components/profile/ListCharacters.vue index a52f74f..c497c99 100644 --- a/resources/assets/js/components/profile/ListCharacters.vue +++ b/resources/assets/js/components/profile/ListCharacters.vue @@ -157,7 +157,7 @@ export default { }, characterUrl: function(char){ if (this.isBuild) { - return (new poeHelpers).getBaseDomain() + '/builds/' + char.buildId + '/' + char.name; + return (new poeHelpers).getBaseDomain() + '/build/' + char.buildId + '/'; } return (new poeHelpers).getBaseDomain() + '/profile/' + window.PHP.account + '/' + char.name; }, diff --git a/resources/assets/js/components/profile/ListSkills.vue b/resources/assets/js/components/profile/ListSkills.vue index 26c587e..6978d09 100644 --- a/resources/assets/js/components/profile/ListSkills.vue +++ b/resources/assets/js/components/profile/ListSkills.vue @@ -115,12 +115,16 @@ export default { } }, - // mounted: function (){ - // this.getSkillImages(); - // }, + mounted: function (){ + console.log("watch items in list skils"); + if(this.items.length>0){ + this.getSkillImages(); + } + }, watch: { 'items': function (val, oldVal) { + console.log("watch items in list skils"); this.getSkillImages(); } }, diff --git a/resources/assets/js/components/profile/ModalSnapshots.vue b/resources/assets/js/components/profile/ModalSnapshots.vue new file mode 100644 index 0000000..aa4751f --- /dev/null +++ b/resources/assets/js/components/profile/ModalSnapshots.vue @@ -0,0 +1,142 @@ + + + + + diff --git a/resources/assets/js/components/profile/PobCode.vue b/resources/assets/js/components/profile/PobCode.vue new file mode 100644 index 0000000..ced2817 --- /dev/null +++ b/resources/assets/js/components/profile/PobCode.vue @@ -0,0 +1,101 @@ + + + + diff --git a/resources/assets/js/components/profile/ProfileNavigation.vue b/resources/assets/js/components/profile/ProfileNavigation.vue index b83ed72..d1ae32e 100644 --- a/resources/assets/js/components/profile/ProfileNavigation.vue +++ b/resources/assets/js/components/profile/ProfileNavigation.vue @@ -1,134 +1,118 @@ @@ -147,40 +131,32 @@ export default { required: true, default: '', }, - character: { type: String, required: true, default: '', }, - - build: { - type: Boolean, + selectedTab: { + type: String, required: true, - default: false, }, - twitch: { type: Object, required: false, default: null, }, - - ranks: { - type: Boolean, - default: false, - }, }, components: { - // 'item': Item, + // 'item': Item, }, data: function() { return { buildLink: window.location.href, buildName: '', - stream: '', + stream: {}, + saving: false, favStore: favStore, profileStore: profileStore, isModalVisible: false, @@ -197,7 +173,20 @@ export default { }, watch: {}, - + mounted: function () { + $('.po-save-build-link').popover({ + trigger: 'click', + html: true, + title: "SaveBuild", + content: this.$refs['popover'], + container: 'body', + placement: 'bottom' + }); + this.$nextTick(function () { + $('.show-tooltip').tooltip(); + }) + new Clipboard('.clipboard'); + }, methods: { toggleFavAcc: function (acc) { @@ -217,43 +206,43 @@ export default { }, isTwitchOnline: function (){ - return this.twitch.streamer.online; + return this.twitch.online; }, playTwitch: function(){ - this.stream = this.twitch.streamer; + this.stream = this.twitch; this.isModalVisible=true; }, - + closeModal: function() { this.stream = null; this.isModalVisible = false; }, saveBuild: function () { - if(this.favStore.isBuildPublic(this.account)){ - var build = this.character; - build.name = this.buildName; - this.favStore.addBuild(build); - this.redirectBuild(build); - } - var vm = this; + this.saving=true; var formData = new FormData(); - formData.append('account', vm.account); - formData.append('char', vm.character); - formData.append('name', vm.buildName); - axios.post('/api/saveBuild', formData).then((response) => { + formData.append('account', this.account); + formData.append('char', this.character); + axios.post('/api/build/save', formData).then((response) => { // save to favStore Build comming from this response - this.favStore.addBuild(response.data); + var build=response.data; + this.saving=false; + build.name = this.buildName; + this.favStore.addBuild(build); this.redirectBuild(response.data); }); }, - redirectBuild: function(build) { - location.replace((new poeHelpers).getBaseDomain() + '/builds/' + build.buildId + '/' + build.name); + removeBuild: function(hash){ + + }, + + redirectBuild: function(build) { + location.replace((new poeHelpers).getBaseDomain() + '/build/' + build.buildId); } } }; - \ No newline at end of file + diff --git a/resources/assets/js/helpers/FavStore.js b/resources/assets/js/helpers/FavStore.js index 4ad008a..dcbc2c0 100644 --- a/resources/assets/js/helpers/FavStore.js +++ b/resources/assets/js/helpers/FavStore.js @@ -2,7 +2,7 @@ module.exports = { favAcc: JSON.parse(localStorage.getItem('favAcc')) ? JSON.parse(localStorage.getItem('favAcc')) : [], favBuilds: JSON.parse(localStorage.getItem('favBuilds')) ? JSON.parse(localStorage.getItem('favBuilds')) : [], favStats: JSON.parse(localStorage.getItem('favStats')) ? JSON.parse(localStorage.getItem('favStats')) : [], - + addStat (stat) { this.favStats.push(stat) this.save('favStats',this.favStats); @@ -54,6 +54,16 @@ module.exports = { this.save('favBuilds', this.favBuilds); }, + getBuild(hash){ + var res=null; + for (var i = 0; i < this.favBuilds.length; i++) { + if (this.favBuilds[i].buildId === hash) { + res=this.favBuilds[i]; + } + } + return res; + }, + removeBuild(name) { for (var i = 0; i < this.favBuilds.length; i++) { if (this.favBuilds[i] === name) { @@ -68,7 +78,7 @@ module.exports = { return false } var acc = account.split('::'); - if (_.find(this.favBuilds, { "buildId": parseInt(acc[1])})) { + if (_.find(this.favBuilds, { "buildId": acc[1]})) { return false } return true; diff --git a/resources/assets/js/profile.js b/resources/assets/js/profile.js index 540bae9..ab15395 100644 --- a/resources/assets/js/profile.js +++ b/resources/assets/js/profile.js @@ -8,13 +8,14 @@ Vue.component('list-characters', require('./components/profile/ListCharacters.vu Vue.component('list-characters-rank', require('./components/home/ListCharacters.vue')); Vue.component('profile-nav', require('./components/profile/ProfileNavigation.vue')); - Vue.component('character-stats', require('./components/profile/CharacterStats.vue')); Vue.component('list-skills', require('./components/profile/ListSkills.vue')); Vue.component('item-info', require('./components/profile/ItemInfo.vue')); Vue.component('loader', require('./components/Loader.vue')); Vue.component('bubble', require('./components/profile/Bubble.vue')); Vue.component('bandits', require('./components/profile/Bandits.vue')); +Vue.component('pob-code', require('./components/profile/PobCode.vue')); + Vue.component('modal-twitch', require('./components/home/ModalTwitch.vue')); Vue.component('drop-down', require('./components/home/DropDown.vue')); @@ -70,16 +71,10 @@ new Vue({ skillTreeUrl: '', showOffHand: false, skillTreeReseted: false, - pobXml: '', - stream: null, - pobText: 'Copy PoB Code', rankArchives: window.PHP.rankArchives, }, - created: function () { - this.setAccountData(); - this.getCharacterItems(); - }, + mounted: function () { $('.po-bandits-link').popover({ @@ -90,15 +85,6 @@ new Vue({ container: 'body', placement: 'top' }); - - $('.po-pob-link').popover({ - trigger: 'click', - html: true, - title: $('.po-title').html(), - content: $('#popper-content-pob'), - container: 'body', - placement: 'bottom' - }); }, computed: { @@ -244,8 +230,62 @@ new Vue({ } }, + created: function () { + if(window.PHP.loadBuild){ + this.setupBuild(); + return; + } + this.setAccountData(); + this.getCharacterItems(); + }, + methods: { + // build initialization + setupBuild:function(){ + this.account = window.PHP.account; + this.isBuild = true; + this.accountCharacters = this.favStore.favBuilds; + + if(this.account==""){ + var build = _.last(this.favStore.favBuilds); + location.replace((new poeHelpers).getBaseDomain() + '/build/' + build.buildId); + } + + var build = window.PHP.build; + //if build null snapshot removed from db + if(build==null){ + this.character = this.favStore.getBuild(this.account.split('::')[1]); + return; + } + + if (this.favStore.isBuildPublic(this.account)){ + this.accountCharacters = []; + this.character = build.item_data.character; + }else{ + this.character = this.favStore.getBuild(build.hash); + } + this.items = build.item_data.items; + }, + + setAccountData: function () { + this.account = window.PHP.account; + + + if (window.PHP.chars === null) { + } else { + this.accountCharacters = window.PHP.chars; + } + + if (window.PHP.char === '') { + this.character = this.accountCharacters[0]; + return; + } + this.character = this.accountCharacters.filter(function(chars){ + return chars.name === window.PHP.char; + })[0]; + }, + checkBuilds: function(){ return this.accountCharacters.length > 0 || this.favStore.isBuildPublic(this.account); }, @@ -392,33 +432,6 @@ new Vue({ })[0].name; }, - setAccountData: function () { - this.account = window.PHP.account; - - // build initialization - if (window.PHP.chars === null) { - this.isBuild = true; - this.accountCharacters = this.favStore.favBuilds; - if (this.favStore.isBuildPublic(this.account)){ - this.accountCharacters = []; - this.character = this.dbAcc.item_data.character; - this.character.buildId = this.account.split('::')[1]; - this.character.name = window.PHP.char; - return - } - } else { - this.accountCharacters = window.PHP.chars; - } - - if (window.PHP.char === '') { - this.character = this.accountCharacters[0]; - return; - } - this.character = this.accountCharacters.filter(function(chars){ - return chars.name === window.PHP.char; - })[0]; - }, - navMoreInfo: function (event) { switch (event.target.getAttribute("data-toggle")) { case 'more-info': @@ -448,6 +461,7 @@ new Vue({ self.setTreeUrl(); return; }else{ + console.log("testSkill-tree"); this.getTreeData(function(response){ self.treeData=response.data; self.setTreeUrl(); @@ -480,52 +494,16 @@ new Vue({ }, getCharacterItems: function () { - if (this.isBuild) { - if (this.account === '') { - this.defaultBuild() - } else { - this.items = this.dbAcc.item_data.items; - } - return; - } - var vm = this; + //start loading bar for items and stats this.loadingItems=true; var formData = new FormData(); - formData.append('account', vm.account); - formData.append('character', vm.character.name); - //start loading bar for items and stats - + formData.append('account', this.account); + formData.append('character', this.character.name); axios.post('/api/char/items', formData).then((response) => { - vm.items = response.data; + this.items = response.data; this.loadingItems=false; }); }, - defaultBuild: function() { - var firstBuild = this.favStore.favBuilds[0]; - - var vm = this; - var formData = new FormData(); - formData.append('id', firstBuild.buildId); - formData.append('name', firstBuild.name); - - axios.post('/api/builds/default', formData).then((response) => { - vm.dbAcc = response.data; - vm.items = this.dbAcc.item_data.items - vm.account = 'build::' + response.data.id - }); - }, - - getPoBCode: function() { - this.showPoB=true; - var vm = this; - var formData = new FormData(); - formData.append('account', vm.account); - formData.append('char', vm.character.name); - axios.post('/api/getPoBCode', formData).then((response) => { - this.pobXml = response.data; - }); - }, - } }); diff --git a/resources/views/layouts/profile.blade.php b/resources/views/layouts/profile.blade.php index 41b7982..25a225c 100644 --- a/resources/views/layouts/profile.blade.php +++ b/resources/views/layouts/profile.blade.php @@ -3,7 +3,7 @@ - + @yield('title', 'PoE Profile Info') @@ -58,13 +58,13 @@