June 7, 2018♦
EVR.include("level/cheers/marquee/Spectrum.js");
EVR.Level.Cheers.Marquee = function(
cheers, color_offset, placement_offset, z_index, opacity)
{
EVR.Graphic.call(this, cheers);
this.cheers = cheers;
this.spectrum = new EVR.Level.Cheers.Marquee.Spectrum(color_offset);
this.placement_offset = placement_offset || [0, 0];
this.z_index = z_index || 0;
this.spectrum_index = CHEERS_SPECTRUM_STARTING_INDEX;
this.font_size = CHEERS_FONT_SIZE;
this.opacity = opacity;
this.glyphs = [];
this.setAttributes();
this.append();
}
EVR.Level.Cheers.Marquee.prototype = new EVR.Graphic;
EVR.Level.Cheers.Marquee.prototype.setAttributes = function()
{
this.set_z(this.z_index);
this.set_opacity(this.opacity);
var css = this.css;
css.fontWeight = "bold";
css.textAlign = "left";
css.whiteSpace = "nowrap";
this.setFontSize();
}
EVR.Level.Cheers.Marquee.prototype.setFontSize = function()
{
var dimensions = this.cheers.level.container.get_dimensions();
var modifier = dimensions[1] / dimensions[0];
var basis = dimensions[0] * modifier;
var size = parseInt(basis * this.font_size);
this.css.fontSize = size + "px";
this.whitespace_length = basis * CHEERS_GLYPH_PADDING;
}
EVR.Level.Cheers.Marquee.prototype.place = function()
{
EVR.Graphic.prototype.place.call(this, 0, CHEERS_MARQUEE_OFFSET);
var x = this.get_coordinates()[0] + this.placement_offset[0];
var y = this.get_coordinates()[1] + this.placement_offset[1];
this.set_coordinates([x, y]);
}
EVR.Level.Cheers.Marquee.prototype.addCheer = function(cheer)
{
var parent = this.element;
for (var ii = cheer.length - 1; ii >= 0; ii--)
{
var color = this.spectrum.get(this.spectrum_index);
this.addGlyph(cheer.charAt(ii), color, ii == cheer.length - 1);
}
}
EVR.Level.Cheers.Marquee.prototype.addGlyph = function(character, color, pad)
{
var parent = this.element;
var element = document.createElement("span");
element.innerHTML = character;
element.style.color = color;
parent.insertBefore(element, parent.firstChild);
if (pad)
{
element.style.paddingRight = this.whitespace_length + "px";
}
this.glyphs.push(element);
this.spectrum_index++;
}
EVR.Level.Cheers.Marquee.prototype.addJeer = function()
{
var color = CHEERS_JEER_COLOR;
var jeer = CHEERS_JEER_TEXT;
for (var ii = jeer.length - 1; ii >= 0; ii--)
{
this.addGlyph(jeer.charAt(ii), color, ii == jeer.length - 1);
}
}
EVR.Level.Cheers.Marquee.prototype.draw = function()
{
EVR.Graphic.prototype.draw.call(this);
this.setFontSize();
var glyph, glyphs = this.glyphs;
for (var ii = 0; ii < glyphs.length; ii++)
{
glyph = glyphs[ii];
if (parseInt(glyph.style.paddingRight) > 0)
{
glyph.style.paddingRight = this.whitespace_length;
}
}
}
EVR.Level.Cheers.Marquee.prototype.toString = function()
{
return "[EVR.Level.Cheers.Marquee]";
}
EVR.Level.Cheers.Marquee.Spectrum = function(offset)
{
this.offset = offset;
this.build();
}
EVR.Level.Cheers.Marquee.Spectrum.prototype.build = function()
{
var max = 255 - this.offset;
var count = CHEERS_SPECTRUM_LENGTH;
var interval = Math.round(count / 6);
var step = Math.round(max / (interval - 1));
var component, color, spectrum = [];
for (var ii = 0; ii < interval; ii++)
{
component = step * ii;
spectrum.push(new EVR.Color([max, component, 0]));
}
for (var ii = interval - 1; ii >= 0; ii--)
{
component = step * ii;
spectrum.push(new EVR.Color([component, max, 0]));
}
for (var ii = 0; ii < interval; ii++)
{
component = step * ii;
spectrum.push(new EVR.Color([0, max, component]));
}
for (var ii = interval - 1; ii >= 0; ii--)
{
component = step * ii;
spectrum.push(new EVR.Color([0, component, max]));
}
for (var ii = 0; ii < interval; ii++)
{
component = step * ii;
spectrum.push(new EVR.Color([component, 0, max]));
}
for (var ii = interval - 1; ii >= 0; ii--)
{
component = step * ii;
spectrum.push(new EVR.Color([max, 0, component]));
}
this.spectrum = spectrum;
}
EVR.Level.Cheers.Marquee.Spectrum.prototype.get = function(index)
{
var spectrum = this.spectrum;
return spectrum[index % spectrum.length].get_string();
}
EVR.Level.Cheers.Marquee.Spectrum.toString = function()
{
return "[object EVR.Level.Cheers.Marquee.Spectrum]";
}
EVR.include("level/loader/Parser.js");
EVR.Level.Loader = function(level)
{
this.level = level;
}
EVR.Level.Loader.prototype.load = function()
{
this.build_requester();
var document = this.requester.execute();
this.parser = new EVR.Level.Loader.Parser(this.level, document);
}
EVR.Level.Loader.prototype.build_requester = function()
{
var path = SOURCE_PATH + "level/loader/fetch.php";
var query = "id=" + this.level.id;
this.requester = new EVR.Requester(path, query);
}
EVR.Level.Loader.prototype.toString = function()
{
return "[object EVR.Level.Loader]";
}
EVR.Level.Loader.Parser = function(level, document)
{
this.level = level;
this.root = document.getElementsByTagName("level")[0];
this.parse();
}
EVR.Level.Loader.Parser.prototype.parse = function()
{
this.parse_attributes();
this.parse_sky();
this.parse_beams();
this.parse_path();
}
EVR.Level.Loader.Parser.prototype.parse_attributes = function()
{
var level = this.level;
var root = this.root;
level.background = root.getAttribute("background");
level.goal = new EVR.Time(root.getAttribute("goal"));
level.advanced = new EVR.Time(root.getAttribute("advanced"));
level.threshold = parseFloat(root.getAttribute("threshold"));
level.sound.set_song(root.getAttribute("song"));
}
EVR.Level.Loader.Parser.prototype.parse_sky = function()
{
var node = this.root.getElementsByTagName("sky")[0];
var tags = node.getElementsByTagName("background");
var sky = this.level.sky = [];
for (var ii = 0; ii < tags.length; ii++)
{
sky.push(tags[ii].getAttribute("color"));
}
}
EVR.Level.Loader.Parser.prototype.parse_beams = function()
{
var node = this.root.getElementsByTagName("beams")[0];
var tags = node.getElementsByTagName("beam");
this.level.beams = [];
for (var ii = 0; ii < tags.length; ii++)
{
this.level.beams.push(tags[ii].getAttribute("color"));
}
}
EVR.Level.Loader.Parser.prototype.parse_path = function()
{
var node = this.root.getElementsByTagName("path")[0];
var tags = node.getElementsByTagName("cluster");
this.level.clusters = [];
for (var ii = 0; ii < tags.length; ii++)
{
this.add_cluster(tags[ii]);
}
}
EVR.Level.Loader.Parser.prototype.add_cluster = function(tag)
{
var level = this.level;
var passage = tag.getAttribute("passage");
var width = tag.getAttribute("width");
var gap = tag.getAttribute("gap");
var cluster = new EVR.Level.Cluster(passage, width, gap, level.practice);
level.clusters.push(cluster);
}
EVR.Level.Loader.Parser.prototype.toString = function()
{
return "[object EVR.Level.Loader.Parser]";
}