Skip to content

Commit

Permalink
add debug for local runner
Browse files Browse the repository at this point in the history
  • Loading branch information
BorisKolganov committed Sep 26, 2017
1 parent fd4b8c4 commit 31d4d05
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 40 deletions.
4 changes: 2 additions & 2 deletions localrunner/visualizer/css/elevators.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
height: 70%;
}

#console {
.console {
background: #000;
color: #fff;
display: block;
overflow: auto;
}

#console span {
.console span {
word-wrap: break-word;
max-width: 430px;
display: inline-block;
Expand Down
11 changes: 10 additions & 1 deletion localrunner/visualizer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,25 @@
</head>
<body>
<div class="container">
<br/>
<div class="preloader">
</div>
<div class="row">
<div class="col-xs-12">
<div class="col-xs-3">
<div id="left-console" class="console">
</div>
</div>
<div class="col-xs-6">
<div class="mechanic-screen">
<div class="world-screen">
<div id="world-wrap"></div>
</div>
</div>
</div>
<div class="col-xs-3">
<div id="right-console" class="console">
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12">
Expand Down
18 changes: 5 additions & 13 deletions localrunner/visualizer/js/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@ define(['conf', 'underscore'], function (conf, _) {
}
}

function getVisio(url) {
return new Promise(function (resolve, reject) {
$.get(url).done(function (result) {
result = JSON.parse(result);
resolve(result);
});
})
}

function registerEvents(init) {
var runButton = $('.js-run');
var pauseButton = $('.js-pause');
Expand All @@ -31,9 +22,8 @@ define(['conf', 'underscore'], function (conf, _) {
var x4Button = $('.js-x4');
var range = $('.range');
var currentSpan = $('.js-score-time-user');
// var world = null;
// var renderer = null;

var leftConsole = $('#left-console');
var rightConsole = $('#right-console');

var visio = data;
var config = visio.config;
Expand All @@ -45,13 +35,15 @@ define(['conf', 'underscore'], function (conf, _) {
conf.HEIGHT = (config.FLOORS_COUNT + 1) * conf.FLOOR_HEIGHT;

var renderer = new PIXI.autoDetectRenderer(conf.WIDTH, conf.HEIGHT);
var world = init.initWorld(visio.game_data, config, renderer, scoreAndTimeSetter(currentSpan, visio.players), range);
var world = init.initWorld(visio.game_data, config, renderer, scoreAndTimeSetter(currentSpan, visio.players), range, leftConsole, rightConsole);

range.val(0);
range.prop("disabled", false);
range.removeClass('btn_disabled');

ww.html(renderer.view);
leftConsole.height(ww.height());
rightConsole.height(ww.height());
$('.preloader').fadeOut();


Expand Down
53 changes: 30 additions & 23 deletions localrunner/visualizer/js/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ define([
'underscore'
], function (conf, Building, PIXI, _) {

function World(data, config, renderer, scoreSetter, timeLine, console, debugInfo) {
function World(data, config, renderer, scoreSetter, timeLine, leftConsole, rightConsole) {
this.data = data;
this.config = config;
this.renderer = renderer;
this.scoreAndTimeSetter = scoreSetter;
this.timeLine = timeLine;
this.console = console;
this.debug = debugInfo;

this.leftConsole = leftConsole;
this.rightConsole = rightConsole;
this.stage = new PIXI.Container();

this.tilingTexture = new PIXI.extras.TilingSprite.fromFrame(window.PATH_IMG + conf.IMG.texture, renderer.width, renderer.height * 3);
Expand All @@ -41,9 +40,8 @@ define([
}

World.prototype.clearConsole = function () {
if (this.console) {
this.console.html('');
}
this.leftConsole.html('');
this.rightConsole.html('');
};

World.prototype.createTicker = function () {
Expand Down Expand Up @@ -99,7 +97,8 @@ define([
};

World.prototype.rewind = function (tick, callback) {
if (this.debug) this.printToConsole(Math.min(20, Math.abs(this.tickNum - tick)));
this.clearConsole();
this.printToConsoles(Math.min(20, Math.abs(this.tickNum - tick)));
this.tickNum = tick - 1;
this.mechanicTick();
this.animationTick();
Expand All @@ -108,25 +107,33 @@ define([
}
};

World.prototype.printToConsole = function (ticksPerFrame) {
World.prototype.printToConsoles = function (ticksPerFrame) {

var print = function (text, type, index) {
if (this.console.children().length > conf.CONSOLE_VOL) {
this.console.children().remove(':nth-child(-n+10)');
var print = function (text, type, index, console) {
if (console.children().length > conf.CONSOLE_VOL) {
console.children().remove(':nth-child(-n+10)');
}
this.console.append('<br><span>Tick[' + (this.tickNum - (ticksPerFrame - index) + 1) + '] ' + type +': ' + _.escape(text) + '</span>');
this.console[0].scrollTop = this.console[0].scrollHeight;
console.append('<br><span>Tick[' + (this.tickNum - (ticksPerFrame - index) + 1) + '] ' + type +': ' + _.escape(text) + '</span>');
console[0].scrollTop = console[0].scrollHeight;
}.bind(this);

_.each(this.debug.slice(this.tickNum - ticksPerFrame, this.tickNum), function (obj, index) {
_.each(obj, function (values, key) {
var self = this;
_.each(this.data.slice(this.tickNum - ticksPerFrame, this.tickNum), function (obj, index) {
var debugInfo = obj.debug;

_.each(debugInfo['FIRST_PLAYER'], function (values, key) {
_.each(values, function (value) {
print(value, key, index);
print(value, key, index, self.leftConsole);
})
});
})
};

_.each(debugInfo['SECOND_PLAYER'], function (values, key) {
_.each(values, function (value) {
print(value, key, index, self.rightConsole);
})
});
});
};

World.prototype.show = function () {
var self = this;
Expand All @@ -140,7 +147,7 @@ define([
self.tickNum = self.tickCount - 1;
self.mechanicTick();
self.animationTick();
if (self.debug) self.printToConsole(ticksPerFrame);
self.printToConsoles(ticksPerFrame);
cancelAnimationFrame(self.animationId);
self.tickNum = 0;
self.animationId = undefined;
Expand All @@ -154,7 +161,7 @@ define([
}
self.mechanicTick();
self.animationTick();
if (self.debug) self.printToConsole(ticksPerFrame);
self.printToConsoles(ticksPerFrame);
self.timeLine.val(self.tickNum);
prevTickTime = currentTickTime;

Expand All @@ -166,11 +173,11 @@ define([
};
var world = null;

function initWorld(data, config, renderer, scoreSetter, timeLine, console, debugInfo) {
function initWorld(data, config, renderer, scoreSetter, timeLine, leftConsole, rightConsole) {
if (world) {
world.destroy();
}
world = new World(data, config, renderer, scoreSetter, timeLine, console, debugInfo);
world = new World(data, config, renderer, scoreSetter, timeLine, leftConsole, rightConsole);
return world;
}

Expand Down
2 changes: 1 addition & 1 deletion localrunner/world/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def shutdown(self):
def write_result(data):
f = open('{}/../visualizer/game.js'.format(os.path.dirname(os.path.realpath(__file__))), 'w')
f.write("var data = ")
f.write(json.dumps(data))
f.write(json.dumps(data, indent=4))
f.write(";")
f.close()

Expand Down

0 comments on commit 31d4d05

Please sign in to comment.