functionality for unlocks, filtering and percentages

This commit is contained in:
Bart van der Braak 2019-04-24 23:48:31 +02:00
parent 2cdb340edd
commit 1c816c74ad
5 changed files with 274 additions and 184 deletions

View file

@ -1 +0,0 @@
,bartvdbraak,BART-MINT,24.04.2019 02:32,file:///home/bartvdbraak/.config/libreoffice/4;

View file

@ -1,28 +1,28 @@
monster,taskweight monster,taskweight,slayer_req
Ankou,6 Ankou,6,1
Aviansie,7 Aviansie,7,1
Bandit,4 Bandit,4,1
Bear,6 Bear,6,1
Black demon,7 Black demon,7,1
Black dragon,4 Black dragon,4,1
Chaos druid,5 Chaos druid,5,1
Dark warrior,4 Dark warrior,4,1
Earth warrior,6 Earth warrior,6,1
Ent,5 Ent,5,1
Fire giant,7 Fire giant,7,1
Greater demon,8 Greater demon,8,1
Green dragon,4 Green dragon,4,1
Hellhound,7 Hellhound,7,1
Ice giant,6 Ice giant,6,1
Ice warrior,7 Ice warrior,7,1
Lava dragon,3 Lava dragon,3,1
Lesser demon,6 Lesser demon,6,1
Magic axe,7 Magic axe,7,1
Mammoth,6 Mammoth,6,1
Revenant,5 Revenant,5,1
Rogue,5 Rogue,5,1
Scorpion,6 Scorpion,6,1
Skeleton,5 Skeleton,5,1
Spider,6 Spider,6,1
Spiritual creatures,6 Spiritual creatures,6,63
Bosses,8 Bosses,8,1

1 monster taskweight slayer_req
2 Ankou 6 1
3 Aviansie 7 1
4 Bandit 4 1
5 Bear 6 1
6 Black demon 7 1
7 Black dragon 4 1
8 Chaos druid 5 1
9 Dark warrior 4 1
10 Earth warrior 6 1
11 Ent 5 1
12 Fire giant 7 1
13 Greater demon 8 1
14 Green dragon 4 1
15 Hellhound 7 1
16 Ice giant 6 1
17 Ice warrior 7 1
18 Lava dragon 3 1
19 Lesser demon 6 1
20 Magic axe 7 1
21 Mammoth 6 1
22 Revenant 5 1
23 Rogue 5 1
24 Scorpion 6 1
25 Skeleton 5 1
26 Spider 6 1
27 Spiritual creatures 6 63
28 Bosses 8 1

View file

