From 1c816c74ad5bdd2cfae3f116671a846aafa43bc1 Mon Sep 17 00:00:00 2001 From: bartvdbraak Date: Wed, 24 Apr 2019 23:48:31 +0200 Subject: [PATCH] functionality for unlocks, filtering and percentages --- data/.~lock.krystilia.csv# | 1 - data/krystilia.csv | 56 ++++----- data/krystilia.json | 249 ++++++++++++++++++++----------------- index.html | 34 ++--- js/script.js | 118 ++++++++++++++---- 5 files changed, 274 insertions(+), 184 deletions(-) delete mode 100644 data/.~lock.krystilia.csv# diff --git a/data/.~lock.krystilia.csv# b/data/.~lock.krystilia.csv# deleted file mode 100644 index eb00120..0000000 --- a/data/.~lock.krystilia.csv# +++ /dev/null @@ -1 +0,0 @@ -,bartvdbraak,BART-MINT,24.04.2019 02:32,file:///home/bartvdbraak/.config/libreoffice/4; \ No newline at end of file diff --git a/data/krystilia.csv b/data/krystilia.csv index cd2dedb..a3c4908 100644 --- a/data/krystilia.csv +++ b/data/krystilia.csv @@ -1,28 +1,28 @@ -monster,taskweight -Ankou,6 -Aviansie,7 -Bandit,4 -Bear,6 -Black demon,7 -Black dragon,4 -Chaos druid,5 -Dark warrior,4 -Earth warrior,6 -Ent,5 -Fire giant,7 -Greater demon,8 -Green dragon,4 -Hellhound,7 -Ice giant,6 -Ice warrior,7 -Lava dragon,3 -Lesser demon,6 -Magic axe,7 -Mammoth,6 -Revenant,5 -Rogue,5 -Scorpion,6 -Skeleton,5 -Spider,6 -Spiritual creatures,6 -Bosses,8 +monster,taskweight,slayer_req +Ankou,6,1 +Aviansie,7,1 +Bandit,4,1 +Bear,6,1 +Black demon,7,1 +Black dragon,4,1 +Chaos druid,5,1 +Dark warrior,4,1 +Earth warrior,6,1 +Ent,5,1 +Fire giant,7,1 +Greater demon,8,1 +Green dragon,4,1 +Hellhound,7,1 +Ice giant,6,1 +Ice warrior,7,1 +Lava dragon,3,1 +Lesser demon,6,1 +Magic axe,7,1 +Mammoth,6,1 +Revenant,5,1 +Rogue,5,1 +Scorpion,6,1 +Skeleton,5,1 +Spider,6,1 +Spiritual creatures,6,63 +Bosses,8,1 diff --git a/data/krystilia.json b/data/krystilia.json index bf4d72e..cef2d59 100644 --- a/data/krystilia.json +++ b/data/krystilia.json @@ -1,112 +1,137 @@ -{ - "data": [ - { - "monster": "Ankou", - "taskweight": 6 - }, - { - "monster": "Aviansie", - "taskweight": 7 - }, - { - "monster": "Bandit", - "taskweight": 4 - }, - { - "monster": "Bear", - "taskweight": 6 - }, - { - "monster": "Black demon", - "taskweight": 7 - }, - { - "monster": "Black dragon", - "taskweight": 4 - }, - { - "monster": "Chaos druid", - "taskweight": 5 - }, - { - "monster": "Dark warrior", - "taskweight": 4 - }, - { - "monster": "Earth warrior", - "taskweight": 6 - }, - { - "monster": "Ent", - "taskweight": 5 - }, - { - "monster": "Fire giant", - "taskweight": 7 - }, - { - "monster": "Greater demon", - "taskweight": 8 - }, - { - "monster": "Green dragon", - "taskweight": 4 - }, - { - "monster": "Hellhound", - "taskweight": 7 - }, - { - "monster": "Ice giant", - "taskweight": 6 - }, - { - "monster": "Ice warrior", - "taskweight": 7 - }, - { - "monster": "Lava dragon", - "taskweight": 3 - }, - { - "monster": "Lesser demon", - "taskweight": 6 - }, - { - "monster": "Magic axe", - "taskweight": 7 - }, - { - "monster": "Mammoth", - "taskweight": 6 - }, - { - "monster": "Revenant", - "taskweight": 5 - }, - { - "monster": "Rogue", - "taskweight": 5 - }, - { - "monster": "Scorpion", - "taskweight": 6 - }, - { - "monster": "Skeleton", - "taskweight": 5 - }, - { - "monster": "Spider", - "taskweight": 6 - }, - { - "monster": "Spiritual creatures", - "taskweight": 6 - }, - { - "monster": "Bosses", - "taskweight": 8 - } - ] -} \ No newline at end of file +[ + { + "monster": "Ankou", + "taskweight": 6, + "slayer_req": 1 + }, + { + "monster": "Aviansie", + "taskweight": 7, + "slayer_req": 1 + }, + { + "monster": "Bandit", + "taskweight": 4, + "slayer_req": 1 + }, + { + "monster": "Bear", + "taskweight": 6, + "slayer_req": 1 + }, + { + "monster": "Black demon", + "taskweight": 7, + "slayer_req": 1 + }, + { + "monster": "Black dragon", + "taskweight": 4, + "slayer_req": 1 + }, + { + "monster": "Chaos druid", + "taskweight": 5, + "slayer_req": 1 + }, + { + "monster": "Dark warrior", + "taskweight": 4, + "slayer_req": 1 + }, + { + "monster": "Earth warrior", + "taskweight": 6, + "slayer_req": 1 + }, + { + "monster": "Ent", + "taskweight": 5, + "slayer_req": 1 + }, + { + "monster": "Fire giant", + "taskweight": 7, + "slayer_req": 1 + }, + { + "monster": "Greater demon", + "taskweight": 8, + "slayer_req": 1 + }, + { + "monster": "Green dragon", + "taskweight": 4, + "slayer_req": 1 + }, + { + "monster": "Hellhound", + "taskweight": 7, + "slayer_req": 1 + }, + { + "monster": "Ice giant", + "taskweight": 6, + "slayer_req": 1 + }, + { + "monster": "Ice warrior", + "taskweight": 7, + "slayer_req": 1 + }, + { + "monster": "Lava dragon", + "taskweight": 3, + "slayer_req": 1 + }, + { + "monster": "Lesser demon", + "taskweight": 6, + "slayer_req": 1 + }, + { + "monster": "Magic axe", + "taskweight": 7, + "slayer_req": 1 + }, + { + "monster": "Mammoth", + "taskweight": 6, + "slayer_req": 1 + }, + { + "monster": "Revenant", + "taskweight": 5, + "slayer_req": 1 + }, + { + "monster": "Rogue", + "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 + } + ] \ No newline at end of file diff --git a/index.html b/index.html index f14d334..f7c0509 100644 --- a/index.html +++ b/index.html @@ -30,20 +30,20 @@

