refactor: worldTime
This commit is contained in:
parent
78c960114a
commit
baacea90a6
|
@ -33,12 +33,12 @@ room.world = new World();
|
|||
const roomView = new RoomView(room, stage.renderer);
|
||||
stage.addChild(roomView);
|
||||
// Time.
|
||||
const time = new WorldTime();
|
||||
let lastWorldTime = time.humanReadable();
|
||||
const worldTime = new WorldTime();
|
||||
let lastWorldTime = worldTime.humanReadable();
|
||||
// Synchronize state.
|
||||
const stateSynchronizer = new StateSynchronizer({
|
||||
room,
|
||||
time,
|
||||
worldTime,
|
||||
});
|
||||
// Handle "own" entity.
|
||||
let selfEntity;
|
||||
|
@ -134,17 +134,17 @@ const predictionHandle = setInterval(() => {
|
|||
selfEntity.inputState = actionState.toJS();
|
||||
}
|
||||
room.tick(elapsed);
|
||||
time.tick(elapsed);
|
||||
worldTime.tick(elapsed);
|
||||
stage.removeAllFilters();
|
||||
let intensity = 0;
|
||||
if (time.hour >= 21 || time.hour < 4) {
|
||||
if (worldTime.hour >= 21 || worldTime.hour < 4) {
|
||||
intensity = 0.8;
|
||||
}
|
||||
if (time.hour >= 4 && time.hour < 7) {
|
||||
intensity = 0.8 * ((7 - time.hour) / 3);
|
||||
if (worldTime.hour >= 4 && worldTime.hour < 7) {
|
||||
intensity = 0.8 * ((7 - worldTime.hour) / 3);
|
||||
}
|
||||
if (time.hour >= 18 && time.hour < 21) {
|
||||
intensity = 0.8 * ((3 - (21 - time.hour)) / 3);
|
||||
if (worldTime.hour >= 18 && worldTime.hour < 21) {
|
||||
intensity = 0.8 * ((3 - (21 - worldTime.hour)) / 3);
|
||||
}
|
||||
if (!isFocused) {
|
||||
stage.paused(intensity);
|
||||
|
@ -174,9 +174,9 @@ function render() {
|
|||
if (!dirty) {
|
||||
return;
|
||||
}
|
||||
if (time.humanReadable() !== lastWorldTime) {
|
||||
timeUi.textContent = time.humanReadable();
|
||||
lastWorldTime = time.humanReadable();
|
||||
if (worldTime.humanReadable() !== lastWorldTime) {
|
||||
timeUi.textContent = worldTime.humanReadable();
|
||||
lastWorldTime = worldTime.humanReadable();
|
||||
}
|
||||
stage.render();
|
||||
dirty = false;
|
||||
|
|
|
@ -16,13 +16,13 @@ export default function() {
|
|||
// Create room.
|
||||
const room = createRoom();
|
||||
// Time :)
|
||||
const time = new WorldTime();
|
||||
time.hour = 4;
|
||||
const worldTime = new WorldTime();
|
||||
worldTime.hour = 4;
|
||||
// Entity tracking.
|
||||
const informables = [];
|
||||
const stateSynchronizer = new StateSynchronizer({
|
||||
room,
|
||||
time,
|
||||
worldTime,
|
||||
});
|
||||
// Connection listener.
|
||||
function createConnectionListener() {
|
||||
|
@ -70,7 +70,7 @@ function createMainLoop() {
|
|||
const elapsed = (now - lastTime) / 1000;
|
||||
lastTime = now;
|
||||
room.tick(elapsed);
|
||||
time.tick(elapsed);
|
||||
worldTime.tick(elapsed);
|
||||
stateSynchronizer.tick();
|
||||
// All informed entities get their own slice.
|
||||
for (const entity of informables) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user