-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
canvas.php
43 lines (37 loc) · 928 Bytes
/
canvas.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
class Canvas {
const SECONDS_TO_ROUND = 10;
/**
* @var array<int, array<int, string>> A multidimensional
* array representing the numbered Y rows and X columns. The nested
* string value is the character at that point.
*/
private array $data;
/**
* @var array<int, array<int, string>> A cache of data that is unread,
* following the same format as the $data array.
*/
private array $newData;
public function __construct() {
$this->data = [];
$this->newData = [];
}
public function setData(int $x, int $y, ?string $c):void {
if(!isset($this->data[$y])) {
$this->data[$y] = [];
}
$this->data[$y][$x] = $c;
if(!isset($this->newData[$y])) {
$this->newData[$y] = [];
}
$this->newData[$y][$x] = $c;
}
public function getData(bool $getNew = false):array {
if($getNew) {
$newData = $this->newData;
$this->newData = [];
return $newData;
}
return $this->data;
}
}