From ed5f9128c1da9f1888c17e9f5e9de4cd6971290e Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 8 Aug 2021 13:12:51 +0200 Subject: Naively implemented Timeline --- derelict.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/derelict.js b/derelict.js index 4be97ef..0e629b9 100644 --- a/derelict.js +++ b/derelict.js @@ -10,23 +10,29 @@ const GRID_EXTENT = 100 * SCALE class Timeline { start finish - current = 0 + current simple_list = [] register(wreck) { - // TODO: Consider expiration right away - if (this.start === undefined || wreck.timestamp < this.start) - this.start = wreck.timestamp - if (this.finish === undefined || wreck.timestamp > this.finish) - this.finish = wreck.timestamp + if (this.start === undefined || wreck.timestamp - EXPIRY < this.start) { + this.start = wreck.timestamp - EXPIRY + if (this.current === undefined || this.current == this.start) + this.current = this.start + } + if (this.finish === undefined || wreck.timestamp + EXPIRY > this.finish) + this.finish = wreck.timestamp + EXPIRY // TODO: Implement more reliable and optimized data structure for timeline. this.simple_list.push(wreck) } - setTo(time) {} // TODO: Implement - moveForward(time) {} // TODO: Implement - moveBackward(time) {} // TODO: Implement + update() { + this.simple_list.forEach(wreck => wreck.toggleKilled(this.current)) + } + + setTo(time) { + this.current = time + } } class Grid { -- cgit v1.1