June 6, 2016♦
EVR.Level.Register.Preview = function(register, index)
{
EVR.Graphic.call(this, register, null, null, ALIGN_BOTTOM_LEFT);
this.index = index;
this.level = register.level;
this.clusters = this.level.clusters;
this.beams = this.level.beams;
this.margin = register.margin;
this.item = index;
this.set_border();
this.set_color();
this.set_proportions();
this.append();
}
EVR.Level.Register.Preview.prototype = new EVR.Graphic;
EVR.Level.Register.Preview.prototype.set_border = function()
{
this.css.border = PREVIEW_BORDER_WIDTH + " " + PREVIEW_BORDER_STYLE;
}
EVR.Level.Register.Preview.prototype.set_color = function()
{
var passage = this.clusters[this.item].passage;
var color = this.beams[passage];
EVR.Graphic.prototype.set_color.call(this, color);
}
EVR.Level.Register.Preview.prototype.set_proportions = function()
{
var width = PREVIEW_FIRST_WIDTH;
if (this.index > 0)
{
width *= PREVIEW_SIZE_VARIANCE / this.index;
}
var height = 1 - this.margin[1];
EVR.Graphic.prototype.set_proportions.call(this, width, height);
}
EVR.Level.Register.Preview.prototype.calculate_width = function(ii)
{
if (typeof(ii) == "undefined")
{
ii = this.index;
}
var width = PREVIEW_FIRST_WIDTH;
if (ii > 0)
{
width *= PREVIEW_SIZE_VARIANCE / ii;
}
return width;
}
EVR.Level.Register.Preview.prototype.place = function()
{
var x = this.margin[0];
for (var ii = 0; ii < this.index; ii++)
{
x += this.calculate_width(ii) + PREVIEW_MARGIN;
}
EVR.Graphic.prototype.place.call(this, x);
}
EVR.Level.Register.Preview.prototype.advance = function(ii)
{
this.item = ii + this.index + 1;
if (this.item < this.clusters.length)
{
this.set_color();
}
}
EVR.Level.Register.Preview.prototype.shape = function()
{
EVR.Graphic.prototype.shape.call(this);
if (!!window.ActiveXObject)
{
var dimensions = this.get_dimensions();
var adjustment = PREVIEW_BORDER_WIDTH * 2;
this.set_dimensions(
dimensions[0] + adjustment, dimensions[1] + adjustment);
}
}
EVR.Level.Register.Preview.prototype.toString = function()
{
return "[object EVR.Level.Register.Preview]";
}
EVR.include("level/register/Preview.js");
EVR.Level.Register = function(level)
{
EVR.Graphic.call(this, level.road, null, null, null, level.road.container);
this.level = level;
this.road = level.road;
this.height = REGISTER_HEIGHT;
this.margin = REGISTER_MARGIN;
this.count = REGISTER_COUNT;
this.previews = [];
this.build();
this.append();
this.add_previews();
}
EVR.Level.Register.prototype = new EVR.Graphic;
EVR.Level.Register.prototype.build = function()
{
this.set_proportions(REGISTER_WIDTH, this.height);
this.set_color(this.level.background);
this.set_opacity(REGISTER_OPACITY);
this.css.borderTop = ROAD_DIVIDER_STYLE;
}
EVR.Level.Register.prototype.add_previews = function()
{
var previews = [];
for (var ii = 0; ii < REGISTER_COUNT; ii++)
{
previews.push(new EVR.Level.Register.Preview(this, ii));
}
this.previews = previews;
}
EVR.Level.Register.prototype.place = function()
{
EVR.Graphic.prototype.place.call(this);
var y = this.road.borders.get_dimensions()[1];
y += this.get_dimensions()[1];
this.set_coordinates([null, -y]);
}
EVR.Level.Register.prototype.draw = function()
{
EVR.Graphic.prototype.draw.call(this);
var previews = this.previews;
for (var ii = 0; ii < previews.length; ii++)
{
previews[ii].draw();
}
}
EVR.Level.Register.prototype.advance = function(item_index)
{
var previews = this.previews;
for (var ii = 0; ii < previews.length; ii++)
{
previews[ii].advance(item_index);
}
}
EVR.Level.Register.prototype.toString = function()
{
return "[object EVR.Level.Register]";
}
EVR.include("level/road/Borders.js");
EVR.include("level/road/racer/Racer.js");
EVR.include("level/road/path/Path.js");
EVR.Level.Road = function(level)
{
EVR.Graphic.call(this, level.container, null, null, ALIGN_CENTER);
this.level = level;
this.dimensions = [0, 0];
this.set_constants();
this.orient();
this.set_color(this.level.background);
this.append();
this.add_children();
}
EVR.Level.Road.prototype = new EVR.Graphic;
EVR.Level.Road.prototype.set_constants = function()
{
this.margin = MENU_OPTION_MARGIN;
this.beam_height = ROAD_BEAM_HEIGHT;
}
EVR.Level.Road.prototype.orient = function()
{
this.set_proportions();
this.place(0, ROAD_OFFSET);
}
EVR.Level.Road.prototype.set_proportions = function()
{
var count = this.level.count_lanes();
var height = count * this.beam_height + this.margin * (count - 1);
EVR.Graphic.prototype.set_proportions.call(this, 1, height);
}
EVR.Level.Road.prototype.add_children = function()
{
this.borders = new EVR.Level.Road.Borders(this, this.level);
this.racer = new EVR.Level.Road.Racer.Player(this, this.level);
if (!this.level.practice)
{
this.ghost = new EVR.Level.Road.Racer.Ghost(this, this.level);
}
this.path = new EVR.Level.Road.Path(this, this.level);
}
EVR.Level.Road.prototype.draw = function()
{
EVR.Graphic.prototype.draw.call(this);
!!this.borders && this.borders.draw();
!!this.racer && this.racer.draw();
!!this.ghost && this.ghost.draw();
if (!this.level.states[LEVEL_STATE_FINISHED])
{
!!this.path && this.path.draw();
}
}
EVR.Level.Road.prototype.shape = function()
{
EVR.Graphic.prototype.shape.call(this);
this.update_dimensions();
}
EVR.Level.Road.prototype.get_dimensions = function(ratio)
{
if (ratio == true)
{
return EVR.Graphic.prototype.get_dimensions.call(this, true);
}
else
{
return this.dimensions;
}
}
EVR.Level.Road.prototype.update_dimensions = function()
{
this.dimensions = EVR.Graphic.prototype.get_dimensions.call(this);
}
EVR.Level.Road.prototype.remove = function()
{
EVR.Graphic.prototype.remove.call(this);
this.racer.avatar.attached && this.racer.remove();
}
EVR.Level.Road.prototype.toString = function()
{
return "[object EVR.Level.Road]";
}