feat: day/night

This commit is contained in:
cha0s 2022-05-03 06:49:44 -05:00
parent 883d231e26
commit e8ae1ef73f
5 changed files with 61 additions and 0 deletions

View File

@ -34,6 +34,8 @@ export default () => {
// Track room. // Track room.
case Room.resourceId: { case Room.resourceId: {
flecks.set('$humus/app.room', created); flecks.set('$humus/app.room', created);
// eslint-disable-next-line no-param-reassign
created.universe = synchronizer.synchronized(7, 0);
setRoom(created); setRoom(created);
break; break;
} }

View File

@ -19,6 +19,8 @@
"files": [ "files": [
"assets", "assets",
"build", "build",
"client.js",
"client.js.map",
"index.css", "index.css",
"index.css.map", "index.css.map",
"index.js", "index.js",
@ -31,6 +33,7 @@
"test.js.map" "test.js.map"
], ],
"dependencies": { "dependencies": {
"@avocado/filters": "^1.0.0",
"@avocado/resource": "^3.0.0", "@avocado/resource": "^3.0.0",
"@avocado/s13n": "^3.0.0", "@avocado/s13n": "^3.0.0",
"@avocado/timing": "^3.0.0", "@avocado/timing": "^3.0.0",

View File

@ -0,0 +1,9 @@
import {Flecks, Hooks} from '@flecks/core';
export default {
[Hooks]: {
'@avocado/resource.resources.decorate': (
Flecks.decorate(require.context('./resources/decorators', false, /\.js$/))
),
},
};

View File

@ -0,0 +1,9 @@
import Renderable from './room/renderable';
export default (Room) => class UniversedRoom extends Room {
static Renderable = Renderable(Room);
universe;
};

View File

@ -0,0 +1,38 @@
import {Night} from '@avocado/filters/client';
export default (Room) => class extends Room.Renderable {
calculateDarkness() {
let darkness = 0;
const hour = this.calculateHour();
if (hour >= 21 || hour < 4) {
darkness = 0.8;
}
if (hour >= 4 && hour < 7) {
darkness = 0.8 * ((7 - hour) / 3);
}
if (hour >= 18 && hour < 21) {
darkness = 0.8 * ((3 - (21 - hour)) / 3);
}
return Math.floor(darkness * 1000) / 1000;
}
calculateHour() {
return (this.room.universe.time % (60 * 24)) / 24;
}
renderTick(elapsed) {
super.renderTick(elapsed);
if (this.room.universe) {
if (!this.container.filters) {
this.container.filters = [new Night()];
}
else if (!this.container.filters.find((filter) => filter instanceof Night)) {
this.container.filters.push(new Night());
}
const night = this.container.filters.find((filter) => filter instanceof Night);
night.setIntensity(this.calculateDarkness());
}
}
};