June 7, 2018♦
EVR.include("level/scoreboard/Speed.js");
EVR.include("level/scoreboard/meter/Meter.js");
EVR.include("level/scoreboard/cheers/Cheers.js");
EVR.Level.Scoreboard = function(level)
{
EVR.Graphic.call(this, level.container, null, null, ALIGN_TOP);
this.level = level;
this.speed = new EVR.Level.Scoreboard.Speed();
this.setAttributes();
this.append();
this.meter = new EVR.Level.Scoreboard.Meter(this);
// this.cheers = new EVR.Level.Scoreboard.Cheers(this);
}
EVR.Level.Scoreboard.prototype = new EVR.Graphic;
EVR.Level.Scoreboard.prototype.setAttributes = function()
{
this.set_proportions(SCOREBOARD_WIDTH, SCOREBOARD_HEIGHT);
this.place(0, SCOREBOARD_OFFSET);
// this.set_color("white");
}
EVR.Level.Scoreboard.prototype.buildYellow = function(index, count, offset)
{
if (offset == null)
{
offset = 0;
}
var max_red = SCOREBOARD_MAX_RED;
var difference = 255 - max_red;
var red = parseInt((max_red / count) * (index + 1) + difference);
return new EVR.Color([red - offset, 255 - offset, 0]);
}
EVR.Level.Scoreboard.prototype.update = function(measurement)
{
var speed = this.speed;
speed.addMeasurement(measurement);
speed.updateAverage();
var level = this.meter.update(speed.getAverage());
// this.cheers.update(level);
}
EVR.Level.Scoreboard.prototype.draw = function()
{
EVR.Graphic.prototype.draw.call(this);
!!this.meter && this.meter.draw();
}
EVR.Level.Scoreboard.prototype.applyToIndicators = function(method)
{
var indicators = this.indicators;
for (var ii = 0; ii < indicators.length; ii++)
{
indicators[ii][method]();
}
}
EVR.Level.Scoreboard.prototype.toString = function()
{
return "[object EVR.Level.Scoreboard]";
}
EVR.include("level/scoreboard/cheers/Cheer.js");
EVR.Level.Scoreboard.Cheers = function(scoreboard)
{
this.scoreboard = scoreboard;
this.cheer_texts = SCOREBOARD_CHEERS;
this.addCheers();
}
EVR.Level.Scoreboard.Cheers.prototype.addCheers = function()
{
var count = this.cheer_texts.length;
var cheers = [];
for (var ii = 0; ii < count; ii++)
{
cheers.push(new EVR.Level.Scoreboard.Cheers.Cheer(this, ii, count));
}
this.cheers = cheers;
}
EVR.Level.Scoreboard.Cheers.prototype.update = function(level)
{
if (level > 1)
{
level = 1;
}
var cheer, cheers = this.cheers;
var count = cheers.length;
var index = Math.round(count * level) - 1;
if (level > 0 && index < 0)
{
index = 0;
}
for (var ii = 0; ii < count; ii++)
{
cheer = cheers[ii];
if (ii != index)
{
if (cheer.attached)
{
cheer.remove();
}
}
else
{
if (!cheer.attached)
{
cheer.append();
}
}
}
}
EVR.Level.Scoreboard.Cheers.prototype.toString = function()
{
return "[object EVR.Level.Scoreboard.Cheers]";
}
EVR.Level.Scoreboard.Cheers.Cheer = function(cheers, index, count)
{
EVR.Graphic.call(this, cheers.scoreboard, null, null, ALIGN_RIGHT);
this.cheers = cheers;
this.index = index;
this.count = count;
this.setAttributes();
this.append();
this.setText();
this.remove();
}
EVR.Level.Scoreboard.Cheers.Cheer.prototype = new EVR.Graphic;
EVR.Level.Scoreboard.Cheers.Cheer.prototype.setAttributes = function()
{
var width = 1 - SCOREBOARD_METER_WIDTH - SCOREBOARD_CHEER_MARGIN;
this.set_proportions(width, 1);
this.css.fontWeight = SCOREBOARD_FONT_WEIGHT;
// this.set_color("purple");
}
EVR.Level.Scoreboard.Cheers.Cheer.prototype.setText = function()
{
var cheers = this.cheers;
var text = cheers.cheer_texts[this.index];
var font = SCOREBOARD_FONT_FAMILY;
var count = this.count;
var color = cheers.scoreboard.buildYellow(count - this.index, count);
var size = SCOREBOARD_FONT_SIZE;
var size_relative = this.container.container;
this.set_shadow(text, font, size, size_relative);
var foreground = new EVR.Graphic(this, null, null, ALIGN_BOTTOM_LEFT);
foreground.set_proportions(0, .8);
foreground.set_text(text, font, color.get_string(), size, size_relative);
foreground.append();
this.foreground = foreground;
}
EVR.Level.Scoreboard.Cheers.Cheer.prototype.set_shadow =
function(text, font, size, size_relative)
{
var shadow = new EVR.Graphic(this, null, null, ALIGN_BOTTOM_LEFT, this.container);
var count = this.count;
var color = this.cheers.scoreboard.buildYellow(count - this.index, count, 70);
shadow.set_proportions(0, .8);
shadow.set_text(text, font, color.get_string(), size, size_relative);
shadow.append();
this.shadow = shadow;
this.place_shadow();
}
EVR.Level.Scoreboard.Cheers.Cheer.prototype.place_shadow = function()
{
var shadow = this.shadow;
var position = shadow.get_coordinates();
var offset = SCOREBOARD_SHADOW_OFFSET;
var coordinates = [position[0] + offset[0], position[1] + offset[1]];
shadow.set_coordinates(coordinates);
}
EVR.Level.Scoreboard.Cheers.Cheer.prototype.draw = function()
{
EVR.Graphic.prototype.draw.call(this);
if (!!this.shadow && !!this.foreground)
{
this.shadow.draw();
this.place_shadow();
this.foreground.draw();
}
}
EVR.Level.Scoreboard.Cheers.Cheer.prototype.toString = function()
{
return "[object EVR.Level.Scoreboard.Cheers.Cheer]";
}
EVR.include("level/scoreboard/indicator/Spectator.js");
EVR.include("level/scoreboard/indicator/Cheer.js");
EVR.include("level/scoreboard/indicator/Base.js");
EVR.Level.Scoreboard.Indicator = function(scoreboard, index)
{
EVR.Graphic.call(this, scoreboard);
this.scoreboard = scoreboard;
this.index = index;
this.count = scoreboard.palette[0].length;
this.cheer_text = scoreboard.cheer_text[index];
this.setColor();
this.setAttributes();
this.append();
this.cheer = new EVR.Level.Scoreboard.Indicator.Cheer(this);
}
EVR.Level.Scoreboard.Indicator.prototype = new EVR.Graphic;
EVR.Level.Scoreboard.Indicator.prototype.setColor = function()
{
var count = this.count;
var index = this.index;
var midpoint = count / 2 - 1;
var red, green;
if (index <= midpoint)
{
red = 255;
green = parseInt((index / midpoint) * 255);
}
else
{
green = 255;
red = parseInt(((count - index - 1) / midpoint) * 255);
}
var offset = SCOREBOARD_SHADOW_COLOR_OFFSET;
red_shadow = this.buildShadowComponent(red);
green_shadow = this.buildShadowComponent(green);
this.color = [
this.buildRGB(red, green), this.buildRGB(red_shadow, green_shadow)];
}
EVR.Level.Scoreboard.Indicator.prototype.buildShadowComponent =
function(component)
{
component -= SCOREBOARD_SHADOW_COLOR_OFFSET;
if (component < 0)
{
component = 0;
}
return component;
}
EVR.Level.Scoreboard.Indicator.prototype.buildRGB = function(red, green)
{
return "rgb(" + red + ", " + green + ", 0)";
}
EVR.Level.Scoreboard.Indicator.prototype.setAttributes = function()
{
var width = 1 / this.count;
this.set_proportions(width, SCOREBOARD_INDICATOR_HEIGHT);
this.place(this.index * width);
this.set_color(this.color[0]);
this.set_opacity(SCOREBOARD_INACTIVE_OPACITY);
}
EVR.Level.Scoreboard.Indicator.prototype.activate = function()
{
this.set_opacity(1);
this.cheer.append();
}
EVR.Level.Scoreboard.Indicator.prototype.deactivate = function()
{
this.set_opacity(SCOREBOARD_INACTIVE_OPACITY);
this.cheer.attached && this.cheer.remove();
}
EVR.Level.Scoreboard.Indicator.prototype.draw = function()
{
EVR.Graphic.prototype.draw.call(this);
if (!!this.cheer)
{
this.cheer.draw();
}
}
EVR.Level.Scoreboard.Indicator.prototype.toString = function()
{
return "[object EVR.Level.Scoreboard.Indicator]";
}