commit a14ce7aaccc0ec930aaccf04c34974796fbdcc06
parent 049ff27ffac035ca139968b11acf374d83fb6ba6
Author: Georges Dupéron <jahvascriptmaniac+github@free.fr>
Date: Thu, 28 Apr 2011 19:22:29 +0200
Affichage du score total, amélioration du calcul des couleurs.
Diffstat:
2 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/code/serveur/php/ressources/my-extensions.js b/code/serveur/php/ressources/my-extensions.js
@@ -4,6 +4,10 @@ Number.prototype.clip = function(min, max, floor) {
} catch(e) {alert("Error Number.prototype.clip");alert(e);}
};
+Number.prototype.mapInterval = function(a,b,x,y) {
+ return x + ((this-a) / (b-a) * (y-x));
+}
+
function dichotomy(start, isBigger, foo) {
try {
var i = 0, min = 0, max, half;
@@ -152,4 +156,17 @@ $.fn.clickOnce = function(fn) {
try {
this.unbind("click",fn).click(fn);
} catch(e) {alert("Error $.fn.clickOnce");alert(e);}
+};
+
+/**
+* startcolor et endcolor sont de la forme {r:0,g:255,b:127}
+*/
+$.fn.goodBad = function(min, max, startcolor, endcolor) {
+ var val = parseInt(this.text(), 10);
+ if (isNaN(val)) return this;
+ this.css("color","rgb("
+ +(val.mapInterval(min,max,startcolor.r,endcolor.r).clip(0, 255, true))+","
+ +(val.mapInterval(min,max,startcolor.g,endcolor.g).clip(0, 255, true))+","
+ +(val.mapInterval(min,max,startcolor.b,endcolor.b).clip(0, 255, true))+")");
+ return this;
};
\ No newline at end of file
diff --git a/code/serveur/php/ressources/pticlic.js b/code/serveur/php/ressources/pticlic.js
@@ -433,17 +433,19 @@ score.enter = function () {
score.leave = function () {
try {
if (runstate.scoreFetched) runstate.scoreFetched = function() {};
+ $("#score .scores").empty();
+ $("#templates .scoreTotal").empty();
} catch(e) {alert("Error score.leave");alert(e);}
};
score.ui = function () {
try {
$("#score .scores").empty();
+ $("#score .scoreTotal")
+ .text(state.game.scoreTotal)
+ .goodBad(-50,100,{r:255,g:0,b:0},{r:0,g:192,b:0});
$.each(state.game.cloud, function(i,e) {
try {
- var percentScore = (e.score - state.game.minScore) / (state.game.maxScore - state.game.minScore);
- u = $("#templates .scoreLine");
- ee = e;
$("#templates .scoreLine")
.clone()
.find(".word")
@@ -451,7 +453,7 @@ score.ui = function () {
.end()
.find(".score")
.text(e.score)
- .css("color","rgb("+(255 - 255*percentScore).clip(0,255)+","+(191*percentScore).clip(0,255,true)+",0)")
+ .goodBad(-5,10,{r:255,g:0,b:0},{r:0,g:192,b:0})
.end()
.appendTo("#score .scores");
} catch(e) {alert("Error anonymous 1 in score.ui");alert(e);}