<?php
require_once "../../../../account/get_user_path.php";
$GLOBALS["GHOSTS_DIRECTORY"] = "ghosts/";
load_ghost();
function load_ghost()
{
   if (file_exists($path = build_path()))
   {
      ob_start();
      readgzfile($path);
      ob_end_flush();
   }
}
function build_path()
{
   $file = $_GET["level"] . ".gz";
   return account\get_user_path() . $GLOBALS["GHOSTS_DIRECTORY"] . $file;
}
<?php
require_once "../../../../account/get_user_path.php";
$GLOBALS["GHOSTS_DIRECTORY"] = "ghosts/";
save_ghost();
function save_ghost()
{
   create_files();
   $trail = str_replace("|", "\n", $_POST["trail"]);
   gzwrite(gzopen(build_path(), "w"), $trail);
}
function create_files()
{
   create_directory();
   create_file();
}
function create_directory()
{
   $path = build_directory_path();
   if (!file_exists($path))
   {
      mkdir($path, 02770);
   }
}
function create_file()
{
   $path = build_path();
   if (!file_exists($path))
   {
      touch($path);
      chmod($path, 0660);
   }
}
function build_directory_path()
{
   return account\get_user_path() . $GLOBALS["GHOSTS_DIRECTORY"];
}
function build_path()
{
   return build_directory_path() . $_POST["level"] . ".gz";
}
EVR.include("level/road/path/trail/Marker.js");
EVR.Level.Road.Path.Trail = function(level)
{
   this.level = level;
   this.trail = [];
}
EVR.Level.Road.Path.Trail.prototype.add = function(speed, lane)
{
   var level = this.level;
   var time = 0;
   if (!!level.clock)
   {
      time = level.clock.time.get();
   }
   var trail = this.trail;
   var marker = new EVR.Level.Road.Path.Trail.Marker(time, speed, lane);
   trail.push(marker);
}
EVR.Level.Road.Path.Trail.prototype.load = function()
{
   var trail = this.trail;
   var parameters, marker, raw = this.get_raw();
   for (var ii = 0; ii < raw.length; ii++)
   {
      parameters = raw[ii].split(" ");
      marker = new EVR.Level.Road.Path.Trail.Marker();
      EVR.Level.Road.Path.Trail.Marker.apply(marker, parameters);
      trail.push(marker);
   }
}
EVR.Level.Road.Path.Trail.prototype.get_raw = function()
{
   var script = this.get_script_root() + "load_ghost.php";
   var query = this.build_query();
   var raw = new EVR.Requester(script, query, true).execute().split("\n");
   if (raw.length <= 1)
   {
      raw = [];
   }
   return raw;
}
EVR.Level.Road.Path.Trail.prototype.build_query = function()
{
   return "level=" + this.level.id;
}
EVR.Level.Road.Path.Trail.prototype.get_script_root = function()
{
   return SOURCE_PATH + "level/road/path/trail/";
}
EVR.Level.Road.Path.Trail.prototype.save = function()
{
   this.fix();
   var script = this.get_script_root() + "save_ghost.php";
   var query = this.build_query() + "&trail=" + this.serialize();
   new EVR.Requester(script, query, true, true).execute();
}
EVR.Level.Road.Path.Trail.prototype.fix = function()
{
   var trail = this.trail;
   var time;
   for (var ii = 0; ii < trail.length - 1; ii++)
   {
      time = trail[ii].time;
      if (time > 0 && time == trail[ii + 1].time)
      {
	 ii = this.fix_duplicates(ii);
      }
   }
}
EVR.Level.Road.Path.Trail.prototype.fix_duplicates = function(ii)
{
   var trail = this.trail;
   var count = this.count_duplicates(ii);
   var previous = trail[ii - 1].time;
   var difference = trail[ii].time - previous;
   var step = parseInt(difference / count);
   var limit = ii + count;
   while (ii < limit)
   {
      trail[ii].time -= step * (limit - ii++ - 1);
   }
   return ii - 1;
}
EVR.Level.Road.Path.Trail.prototype.count_duplicates = function(ii)
{
   var trail = this.trail;
   var time = trail[ii].time;
   var count = 1;
   while (ii < trail.length - 1 && trail[++ii].time == time)
   {
      count++;
   }
   return count;
}
EVR.Level.Road.Path.Trail.prototype.serialize = function()
{
   return this.trail.join("|");
}
EVR.Level.Road.Path.Trail.prototype.toString = function()
{
   return "[EVR.Level.Road.Path.Trail]";
}
EVR.Level.Road.Path.Trail.Marker = function(time, speed, lane)
{
   this.time = parseInt(time);
   this.speed = parseFloat(speed);
   this.lane = parseInt(lane);
}
EVR.Level.Road.Path.Trail.Marker.prototype.toString = function()
{
   return this.time + " " + this.speed + " " + this.lane;
}
EVR.include("/level/map/Indicator.js");
EVR.Level.Map.Display = function(container, level)
{
   EVR.Component.call(this, container, "table");
   this.level = level;
   this.clusters = level.clusters;
   this.colors = level.beams;
   this.current = 0;
   this.row = this.element.insertRow(-1);
   this.style();
   this.populate();
   this.append();
   this.align();
   this.add_indicators();
}
EVR.Level.Map.Display.prototype = new EVR.Component;
EVR.Level.Map.Display.prototype.style = function()
{
   this.element.cellSpacing = "0";
   this.css.width = MAP_WIDTH;
   this.css.position = "absolute";
   this.css.border = MAP_BORDER;
}
EVR.Level.Map.Display.prototype.populate = function()
{
   var passage, cell;
   for (var ii = 0; ii < this.clusters.length; ii++)
   {
      passage = this.clusters[ii].passage;
      cell = this.row.insertCell(-1);
      cell.style.backgroundColor = this.colors[passage];
   }
}
EVR.Level.Map.Display.prototype.align = function()
{
   var relative = this.level.register.previews[0];
   var coordinates = relative.get_coordinates();
   this.css.height = relative.get_dimensions()[1];
   this.css.left = coordinates[0];
   this.css.top = coordinates[1];
}
EVR.Level.Map.Display.prototype.add_indicators = function()
{
   this.player_indicator = new EVR.Level.Map.Indicator(this, INDICATOR_OPACITY);
   this.ghost_indicator = new EVR.Level.Map.Indicator(
      this, GHOST_INDICATOR_OPACITY);
}
EVR.Level.Map.Display.prototype.draw = function()
{
   this.align();
   this.player_indicator.draw(+this.css.height.slice(0, -2));
   this.ghost_indicator.draw(+this.css.height.slice(0, -2));
}
EVR.Level.Map.Display.prototype.advance_player = function(ii)
{
   var ghost = this.ghost_indicator;
   if (ghost.attached && ghost.get_position() == ii)
   {
      ghost.remove();
   }
   this.player_indicator.advance(ii);
}
EVR.Level.Map.Display.prototype.advance_ghost = function(ii)
{
   var ghost = this.ghost_indicator;
   var player = this.player_indicator;
   if (!player.attached || player.get_position() != ii)
   {
      ghost.advance(ii);
   }
   else
   {
      ghost.remove();
   }
}
EVR.Level.Map.Display.prototype.get_player_position = function()
{
   return this.player_indicator.get_position();
}
EVR.Level.Map.Display.prototype.toString = function()
{
   return "[object EVR.Level.Map.Display]";
}
54.91.121.255
54.91.121.255
54.91.121.255
 
June 7, 2018


↠ RSS Feed ↞