feat: day/night
This commit is contained in:
parent
883d231e26
commit
e8ae1ef73f
|
@ -34,6 +34,8 @@ export default () => {
|
|||
// Track room.
|
||||
case Room.resourceId: {
|
||||
flecks.set('$humus/app.room', created);
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
created.universe = synchronizer.synchronized(7, 0);
|
||||
setRoom(created);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
"files": [
|
||||
"assets",
|
||||
"build",
|
||||
"client.js",
|
||||
"client.js.map",
|
||||
"index.css",
|
||||
"index.css.map",
|
||||
"index.js",
|
||||
|
@ -31,6 +33,7 @@
|
|||
"test.js.map"
|
||||
],
|
||||
"dependencies": {
|
||||
"@avocado/filters": "^1.0.0",
|
||||
"@avocado/resource": "^3.0.0",
|
||||
"@avocado/s13n": "^3.0.0",
|
||||
"@avocado/timing": "^3.0.0",
|
||||
|
|
9
packages/universe/src/client/index.js
Normal file
9
packages/universe/src/client/index.js
Normal 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$/))
|
||||
),
|
||||
},
|
||||
};
|
|
@ -0,0 +1,9 @@
|
|||
import Renderable from './room/renderable';
|
||||
|
||||
export default (Room) => class UniversedRoom extends Room {
|
||||
|
||||
static Renderable = Renderable(Room);
|
||||
|
||||
universe;
|
||||
|
||||
};
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
};
|
Loading…
Reference in New Issue
Block a user