(function(){ "use strict"; // some PureScript librarys, imported locally. let ExpedInfo = PS["KanColle.Expedition.New.Info"]; let ExpedSType = PS["KanColle.Expedition.New.SType"]; let ExpedCostModel = PS["KanColle.Expedition.New.CostModel"]; let Maybe = PS["Data.Maybe"]; let PartialUnsafe = PS["Partial.Unsafe"]; let fromJust = PartialUnsafe.unsafePartial(Maybe.fromJust); function enumFromTo(from,to,step=1) { var arr = []; for (let i=from; i<=to; i+=step) arr.push(i); return arr; } let allExpedIds = Expedition.allExpedIds; let modifierToNumber = Expedition.modifierToNumber; let computeActualCost = Expedition.computeActualCost; let eqConfig = Expedition.eqConfig; let loadExpedConfig = Expedition.loadExpedConfig; let saveExpedConfig = Expedition.saveExpedConfig; function prettyFloat(n,precision=2,positiveSign=false) { let fixed = n.toFixed(precision); let str = String(n); // we want "0" to be "+0" let pre = (positiveSign && n >= 0) ? "+" : ""; return pre + ((str.length <= fixed.length) ? str : fixed); } function saturate(v,min,max) { return Math.max(Math.min(v,max),min); } function generateCostGrouping() { let allExpeds = allExpedIds.map( function(x) { let info = ExpedInfo.getInformation(x); return { ammo: Math.round( info.ammoCostPercent * 100), ammoP: info.ammoCostPercent, fuel: Math.round( info.fuelCostPercent * 100), fuelP: info.fuelCostPercent, id: x }; }); allExpeds.sort( function(a,b) { // key 1: group by total consumption let aTotal = a.ammo + a.fuel; let bTotal = b.ammo + b.fuel; if (aTotal != bTotal) return aTotal - bTotal; // key 2: group by either (begin with fuel because all expeds // is sure to spend some) if (a.fuel != b.fuel) return a.fuel - b.fuel; if (a.ammo != b.ammo) return a.ammo - b.ammo; // finally tie break by exped id return a.id - b.id; }); let currentGrp = false; let grouped = []; function eq(a,b) { return (a.fuel == b.fuel) && (a.ammo == b.ammo); } while (allExpeds.length > 0) { let curExped = allExpeds.shift(); if (currentGrp === false) { currentGrp = [curExped]; } else if (eq(currentGrp[0], curExped)) { currentGrp.push( curExped ); } else { grouped.push( currentGrp ); currentGrp = [curExped]; } } if (currentGrp !== false) { grouped.push( currentGrp ); currentGrp = false; } grouped = grouped.map( function(x) { return { ammo: x[0].ammo, fuel: x[0].fuel, expeds: x.map( y => y.id ) }; }); grouped.sort( function(a,b) { if (b.expeds.length !== a.expeds.length) return b.expeds.length- a.expeds.length; let aTotal = a.ammo + a.fuel; let bTotal = b.ammo + b.fuel; return bTotal - aTotal; }); console.log(JSON.stringify(grouped)); } // generated from generateCostGrouping() let expedCostGrouping = [ {ammo:0,fuel:50,expeds:[2,4,5,7,9,11,12,14,31]}, {ammo:80,fuel:80,expeds:[23,26,27,28,35,36,37,38]}, {ammo:40,fuel:50,expeds:[13,15,16,19,20]}, {ammo:70,fuel:80,expeds:[21,22,40]}, {ammo:80,fuel:50,expeds:[25,33,34]}, {ammo:20,fuel:50,expeds:[8,18]},{ammo:20,fuel:30,expeds:[3,6]}, {ammo:0,fuel:30,expeds:[1,10]},{ammo:90,fuel:90,expeds:[39]}, {ammo:70,fuel:90,expeds:[30]},{ammo:60,fuel:90,expeds:[24]}, {ammo:40,fuel:90,expeds:[29]},{ammo:30,fuel:90,expeds:[32]}, {ammo:40,fuel:30,expeds:[17]}]; KC3StrategyTabs.expedtable = new KC3StrategyTab("expedtable"); KC3StrategyTabs.expedtable.definition = { tabSelf: KC3StrategyTabs.expedtable, /* INIT: mandatory Prepares initial static data needed. ---------------------------------*/ init: function() { }, /* RELOAD: optional Loads latest player or game data if needed. ---------------------------------*/ reload: function() { }, setupCostModelSection: function() { let contentRoot = $(".tab_expedtable #cost_model_content_root"); let tableRoot = $("table", contentRoot); let jqPreset = $("select.cost_preset", contentRoot); let presetFlag = false; let calcCostModel = (stypeInstance, num) => ExpedCostModel.normalCostModel(stypeInstance)(num); // setup slider controls let sliderSettings = { ticks: enumFromTo(0,100,10), step: 10, // default of both fuel and ammo are 80% value: 80, tooltip: "hide" }; let viewFuelPercent = $(".control_row.fuel .val"); let viewAmmoPercent = $(".control_row.ammo .val"); let tableBody = $("tbody",tableRoot); function updateCostModelTable( which, newValue ){ console.assert( which === "fuel" || which === "ammo" ); ( which === "fuel" ? viewFuelPercent : which === "ammo" ? viewAmmoPercent : undefined ).text( newValue + "%" ); let actualPercent = (newValue + 0.0) / 100.0; $(".cost_cell", tableBody).each( function() { let jq = $(this); let maxCostArr = jq.data("max-cost-arr"); let actualCost = maxCostArr .map( x => Math.floor( x[which] * actualPercent ) ) .reduce( (x,y) => x+y, 0); $("." + which, this).text( actualCost ); }); } let sliderFuel = $("input#cost_model_fuel") .slider(sliderSettings) .on("change", function(e) { updateCostModelTable( "fuel", e.value.newValue ); if (!presetFlag) jqPreset.val("title"); }); let sliderAmmo = $("input#cost_model_ammo") .slider(sliderSettings) .on("change", function(e) { updateCostModelTable( "ammo", e.value.newValue ); if (!presetFlag) jqPreset.val("title"); }); // setup table let stypeTexts = [ "DD", "CL", "CVLike", "SSLike", "CA", "BBV", "AS", "CT", "AV"]; stypeTexts.map( function(stype) { let tblRow = $(""); let stypeHead = $(""); if (stype === "CVLike") { stypeHead .text("CV(*)") .attr("title", "CV / CVL / AV / CVB"); } else if (stype === "SSLike") { stypeHead .text( "SS(*)" ) .attr("title", "SS / SSV"); } else { stypeHead.text( stype ); } tblRow.append( stypeHead ); for (let i=1; i<=6; ++i) { let stypeInst = ExpedSType[stype].value; let costResult = calcCostModel(stypeInst, i); let cell; if (Maybe.isJust( costResult )) { cell = $(".tab_expedtable .factory .cost_cell").clone(); let costArr = fromJust(costResult); cell.data( "max-cost-arr", costArr ); } else { cell = $(".tab_expedtable .factory .cost_cell_na").clone(); } tblRow.append( $("").append(cell) ); } tableBody.append( tblRow ); }); // sync controls with default value updateCostModelTable("fuel", sliderFuel.slider("getValue")); updateCostModelTable("ammo", sliderAmmo.slider("getValue")); expedCostGrouping.map( function(x,i) { let desc = "" + x.fuel + "% Fuel, " + x.ammo + "% Ammo,"; desc += " " + (x.expeds.length > 1 ? "Expeditions" : "Expedition")+ ": " + x.expeds.join(","); jqPreset.append( $("