| 1 |
var profilesCache = Array(); |
| 2 |
var chatFocused = false; |
| 3 |
var cachedUsers = new Object(); |
| 4 |
var inputtext_focused = false; |
| 5 |
var game; |
| 6 |
var ufopos = 0; |
| 7 |
var ufostr = ''; |
| 8 |
var speedpanel_top_loaded = false, speedpanel_arrow_loaded = false, speedpanel_back_loaded = false; |
| 9 |
Class.Methods.toArray = function() |
| 10 |
{ |
| 11 |
return 'asd'; |
| 12 |
} |
| 13 |
var Player = Class.create |
| 14 |
({ |
| 15 |
initialize: function(info) |
| 16 |
{this.pos = 0; |
| 17 |
var cookie; |
| 18 |
if(url_suffix && Prototype.Browser.IE) |
| 19 |
{ |
| 20 |
var m = game.cookies.match(/player!!!(\d+),[a-z0-9]+@@@/); |
| 21 |
if(m && m[1] == info.id) |
| 22 |
this.you = true; |
| 23 |
} |
| 24 |
if(cookie = getCookie('player')) |
| 25 |
{ |
| 26 |
var m = cookie.split(','); |
| 27 |
if(m[0] == info.id) |
| 28 |
this.you = true; |
| 29 |
} |
| 30 |
this.move_effect = {state: 'finished'}; |
| 31 |
this.update(info); |
| 32 |
}, |
| 33 |
setPos: function(pos) |
| 34 |
{ |
| 35 |
tlog("Player::setPos "+this.info.id, {pos: pos}); |
| 36 |
this.pos = pos; |
| 37 |
$('car'+this.info.id).style.top = 0; |
| 38 |
var w = url_suffix?380:480; |
| 39 |
var x = Math.floor(pos * w / (game.params.qual ? game.wordsTotal : game.errorWork ? game.original_words.length : game.words.length) ); |
| 40 |
if(game.custom && game.params.mode=='marathon') |
| 41 |
{ |
| 42 |
x = Math.floor(pos * w / game.marathon_length); |
| 43 |
if(game.finished) |
| 44 |
x = w; |
| 45 |
} |
| 46 |
if(game.custom && game.params.gametype == 'noerror' && this.info.errors) |
| 47 |
{ |
| 48 |
this.errorKick(); |
| 49 |
} |
| 50 |
else if(this.info.skiptrackerror_kicked) { |
| 51 |
$('rating_loading').hide(); |
| 52 |
var rating = $('rating'+this.info.id); |
| 53 |
rating.update(tplSkiptrackerrorFail.evaluate(this.info)); |
| 54 |
rating.show(); |
| 55 |
$('car'+this.info.id).setStyle({left: '480px'}); |
| 56 |
} |
| 57 |
else if(pos) |
| 58 |
{if(params.carmove == 'smooth' && (!game.params || !game.params.regularcompetition)) |
| 59 |
{ |
| 60 |
if(this.move_effect.state != 'finished') |
| 61 |
this.move_effect.cancel(); |
| 62 |
this.move_effect = new Effect.Move($('car'+this.info.id), {x: x, y: 0, mode: 'absolute'}); |
| 63 |
} |
| 64 |
else |
| 65 |
$('car'+this.info.id).setStyle({left: x+'px', top: 0}); |
| 66 |
} |
| 67 |
}, |
| 68 |
errorKick: function() |
| 69 |
{ |
| 70 |
$$$('#player'+this.info.id+' table .car') |
| 71 |
.prepend('<img class="noerror-fail" src="/img/noerror_fail.png">') |
| 72 |
.find('.imgcont').css({opacity: '0.6'}); |
| 73 |
}, |
| 74 |
dump: function() |
| 75 |
{ |
| 76 |
if(!__testmode) |
| 77 |
return null; |
| 78 |
var result = {}; |
| 79 |
for(var i in this) |
| 80 |
{ |
| 81 |
if(typeof this[i] != 'function' && typeof this[i] != 'object') |
| 82 |
result[i] = this[i]; |
| 83 |
} |
| 84 |
result.info = this.info; |
| 85 |
return result; |
| 86 |
}, |
| 87 |
update: function(info) |
| 88 |
{ |
| 89 |
tlog("Player::update "+(this.info ? this.info.id : '?'), {that: this.dump(), info: info}); |
| 90 |
if(this.info && info.v <= this.info.v) |
| 91 |
return; |
| 92 |
this.tpl = tplAnonymPlayer; |
| 93 |
info.game_id = game.id; |
| 94 |
// кэш юзеров |
| 95 |
if(info.user !== null) |
| 96 |
{ |
| 97 |
if(typeof info.user == 'object') { |
| 98 |
info.user.carData = JSON.stringify({ |
| 99 |
car: info.user.car, |
| 100 |
color: info.user.background, |
| 101 |
tuning: info.user.tuning |
| 102 |
}) |
| 103 |
cachedUsers[info.user.id] = info.user; |
| 104 |
} |
| 105 |
if(typeof info.user == 'number') |
| 106 |
info.user = cachedUsers[info.user]; |
| 107 |
} |
| 108 |
if(info.user) |
| 109 |
this.tpl = tplUserPlayer; |
| 110 |
var oldinfo = clone(this.info); |
| 111 |
this.info = clone(info); |
| 112 |
this.info.you = 'other'; |
| 113 |
if(this.you) |
| 114 |
this.info.you = 'you'; |
| 115 |
if(this.info.user) |
| 116 |
{ |
| 117 |
this.info.color = '#000000'; |
| 118 |
if(/#[a-fA-F0-9]+/.test(this.info.user.color)) |
| 119 |
this.info.color = colortools.capByBrightness(this.info.user.color); |
| 120 |
if(info.leave && Prototype.Browser.Opera) |
| 121 |
this.info.user.background = 'white'; |
| 122 |
} |
Комментарии