refactor: remove worldTimeTicker

This commit is contained in:
cha0s 2019-04-13 16:35:44 -05:00
parent ffb3657ad8
commit c5d0909dd5
3 changed files with 8 additions and 15 deletions

View File

@ -37,8 +37,6 @@ stage.element.addEventListener('focus', () => {
isFocused = true;
});
stage.addToDom(appNode);
// World time ticker.
const worldTimeTicker = new Ticker(1 / 10);
// Handle "own" entity.
let selfEntity;
function hasSelfEntity() {
@ -51,9 +49,6 @@ const roomView = new RoomView(room, stage.renderer);
stage.addChild(roomView);
// Time.
const worldTime = new WorldTime();
worldTimeTicker.on('tick', () => {
worldTimeTicker.emit('updateTime', worldTime.hour)
});
// Synchronize state.
let state = undefined;
const synchronizer = new Synchronizer({
@ -208,8 +203,6 @@ const predictionHandle = setInterval(() => {
state = synchronizer.state;
// Render timing.
renderTicker.tick(elapsed);
// World time ticker.
worldTimeTicker.tick(elapsed);
// Throughput ticker.
throughputTicker.tick(elapsed);
// Apply environmental lighting.
@ -267,7 +260,7 @@ function render() {
const renderHandle = setAnimation(render);
// UI.
const UiComponent = <Ui
worldTimeTicker={worldTimeTicker}
worldTime={worldTime}
throughputTicker={throughputTicker}
/>;
ReactDOM.render(UiComponent, stage.ui);

View File

@ -5,9 +5,9 @@ import {hot} from 'react-hot-loader/root';
import Throughput from './throughput';
import WorldTime from './world-time';
const Ui = ({throughputTicker, worldTimeTicker}) => {
const Ui = ({throughputTicker, worldTime}) => {
return <React.Fragment>
<WorldTime ticker={worldTimeTicker} />
<WorldTime worldTime={worldTime} />
<Throughput ticker={throughputTicker} />
</React.Fragment>;
};

View File

@ -23,15 +23,15 @@ const decorate = compose(
`),
);
const WorldTimeComponent = ({ticker}) => {
const WorldTimeComponent = ({worldTime}) => {
const [time, setTime] = useState('--:-- --');
useEffect(() => {
const updater = (hour) => {
setTime(WorldTime.format(hour));
const updater = () => {
setTime(WorldTime.format(worldTime.hour));
};
ticker.on('updateTime', updater);
worldTime.ticker.on('tick', updater);
return () => {
ticker.off('updateTime', updater);
worldTime.ticker.off('tick', updater);
};
}, []);
return <div className="time unselectable">{time}</div>;