feat: rotation updates
This commit is contained in:
parent
fd3d679a09
commit
b11be0c0a3
|
@ -1,3 +1,4 @@
|
|||
import {TWO_PI} from '@avocado/math';
|
||||
import {Packet} from '@latus/socket';
|
||||
|
||||
export default () => class TraitUpdateVisiblePacket extends Packet {
|
||||
|
@ -6,6 +7,7 @@ export default () => class TraitUpdateVisiblePacket extends Packet {
|
|||
return {
|
||||
isVisible: data.isVisible,
|
||||
opacity: Math.floor(data.opacity * 255),
|
||||
rotation: Math.floor(((data.rotation % TWO_PI) / TWO_PI) * 65536),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -13,6 +15,7 @@ export default () => class TraitUpdateVisiblePacket extends Packet {
|
|||
return {
|
||||
isVisible: 'bool',
|
||||
opacity: 'uint8',
|
||||
rotation: 'uint16',
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -20,6 +23,7 @@ export default () => class TraitUpdateVisiblePacket extends Packet {
|
|||
return {
|
||||
isVisible: data.isVisible,
|
||||
opacity: data.opacity / 255,
|
||||
rotation: (data.rotation / 65536) * TWO_PI,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -51,6 +51,7 @@ export default () => class Visible extends decorate(Trait) {
|
|||
if ('TraitUpdateVisible' === packet.constructor.type) {
|
||||
this.entity.isVisible = packet.data.isVisible;
|
||||
this.entity.opacity = packet.data.opacity;
|
||||
this.entity.rotation = packet.data.rotation;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -229,13 +230,14 @@ export default () => class Visible extends decorate(Trait) {
|
|||
}
|
||||
|
||||
packets() {
|
||||
const {isVisible, opacity} = this.stateDifferences();
|
||||
if (isVisible || opacity) {
|
||||
const {isVisible, opacity, rotation} = this.stateDifferences();
|
||||
if (isVisible || opacity || rotation) {
|
||||
return [[
|
||||
'TraitUpdateVisible',
|
||||
{
|
||||
isVisible: this.state.isVisible,
|
||||
opacity: this.state.opacity,
|
||||
rotation: this.state.rotation,
|
||||
},
|
||||
]];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user