diff options
author | Aki <please@ignore.pl> | 2021-04-05 15:57:38 +0200 |
---|---|---|
committer | Aki <please@ignore.pl> | 2021-04-05 15:57:38 +0200 |
commit | 7c3fb908dbf3d5147102a72e3a0dbe20127c8ca0 (patch) | |
tree | cc0841659a9cd888da5b55b75c0b71c45f7ff060 | |
parent | 2464b281d9cdfe2902c526db0357fd89a0177690 (diff) | |
download | derelict-prototype-7c3fb908dbf3d5147102a72e3a0dbe20127c8ca0.zip derelict-prototype-7c3fb908dbf3d5147102a72e3a0dbe20127c8ca0.tar.gz derelict-prototype-7c3fb908dbf3d5147102a72e3a0dbe20127c8ca0.tar.bz2 |
Cleaned-up Wreck creation
-rw-r--r-- | derelict.js | 48 |
1 files changed, 22 insertions, 26 deletions
diff --git a/derelict.js b/derelict.js index 7e2da08..c35f285 100644 --- a/derelict.js +++ b/derelict.js @@ -13,10 +13,10 @@ class SkirmishGrid { renderer renderer2d - constructor(obj) { - this.container = obj.container - this.renderer = obj.renderer - this.renderer2d = obj.renderer2d + constructor({container, renderer, renderer2d}) { + this.container = container + this.renderer = renderer + this.renderer2d = renderer2d const aspect = this.container.clientWidth / this.container.clientHeight this.camera = new THREE.PerspectiveCamera(80, aspect, 0.1, 1000) @@ -45,18 +45,21 @@ class SkirmishGrid { } } -function Wreck(vec3, km) { - const point = new THREE.Object3D() - point.position.copy(vec3) +class Wreck { + domElement = document.createElement('div') + point = new THREE.Object3D() + killmail - const div = document.createElement('div') - div.className = 'wreck' - const w = document.importNode(wreck, true) - div.appendChild(w) - const label = new CSS2DObject(div) - point.add(label) + constructor({killmail, position}) { + const icon = document.importNode(obj.icon, true) + const object2d = new CSS2DObject(this.domElement) - return point; + this.killmail = killmail + this.domElement.className = 'wreck' + this.domElement.appendChild(icon) + this.point.position.copy(position) + this.point.add(object2d) + } } function loadWreckIcon() { @@ -94,20 +97,13 @@ function processKillmails(grid, killmails) { center.divideScalar(positions.length) clusters[0].sort((a, b) => a.killmail_time.localeCompare(b.killmail_time)) let elements = [] - clusters[0].forEach(km => { - const vec3 = km.victim.position + clusters[0].forEach(killmail => { + const vec3 = killmail.victim.position vec3.sub(center) vec3.divideScalar(SCALE) - const point = new THREE.Object3D() - point.position.copy(vec3) - const div = document.createElement('div') - div.className = 'wreck' - const w = document.importNode(wreck, true) - div.appendChild(w) - const label = new CSS2DObject(div) - point.add(label) - grid.add(point) - elements.push(div) + const wreck = new Wreck({position: vec3, killmail}) + grid.add(wreck.point) + elements.push(wreck.domElement) }) const timeline = document.getElementById("timeline") timeline.max = elements.length + 1 |