(function(){ "use strict"; KC3StrategyTabs.shipquests = new KC3StrategyTab("shipquests"); KC3StrategyTabs.shipquests.definition = { tabSelf: KC3StrategyTabs.shipquests, shipCache:[], shipQuests:[], /* INIT Prepares all data needed ---------------------------------*/ init :function(){ var questsData = $.ajax('../../data/ship_quests.json', { async: false }).responseText; this.shipQuests = JSON.parse(questsData); }, /* RELOAD Prepares latest ships data ---------------------------------*/ reload :function(){ // Cache ship info KC3ShipManager.load(); KC3QuestManager.load(); this.shipCache = []; var ctr, ThisShip, ThisShipData; for(ctr in KC3ShipManager.list){ ThisShip = KC3ShipManager.list[ctr]; ThisShipData = this.prepareShipData(ThisShip); this.shipCache.push(ThisShipData); } }, getShipQuests: function(shipId) { var entry = this.shipQuests[shipId]; return entry ? entry : []; }, // Prepares necessary info prepareShipData: function(ship) { var ThisShip = ship; var MasterShip = ThisShip.master(); var Quests = this.getShipQuests(MasterShip.kc3_bship); var cached = { id: ThisShip.rosterId, bid: ThisShip.masterId, stype: MasterShip.api_stype, english: ThisShip.name(), level: ThisShip.level, quests: Quests, }; return cached; }, /* EXECUTE ---------------------------------*/ execute :function(){ var self = this; this.shipList = $(".tab_shipquests .ship_list"); this.showPage(); }, /* SHOW PAGE ---------------------------------*/ showPage :function(){ var self = this; this.startTime = Date.now(); // Clear list this.shipList.html("").hide(); // Wait until execute setTimeout(function(){ var shipCtr, cElm, qElm, cShip, shipLevel, questCtr; Object.keys(self.shipCache).forEach(function(shipCtr){ cShip = self.shipCache[shipCtr]; shipLevel = cShip.level; cElm = $(".tab_shipquests .factory .ship_item").clone().appendTo(self.shipList); $(".ship_id", cElm).text( cShip.id ); $(".ship_img .ship_icon", cElm).attr("src", KC3Meta.shipIcon(cShip.bid)); $(".ship_img .ship_icon", cElm).attr("alt", cShip.bid); $(".ship_img .ship_icon", this).click(self.shipClickFunc); $(".ship_name", cElm).text( cShip.english ); if(shipLevel >= 100) { $(".ship_name", cElm).addClass("ship_kekkon-color"); } $(".ship_type", cElm).text( KC3Meta.stype(cShip.stype) ); var shipLevelConv = shipLevel; $(".ship_lv", cElm).html( "Lv." + shipLevelConv); Object.keys(cShip.quests).forEach(function(questCtr){ var quest_id = cShip.quests[questCtr]; var thisQuest = KC3Meta.quest(quest_id); var status = ""; if(KC3QuestManager.exists(quest_id)){ var questRecord = KC3QuestManager.get(quest_id); switch (questRecord.status){ case 2: status = " progress"; break; case 3: status = " ticked"; break; default: status = ""; break; } } var divTag = $("
").addClass("ship_field"); divTag.addClass("ship_stat_mod"); divTag.addClass("questIcon"); divTag.addClass("type"+(String(quest_id).substring(0,1))); divTag.addClass(status); divTag.attr("title", thisQuest.desc); divTag.text(thisQuest.code); $(".ship_quests", cElm).append(divTag); }); }); self.shipList.show(); console.log("Showing this list took", (Date.now() - self.startTime)-100 , "milliseconds"); },100); }, shipClickFunc: function(e){ KC3StrategyTabs.gotoTab("mstship", $(this).attr("alt")); }, }; })();