-
Notifications
You must be signed in to change notification settings - Fork 0
/
ColliderManager.js
117 lines (96 loc) · 3.75 KB
/
ColliderManager.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
const fs = require('fs');
var _circle = require('./libs/Collisions/modules/Circle.js');
var Circle = _interopRequireDefault(_circle);
var _polygon = require('./libs/Collisions/modules/Polygon.js');
var Polygon = _interopRequireDefault(_polygon);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const ColliderManager = module.exports = {};
var Maps = new Map();
var Objects = new Map();
var Heroes = new Map();
var MapsWithObject = new Map();
ColliderManager.getMap = function (name) {
if (Maps.has(name) && !Maps.get(name).dirty)//Dirty Param Becomes True When Map Updated From Control Panel And Server Was Up
{
var content = Maps.get(name).shapes;
var items = [];
for (var i = 0; i < content.length; i++) {
var data = content[i];
switch (data[0]) {
case 0:
items.push(new Circle.default(data[1], data[2], data[3]));
break;
case 1:
items.push(new Polygon.default(data[1], data[2], data[3]));
break;
}
}
return items;
}
else {
var content = fs.readFileSync(__dirname + `/Colliders/Maps/${name}.hm`, "utf8");
var lines = content.split("\r\n");
var temp = [];
var items = [];
for (var k = 0; k < lines.length; k++) {
if (lines[k].trim() == "")
return;
var raw = lines[k].split(";");
var shapeType = raw[0];
var shapeData = raw[1];
var x, y;
switch (shapeType) {
case "0": // Circle
let r;
var rawCoord = shapeData.split(",");
x = parseInt(rawCoord[0]), y = parseInt(rawCoord[1]), r = parseInt(rawCoord[2]);
var input = [0, x, y, r];
temp.push(input);
items.push(new Circle.default(x, y, r));
break;
case "1": // Polygon
var rawCoord = shapeData.split(",");
x = parseInt(rawCoord[0]), y = parseInt(rawCoord[1]);
var input = [];
var coord = [];
for (var i = 2; i < rawCoord.length; i += 2) {
coord.push([parseInt(rawCoord[i]), parseInt(rawCoord[i + 1])]);
}
temp.push([1, x, y, coord]);
items.push(new Polygon.default(x, y, coord));
break;
case "2": // Objects
var rawCoord = shapeData.split(",");
x = parseInt(rawCoord[0]), y = parseInt(rawCoord[1]);
var coord = this.getObject(rawCoord[2]);
temp.push([1, x, y, coord]);
items.push(new Polygon.default(x, y, coord));
break;
}
}
Maps.set(name, { shapes: temp, dirty: false });
return items;
}
}
ColliderManager.getObject = function (name) {
if (Objects.has(name) && !Objects.get(name).dirty) {
return Objects.get(name).shape;
} else {
var content = fs.readFileSync(__dirname + `/Colliders/Objects/${name}.pop`, "utf8");
var rawCoord = content.split(",");
var coord = [];
for (var i = 0; i < rawCoord.length; i += 2) {
coord.push([parseInt(rawCoord[i]), parseInt(rawCoord[i + 1])]);
}
Objects.set(name, { shape: coord, dirty: false });
return coord;
}
}
ColliderManager.getHero = function (name) {
}
ColliderManager.newMap = function (name, data) {
}
ColliderManager.newObject = function (name, data) {
}
ColliderManager.newHero = function (name, data) {
}