Entity: split getSyncedNetworkData() into two functions

to avoid opaque boolean parameters
This commit is contained in:
Dylan K. Taylor
2021-01-08 13:59:52 +00:00
parent e53b57732b
commit 053a7a1a61
3 changed files with 15 additions and 7 deletions

View File

@ -589,7 +589,7 @@ abstract class Entity{
}
}
$changedProperties = $this->getSyncedNetworkData(true);
$changedProperties = $this->getDirtyNetworkData();
if(count($changedProperties) > 0){
$this->sendData(null, $changedProperties);
$this->networkProperties->clearDirtyProperties();
@ -1436,7 +1436,7 @@ abstract class Entity{
$pk->attributes = array_map(function(Attribute $attr) : NetworkAttribute{
return new NetworkAttribute($attr->getId(), $attr->getMinValue(), $attr->getMaxValue(), $attr->getValue(), $attr->getDefaultValue());
}, $this->attributeMap->getAll());
$pk->metadata = $this->getSyncedNetworkData(false);
$pk->metadata = $this->getAllNetworkData();
$player->getNetworkSession()->sendDataPacket($pk);
}
@ -1557,7 +1557,7 @@ abstract class Entity{
*/
public function sendData(?array $targets, ?array $data = null) : void{
$targets = $targets ?? $this->hasSpawned;
$data = $data ?? $this->getSyncedNetworkData(false);
$data = $data ?? $this->getAllNetworkData();
foreach($targets as $p){
$p->getNetworkSession()->syncActorData($this, $data);
@ -1568,10 +1568,18 @@ abstract class Entity{
* @return MetadataProperty[]
* @phpstan-return array<int, MetadataProperty>
*/
final protected function getSyncedNetworkData(bool $dirtyOnly) : array{
final protected function getDirtyNetworkData() : array{
$this->syncNetworkData($this->networkProperties);
return $this->networkProperties->getDirty();
}
return $dirtyOnly ? $this->networkProperties->getDirty() : $this->networkProperties->getAll();
/**
* @return MetadataProperty[]
* @phpstan-return array<int, MetadataProperty>
*/
final protected function getAllNetworkData() : array{
$this->syncNetworkData($this->networkProperties);
return $this->networkProperties->getAll();
}
protected function syncNetworkData(EntityMetadataCollection $properties) : void{