summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2021-05-20 22:27:50 +0200
committerAki <please@ignore.pl>2021-05-20 22:27:50 +0200
commitcf657af54ee9b5a7aff5b97a42dbee9fcfae8def (patch)
tree554a183d561cf01448568c7263870753cc9f53f6
parentb77a4239dd86bd8595cff94870f89607d1a5e403 (diff)
downloadderelict-prototype-cf657af54ee9b5a7aff5b97a42dbee9fcfae8def.zip
derelict-prototype-cf657af54ee9b5a7aff5b97a42dbee9fcfae8def.tar.gz
derelict-prototype-cf657af54ee9b5a7aff5b97a42dbee9fcfae8def.tar.bz2
Adjusted client to new battle model
-rw-r--r--derelict.js45
1 files changed, 16 insertions, 29 deletions
diff --git a/derelict.js b/derelict.js
index 59bea14..3f234e6 100644
--- a/derelict.js
+++ b/derelict.js
@@ -2,7 +2,6 @@ import * as THREE from 'https://unpkg.com/three@0.126.1/build/three.module.js'
import { OrbitControls } from 'https://unpkg.com/three@0.126.1/examples/jsm/controls/OrbitControls.js'
import { CSS2DRenderer, CSS2DObject } from 'https://unpkg.com/three@0.126.1/examples/jsm/renderers/CSS2DRenderer.js'
-const ESI = "https://esi.evetech.net/latest"
const SCALE = 10000
const METERS_IN_AU = 149597871000
const EXPIRY = 1000 * 60 * 5
@@ -71,23 +70,19 @@ class Wreck {
point = new THREE.Object3D()
killmail
- constructor({killmail, grid}) {
+ constructor({killmail, grid, battle}) {
const labelElement = document.createElement('div')
const object2d = new CSS2DObject(this.domElement)
const ownerId = "alliance_id" in killmail.victim ? killmail.victim.alliance_id : killmail.victim.corporation_id
- const team = killmail.teams.findIndex(team => undefined !== team.find(id => id == ownerId)) == 0 ? "teamA" : "teamB"
+ const team = battle.teams.findIndex(team => undefined !== team.find(id => id == ownerId)) == 0 ? "teamA" : "teamB"
const shipTypeId = killmail.victim.ship_type_id
- fetch(`${ESI}/universe/types/${shipTypeId}/`, {cache: "force-cache"})
- .then(response => response.json())
- .then(typeId => {
- labelElement.textContent = typeId.name
- this.domElement.dataset.type = typeId.name
- return fetch(`${ESI}/universe/groups/${typeId.group_id}/`, {cache: "force-cache"})
- })
- .then(response => response.json())
- .then(group => this.domElement.dataset.group = group.name)
+ const typeName = battle.ships[shipTypeId].name
+ const groupName = battle.ships[shipTypeId].group
+ this.domElement.dataset.type = typeName
+ this.domElement.dataset.group = groupName
+ labelElement.textContent = typeName
labelElement.classList.add('label')
this.killmail = killmail
@@ -143,11 +138,8 @@ function averagePosition(positions) {
return sum.divideScalar(positions.length)
}
-function processKillmails(obj, killmails) {
- const dates = killmails.map(km => Date.parse(km.killmail_time))
- const start = Math.min(...dates)
- const end = Math.max(...dates)
- const clusters = killmails.reduce(splitKillmails, new Array())
+function processBattle({battle, renderer, renderer2d, container, toolbar, skybox}) {
+ const clusters = battle.killmails.reduce(splitKillmails, new Array())
let elements = []
let grids = []
@@ -161,10 +153,10 @@ function processKillmails(obj, killmails) {
gridSelection.options.add(option)
const center = averagePosition(cluster.map(km => km.victim.position))
- const grid = new SkirmishGrid(obj)
+ const grid = new SkirmishGrid({container, renderer, renderer2d})
cluster.forEach(killmail => {
killmail.victim.position.sub(center).divideScalar(SCALE)
- const wreck = new Wreck({killmail, grid})
+ const wreck = new Wreck({killmail, grid, battle})
grid.add(wreck.point)
elements.push(wreck)
})
@@ -178,12 +170,14 @@ function processKillmails(obj, killmails) {
}
gridSelection.oninput()
- obj.skybox.then(skybox => {
+ skybox.then(skybox => {
const rt = new THREE.WebGLCubeRenderTarget(skybox.image.height)
- rt.fromEquirectangularTexture(obj.renderer, skybox)
+ rt.fromEquirectangularTexture(renderer, skybox)
grids.forEach(g => g.scene.background = rt)
})
+ const start = Date.parse(battle.started_at)
+ const end = Date.parse(battle.ended_at)
const timeline = document.getElementById("timeline")
const step = 1000
const toggleAll = () => elements.forEach(item => item.toggleKilled(timeline.value))
@@ -212,12 +206,5 @@ export function init({id, container, toolbar}) {
fetch(`/battles/${id}`)
.then(response => response.json())
- .then(killmails => {
- const url = km => `${ESI}/killmails/${km.id}/${km.hash}/?datasource=tranquility`
- const retrieve = km => fetch(url(km))
- .then(response => response.json())
- .then(data => { data.teams = killmails.teams; return data })
- return Promise.all(killmails.killmails.map(retrieve))
- })
- .then(killmails => processKillmails({skybox, renderer, renderer2d, container}, killmails))
+ .then(battle => processBattle({battle, renderer, renderer2d, container, toolbar, skybox}))
}