]> _ Git - fluidbook-html5.git/commitdiff
wait #4358 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 31 Mar 2021 10:47:46 +0000 (12:47 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 31 Mar 2021 10:47:46 +0000 (12:47 +0200)
js/libs/fluidbook/fluidbook.gamify.js

index 6291ae51de8159e924c3886b310a7d270e658b23..60d35c13029e57e6c86233de3799e2ed81954215 100644 (file)
@@ -1,6 +1,7 @@
 function FluidbookGamify(fluidbook) {
     this.fluidbook = fluidbook;
     this.coinsLinksSeen = [];
+    this.addedCoins = {};
     this.totalCoins = 0;
 }
 
@@ -17,6 +18,18 @@ FluidbookGamify.prototype = {
         }
     },
 
+    addCoins: function (id, coins) {
+        this.addedCoins[id] = coins;
+        this.updateTotalCoins();
+    },
+
+    setMaxCoins: function (id, coins) {
+        if (this.addedCoins[id] === undefined) {
+            return this.addCoins(id, coins);
+        }
+        this.addCoins(id, Math.max(coins, this.addedCoins[id]));
+    },
+
     updateTotalCoins: function () {
         var $this = this;
         this.totalCoins = 0;
@@ -25,7 +38,10 @@ FluidbookGamify.prototype = {
                 $this.totalCoins += $this.fluidbook.settings.gamifyCoins[uid];
             }
         });
-        console.log('new coins score : '+this.totalCoins);
+        $.each(this.addedCoins,function(id,coins){
+           $this.totalCoins+=coins;
+        });
+        console.log('new coins score : ' + this.totalCoins);
 
     },
     getTotalCoins: function () {