@ -1,112 +1,137 @@
{ [
"data": [ {
{ "monster": "Ankou",
"monster": "Ankou", "taskweight": 6,
"taskweight": 6 "slayer_req": 1
}, },
{ {
"monster": "Aviansie", "monster": "Aviansie",
"taskweight": 7 "taskweight": 7,
}, "slayer_req": 1
{ },
"monster": "Bandit", {
"taskweight": 4 "monster": "Bandit",
}, "taskweight": 4,
{ "slayer_req": 1
"monster": "Bear", },
"taskweight": 6 {
}, "monster": "Bear",
{ "taskweight": 6,
"monster": "Black demon", "slayer_req": 1
"taskweight": 7 },
}, {
{ "monster": "Black demon",
"monster": "Black dragon", "taskweight": 7,
"taskweight": 4 "slayer_req": 1
}, },
{ {
"monster": "Chaos druid", "monster": "Black dragon",
"taskweight": 5 "taskweight": 4,
}, "slayer_req": 1
{ },
"monster": "Dark warrior", {
"taskweight": 4 "monster": "Chaos druid",
}, "taskweight": 5,
{ "slayer_req": 1
"monster": "Earth warrior", },
"taskweight": 6 {
}, "monster": "Dark warrior",
{ "taskweight": 4,
"monster": "Ent", "slayer_req": 1
"taskweight": 5 },
}, {
{ "monster": "Earth warrior",
"monster": "Fire giant", "taskweight": 6,
"taskweight": 7 "slayer_req": 1
}, },
{ {
"monster": "Greater demon", "monster": "Ent",
"taskweight": 8 "taskweight": 5,
}, "slayer_req": 1
{ },
"monster": "Green dragon", {
"taskweight": 4 "monster": "Fire giant",
}, "taskweight": 7,
{ "slayer_req": 1
"monster": "Hellhound", },
"taskweight": 7 {
}, "monster": "Greater demon",
{ "taskweight": 8,
"monster": "Ice giant", "slayer_req": 1
"taskweight": 6 },
}, {
{ "monster": "Green dragon",
"monster": "Ice warrior", "taskweight": 4,
"taskweight": 7 "slayer_req": 1
}, },
{ {
"monster": "Lava dragon", "monster": "Hellhound",
"taskweight": 3 "taskweight": 7,
}, "slayer_req": 1
{ },
"monster": "Lesser demon", {
"taskweight": 6 "monster": "Ice giant",
}, "taskweight": 6,
{ "slayer_req": 1
"monster": "Magic axe", },
"taskweight": 7 {
}, "monster": "Ice warrior",
{ "taskweight": 7,
"monster": "Mammoth", "slayer_req": 1
"taskweight": 6 },
}, {
{ "monster": "Lava dragon",
"monster": "Revenant", "taskweight": 3,
"taskweight": 5 "slayer_req": 1
}, },
{ {
"monster": "Rogue", "monster": "Lesser demon",
"taskweight": 5 "taskweight": 6,
}, "slayer_req": 1
{ },
"monster": "Scorpion", {
"taskweight": 6 "monster": "Magic axe",
}, "taskweight": 7,
{ "slayer_req": 1
"monster": "Skeleton", },
"taskweight": 5 {
}, "monster": "Mammoth",
{ "taskweight": 6,
"monster": "Spider", "slayer_req": 1
"taskweight": 6 },
}, {
{ "monster": "Revenant",
"monster": "Spiritual creatures", "taskweight": 5,
"taskweight": 6 "slayer_req": 1
}, },
{ {
"monster": "Bosses", "monster": "Rogue",
"taskweight": 8 "taskweight": 5,
} "slayer_req": 1
] },
} {
"monster": "Scorpion",
"taskweight": 6,
"slayer_req": 1
},
{
"monster": "Skeleton",
"taskweight": 5,
"slayer_req": 1
},
{
"monster": "Spider",
"taskweight": 6,
"slayer_req": 1
},
{
"monster": "Spiritual creatures",
"taskweight": 6,
"slayer_req": 63
},
{
"monster": "Bosses",
"taskweight": 8,
"slayer_req": 1
}
]

View file

@ -30,20 +30,20 @@
<div class="col-6"> <div class="col-6">
<p>Unlocks:</p> <p>Unlocks:</p>
<form> <form>
<ul><input type="checkbox" name="reddrags" id="reddrags"> <ul><label><input type="checkbox" name="reddrags" id="reddrags">
Seeing red (Unlocks Red Dragons)</ul> Seeing red (Unlocks Red Dragons)</label></ul>
<ul><input type="checkbox" name="mithdrags" id="mithdrags"> <ul><label><input type="checkbox" name="mithdrags" id="mithdrags">
I hope you mith me (Unlocks Mithril Dragons)</ul> I hope you mith me (Unlocks Mithril Dragons)</label></ul>
<ul><input type="checkbox" name="aviansie" id="aviansie"> <ul><label><input type="checkbox" name="aviansies" id="aviansies">
Watch the birdie (Unlocks Aviansies)</ul> Watch the birdie (Unlocks Aviansies)</label></ul>
<ul><input type="checkbox" name="tzhaars" id="tzhaars"> <ul><label><input type="checkbox" name="tzhaar" id="tzhaar">
Hot stuff (Unlocks TzHaars)</ul> Hot stuff (Unlocks TzHaars)</label></ul>
<ul><input type="checkbox" name="lizardmen" id="lizardmen"> <ul><label><input type="checkbox" name="lizardmen" id="lizardmen">
Reptile got ripped (Unlocks Lizardmen)</ul> Reptile got ripped (Unlocks Lizardmen)</label></ul>
<ul><input type="checkbox" name="bosses" id="bosses"> <ul><label><input type="checkbox" name="bosses" id="bosses">
Like a boss (Unlocks Bosses)</ul> Like a boss (Unlocks Bosses)</label></ul>
<ul><input type="checkbox" name="fossilwyverns" id="fossilwyverns"> <ul><label><input type="checkbox" name="fossilwyverns" id="fossilwyverns">
Stop the Wyvern (Disables Fossil Island Wyverns)</ul> Stop the Wyvern (Disables Fossil Island Wyverns)</label></ul>
</form> </form>
</div> </div>
<div class="col-6"> <div class="col-6">
@ -59,17 +59,17 @@
</div> </div>
<div class="col-6 text-center"> <div class="col-6 text-center">
Slayer level: Slayer level:
<input type="text" name="slayerlevel" value=""> <input type="text" min="1" max="99" name="slayerlevel" id="slayerlevel" maxlength="2" placeholder="99" value="99">
</div> </div>
<div class="col-6 text-center"> <div class="col-6 text-center">
<input type="submit" value="Apply changes" onclick="applyChanges()"> <input type="submit" value="Apply changes" onclick="applyChanges('krystilia')">
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="col"> <div class="col">
<h3>Krystilia</h3> <h3>Krystilia</h3>
<p>Krystilia is a Slayer master found in Edgeville's jail north-east of the bank. When spoken to, she expresses her love for magic and the Wilderness, and claims the guards locked her in the cell for trouble-making.</p> <p>Krystilia is a Slayer master found in Edgeville's jail north-east of the bank. When spoken to, she expresses her love for magic and the Wilderness, and claims the guards locked her in the cell for trouble-making.</p>
<table id="example" class="display nowrap" width="100%"> <table id="master" class="display nowrap" width="100%">
<thead> <thead>
<tr> <tr>
<th>Monster</th> <th>Monster</th>

