Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions src/Editor/DTOs/HierarchyObjectDTO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Sendama\Console\Editor\DTOs;

use Serializable;

/**
* HierarchyObjectDTO class.
*/
class HierarchyObjectDTO
{
public function __construct(
public string $name,
public string $tag = '',
public array $position = [1, 1],
public array $rotation = [0, 0],
public array $scale = [1, 1]
)
{
}

public function __serialize(): array
{
return [
'name' => $this->name,
'tag' => $this->tag,
'position' => $this->position,
'rotation' => $this->rotation,
'scale' => $this->scale
];
}

public function __unserialize(array $data): void
{
$this->name = $data['name'] ?? '';
$this->tag = $data['tag'] ?? '';
$this->position = $data['position'] ?? [1, 1];
$this->rotation = $data['rotation'] ?? [0, 0];
$this->scale = $data['scale'] ?? [1, 1];
}

public static function fromArray(array $data): self
{

Comment on lines +42 to +44

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Return a DTO instance from fromArray

HierarchyObjectDTO::fromArray is declared to return self but has an empty body, so any call will return null and trigger a runtime TypeError. This makes array-to-DTO deserialization unusable and will fail immediately once the method is invoked.

Useful? React with 👍 / 👎.

}
}
42 changes: 42 additions & 0 deletions src/Editor/DTOs/SceneDTO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Sendama\Console\Editor\DTOs;

/**
* SceneDTO class. Data Transfer Object for scene data in the editor.
*/
class SceneDTO
{
public function __construct(
public string $name,
public int $width = DEFAULT_TERMINAL_WIDTH,
public int $height = DEFAULT_TERMINAL_HEIGHT,
public string $environmentTileMapPath = "Maps/example",
public bool $isDirty = false,
public array $hierarchy = [],
)
{
}

public function __serialize(): array
{
return [
"name" => $this->name,
"width" => $this->width,
"height" => $this->height,
"environmentTileMapPath" => $this->environmentTileMapPath,
"isDirty" => $this->isDirty,
"hierarchy" => $this->hierarchy,
];
}

public function __unserialize(array $data): void
{
$this->name = $data['name'] ?? '';
$this->width = $data['width'] ?? DEFAULT_TERMINAL_WIDTH;
$this->height = $data['height'] ?? DEFAULT_TERMINAL_HEIGHT;
$this->environmentTileMapPath = $data['environmentTileMapPath'] ?? "Maps/example";
$this->isDirty = $data['isDirty'] ?? false;
$this->hierarchy = $data['hierarchy'] ?? [];
}
}
Loading
Loading