Unlocks:

-
    - Seeing red (Unlocks Red Dragons)
-
    - I hope you mith me (Unlocks Mithril Dragons)
-
    - Watch the birdie (Unlocks Aviansies)
-
    - Hot stuff (Unlocks TzHaars)
-
    - Reptile got ripped (Unlocks Lizardmen)
-
    - Like a boss (Unlocks Bosses)
-
    - Stop the Wyvern (Disables Fossil Island Wyverns)
+
+
+
+
+
+
+
@@ -59,17 +59,17 @@
Slayer level: - +
- +

Krystilia

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.

- +
diff --git a/js/script.js b/js/script.js index 438d613..d9bce69 100644 --- a/js/script.js +++ b/js/script.js @@ -1,32 +1,98 @@ -$(document).ready(function() { - $('#example').DataTable({ - ajax: "data/krystilia.json", - columns: [ +jQuery.fn.dataTable.Api.register( 'sum()', function ( ) { + return this.flatten().reduce( function ( a, b ) { + if ( typeof a === 'string' ) { + 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: 'taskweight'}, - { - data: null, - render: function ( data, type, row ) { - return Math.round( col.taskweight * row.taskweight * 100 )+'%'; + { data: null, render: function ( data, type, row ) { + return (row.taskweight / totalweight * 100 ).toFixed(2)+'%'; } } ] - }); -} ); - - - - -function filterEntries() { - -} - -function addPercentages() { - -} - -function applyChanges() { - filterEntries(); - addPercentages(); - alert('Done.') + }); + }); + + }) } \ No newline at end of file
Monster