From 2ecc9a72e9e932f1bf0431f391814837d8694884 Mon Sep 17 00:00:00 2001 From: piernov Date: Sun, 8 May 2016 14:40:02 +0200 Subject: Create updatePerso() JS function --- js/craftmine.js | 7 +------ js/perso.js | 7 +++++++ 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'js') diff --git a/js/craftmine.js b/js/craftmine.js index 347ce65..77cafee 100644 --- a/js/craftmine.js +++ b/js/craftmine.js @@ -56,12 +56,7 @@ function initCraftMine() { console.log(ret.perso); data.gold = parseInt(ret.gold); // Server's response is a string data.mine = 0; // Reset mine - if(ret.perso){ - data.hp = ret.perso.hp; - data.xp = ret.perso.xp; - data.level = ret.perso.lv; - displayPerso(ret.perso.hp,ret.perso.xp,ret.perso.lv); - } + if(ret.perso) updatePerso(ret.perso); if(ret.shop) displayShop(ret.shop); if(ret.inventory) displayInventory(ret.inventory); if(ret.dungeon == false){}//if we have left the donjon diff --git a/js/perso.js b/js/perso.js index 365cf54..02a8892 100644 --- a/js/perso.js +++ b/js/perso.js @@ -3,3 +3,10 @@ function displayPerso(hp,xp,lv){ document.getElementById("lv").innerHTML = lv; document.getElementById("xp").innerHTML = xp; } + +function updatePerso(perso) { + data.hp = perso.hp; + data.xp = perso.xp; + data.level = perso.lv; + displayPerso(perso.hp, perso.xp, perso.lv); +} -- cgit v1.2.3-70-g09d2