Commit 920b3dd8 authored by Hubert Denkmair's avatar Hubert Denkmair
Browse files

follow snakes by username, not by database id

parent 840dd18c
......@@ -41,7 +41,7 @@ function setupPreview()
game.SetViewerKey(viewer_key);
game.AddLogHandler(addLogLine);
game.Run();
game.vis.FollowDbId(snake_id);
game.vis.FollowName(snake_follow_name);
}
function setupToolbar()
......@@ -161,7 +161,7 @@ function save(action, title)
$.post('/snake/edit/save', JSON.stringify(json_req), function(data) {
snake_id = data.snake_id;
snake_title = data.comment;
game.vis.FollowDbId(snake_id);
game.vis.FollowName(snake_follow_name);
let logline = 'saved code as version #' + data.version;
if (data.comment) { logline += "(\"" + data.comment + "\")"; }
addLogLine(null, logline);
......
......@@ -66,6 +66,7 @@
<script type="text/javascript">
let snake_title = "{{ snake.comment | default:"" }}";
let snake_id = {{ snake.id | default:"null" }};
let snake_follow_name = "{{ snake.user.username }}";
let viewer_key = "{{ profile.viewer_key }}";
let csrftoken = $("[name=csrfmiddlewaretoken]").val();
</script>
......
......@@ -5,8 +5,7 @@ function GameVisualization(assets, snakeMoveStrategy, container)
this.container = container;
this.snakeMoveStrategy = snakeMoveStrategy;
this.snakes = {};
this.ego_id = 0;
this.follow_db_id = null;
this.follow_name = null;
this.nextFoodDecayRow = 0;
this.world_size_x = 1024;
this.world_size_y = 1024;
......@@ -85,9 +84,8 @@ GameVisualization.prototype.CreateSnake = function(bot)
this.snakes[bot.id] = snake;
this.snakesContainer.addChild(snake.Container);
if (snake.db_id == this.follow_db_id)
if (snake.GetName() == this.follow_name)
{
this.ego_id = snake.snake_id;
this.viewport.follow(snake.GetHeadSprite(), { radius: 0 });
}
......@@ -239,18 +237,18 @@ GameVisualization.prototype.HandleBotMoved2Message = function(bot_id, heading, s
}
};
GameVisualization.prototype.FollowDbId = function(db_id)
GameVisualization.prototype.FollowName = function(name)
{
this.follow_db_id = db_id;
this.follow_name = name;
for (let id in this.snakes)
{
let snake = this.snakes[id];
if (snake.db_id == db_id)
if (snake.GetName() == this.follow_name)
{
this.viewport.follow(snake.GetHeadSprite(), { radius: 200 });
}
}
}
};
GameVisualization.prototype.UpdateStagePosition = function()
{
......@@ -267,7 +265,6 @@ GameVisualization.prototype.UpdateStagePosition = function()
this.foodMap.Update(center.x, center.y, width, height);
const minimumVisibleFoodSize = 0.5 / this.viewport.scale.x;
console.log(minimumVisibleFoodSize);
this.foodMap.Iterate(function(foodSprite) {
foodSprite.visible = foodSprite.food_value > minimumVisibleFoodSize;
});
......
......@@ -156,6 +156,11 @@ Snake.prototype.GetSegmentRadius = function()
return this._segmentRadius;
};
Snake.prototype.GetName = function()
{
return this._name;
};
Snake.prototype.UpdateHead = function()
{
let seg0 = this.GetSegment(0);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment