humus-old/client/ui/debug/self-entity.js

58 lines
1.2 KiB
JavaScript
Raw Normal View History

2019-04-14 01:03:09 -05:00
// 3rd party.
import React, {useEffect, useState} from 'react';
// 2nd party.
import {compose} from '@avocado/core';
import {Vector} from '@avocado/math';
import contempo from 'contempo';
// 1st party.
import {usePropertyChange} from '../hooks/use-property-change';
import {useSelfEntity} from '../hooks/use-self-entity';
2019-04-14 01:03:09 -05:00
const decorate = compose(
contempo(`
.self-entity {
background-color: rgba(0, 0, 0, .3);
border: 1px solid white;
color: white;
font-size: 0.8em;
position: absolute;
2019-04-20 02:14:40 -05:00
bottom: 0.5em;
2019-04-14 01:03:09 -05:00
left: 0.5em;
line-height: 1em;
2019-04-14 13:28:50 -05:00
width: 10em;
2019-04-14 01:03:09 -05:00
padding: 0.125em;
font-family: monospace;
}
.location {
}
.x {
display: inline-block;
2019-04-14 13:28:50 -05:00
width: 5em;
2019-04-14 01:03:09 -05:00
}
.y {
display: inline-block;
2019-04-14 13:28:50 -05:00
width: 4.125em;
2019-04-14 01:03:09 -05:00
}
.x:before {
content: 'x: ';
}
.y:before {
content: 'y: ';
}
`),
);
2019-04-14 16:33:26 -05:00
const SelfEntityComponent = ({app}) => {
const selfEntity = useSelfEntity(app);
const position = usePropertyChange(selfEntity, 'position', [0, 0]);
2019-04-14 13:28:50 -05:00
const roundedPosition = Vector.round(position);
2019-04-14 01:03:09 -05:00
return <div className="self-entity unselectable">
<div className="location">
<div className="x">{roundedPosition[0]}</div>
<div className="y">{roundedPosition[1]}</div>
</div>
</div>;
}
export default decorate(SelfEntityComponent);