diff --git a/_assets/js/app.js b/_assets/js/app.js index 1cf1147..dc51c9c 100644 --- a/_assets/js/app.js +++ b/_assets/js/app.js @@ -1,14 +1,14 @@ -var DEBUG_APP = false; +var DEBUG_APP = true; $('#dataform').on('submit', function (e) { e.preventDefault(); - var inputContent = $.trim( $('#data').val() ); + var inputContent = $.trim($('#data').val()); if (inputContent.length > 0) { - var warData = JSON.parse( inputContent ); - if (initApp(warData, 'withSave', warData) != false){ + var warData = JSON.parse(inputContent); + if (initApp(warData, 'withSave', warData) != false) { $('#data').val(''); } } @@ -16,43 +16,43 @@ $('#dataform').on('submit', function (e) { $('#fileUpload').on('change', function () { var fileUploader = document.getElementById("fileUpload"); - if ( fileUploader.files.length > 0 ) { - getFileContents( fileUploader.files[0] ); + if (fileUploader.files.length > 0) { + getFileContents(fileUploader.files[0]); } }); -function initApp (data, callback, callbackData) { - if( data.results && data.results.length == 3 ){ +function initApp(data, callback, callbackData) { + if (data.results && data.results.length == 3) { var reWriteMapData = JSON.parse(JSON.stringify(data)); reWriteMapData.results[1].ident = reWriteMapData.results[1].ident.replace(/group_\d+_/g, ""); reWriteMapData.results[2].ident = reWriteMapData.results[2].ident.replace(/group_\d+_/g, ""); reWriteMapData.results.shift(); - callbackData = data = JSON.parse(JSON.stringify(reWriteMapData)) ; + callbackData = data = JSON.parse(JSON.stringify(reWriteMapData)); delete reWriteMapData; if (DEBUG_APP) console.log(data); } - if( !data.results || data.results.length !=2 || - !data.results[0] || - data.results[0].ident != "body" || - !data.results[1] || - data.results[1].ident != "clanWarGetInfo" || - !data.results[1].result || - !data.results[1].result.response ) { - alert("Please recreate the JSON, switch to the main screen, and switch back to GuildWars. Then copy the JSON!"); + if (!data.results || data.results.length != 2 || + !data.results[0] || + data.results[0].ident != "body" || + !data.results[1] || + data.results[1].ident != "clanWarGetInfo" || + !data.results[1].result || + !data.results[1].result.response) { + alert("Please recreate the JSON, switch to the main screen, and switch back to GuildWars. Then copy the JSON!"); return false; } if (DEBUG_APP) console.log(data) var mapData = data.results[1].result.response; - if (DEBUG_APP) console.log('data', JSON.parse( JSON.stringify(data)) ); + if (DEBUG_APP) console.log('data', JSON.parse(JSON.stringify(data))); enhanceMap(mapData.enemySlots); enhanceMap(mapData.ourSlots); app.map = mapData; - app.map.warDate = data.date; + app.map.warDate = data.warDate; - if (DEBUG_APP) console.log('app.map', JSON.parse( JSON.stringify(mapData)) ); + if (DEBUG_APP) console.log('app.map', JSON.parse(JSON.stringify(mapData))); Vue.nextTick(function () { // Determine which player team has more power: titans or heroes @@ -65,45 +65,91 @@ function initApp (data, callback, callbackData) { // Highlights the other player team when the other one is hovered highlightHovered(); - if(callback == 'withSave') { + if (callback == 'withSave') { saveToStorage(callbackData); } }); } -var app = new Vue({ - el : '#app', - data : { - map: {}, //mapData, the data obtained from the game - mapSlots: mapSlots, // maps building names and types of data obtained from the game - storage: JSON.parse( localStorage.getItem('HeroWarsHistory') ) || [] - }, - computed: { - // Helps render enemy teams in order by power level - orderedEnemies: function () { - return orderByPower(this.map.enemySlots); - }, - // Helps render allied teams in order by power level - orderedAllies: function () { - return orderByPower(this.map.ourSlots); - }, - // Renders total team powers: hero, titan, total - getAllyPower: function () { - return getTotalPower(this.map.ourSlots); - }, - // Renders total enemy team powers: hero, titan, total - getEnemyPower: function () { - return getTotalPower(this.map.enemySlots); - } - }, - filters: { - formatNumber: function (value) { - return value.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,'); - }, - unixToLocale: function (value) { - return new Date(value * 1000).toDateString(); - } - } -}); +function initApp2(data) { + var mapData = data; + if (DEBUG_APP) console.log('data', JSON.parse(JSON.stringify(data))); + enhanceMap(mapData.enemySlots); + enhanceMap(mapData.ourSlots); + app.map = mapData; + app.map.warDate = data.warDate; + + if (DEBUG_APP) console.log('app.map', JSON.parse(JSON.stringify(mapData))); + + Vue.nextTick(function () { + // Determine which player team has more power: titans or heroes + determineBestTeam('ally'); + determineBestTeam('enemy'); + + // Syncs checkboxes between hero/titan teams + syncCheckboxes(); + + // Highlights the other player team when the other one is hovered + highlightHovered(); + }); +} + +var app = {}; +var jsondata = []; + +if (DEBUG_APP) { + Vue.config.devtools = true; +} +console.log("hello"); +$.getJSON('/hwtools/data/clanWarGetInfo.json', function (data) { + console.log("hello 222222222"); + jsondata = data + jsondata = jsondata.filter(function (el) { + return !!(el.enemyClan && el.enemyClan.title); + }); + mapData = jsondata[0]; + enhanceMap(mapData.enemySlots); + enhanceMap(mapData.ourSlots); + + console.log(jsondata[0]); + app = new Vue({ + el: '#app', + data: { + map: mapData, //mapData, the data obtained from the game + mapSlots: mapSlots, // maps building names and types of data obtained from the game + storage: jsondata || [] + }, + computed: { + // Helps render enemy teams in order by power level + orderedEnemies: function () { + return orderByPower(this.map.enemySlots); + }, + // Helps render allied teams in order by power level + orderedAllies: function () { + return orderByPower(this.map.ourSlots); + }, + // Renders total team powers: hero, titan, total + getAllyPower: function () { + return getTotalPower(this.map.ourSlots); + }, + // Renders total enemy team powers: hero, titan, total + getEnemyPower: function () { + return getTotalPower(this.map.enemySlots); + } + }, + filters: { + formatNumber: function (value) { + return value.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,'); + }, + unixToLocale: function (value) { + return new Date(value * 1000).toDateString(); + } + } + }); +}) +.fail(function( jqxhr, textStatus, error ) { + var err = textStatus + ", " + error; + console.log( "Request Failed: " + err ); +}) \ No newline at end of file diff --git a/_assets/js/localstorage.js b/_assets/js/localstorage.js index 760c6a4..4638eb2 100644 --- a/_assets/js/localstorage.js +++ b/_assets/js/localstorage.js @@ -16,30 +16,35 @@ function compareDates(a, b) { function saveToStorage(warData) { - var storageData = JSON.parse( localStorage.getItem('HeroWarsHistory') ) || []; + //var storageData = JSON.parse( localStorage.getItem('HeroWarsHistory') ) || []; + var storageData = JSON.parse(jsondata) || []; storageData.push(warData); storageData.sort(compareDates); - localStorage.setItem('HeroWarsHistory', JSON.stringify(storageData) ); + localStorage.setItem('HeroWarsHistory', JSON.stringify(storageData)); app.storage = storageData; }; -$('body').on('click', '.js--load-war', function(){ +$('body').on('click', '.js--load-war', function () { var $t = $(this), - index = $t.attr('data-item'), - localData = JSON.parse( localStorage.getItem('HeroWarsHistory') ), - localWar = localData[index]; + index = $t.attr('data-item'), + //localData = JSON.parse( localStorage.getItem('HeroWarsHistory') ), + //localData = JSON.parse(jsondata), + //localWar = localData[index]; + localWar = jsondata[index]; - initApp(localWar); + initApp2(localWar); toggleHamburger(); }); -$('body').on('click', '.js--remove-storage', function (){ - var storageData = JSON.parse( localStorage.getItem('HeroWarsHistory') ) || []; +$('body').on('click', '.js--remove-storage', function () { + // var storageData = JSON.parse( localStorage.getItem('HeroWarsHistory') ) || []; + //var storageData = JSON.parse(jsondata) || []; + var storageData = jsondata || []; var index = $(this).attr('data-item'); storageData.splice(index, 1); - localStorage.setItem('HeroWarsHistory', JSON.stringify(storageData) ); + localStorage.setItem('HeroWarsHistory', JSON.stringify(storageData)); app.storage = storageData; }); \ No newline at end of file diff --git a/_config.dev.yml b/_config.dev.yml index 7f99228..4f67746 100644 --- a/_config.dev.yml +++ b/_config.dev.yml @@ -9,7 +9,7 @@ meta_image: '' # Global fallback for meta image is_production: false # Root folder is always "/" regardless of production build settings. -baseurl: "/" +baseurl: "/hwtools/" url: "http://localhost:3000" hostname: "localhost" diff --git a/_config.yml b/_config.yml index 12f2548..dd7b318 100644 --- a/_config.yml +++ b/_config.yml @@ -5,8 +5,8 @@ meta_description: '' # Global fallback meta description meta_image: '' # Global fallback for meta image # Build settings -baseurl: "/" # The subfolder where the site will live, no trailing slash. Ex: "investors/reports/2019" -url: "https://hw.deineagentur.biz" # The base url, no trailing slash. Ex: "https://www.example.com" +baseurl: "/hwtools/" # The subfolder where the site will live, no trailing slash. Ex: "investors/reports/2019" +url: "https://hwcollector.derhost.com" # The base url, no trailing slash. Ex: "https://www.example.com" hostname: "localhost" is_production: true # Leave unchanged. Used for production build. diff --git a/_includes/header.html b/_includes/header.html index 9b30c0d..982994c 100644 --- a/_includes/header.html +++ b/_includes/header.html @@ -5,7 +5,7 @@ Load War -
+ diff --git a/_layouts/war-planner.html b/_layouts/war-planner.html index 488ae12..4bfa1ea 100644 --- a/_layouts/war-planner.html +++ b/_layouts/war-planner.html @@ -7,15 +7,17 @@ layout: default

- {{ map.ourSlots[1].user.clanTitle }} VS. {{ map.enemyClan.title }} + {{ map.ourSlots[1].user.clanTitle }} VS. {{ map.enemyClan.title || "unknown" }} {{ map.warDate | unixToLocale }}

@@ -26,8 +28,8 @@ layout: default v-if="ally.location.type == 'Hero' && ally.user.name != 'Empty'" v-for="ally in orderedAllies"> - - + +
{{ ally.location.name }} {{ ally.user.name }} - {{ ally.power | formatNumber }} @@ -40,8 +42,8 @@ layout: default