Skip to content

Commit 43c7b8c

Browse files
author
p.suponev
committed
Inital commit
0 parents  commit 43c7b8c

16 files changed

+658
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/.vscode

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# js-cgdk

model/Action.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Created by Quake on 18.12.2018
3+
*/
4+
'use strict';
5+
6+
function Action() {
7+
this.target_velocity_x = 0;
8+
this.target_velocity_y = 0;
9+
this.target_velocity_z = 0;
10+
this.jump_speed = 0;
11+
this.use_nitro = false;
12+
};
13+
14+
Action.prototype.toJson = function() {
15+
return JSON.stringify({
16+
target_velocity_x: this.target_velocity_x,
17+
target_velocity_y: this.target_velocity_y,
18+
target_velocity_z: this.target_velocity_z,
19+
jump_speed: this.jump_speed,
20+
use_nitro: this.use_nitro
21+
});
22+
}
23+
24+
Action.prototype.toObject = function() {
25+
return {
26+
target_velocity_x: this.target_velocity_x,
27+
target_velocity_y: this.target_velocity_y,
28+
target_velocity_z: this.target_velocity_z,
29+
jump_speed: this.jump_speed,
30+
use_nitro: this.use_nitro
31+
};
32+
}
33+
34+
module.exports = Action;

model/Arena.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Created by Quake on 18.12.2018
3+
*/
4+
'use strict';
5+
6+
function Arena() {
7+
8+
}
9+
10+
Arena.prototype.read = function(json) {
11+
if (typeof json == 'string') {
12+
json = JSON.parse(json);
13+
}
14+
15+
this.width = json.width;
16+
this.height = json.height;
17+
this.depth = json.depth;
18+
this.bottom_radius = json.bottom_radius;
19+
this.top_radius = json.top_radius;
20+
this.corner_radius = json.corner_radius;
21+
this.goal_top_radius = json.goal_top_radius;
22+
this.goal_width = json.goal_width;
23+
this.goal_height = json.goal_height;
24+
this.goal_depth = json.goal_depth;
25+
this.goal_side_radius = json.goal_side_radius;
26+
}
27+
28+
module.exports = Arena;

model/Ball.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Created by Quake on 18.12.2018
3+
*/
4+
'use strict';
5+
6+
function Ball() {
7+
8+
}
9+
10+
Ball.prototype.read = function(json) {
11+
if (typeof json == 'string') {
12+
json = JSON.parse(json);
13+
}
14+
15+
this.x = json.x;
16+
this.y = json.y;
17+
this.z = json.z;
18+
this.velocity_x = json.velocity_x;
19+
this.velocity_y = json.velocity_y;
20+
this.velocity_z = json.velocity_z;
21+
this.radius = json.radius;
22+
}
23+
24+
module.exports = Ball;

model/Game.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* Created by Quake on 18.12.2018
3+
*/
4+
'use strict';
5+
6+
let Player = require('./Player')
7+
, Arena = require('./Arena')
8+
, Robot = require('./Robot')
9+
, NitroPack = require('./NitroPack')
10+
, Ball = require('./Ball')
11+
;
12+
13+
function Game() {
14+
15+
}
16+
17+
Game.prototype.read = function(json) {
18+
if (typeof json == 'string') {
19+
json = JSON.parse(json);
20+
}
21+
22+
this.current_tick = json.current_tick;
23+
this.players = this.players || [];
24+
this.players = this.players.slice(0, json.players.length - 1);
25+
26+
for (let i = 0; i < json.players.length; ++i) {
27+
if (!this.players[i]) {
28+
this.players[i] = new Player();
29+
}
30+
this.players[i].read(json.players[i]);
31+
}
32+
33+
this.robots = this.robots || [];
34+
this.robots = this.robots.slice(0, json.robots.length - 1);
35+
36+
for (let i = 0; i < json.robots.length; ++i) {
37+
if (!this.robots[i]) {
38+
this.robots[i] = new Robot();
39+
}
40+
this.robots[i].read(json.robots[i]);
41+
}
42+
43+
this.nitro_packs = this.nitro_packs || [];
44+
this.nitro_packs = this.nitro_packs.slice(0, json.nitro_packs.length - 1);
45+
46+
for (let i = 0; i < json.nitro_packs.length; ++i) {
47+
if (!this.nitro_packs[i]) {
48+
this.nitro_packs[i] = new NitroPack();
49+
}
50+
this.nitro_packs[i].read(json.nitro_packs[i]);
51+
}
52+
53+
this.ball = this.ball || new Ball();
54+
this.ball.read(json.ball);
55+
}
56+
57+
module.exports = Game;

model/NitroPack.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Created by Quake on 18.12.2018
3+
*/
4+
'use strict';
5+
6+
function NitroPack() {
7+
8+
}
9+
10+
NitroPack.prototype.read = function(json) {
11+
if (typeof json == 'string') {
12+
json = JSON.parse(json);
13+
}
14+
15+
this.id = json.id;
16+
this.x = json.x;
17+
this.y = json.y;
18+
this.z = json.z;
19+
this.radius = json.radius;
20+
this.alive = json.respawn_ticks === null;
21+
if (!this.alive) {
22+
this.respawn_ticks = json.respawn_ticks;
23+
}
24+
}
25+
26+
module.exports = NitroPack;

model/Player.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Created by Quake on 18.12.2018
3+
*/
4+
'use strict';
5+
6+
function Player() {
7+
8+
}
9+
10+
Player.prototype.read = function (json) {
11+
if (typeof json == 'string') {
12+
json = JSON.parse(json);
13+
}
14+
15+
this.id = json.id;
16+
this.me = json.me;
17+
this.strategy_crashed = json.strategy_crashed;
18+
this.score = json.score;
19+
}
20+
21+
module.exports = Player;

model/Robot.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Created by Quake on 18.12.2018
3+
*/
4+
'use strict';
5+
6+
function Robot() {
7+
8+
}
9+
10+
Robot.prototype.read = function(json) {
11+
if (typeof json == 'string') {
12+
json = JSON.parse(json);
13+
}
14+
15+
this.id = json.id;
16+
this.player_id = json.player_id;
17+
this.is_teammate = json.is_teammate;
18+
this.x = json.x;
19+
this.y = json.y;
20+
this.z = json.z;
21+
this.velocity_x = json.velocity_x;
22+
this.velocity_y = json.velocity_y;
23+
this.velocity_z = json.velocity_z;
24+
this.radius = json.radius;
25+
this.nitro_amount = json.nitro_amount;
26+
this.touch = json.touch;
27+
if (this.touch) {
28+
this.touch_normal_x = json.touch_normal_x;
29+
this.touch_normal_y = json.touch_normal_y;
30+
this.touch_normal_z = json.touch_normal_z;
31+
}
32+
}
33+
34+
module.exports = Robot;

model/Rules.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Created by Quake on 18.12.2018
3+
*/
4+
'use strict';
5+
6+
let Arena = require('./Arena')
7+
;
8+
9+
function Rules() {
10+
this.arena = new Arena();
11+
}
12+
13+
Rules.prototype.read = function(json) {
14+
if (typeof json == 'string') {
15+
json = JSON.parse(json);
16+
}
17+
18+
this.max_tick_count = json.max_tick_count;
19+
this.arena.read(json.arena);
20+
}
21+
22+
module.exports = Rules;

0 commit comments

Comments
 (0)