View file

@ -1,32 +1,98 @@
$(document).ready(function() { jQuery.fn.dataTable.Api.register( 'sum()', function ( ) {
$('#example').DataTable({ return this.flatten().reduce( function ( a, b ) {
ajax: "data/krystilia.json", if ( typeof a === 'string' ) {
columns: [ a = a.replace(/[^\d.-]/g, '') * 1;
}
if ( typeof b === 'string' ) {
b = b.replace(/[^\d.-]/g, '') * 1;
}
return a + b;
}, 0 );
} );
function filterTasks(data) {
index_list = []
for (i = 0; i < data.length; i++) {
switch (data[i].monster) {
case 'Red dragons':
if ($("#reddrags").prop("checked") == false) {
index_list.push(i)
}
break;
case 'Mithril dragons':
if ($("#mithdrags").prop("checked") == false) {
index_list.push(i)
}
break;
case 'Aviansie':
if ($("#aviansies").prop("checked") == false) {
index_list.push(i)
}
break;
case 'Tzhaar':
if ($("#tzhaar").prop("checked") == false) {
index_list.push(i)
}
break;
case 'Lizardmen':
if ($("#lizardmen").prop("checked") == false) {
index_list.push(i)
}
break;
case 'Bosses':
if ($("#bosses").prop("checked") == false) {
index_list.push(i)
}
break;
case 'Fossil Island Wyverns':
if ($("#wyverns").prop("checked") == true) {
index_list.push(i)
}
}
}
console.log(index_list,data)
return data
}
function sumWeights(data) {
var total = 0;
for (var i in data) {
total += data[i].taskweight
}
return total
}
var table;
function deleteOldDataTable(table) {
if ( $.fn.dataTable.isDataTable( '#master' ) ) {
table.destroy();
}
}
function applyChanges(master) {
deleteOldDataTable();
$.getJSON( "data/"+master+".json", function( data ) {
var data = filterTasks(data),
totalweight = sumWeights(data);
$(document).ready(function() {
table = $('#master').DataTable({
"data": data,
"columns": [
{ data: 'monster'}, { data: 'monster'},
{ data: 'taskweight'}, { data: 'taskweight'},
{ { data: null, render: function ( data, type, row ) {
data: null, return (row.taskweight / totalweight * 100 ).toFixed(2)+'%';
render: function ( data, type, row ) {
return Math.round( col.taskweight * row.taskweight * 100 )+'%';
} }
} }
] ]
}); });
} ); });
function filterEntries() {
} })
function addPercentages() {
}
function applyChanges() {
filterEntries();
addPercentages();
alert('Done.')
} }